26 #require_once 'Zend/Db/Adapter/Abstract.php'; 31 #require_once 'Zend/Db/Statement/Sqlsrv.php'; 120 if (!extension_loaded(
'sqlsrv')) {
124 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 128 $serverName = $this->_config[
'host'];
129 if (isset($this->_config[
'port'])) {
130 $port = (integer) $this->_config[
'port'];
131 $serverName .=
', ' . $port;
134 $connectionInfo = array(
135 'Database' => $this->_config[
'dbname'],
138 if (isset($this->_config[
'username']) && isset($this->_config[
'password']))
140 $connectionInfo += array(
141 'UID' => $this->_config[
'username'],
142 'PWD' => $this->_config[
'password'],
147 if (!empty($this->_config[
'driver_options'])) {
148 foreach ($this->_config[
'driver_options'] as
$option =>
$value) {
151 $constantName = strtoupper(
$value);
152 if (defined($constantName)) {
153 $connectionInfo[
$option] = constant($constantName);
161 $this->_connection = sqlsrv_connect($serverName, $connectionInfo);
163 if (!$this->_connection) {
167 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 182 if (! array_key_exists(
'dbname',
$config)) {
184 #require_once 'Zend/Db/Adapter/Exception.php'; 185 throw new Zend_Db_Adapter_Exception(
"Configuration array must have a key for 'dbname' that names the database instance");
188 if (! array_key_exists(
'password',
$config) && array_key_exists(
'username',
$config)) {
192 #require_once 'Zend/Db/Adapter/Exception.php'; 194 If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
197 if (array_key_exists(
'password',
$config) && !array_key_exists(
'username',
$config)) {
201 #require_once 'Zend/Db/Adapter/Exception.php'; 203 If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
222 $level = SQLSRV_TXN_READ_COMMITTED;
226 case SQLSRV_TXN_READ_UNCOMMITTED:
227 $sql =
"READ UNCOMMITTED";
229 case SQLSRV_TXN_READ_COMMITTED:
230 $sql =
"READ COMMITTED";
232 case SQLSRV_TXN_REPEATABLE_READ:
233 $sql =
"REPEATABLE READ";
235 case SQLSRV_TXN_SNAPSHOT:
238 case SQLSRV_TXN_SERIALIZABLE:
239 $sql =
"SERIALIZABLE";
242 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 246 if (!sqlsrv_query($this->_connection,
"SET TRANSACTION ISOLATION LEVEL $sql;")) {
247 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 274 sqlsrv_close($this->_connection);
276 $this->_connection =
null;
294 #require_once 'Zend/Loader.php'; 298 $stmt =
new $stmtClass($this, $sql);
299 $stmt->setFetchMode($this->_fetchMode);
314 return sprintf(
'%F',
$value);
318 return "'" . str_replace(
"'",
"''",
$value) .
"'";
339 $sql =
'SELECT IDENT_CURRENT (' .
$tableName .
') as Current_Identity';
340 return (
string) $this->
fetchOne($sql);
343 if ($this->_lastInsertId > 0) {
348 return (
string) $this->
fetchOne($sql);
363 foreach ($bind as $col => $val) {
366 $vals[] = $val->__toString();
374 $sql =
"INSERT INTO " 376 .
' (' . implode(
', ', $cols) .
') ' 377 .
'VALUES (' . implode(
', ', $vals) .
')' 381 $stmt = $this->
query($sql, array_values($bind));
386 $this->_lastInsertId = $stmt->fetchColumn();
399 $sql =
"SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
439 $stmt = $this->
query($sql);
443 $stmt->closeCursor();
458 $column_position = 16;
463 $tableOwner =
$result[0][$owner];
464 $sql =
"exec sp_pkeys @table_owner = " . $tableOwner
466 $stmt = $this->
query($sql);
469 $primaryKeyColumn = array();
475 $pkey_column_name = 3;
477 foreach ($primaryKeysResult as $pkeysRow) {
478 $primaryKeyColumn[$pkeysRow[$pkey_column_name]] = $pkeysRow[$pkey_key_seq];
485 $words = explode(
' ',
$row[$type_name], 2);
486 if (isset($words[0])) {
488 if (isset($words[1])) {
489 $identity = (bool) preg_match(
'/identity/', $words[1]);
493 $isPrimary = array_key_exists(
$row[$column_name], $primaryKeyColumn);
495 $primaryPosition = $primaryKeyColumn[
$row[$column_name]];
497 $primaryPosition =
null;
501 'SCHEMA_NAME' =>
null,
504 'COLUMN_POSITION' => (
int)
$row[$column_position],
505 'DATA_TYPE' =>
$type,
506 'DEFAULT' =>
$row[$column_def],
507 'NULLABLE' => (
bool)
$row[$nullable],
508 'LENGTH' =>
$row[$length],
509 'SCALE' =>
$row[$scale],
510 'PRECISION' =>
$row[$precision],
512 'PRIMARY' => $isPrimary,
513 'PRIMARY_POSITION' => $primaryPosition,
514 'IDENTITY' => $identity,
529 if (!sqlsrv_begin_transaction($this->_connection)) {
530 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 543 if (!sqlsrv_commit($this->_connection)) {
544 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 557 if (!sqlsrv_rollback($this->_connection)) {
558 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 579 $this->_fetchMode =
$mode;
582 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 586 #require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php'; 605 #require_once 'Zend/Db/Adapter/Exception.php'; 609 $offset = intval($offset);
612 #require_once 'Zend/Db/Adapter/Exception.php'; 617 $sql = preg_replace(
'/^SELECT\s/i',
'SELECT TOP ' .
$count .
' ', $sql);
619 $orderby = stristr($sql,
'ORDER BY');
622 $over =
'ORDER BY (SELECT 0)';
624 $over = preg_replace(
'/\"[^,]*\".\"([^,]*)\"/i',
'"inner_tbl"."$1"', $orderby);
628 $sql = preg_replace(
'/\s+ORDER BY(.*)/',
'', $sql);
631 $sql =
"SELECT ROW_NUMBER() OVER ($over) AS \"ZEND_DB_ROWNUM\", * FROM ($sql) AS inner_tbl";
635 if (
$count == PHP_INT_MAX) {
636 $sql =
"WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" >= $start";
640 $sql =
"WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" BETWEEN $start AND $end";
655 if (
$type ==
'positional') {
671 $serverInfo = sqlsrv_server_info($this->_connection);
673 if ($serverInfo !==
false) {
674 return $serverInfo[
'SQLServerVersion'];
fetchOne($sql, $bind=array())
elseif(isset( $params[ 'redirect_parent']))
static loadClass($class, $dirs=null)
fetchCol($sql, $bind=array())
quote($value, $type=null)
insert($table, array $bind)
lastInsertId($tableName=null, $primaryKey=null)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
_checkRequiredOptions(array $config)
query($sql, $bind=array())
limit($sql, $count, $offset=0)
quoteIdentifier($ident, $auto=false)
supportsParameters($type)
setTransactionIsolationLevel($level=null)
describeTable($tableName, $schemaName=null)