Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libs/Zend/Db/Adapter/Sqlsrv.php')
-rw-r--r--libs/Zend/Db/Adapter/Sqlsrv.php93
1 files changed, 50 insertions, 43 deletions
diff --git a/libs/Zend/Db/Adapter/Sqlsrv.php b/libs/Zend/Db/Adapter/Sqlsrv.php
index 3de2500ea1..533523759e 100644
--- a/libs/Zend/Db/Adapter/Sqlsrv.php
+++ b/libs/Zend/Db/Adapter/Sqlsrv.php
@@ -15,25 +15,26 @@
* @category Zend
* @package Zend_Db
* @subpackage Adapter
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Sqlsrv.php 21197 2010-02-24 16:12:53Z rob $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
-require_once 'Zend/Db/Adapter/Abstract.php';
+// require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Db_Statement_Sqlsrv
*/
-require_once 'Zend/Db/Statement/Sqlsrv.php';
+// require_once 'Zend/Db/Statement/Sqlsrv.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
@@ -120,7 +121,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
/**
* @see Zend_Db_Adapter_Sqlsrv_Exception
*/
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception('The Sqlsrv extension is required for this adapter but the extension is not loaded');
}
@@ -147,11 +148,11 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
foreach ($this->_config['driver_options'] as $option => $value) {
// A value may be a constant.
if (is_string($value)) {
- $constantValue = @constant(strtoupper($value));
- if ($constantValue === null) {
- $connectionInfo[$option] = $value;
+ $constantName = strtoupper($value);
+ if (defined($constantName)) {
+ $connectionInfo[$option] = constant($constantName);
} else {
- $connectionInfo[$option] = $constantValue;
+ $connectionInfo[$option] = $value;
}
}
}
@@ -163,7 +164,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
/**
* @see Zend_Db_Adapter_Sqlsrv_Exception
*/
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
}
}
@@ -180,7 +181,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
// we need at least a dbname
if (! array_key_exists('dbname', $config)) {
/** @see Zend_Db_Adapter_Exception */
- require_once 'Zend/Db/Adapter/Exception.php';
+ // require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
}
@@ -188,7 +189,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
/**
* @see Zend_Db_Adapter_Exception
*/
- require_once 'Zend/Db/Adapter/Exception.php';
+ // require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'password' for login credentials.
If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
}
@@ -197,7 +198,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
/**
* @see Zend_Db_Adapter_Exception
*/
- require_once 'Zend/Db/Adapter/Exception.php';
+ // require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'username' for login credentials.
If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
}
@@ -238,12 +239,12 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
$sql = "SERIALIZABLE";
break;
default:
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception("Invalid transaction isolation level mode '$level' specified");
}
if (!sqlsrv_query($this->_connection, "SET TRANSACTION ISOLATION LEVEL $sql;")) {
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception("Transaction cannot be changed to '$level'");
}
@@ -286,13 +287,13 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
- if (!class_exists($stmtClass)) {
+ // if (!class_exists($stmtClass)) {
/**
* @see Zend_Loader
*/
- require_once 'Zend/Loader.php';
- Zend_Loader::loadClass($stmtClass);
- }
+ // require_once 'Zend/Loader.php';
+ // Zend_Loader::loadClass($stmtClass);
+ // }
$stmt = new $stmtClass($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
@@ -518,7 +519,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
protected function _beginTransaction()
{
if (!sqlsrv_begin_transaction($this->_connection)) {
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
}
}
@@ -532,7 +533,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
protected function _commit()
{
if (!sqlsrv_commit($this->_connection)) {
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
}
}
@@ -546,7 +547,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
protected function _rollBack()
{
if (!sqlsrv_rollback($this->_connection)) {
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
}
}
@@ -570,11 +571,11 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
$this->_fetchMode = $mode;
break;
case Zend_Db::FETCH_BOUND: // bound to PHP variable
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception('FETCH_BOUND is not supported yet');
break;
default:
- require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
+ // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
throw new Zend_Db_Adapter_Sqlsrv_Exception("Invalid fetch mode '$mode' specified");
break;
}
@@ -593,34 +594,40 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
{
$count = intval($count);
if ($count <= 0) {
- require_once 'Zend/Db/Adapter/Exception.php';
+ // require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
- require_once 'Zend/Db/Adapter/Exception.php';
+ // require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
- $orderby = stristr($sql, 'ORDER BY');
- if ($orderby !== false) {
- $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
- $order = str_ireplace('ORDER BY', '', $orderby);
- $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
- }
-
- $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql);
-
- $sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl';
- if ($orderby !== false) {
- $sql .= ' ORDER BY ' . $order . ' ';
- $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
- }
- $sql .= ') AS outer_tbl';
- if ($orderby !== false) {
- $sql .= ' ORDER BY ' . $order . ' ' . $sort;
+ if ($offset == 0) {
+ $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $sql);
+ } else {
+ $orderby = stristr($sql, 'ORDER BY');
+ if ($orderby !== false) {
+ $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
+ $order = str_ireplace('ORDER BY', '', $orderby);
+ $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
+ }
+
+ $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql);
+
+ $sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl';
+ if ($orderby !== false) {
+ $innerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"inner_tbl"."$1"', $order);
+ $sql .= ' ORDER BY ' . $innerOrder . ' ';
+ $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
+ }
+ $sql .= ') AS outer_tbl';
+ if ($orderby !== false) {
+ $outerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"outer_tbl"."$1"', $order);
+ $sql .= ' ORDER BY ' . $outerOrder . ' ' . $sort;
+ }
}
return $sql;