import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 12629 2008-11-13 17:23:13Z alexander $
|
||||
* @version $Id: Abstract.php 15577 2009-05-14 12:43:34Z matthew $
|
||||
*/
|
||||
|
||||
|
||||
@ -27,12 +27,6 @@
|
||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Statement_Pdo
|
||||
*/
|
||||
@ -72,6 +66,7 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
unset($dsn['username']);
|
||||
unset($dsn['password']);
|
||||
unset($dsn['options']);
|
||||
unset($dsn['charset']);
|
||||
unset($dsn['driver_options']);
|
||||
|
||||
// use all remaining parts in the DSN
|
||||
@ -145,6 +140,16 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) ($this->_connection instanceof PDO));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the connection to close.
|
||||
*
|
||||
@ -166,7 +171,10 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
{
|
||||
$this->_connect();
|
||||
$stmtClass = $this->_defaultStmtClass;
|
||||
Zend_Loader::loadClass($stmtClass);
|
||||
if (!class_exists($stmtClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($stmtClass);
|
||||
}
|
||||
$stmt = new $stmtClass($this, $sql);
|
||||
$stmt->setFetchMode($this->_fetchMode);
|
||||
return $stmt;
|
||||
@ -206,6 +214,10 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function query($sql, $bind = array())
|
||||
{
|
||||
if (empty($bind) && $sql instanceof Zend_Db_Select) {
|
||||
$bind = $sql->getBind();
|
||||
}
|
||||
|
||||
if (is_array($bind)) {
|
||||
foreach ($bind as $name => $value) {
|
||||
if (!is_int($name) && !preg_match('/^:/', $name)) {
|
||||
@ -227,6 +239,42 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL statement and return the number of affected rows
|
||||
*
|
||||
* @param mixed $sql The SQL statement with placeholders.
|
||||
* May be a string or Zend_Db_Select.
|
||||
* @return integer Number of rows that were modified
|
||||
* or deleted by the SQL statement
|
||||
*/
|
||||
public function exec($sql)
|
||||
{
|
||||
if ($sql instanceof Zend_Db_Select) {
|
||||
$sql = $sql->assemble();
|
||||
}
|
||||
|
||||
try {
|
||||
$affected = $this->getConnection()->exec($sql);
|
||||
|
||||
if ($affected === false) {
|
||||
$errorInfo = $this->getConnection()->errorInfo();
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception($errorInfo[2]);
|
||||
}
|
||||
|
||||
return $affected;
|
||||
} catch (PDOException $e) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote a raw string.
|
||||
*
|
||||
@ -322,5 +370,26 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
try {
|
||||
$version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
} catch (PDOException $e) {
|
||||
// In case of the driver doesn't support getting attributes
|
||||
return null;
|
||||
}
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Ibm.php 9577 2008-05-31 01:50:27Z peptolab $
|
||||
* @version $Id: Ibm.php 13522 2009-01-06 16:35:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -260,7 +260,7 @@ class Zend_Db_Adapter_Pdo_Ibm extends Zend_Db_Adapter_Pdo_Abstract
|
||||
$newbind = array();
|
||||
if (is_array($bind)) {
|
||||
foreach ($bind as $name => $value) {
|
||||
if(!is_null($value)) {
|
||||
if($value !== null) {
|
||||
$newbind[$name] = $value;
|
||||
}
|
||||
}
|
||||
@ -333,4 +333,28 @@ class Zend_Db_Adapter_Pdo_Ibm extends Zend_Db_Adapter_Pdo_Abstract
|
||||
$this->_connect();
|
||||
return $this->_serverType->nextSequenceId($sequenceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
* Pdo_Idm doesn't support getAttribute(PDO::ATTR_SERVER_VERSION)
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
try {
|
||||
$stmt = $this->query('SELECT service_level, fixpack_num FROM TABLE (sysproc.env_get_inst_info()) as INSTANCEINFO');
|
||||
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
|
||||
if (count($result)) {
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $result[0][0], $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (PDOException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Mssql.php 9101 2008-03-30 19:54:38Z thomas $
|
||||
* @version $Id: Mssql.php 12960 2008-11-30 11:04:38Z mikaelkael $
|
||||
*/
|
||||
|
||||
|
||||
@ -360,4 +360,22 @@ class Zend_Db_Adapter_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Abstract
|
||||
return (int)$this->fetchOne($sql);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
* Pdo_Mssql doesn't support getAttribute(PDO::ATTR_SERVER_VERSION)
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
try {
|
||||
$stmt = $this->query("SELECT SERVERPROPERTY('productversion')");
|
||||
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
|
||||
if (count($result)) {
|
||||
return $result[0][0];
|
||||
}
|
||||
return null;
|
||||
} catch (PDOException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Mysql.php 9101 2008-03-30 19:54:38Z thomas $
|
||||
* @version $Id: Mysql.php 14953 2009-04-17 00:56:16Z norm2782 $
|
||||
*/
|
||||
|
||||
|
||||
@ -76,6 +76,26 @@ class Zend_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Abstract
|
||||
'FLOAT' => Zend_Db::FLOAT_TYPE
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a PDO object and connects to the database.
|
||||
*
|
||||
* @return void
|
||||
* @throws Zend_Db_Adapter_Exception
|
||||
*/
|
||||
protected function _connect()
|
||||
{
|
||||
if ($this->_connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($this->_config['charset'])) {
|
||||
$initCommand = "SET NAMES '" . $this->_config['charset'] . "'";
|
||||
$this->_config['driver_options'][PDO::MYSQL_ATTR_INIT_COMMAND] = $initCommand;
|
||||
}
|
||||
|
||||
parent::_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -161,6 +181,10 @@ class Zend_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Abstract
|
||||
$row[$type] = 'decimal';
|
||||
$precision = $matches[1];
|
||||
$scale = $matches[2];
|
||||
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row[$type], $matches)) {
|
||||
$row[$type] = 'float';
|
||||
$precision = $matches[1];
|
||||
$scale = $matches[2];
|
||||
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row[$type], $matches)) {
|
||||
$row[$type] = $matches[1];
|
||||
// The optional argument of a MySQL int type is not precision
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Oci.php 11942 2008-10-13 20:21:18Z mikaelkael $
|
||||
* @version $Id: Oci.php 14107 2009-02-18 21:58:36Z norm2782 $
|
||||
*/
|
||||
|
||||
|
||||
@ -46,6 +46,13 @@ class Zend_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract
|
||||
*/
|
||||
protected $_pdoType = 'oci';
|
||||
|
||||
/**
|
||||
* Default class name for a DB statement.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo_Oci';
|
||||
|
||||
/**
|
||||
* Keys are UPPERCASE SQL datatypes or the constants
|
||||
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
|
||||
@ -76,20 +83,22 @@ class Zend_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract
|
||||
// baseline of DSN parts
|
||||
$dsn = $this->_config;
|
||||
|
||||
$tns = 'dbname=(DESCRIPTION=';
|
||||
if (isset($dsn['host'])) {
|
||||
$tns .= '(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=' . $dsn['host'] . ')';
|
||||
$tns = 'dbname=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
|
||||
'(HOST=' . $dsn['host'] . ')';
|
||||
|
||||
if (isset($dsn['port'])) {
|
||||
$tns .= '(PORT=' . $dsn['port'] . ')';
|
||||
} else {
|
||||
$tns .= '(PORT=1521)';
|
||||
}
|
||||
$tns .= '))';
|
||||
}
|
||||
$tns .= '(CONNECT_DATA=(SID=' . $dsn['dbname'] . ')))';
|
||||
|
||||
if (isset($dsn['charset']))
|
||||
{
|
||||
$tns .= '))(CONNECT_DATA=(SID=' . $dsn['dbname'] . ')))';
|
||||
} else {
|
||||
$tns = 'dbname=' . $dsn['dbname'];
|
||||
}
|
||||
|
||||
if (isset($dsn['charset'])) {
|
||||
$tns .= ';charset=' . $dsn['charset'];
|
||||
}
|
||||
|
||||
@ -170,21 +179,46 @@ class Zend_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract
|
||||
*/
|
||||
public function describeTable($tableName, $schemaName = null)
|
||||
{
|
||||
$sql = "SELECT TC.TABLE_NAME, TB.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
|
||||
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
|
||||
TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
|
||||
FROM ALL_TAB_COLUMNS TC
|
||||
LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
|
||||
ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P'))
|
||||
ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
|
||||
JOIN ALL_TABLES TB ON (TB.TABLE_NAME = TC.TABLE_NAME AND TB.OWNER = TC.OWNER)
|
||||
WHERE TC.TABLE_NAME = :TBNAME";
|
||||
$bind[':TBNAME'] = $tableName;
|
||||
if ($schemaName) {
|
||||
$sql .= ' AND TB.OWNER = :SCNAME';
|
||||
$bind[':SCNAME'] = $schemaName;
|
||||
$version = $this->getServerVersion();
|
||||
if (($version === null) || version_compare($version, '9.0.0', '>=')) {
|
||||
$sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
|
||||
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
|
||||
TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
|
||||
FROM ALL_TAB_COLUMNS TC
|
||||
LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
|
||||
ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P'))
|
||||
ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
|
||||
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
|
||||
$bind[':TBNAME'] = $tableName;
|
||||
if ($schemaName) {
|
||||
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
|
||||
$bind[':SCNAME'] = $schemaName;
|
||||
}
|
||||
$sql .= ' ORDER BY TC.COLUMN_ID';
|
||||
} else {
|
||||
$subSql="SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION
|
||||
from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC
|
||||
WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
|
||||
AND ACC.TABLE_NAME = AC.TABLE_NAME
|
||||
AND ACC.OWNER = AC.OWNER
|
||||
AND AC.CONSTRAINT_TYPE = 'P'
|
||||
AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
|
||||
$bind[':TBNAME'] = $tableName;
|
||||
if ($schemaName) {
|
||||
$subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
|
||||
$bind[':SCNAME'] = $schemaName;
|
||||
}
|
||||
$sql="SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
|
||||
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
|
||||
TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION
|
||||
FROM ALL_TAB_COLUMNS TC, ($subSql) CC
|
||||
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)
|
||||
AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
|
||||
if ($schemaName) {
|
||||
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
|
||||
}
|
||||
$sql .= ' ORDER BY TC.COLUMN_ID';
|
||||
}
|
||||
$sql .= ' ORDER BY TC.COLUMN_ID';
|
||||
|
||||
$stmt = $this->query($sql, $bind);
|
||||
|
||||
@ -332,12 +366,12 @@ class Zend_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract
|
||||
*/
|
||||
$limit_sql = "SELECT z2.*
|
||||
FROM (
|
||||
SELECT ROWNUM AS zend_db_rownum, z1.*
|
||||
SELECT z1.*, ROWNUM AS \"zend_db_rownum\"
|
||||
FROM (
|
||||
" . $sql . "
|
||||
) z1
|
||||
) z2
|
||||
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
|
||||
WHERE z2.\"zend_db_rownum\" BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
|
||||
return $limit_sql;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Pgsql.php 9101 2008-03-30 19:54:38Z thomas $
|
||||
* @version $Id: Pgsql.php 14953 2009-04-17 00:56:16Z norm2782 $
|
||||
*/
|
||||
|
||||
|
||||
@ -72,6 +72,26 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
|
||||
'REAL' => Zend_Db::FLOAT_TYPE
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a PDO object and connects to the database.
|
||||
*
|
||||
* @return void
|
||||
* @throws Zend_Db_Adapter_Exception
|
||||
*/
|
||||
protected function _connect()
|
||||
{
|
||||
if ($this->_connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::_connect();
|
||||
|
||||
if (!empty($this->_config['charset'])) {
|
||||
$sql = "SET NAMES '" . $this->_config['charset'] . "'";
|
||||
$this->_connection->exec($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the tables in the database.
|
||||
*
|
||||
|
Reference in New Issue
Block a user