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 10975 2008-08-22 15:47:04Z doctorrock83 $
|
||||
* @version $Id: Abstract.php 16029 2009-06-12 18:01:37Z doctorrock83 $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,12 +31,6 @@ require_once 'Zend/Db.php';
|
||||
*/
|
||||
require_once 'Zend/Db/Select.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class for connecting to SQL databases and performing common operations.
|
||||
*
|
||||
@ -131,6 +125,20 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE
|
||||
);
|
||||
|
||||
/** Weither or not that object can get serialized
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_allowSerialization = true;
|
||||
|
||||
/**
|
||||
* Weither or not the database should be reconnected
|
||||
* to that adapter when waking up
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_autoReconnectOnUnserialize = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -176,7 +184,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
|
||||
$options = array(
|
||||
Zend_Db::CASE_FOLDING => $this->_caseFolding,
|
||||
Zend_DB::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers
|
||||
Zend_Db::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers
|
||||
);
|
||||
$driverOptions = array();
|
||||
|
||||
@ -197,10 +205,16 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_config = array_merge($this->_config, $config);
|
||||
|
||||
if (!isset($config['charset'])) {
|
||||
$config['charset'] = null;
|
||||
}
|
||||
|
||||
$this->_config = array_merge($this->_config, $config);
|
||||
$this->_config['options'] = $options;
|
||||
$this->_config['driver_options'] = $driverOptions;
|
||||
|
||||
|
||||
// obtain the case setting, if there is one
|
||||
if (array_key_exists(Zend_Db::CASE_FOLDING, $options)) {
|
||||
$case = (int) $options[Zend_Db::CASE_FOLDING];
|
||||
@ -211,6 +225,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
$this->_caseFolding = $case;
|
||||
break;
|
||||
default:
|
||||
/** @see Zend_Db_Adapter_Exception */
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception('Case must be one of the following constants: '
|
||||
. 'Zend_Db::CASE_NATURAL, Zend_Db::CASE_LOWER, Zend_Db::CASE_UPPER');
|
||||
@ -222,6 +237,16 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
$this->_autoQuoteIdentifiers = (bool) $options[Zend_Db::AUTO_QUOTE_IDENTIFIERS];
|
||||
}
|
||||
|
||||
// obtain allow serialization property if there is one
|
||||
if (array_key_exists(Zend_Db::ALLOW_SERIALIZATION, $options)) {
|
||||
$this->_allowSerialization = (bool) $options[Zend_Db::ALLOW_SERIALIZATION];
|
||||
}
|
||||
|
||||
// obtain auto reconnect on unserialize property if there is one
|
||||
if (array_key_exists(Zend_Db::AUTO_RECONNECT_ON_UNSERIALIZE, $options)) {
|
||||
$this->_autoReconnectOnUnserialize = (bool) $options[Zend_Db::AUTO_RECONNECT_ON_UNSERIALIZE];
|
||||
}
|
||||
|
||||
// create a profiler object
|
||||
$profiler = false;
|
||||
if (array_key_exists(Zend_Db::PROFILER, $this->_config)) {
|
||||
@ -242,6 +267,7 @@ abstract class 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';
|
||||
throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
|
||||
}
|
||||
@ -349,11 +375,15 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
}
|
||||
|
||||
if ($profilerInstance === null) {
|
||||
@Zend_Loader::loadClass($profilerClass);
|
||||
if (!class_exists($profilerClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($profilerClass);
|
||||
}
|
||||
$profilerInstance = new $profilerClass();
|
||||
}
|
||||
|
||||
if (!$profilerInstance instanceof Zend_Db_Profiler) {
|
||||
/** @see Zend_Db_Profiler_Exception */
|
||||
require_once 'Zend/Db/Profiler/Exception.php';
|
||||
throw new Zend_Db_Profiler_Exception('Class ' . get_class($profilerInstance) . ' does not extend '
|
||||
. 'Zend_Db_Profiler');
|
||||
@ -392,7 +422,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
/**
|
||||
* Set the default statement class.
|
||||
*
|
||||
* @return Zend_Db_Abstract Fluent interface
|
||||
* @return Zend_Db_Adapter_Abstract Fluent interface
|
||||
*/
|
||||
public function setStatementClass($class)
|
||||
{
|
||||
@ -415,6 +445,10 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
|
||||
// is the $sql a Zend_Db_Select object?
|
||||
if ($sql instanceof Zend_Db_Select) {
|
||||
if (empty($bind)) {
|
||||
$bind = $sql->getBind();
|
||||
}
|
||||
|
||||
$sql = $sql->assemble();
|
||||
}
|
||||
|
||||
@ -525,12 +559,26 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
* except for Zend_Db_Expr which is treated literally.
|
||||
*/
|
||||
$set = array();
|
||||
$i = 0;
|
||||
foreach ($bind as $col => $val) {
|
||||
if ($val instanceof Zend_Db_Expr) {
|
||||
$val = $val->__toString();
|
||||
unset($bind[$col]);
|
||||
} else {
|
||||
$val = '?';
|
||||
if ($this->supportsParameters('positional')) {
|
||||
$val = '?';
|
||||
} else {
|
||||
if ($this->supportsParameters('named')) {
|
||||
unset($bind[$col]);
|
||||
$bind[':'.$col.$i] = $val;
|
||||
$val = ':'.$col.$i;
|
||||
$i++;
|
||||
} else {
|
||||
/** @see Zend_Db_Adapter_Exception */
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding");
|
||||
}
|
||||
}
|
||||
}
|
||||
$set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;
|
||||
}
|
||||
@ -548,7 +596,11 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
/**
|
||||
* Execute the statement and return the number of affected rows
|
||||
*/
|
||||
$stmt = $this->query($sql, array_values($bind));
|
||||
if ($this->supportsParameters('positional')) {
|
||||
$stmt = $this->query($sql, array_values($bind));
|
||||
} else {
|
||||
$stmt = $this->query($sql, $bind);
|
||||
}
|
||||
$result = $stmt->rowCount();
|
||||
return $result;
|
||||
}
|
||||
@ -594,12 +646,21 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
if (!is_array($where)) {
|
||||
$where = array($where);
|
||||
}
|
||||
foreach ($where as &$term) {
|
||||
if ($term instanceof Zend_Db_Expr) {
|
||||
$term = $term->__toString();
|
||||
foreach ($where as $cond => &$term) {
|
||||
// is $cond an int? (i.e. Not a condition)
|
||||
if (is_int($cond)) {
|
||||
// $term is the full condition
|
||||
if ($term instanceof Zend_Db_Expr) {
|
||||
$term = $term->__toString();
|
||||
}
|
||||
} else {
|
||||
// $cond is the condition with placeholder,
|
||||
// and $term is quoted into the condition
|
||||
$term = $this->quoteInto($cond, $term);
|
||||
}
|
||||
$term = '(' . $term . ')';
|
||||
}
|
||||
|
||||
$where = implode(' AND ', $where);
|
||||
return $where;
|
||||
}
|
||||
@ -829,7 +890,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
* @param mixed $value The value to quote.
|
||||
* @param string $type OPTIONAL SQL datatype
|
||||
* @param integer $count OPTIONAL count of placeholders to replace
|
||||
* @return string An SQL-safe quoted value placed into the orignal text.
|
||||
* @return string An SQL-safe quoted value placed into the original text.
|
||||
*/
|
||||
public function quoteInto($text, $value, $type = null, $count = null)
|
||||
{
|
||||
@ -904,8 +965,8 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
*
|
||||
* @param string|array|Zend_Db_Expr $ident The identifier or expression.
|
||||
* @param string $alias An optional alias.
|
||||
* @param string $as The string to add between the identifier/expression and the alias.
|
||||
* @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
|
||||
* @param string $as The string to add between the identifier/expression and the alias.
|
||||
* @return string The quoted identifier and alias.
|
||||
*/
|
||||
protected function _quoteIdentifierAs($ident, $alias = null, $auto = false, $as = ' AS ')
|
||||
@ -1003,7 +1064,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
* can invoke it.
|
||||
*
|
||||
* @param string $key
|
||||
* @returns string
|
||||
* @return string
|
||||
*/
|
||||
public function foldCase($key)
|
||||
{
|
||||
@ -1021,6 +1082,36 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* called when object is getting serialized
|
||||
* This disconnects the DB object that cant be serialized
|
||||
*
|
||||
* @throws Zend_Db_Adapter_Exception
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
if ($this->_allowSerialization == false) {
|
||||
/** @see Zend_Db_Adapter_Exception */
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception(get_class($this) ." is not allowed to be serialized");
|
||||
}
|
||||
$this->_connection = false;
|
||||
return array_keys(array_diff_key(get_object_vars($this), array('_connection'=>false)));
|
||||
}
|
||||
|
||||
/**
|
||||
* called when object is getting unserialized
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
if ($this->_autoReconnectOnUnserialize == true) {
|
||||
$this->getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Methods
|
||||
*/
|
||||
@ -1068,6 +1159,13 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
abstract protected function _connect();
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
abstract public function isConnected();
|
||||
|
||||
/**
|
||||
* Force the connection to close.
|
||||
*
|
||||
@ -1079,7 +1177,7 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
* Prepare a statement and return a PDOStatement-like object.
|
||||
*
|
||||
* @param string|Zend_Db_Select $sql SQL query
|
||||
* @return Zend_Db_Statment|PDOStatement
|
||||
* @return Zend_Db_Statement|PDOStatement
|
||||
*/
|
||||
abstract public function prepare($sql);
|
||||
|
||||
@ -1141,4 +1239,10 @@ abstract class Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
abstract public function supportsParameters($type);
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getServerVersion();
|
||||
}
|
||||
|
@ -29,11 +29,6 @@ require_once 'Zend/Db.php';
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Statement_Db2
|
||||
*/
|
||||
@ -60,6 +55,8 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
* protocol => (string) Protocol to use, defaults to "TCPIP"
|
||||
* port => (integer) Port number to use for TCP/IP if protocol is "TCPIP"
|
||||
* persistent => (boolean) Set TRUE to use a persistent connection (db2_pconnect)
|
||||
* os => (string) This should be set to 'i5' if the db is on an os400/i5
|
||||
* schema => (string) The default schema the connection should use
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
@ -70,7 +67,9 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
'host' => 'localhost',
|
||||
'port' => '50000',
|
||||
'protocol' => 'TCPIP',
|
||||
'persistent' => false
|
||||
'persistent' => false,
|
||||
'os' => null,
|
||||
'schema' => null
|
||||
);
|
||||
|
||||
/**
|
||||
@ -86,6 +85,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultStmtClass = 'Zend_Db_Statement_Db2';
|
||||
protected $_isI5 = false;
|
||||
|
||||
/**
|
||||
* Keys are UPPERCASE SQL datatypes or the constants
|
||||
@ -129,6 +129,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
throw new Zend_Db_Adapter_Db2_Exception('The IBM DB2 extension is required for this adapter but the extension is not loaded');
|
||||
}
|
||||
|
||||
$this->_determineI5();
|
||||
if ($this->_config['persistent']) {
|
||||
// use persistent connection
|
||||
$conn_func_name = 'db2_pconnect';
|
||||
@ -151,7 +152,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
$this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]];
|
||||
}
|
||||
|
||||
if ($this->_config['host'] !== 'localhost') {
|
||||
if ($this->_config['host'] !== 'localhost' && !$this->_isI5) {
|
||||
// if the host isn't localhost, use extended connection params
|
||||
$dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
|
||||
';DATABASE=' . $this->_config['dbname'] .
|
||||
@ -186,6 +187,17 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) (is_resource($this->_connection)
|
||||
&& get_resource_type($this->_connection) == 'DB2 Connection'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the connection to close.
|
||||
*
|
||||
@ -193,7 +205,9 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function closeConnection()
|
||||
{
|
||||
db2_close($this->_connection);
|
||||
if ($this->isConnected()) {
|
||||
db2_close($this->_connection);
|
||||
}
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
@ -207,7 +221,10 @@ class Zend_Db_Adapter_Db2 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;
|
||||
@ -274,32 +291,49 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
{
|
||||
$this->_connect();
|
||||
$info = db2_server_info($this->_connection);
|
||||
$identQuote = $info->IDENTIFIER_QUOTE_CHAR;
|
||||
if ($info) {
|
||||
$identQuote = $info->IDENTIFIER_QUOTE_CHAR;
|
||||
} else {
|
||||
// db2_server_info() does not return result on some i5 OS version
|
||||
if ($this->_isI5) {
|
||||
$identQuote ="'";
|
||||
}
|
||||
}
|
||||
return $identQuote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the tables in the database.
|
||||
*
|
||||
* @param string $schema OPTIONAL
|
||||
* @return array
|
||||
*/
|
||||
public function listTables()
|
||||
public function listTables($schema = null)
|
||||
{
|
||||
$this->_connect();
|
||||
|
||||
// take the most general case and assume no z/OS
|
||||
// since listTables() takes no parameters
|
||||
$stmt = db2_tables($this->_connection);
|
||||
if ($schema === null && $this->_config['schema'] != null) {
|
||||
$schema = $this->_config['schema'];
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
|
||||
while ($row = db2_fetch_assoc($stmt)) {
|
||||
$tables[] = $row['TABLE_NAME'];
|
||||
if (!$this->_isI5) {
|
||||
if ($schema) {
|
||||
$stmt = db2_tables($this->_connection, null, $schema);
|
||||
} else {
|
||||
$stmt = db2_tables($this->_connection);
|
||||
}
|
||||
while ($row = db2_fetch_assoc($stmt)) {
|
||||
$tables[] = $row['TABLE_NAME'];
|
||||
}
|
||||
} else {
|
||||
$tables = $this->_i5listTables($schema);
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the column descriptions for a table.
|
||||
*
|
||||
@ -320,35 +354,69 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
* SCALE => number; scale of NUMERIC/DECIMAL
|
||||
* PRECISION => number; precision of NUMERIC/DECIMAL
|
||||
* UNSIGNED => boolean; unsigned property of an integer type
|
||||
* DB2 not supports UNSIGNED integer.
|
||||
* PRIMARY => boolean; true if column is part of the primary key
|
||||
* PRIMARY_POSITION => integer; position of column in primary key
|
||||
* IDENTITY => integer; true if column is auto-generated with unique values
|
||||
*
|
||||
* @todo Discover integer unsigned property.
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $schemaName OPTIONAL
|
||||
* @return array
|
||||
*/
|
||||
public function describeTable($tableName, $schemaName = null)
|
||||
{
|
||||
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
|
||||
c.typename, c.default, c.nulls, c.length, c.scale,
|
||||
c.identity, tc.type AS tabconsttype, k.colseq
|
||||
FROM syscat.columns c
|
||||
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
|
||||
ON (k.tabschema = tc.tabschema
|
||||
AND k.tabname = tc.tabname
|
||||
AND tc.type = 'P'))
|
||||
ON (c.tabschema = k.tabschema
|
||||
AND c.tabname = k.tabname
|
||||
AND c.colname = k.colname)
|
||||
WHERE "
|
||||
. $this->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
|
||||
if ($schemaName) {
|
||||
$sql .= $this->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
|
||||
// Ensure the connection is made so that _isI5 is set
|
||||
$this->_connect();
|
||||
|
||||
if ($schemaName === null && $this->_config['schema'] != null) {
|
||||
$schemaName = $this->_config['schema'];
|
||||
}
|
||||
|
||||
if (!$this->_isI5) {
|
||||
|
||||
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
|
||||
c.typename, c.default, c.nulls, c.length, c.scale,
|
||||
c.identity, tc.type AS tabconsttype, k.colseq
|
||||
FROM syscat.columns c
|
||||
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
|
||||
ON (k.tabschema = tc.tabschema
|
||||
AND k.tabname = tc.tabname
|
||||
AND tc.type = 'P'))
|
||||
ON (c.tabschema = k.tabschema
|
||||
AND c.tabname = k.tabname
|
||||
AND c.colname = k.colname)
|
||||
WHERE "
|
||||
. $this->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
|
||||
|
||||
if ($schemaName) {
|
||||
$sql .= $this->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY c.colno";
|
||||
|
||||
} else {
|
||||
|
||||
// DB2 On I5 specific query
|
||||
$sql = "SELECT DISTINCT C.TABLE_SCHEMA, C.TABLE_NAME, C.COLUMN_NAME, C.ORDINAL_POSITION,
|
||||
C.DATA_TYPE, C.COLUMN_DEFAULT, C.NULLS ,C.LENGTH, C.SCALE, LEFT(C.IDENTITY,1),
|
||||
LEFT(tc.TYPE, 1) AS tabconsttype, k.COLSEQ
|
||||
FROM QSYS2.SYSCOLUMNS C
|
||||
LEFT JOIN (QSYS2.syskeycst k JOIN QSYS2.SYSCST tc
|
||||
ON (k.TABLE_SCHEMA = tc.TABLE_SCHEMA
|
||||
AND k.TABLE_NAME = tc.TABLE_NAME
|
||||
AND LEFT(tc.type,1) = 'P'))
|
||||
ON (C.TABLE_SCHEMA = k.TABLE_SCHEMA
|
||||
AND C.TABLE_NAME = k.TABLE_NAME
|
||||
AND C.COLUMN_NAME = k.COLUMN_NAME)
|
||||
WHERE "
|
||||
. $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName);
|
||||
|
||||
if ($schemaName) {
|
||||
$sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY C.ORDINAL_POSITION FOR FETCH ONLY";
|
||||
}
|
||||
$sql .= " ORDER BY c.colno";
|
||||
|
||||
$desc = array();
|
||||
$stmt = $this->query($sql);
|
||||
@ -372,12 +440,12 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
$length = 7;
|
||||
$scale = 8;
|
||||
$identityCol = 9;
|
||||
$tabconstype = 10;
|
||||
$tabconstType = 10;
|
||||
$colseq = 11;
|
||||
|
||||
foreach ($result as $key => $row) {
|
||||
list ($primary, $primaryPosition, $identity) = array(false, null, false);
|
||||
if ($row[$tabconstype] == 'P') {
|
||||
if ($row[$tabconstType] == 'P') {
|
||||
$primary = true;
|
||||
$primaryPosition = $row[$colseq];
|
||||
}
|
||||
@ -394,14 +462,14 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
'SCHEMA_NAME' => $this->foldCase($row[$tabschema]),
|
||||
'TABLE_NAME' => $this->foldCase($row[$tabname]),
|
||||
'COLUMN_NAME' => $this->foldCase($row[$colname]),
|
||||
'COLUMN_POSITION' => $row[$colno]+1,
|
||||
'COLUMN_POSITION' => (!$this->_isI5) ? $row[$colno]+1 : $row[$colno],
|
||||
'DATA_TYPE' => $row[$typename],
|
||||
'DEFAULT' => $row[$default],
|
||||
'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
|
||||
'LENGTH' => $row[$length],
|
||||
'SCALE' => $row[$scale],
|
||||
'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
|
||||
'UNSIGNED' => null, // @todo
|
||||
'UNSIGNED' => false,
|
||||
'PRIMARY' => $primary,
|
||||
'PRIMARY_POSITION' => $primaryPosition,
|
||||
'IDENTITY' => $identity
|
||||
@ -422,7 +490,15 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
public function lastSequenceId($sequenceName)
|
||||
{
|
||||
$this->_connect();
|
||||
$sql = 'SELECT PREVVAL FOR '.$this->quoteIdentifier($sequenceName, true).' AS VAL FROM SYSIBM.SYSDUMMY1';
|
||||
|
||||
if (!$this->_isI5) {
|
||||
$quotedSequenceName = $this->quoteIdentifier($sequenceName, true);
|
||||
$sql = 'SELECT PREVVAL FOR ' . $quotedSequenceName . ' AS VAL FROM SYSIBM.SYSDUMMY1';
|
||||
} else {
|
||||
$quotedSequenceName = $sequenceName;
|
||||
$sql = 'SELECT PREVVAL FOR ' . $this->quoteIdentifier($sequenceName, true) . ' AS VAL FROM QSYS2.QSQPTABL';
|
||||
}
|
||||
|
||||
$value = $this->fetchOne($sql);
|
||||
return (string) $value;
|
||||
}
|
||||
@ -458,12 +534,18 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
*
|
||||
* @param string $tableName OPTIONAL
|
||||
* @param string $primaryKey OPTIONAL
|
||||
* @param string $idType OPTIONAL used for i5 platform to define sequence/idenity unique value
|
||||
* @return string
|
||||
*/
|
||||
public function lastInsertId($tableName = null, $primaryKey = null)
|
||||
|
||||
public function lastInsertId($tableName = null, $primaryKey = null, $idType = null)
|
||||
{
|
||||
$this->_connect();
|
||||
|
||||
if ($this->_isI5) {
|
||||
return (string) $this->_i5LastInsertId($tableName, $idType);
|
||||
}
|
||||
|
||||
if ($tableName !== null) {
|
||||
$sequenceName = $tableName;
|
||||
if ($primaryKey) {
|
||||
@ -618,13 +700,131 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function supportsParameters($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'positional':
|
||||
return true;
|
||||
case 'named':
|
||||
default:
|
||||
return false;
|
||||
if ($type == 'positional') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if its 'named' or anything else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
$server_info = db2_server_info($this->_connection);
|
||||
if ($server_info !== false) {
|
||||
$version = $server_info->DBMS_VER;
|
||||
if ($this->_isI5) {
|
||||
$version = (int) substr($version, 0, 2) . '.' . (int) substr($version, 2, 2) . '.' . (int) substr($version, 4);
|
||||
}
|
||||
return $version;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not this is running on i5
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isI5()
|
||||
{
|
||||
if ($this->_isI5 === null) {
|
||||
$this->_determineI5();
|
||||
}
|
||||
|
||||
return (bool) $this->_isI5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the connection parameters according to verify
|
||||
* type of used OS
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _determineI5()
|
||||
{
|
||||
// first us the compiled flag.
|
||||
$this->_isI5 = (php_uname('s') == 'OS400') ? true : false;
|
||||
|
||||
// if this is set, then us it
|
||||
if (isset($this->_config['os'])){
|
||||
if (strtolower($this->_config['os']) === 'i5') {
|
||||
$this->_isI5 = true;
|
||||
} else {
|
||||
// any other value passed in, its null
|
||||
$this->_isI5 = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Db2 On I5 specific method
|
||||
*
|
||||
* Returns a list of the tables in the database .
|
||||
* Used only for DB2/400.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _i5listTables($schema = null)
|
||||
{
|
||||
//list of i5 libraries.
|
||||
$tables = array();
|
||||
if ($schema) {
|
||||
$tablesStatement = db2_tables($this->_connection, null, $schema);
|
||||
while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
|
||||
if ($rowTables['TABLE_NAME'] !== null) {
|
||||
$tables[] = $rowTables['TABLE_NAME'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$schemaStatement = db2_tables($this->_connection);
|
||||
while ($schema = db2_fetch_assoc($schemaStatement)) {
|
||||
if ($schema['TABLE_SCHEM'] !== null) {
|
||||
// list of the tables which belongs to the selected library
|
||||
$tablesStatement = db2_tables($this->_connection, NULL, $schema['TABLE_SCHEM']);
|
||||
if (is_resource($tablesStatement)) {
|
||||
while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
|
||||
if ($rowTables['TABLE_NAME'] !== null) {
|
||||
$tables[] = $rowTables['TABLE_NAME'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
protected function _i5LastInsertId($objectName = null, $idType = null)
|
||||
{
|
||||
|
||||
if ($objectName === null) {
|
||||
$sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM QSYS2.QSQPTABL';
|
||||
$value = $this->fetchOne($sql);
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (strtoupper($idType) === 'S'){
|
||||
//check i5_lib option
|
||||
$sequenceName = $objectName;
|
||||
return $this->lastSequenceId($sequenceName);
|
||||
}
|
||||
|
||||
//returns last identity value for the specified table
|
||||
//if (strtoupper($idType) === 'I') {
|
||||
$tableName = $objectName;
|
||||
return $this->fetchOne('SELECT IDENTITY_VAL_LOCAL() from ' . $this->quoteIdentifier($tableName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,15 +17,10 @@
|
||||
* @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: Mysqli.php 12330 2008-11-06 17:03:39Z till $
|
||||
* @version $Id: Mysqli.php 15599 2009-05-16 01:30:48Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
@ -234,6 +229,10 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$row['Type'] = 'decimal';
|
||||
$row['Precision'] = $matches[1];
|
||||
$row['Scale'] = $matches[2];
|
||||
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row['Type'], $matches)) {
|
||||
$row['Type'] = 'float';
|
||||
$row['Precision'] = $matches[1];
|
||||
$row['Scale'] = $matches[2];
|
||||
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row['Type'], $matches)) {
|
||||
$row['Type'] = $matches[1];
|
||||
/**
|
||||
@ -298,22 +297,55 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$port = null;
|
||||
}
|
||||
|
||||
$this->_connection = mysqli_init();
|
||||
|
||||
if(!empty($this->_config['driver_options'])) {
|
||||
foreach($this->_config['driver_options'] as $option=>$value) {
|
||||
if(is_string($option)) {
|
||||
// Suppress warnings here
|
||||
// Ignore it if it's not a valid constant
|
||||
$option = @constant(strtoupper($option));
|
||||
if($option === null)
|
||||
continue;
|
||||
}
|
||||
mysqli_options($this->_connection, $option, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress connection warnings here.
|
||||
// Throw an exception instead.
|
||||
@$this->_connection = new mysqli(
|
||||
$_isConnected = @mysqli_real_connect(
|
||||
$this->_connection,
|
||||
$this->_config['host'],
|
||||
$this->_config['username'],
|
||||
$this->_config['password'],
|
||||
$this->_config['dbname'],
|
||||
$port
|
||||
);
|
||||
if ($this->_connection === false || mysqli_connect_errno()) {
|
||||
|
||||
if ($_isConnected === false || mysqli_connect_errno()) {
|
||||
|
||||
$this->closeConnection();
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Mysqli_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
|
||||
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
|
||||
}
|
||||
|
||||
if (!empty($this->_config['charset'])) {
|
||||
mysqli_set_charset($this->_connection, $this->_config['charset']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) ($this->_connection instanceof mysqli));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,7 +355,9 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function closeConnection()
|
||||
{
|
||||
$this->_connection->close();
|
||||
if ($this->isConnected()) {
|
||||
$this->_connection->close();
|
||||
}
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
@ -340,7 +374,10 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$this->_stmt->close();
|
||||
}
|
||||
$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);
|
||||
if ($stmt === false) {
|
||||
return false;
|
||||
@ -495,4 +532,18 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
*@return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
$version = $this->_connection->server_version;
|
||||
$major = (int) ($version / 10000);
|
||||
$minor = (int) ($version % 10000 / 100);
|
||||
$revision = (int) ($version % 100);
|
||||
return $major . '.' . $minor . '.' . $revision;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
@ -93,6 +88,14 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
protected $_defaultStmtClass = 'Zend_Db_Statement_Oracle';
|
||||
|
||||
/**
|
||||
* Check if LOB field are returned as string
|
||||
* instead of OCI-Lob object
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_lobAsString = null;
|
||||
|
||||
/**
|
||||
* Creates a connection resource.
|
||||
*
|
||||
@ -114,16 +117,11 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
throw new Zend_Db_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but the extension is not loaded');
|
||||
}
|
||||
|
||||
if (isset($this->_config['dbname'])) {
|
||||
$this->_connection = @oci_connect(
|
||||
$this->_connection = @oci_connect(
|
||||
$this->_config['username'],
|
||||
$this->_config['password'],
|
||||
$this->_config['dbname']);
|
||||
} else {
|
||||
$this->_connection = oci_connect(
|
||||
$this->_config['username'],
|
||||
$this->_config['password']);
|
||||
}
|
||||
$this->_config['dbname'],
|
||||
$this->_config['charset']);
|
||||
|
||||
// check the connection
|
||||
if (!$this->_connection) {
|
||||
@ -135,6 +133,17 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) (is_resource($this->_connection)
|
||||
&& get_resource_type($this->_connection) == 'oci8 connection'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the connection to close.
|
||||
*
|
||||
@ -142,12 +151,43 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function closeConnection()
|
||||
{
|
||||
if (is_resource($this->_connection)) {
|
||||
if ($this->isConnected()) {
|
||||
oci_close($this->_connection);
|
||||
}
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate/deactivate return of LOB as string
|
||||
*
|
||||
* @param string $lob_as_string
|
||||
* @return Zend_Db_Adapter_Oracle
|
||||
*/
|
||||
public function setLobAsString($lobAsString)
|
||||
{
|
||||
$this->_lobAsString = (bool) $lobAsString;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not LOB are returned as string
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLobAsString()
|
||||
{
|
||||
if ($this->_lobAsString === null) {
|
||||
// if never set by user, we use driver option if it exists otherwise false
|
||||
if (isset($this->_config['driver_options']) &&
|
||||
isset($this->_config['driver_options']['lob_as_string'])) {
|
||||
$this->_lobAsString = (bool) $this->_config['driver_options']['lob_as_string'];
|
||||
} else {
|
||||
$this->_lobAsString = false;
|
||||
}
|
||||
}
|
||||
return $this->_lobAsString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an SQL statement for preparation.
|
||||
*
|
||||
@ -158,8 +198,14 @@ class Zend_Db_Adapter_Oracle 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);
|
||||
if ($stmt instanceof Zend_Db_Statement_Oracle) {
|
||||
$stmt->setLobAsString($this->getLobAsString());
|
||||
}
|
||||
$stmt->setFetchMode($this->_fetchMode);
|
||||
return $stmt;
|
||||
}
|
||||
@ -301,21 +347,46 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_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 UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
|
||||
$bind[':TBNAME'] = $tableName;
|
||||
if ($schemaName) {
|
||||
$sql .= ' AND UPPER(TB.OWNER) = UPPER(: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);
|
||||
|
||||
@ -486,12 +557,12 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_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;
|
||||
}
|
||||
|
||||
@ -565,48 +636,6 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates table rows with specified data based on a WHERE clause.
|
||||
*
|
||||
* @param mixed $table The table to update.
|
||||
* @param array $bind Column-value pairs.
|
||||
* @param array|string $where UPDATE WHERE clause(s).
|
||||
* @return int The number of affected rows.
|
||||
*/
|
||||
public function update($table, array $bind, $where = '')
|
||||
{
|
||||
$i = 0;
|
||||
// build "col = ?" pairs for the statement
|
||||
$set = array();
|
||||
foreach ($bind as $col => $val) {
|
||||
if ($val instanceof Zend_Db_Expr) {
|
||||
$val = $val->__toString();
|
||||
unset($bind[$col]);
|
||||
} else {
|
||||
unset($bind[$col]);
|
||||
$bind[':'.$col.$i] = $val;
|
||||
$val = ':'.$col.$i;
|
||||
}
|
||||
$set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = implode(' AND ', $where);
|
||||
}
|
||||
|
||||
// build the statement
|
||||
$sql = "UPDATE "
|
||||
. $this->quoteIdentifier($table, true)
|
||||
. ' SET ' . implode(', ', $set)
|
||||
. (($where) ? " WHERE $where" : '');
|
||||
|
||||
// execute the statement and return the number of affected rows
|
||||
$stmt = $this->query($sql, $bind);
|
||||
$result = $stmt->rowCount();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the adapter supports real SQL parameters.
|
||||
*
|
||||
@ -624,5 +653,24 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
$version = oci_server_version($this->_connection);
|
||||
if ($version !== false) {
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} 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: 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.
|
||||
*
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Profiler
|
||||
* @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: Profiler.php 9101 2008-03-30 19:54:38Z thomas $
|
||||
* @version $Id: Profiler.php 15403 2009-05-08 12:13:49Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
|
||||
@ -247,7 +247,7 @@ class Zend_Db_Profiler
|
||||
|
||||
// make sure we have a query type
|
||||
if (null === $queryType) {
|
||||
switch (strtolower(substr($queryText, 0, 6))) {
|
||||
switch (strtolower(substr(ltrim($queryText), 0, 6))) {
|
||||
case 'insert':
|
||||
$queryType = self::INSERT;
|
||||
break;
|
||||
|
@ -95,6 +95,7 @@ class Zend_Db_Profiler_Firebug extends Zend_Db_Profiler
|
||||
$this->_message->setBuffered(true);
|
||||
$this->_message->setHeader(array('Time','Event','Parameters'));
|
||||
$this->_message->setDestroy(true);
|
||||
$this->_message->setOption('includeLineNumbers', false);
|
||||
Zend_Wildfire_Plugin_FirePhp::getInstance()->send($this->_message);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,13 @@ class Zend_Db_Select
|
||||
const SQL_ASC = 'ASC';
|
||||
const SQL_DESC = 'DESC';
|
||||
|
||||
/**
|
||||
* Bind variables for query
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_bind = array();
|
||||
|
||||
/**
|
||||
* Zend_Db_Adapter_Abstract object.
|
||||
*
|
||||
@ -159,6 +166,29 @@ class Zend_Db_Select
|
||||
$this->_parts = self::$_partsInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bind variables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBind()
|
||||
{
|
||||
return $this->_bind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bind variables
|
||||
*
|
||||
* @param mixed $bind
|
||||
* @return Zend_Db_Select
|
||||
*/
|
||||
public function bind($bind)
|
||||
{
|
||||
$this->_bind = $bind;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the query SELECT DISTINCT.
|
||||
*
|
||||
@ -632,10 +662,15 @@ class Zend_Db_Select
|
||||
* Executes the current select object and returns the result
|
||||
*
|
||||
* @param integer $fetchMode OPTIONAL
|
||||
* @param mixed $bind An array of data to bind to the placeholders.
|
||||
* @return PDO_Statement|Zend_Db_Statement
|
||||
*/
|
||||
public function query($fetchMode = null)
|
||||
public function query($fetchMode = null, $bind = array())
|
||||
{
|
||||
if (!empty($bind)) {
|
||||
$this->bind($bind);
|
||||
}
|
||||
|
||||
$stmt = $this->_adapter->query($this);
|
||||
if ($fetchMode == null) {
|
||||
$fetchMode = $this->_adapter->getFetchMode();
|
||||
@ -730,7 +765,7 @@ class Zend_Db_Select
|
||||
$correlationName = $_correlationName;
|
||||
} else {
|
||||
// We assume just an array of identifiers, with no correlation name
|
||||
$tableName = $name;
|
||||
$tableName = $_tableName;
|
||||
$correlationName = $this->_uniqueCorrelation($tableName);
|
||||
}
|
||||
break;
|
||||
@ -1233,7 +1268,7 @@ class Zend_Db_Select
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
$sql = '';
|
||||
}
|
||||
return $sql;
|
||||
return (string)$sql;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ abstract class Zend_Db_Statement implements Zend_Db_Statement_Interface
|
||||
$data[] = $row;
|
||||
}
|
||||
} else {
|
||||
while ($val = $this->fetchColumn($col)) {
|
||||
while (false !== ($val = $this->fetchColumn($col))) {
|
||||
$data[] = $val;
|
||||
}
|
||||
}
|
||||
@ -445,4 +445,14 @@ abstract class Zend_Db_Statement implements Zend_Db_Statement_Interface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Zend_Db_Adapter_Abstract for this
|
||||
* particular Zend_Db_Statement object.
|
||||
*
|
||||
* @return Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->_adapter;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,9 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
{
|
||||
$connection = $this->_adapter->getConnection();
|
||||
|
||||
$this->_stmt = db2_prepare($connection, $sql);
|
||||
// db2_prepare on i5 emits errors, these need to be
|
||||
// suppressed so that proper exceptions can be thrown
|
||||
$this->_stmt = @db2_prepare($connection, $sql);
|
||||
|
||||
if (!$this->_stmt) {
|
||||
/**
|
||||
@ -102,8 +104,8 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Db2/Exception.php';
|
||||
throw new Zend_Db_Statement_Db2_Exception(
|
||||
db2_stmt_errormsg($this->_stmt),
|
||||
db2_stmt_error($this->_stmt)
|
||||
db2_stmt_errormsg(),
|
||||
db2_stmt_error()
|
||||
);
|
||||
}
|
||||
|
||||
@ -149,10 +151,15 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
public function errorCode()
|
||||
{
|
||||
if (!$this->_stmt) {
|
||||
return '0000';
|
||||
return false;
|
||||
}
|
||||
|
||||
return db2_stmt_error($this->_stmt);
|
||||
$error = db2_stmt_error();
|
||||
if ($error === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,18 +170,19 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
if (!$this->_stmt) {
|
||||
return array(false, 0, '');
|
||||
}
|
||||
$error = $this->errorCode();
|
||||
if ($error === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return three-valued array like PDO. But DB2 does not distinguish
|
||||
* between SQLCODE and native RDBMS error code, so repeat the SQLCODE.
|
||||
*/
|
||||
return array(
|
||||
db2_stmt_error($this->_stmt),
|
||||
db2_stmt_error($this->_stmt),
|
||||
db2_stmt_errormsg($this->_stmt)
|
||||
$error,
|
||||
$error,
|
||||
db2_stmt_errormsg()
|
||||
);
|
||||
}
|
||||
|
||||
@ -204,8 +212,8 @@ class Zend_Db_Statement_Db2 extends Zend_Db_Statement
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Db2/Exception.php';
|
||||
throw new Zend_Db_Statement_Db2_Exception(
|
||||
db2_stmt_errormsg($this->_stmt),
|
||||
db2_stmt_error($this->_stmt));
|
||||
db2_stmt_errormsg(),
|
||||
db2_stmt_error());
|
||||
}
|
||||
|
||||
$this->_keys = array();
|
||||
|
@ -51,6 +51,36 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
*/
|
||||
protected $_values;
|
||||
|
||||
/**
|
||||
* Check if LOB field are returned as string
|
||||
* instead of OCI-Lob object
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_lobAsString = false;
|
||||
|
||||
/**
|
||||
* Activate/deactivate return of LOB as string
|
||||
*
|
||||
* @param string $lob_as_string
|
||||
* @return Zend_Db_Statement_Oracle
|
||||
*/
|
||||
public function setLobAsString($lob_as_string)
|
||||
{
|
||||
$this->_lobAsString = (bool) $lob_as_string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not LOB are returned as string
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLobAsString()
|
||||
{
|
||||
return $this->_lobAsString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares statement handle
|
||||
*
|
||||
@ -279,21 +309,23 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
$style = $this->_fetchMode;
|
||||
}
|
||||
|
||||
$lob_as_string = $this->getLobAsString() ? OCI_RETURN_LOBS : 0;
|
||||
|
||||
switch ($style) {
|
||||
case Zend_Db::FETCH_NUM:
|
||||
$row = oci_fetch_row($this->_stmt);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_NUM | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_ASSOC:
|
||||
$row = oci_fetch_assoc($this->_stmt);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_ASSOC | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_BOTH:
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
|
||||
break;
|
||||
case Zend_Db::FETCH_OBJ:
|
||||
$row = oci_fetch_object($this->_stmt);
|
||||
break;
|
||||
case Zend_Db::FETCH_BOUND:
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH);
|
||||
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
|
||||
if ($row !== false) {
|
||||
return $this->_fetchBound($row);
|
||||
}
|
||||
@ -320,6 +352,10 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
|
||||
unset($row['zend_db_rownum']);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
@ -404,6 +440,11 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
if ($style == Zend_Db::FETCH_COLUMN) {
|
||||
$result = $result[$col];
|
||||
}
|
||||
foreach ($result as &$row) {
|
||||
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
|
||||
unset($row['zend_db_rownum']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (($row = oci_fetch_object($this->_stmt)) !== false) {
|
||||
$result [] = $row;
|
||||
@ -435,7 +476,15 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
}
|
||||
|
||||
if (!oci_fetch($this->_stmt)) {
|
||||
/* TODO ERROR */
|
||||
// if no error, there is simply no record
|
||||
if (!$error = oci_error($this->_stmt)) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Oracle_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
$data = oci_result($this->_stmt, $col+1); //1-based
|
||||
@ -446,10 +495,18 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
|
||||
}
|
||||
|
||||
if ($this->getLobAsString()) {
|
||||
// instanceof doesn't allow '-', we must use a temporary string
|
||||
$type = 'OCI-Lob';
|
||||
if ($data instanceof $type) {
|
||||
$data = $data->read($data->size());
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the next row and returns it as an object.
|
||||
*
|
||||
@ -466,12 +523,12 @@ class Zend_Db_Statement_Oracle extends Zend_Db_Statement
|
||||
|
||||
$obj = oci_fetch_object($this->_stmt);
|
||||
|
||||
if ($obj === false) {
|
||||
if ($error = oci_error($this->_stmt)) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Oracle_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Oracle/Exception.php';
|
||||
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
|
||||
throw new Zend_Db_Statement_Oracle_Exception($error);
|
||||
}
|
||||
|
||||
/* @todo XXX handle parameters */
|
||||
|
@ -37,11 +37,11 @@ require_once 'Zend/Db/Statement.php';
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
* The mysqli_stmt object.
|
||||
* The statement object.
|
||||
*
|
||||
* @var PDOStatement
|
||||
*/
|
||||
@ -82,7 +82,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
public function bindColumn($column, &$param, $type = null)
|
||||
{
|
||||
try {
|
||||
if (is_null($type)) {
|
||||
if ($type === null) {
|
||||
return $this->_stmt->bindColumn($column, $param);
|
||||
} else {
|
||||
return $this->_stmt->bindColumn($column, $param, $type);
|
||||
@ -110,7 +110,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
if ($type === null) {
|
||||
if (is_bool($variable)) {
|
||||
$type = PDO::PARAM_BOOL;
|
||||
} elseif (is_null($variable)) {
|
||||
} elseif ($variable === null) {
|
||||
$type = PDO::PARAM_NULL;
|
||||
} elseif (is_integer($variable)) {
|
||||
$type = PDO::PARAM_INT;
|
||||
@ -140,7 +140,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
$parameter = ":$parameter";
|
||||
}
|
||||
try {
|
||||
if (is_null($type)) {
|
||||
if ($type === null) {
|
||||
return $this->_stmt->bindValue($parameter, $value);
|
||||
} else {
|
||||
return $this->_stmt->bindValue($parameter, $value, $type);
|
||||
@ -261,6 +261,16 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by IteratorAggregate interface
|
||||
*
|
||||
* @return IteratorIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new IteratorIterator($this->_stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the result set rows.
|
||||
*
|
||||
|
@ -80,7 +80,7 @@ class Zend_Db_Statement_Pdo_Ibm extends Zend_Db_Statement_Pdo
|
||||
public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
|
||||
{
|
||||
try {
|
||||
if ( is_null($type) && is_null($length) && is_null($options) ) {
|
||||
if (($type === null) && ($length === null) && ($options === null)) {
|
||||
return $this->_stmt->bindParam($parameter, $variable);
|
||||
} else {
|
||||
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
|
||||
|
69
libs/Zend/Db/Statement/Pdo/Oci.php
Normal file
69
libs/Zend/Db/Statement/Pdo/Oci.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Statement
|
||||
* @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: Mysqli.php 4874 2007-05-19 01:26:32Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Statement_Pdo
|
||||
*/
|
||||
require_once 'Zend/Db/Statement/Pdo.php';
|
||||
|
||||
/**
|
||||
* Proxy class to wrap a PDOStatement object for IBM Databases.
|
||||
* Matches the interface of PDOStatement. All methods simply proxy to the
|
||||
* matching method in PDOStatement. PDOExceptions thrown by PDOStatement
|
||||
* are re-thrown as Zend_Db_Statement_Exception.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Statement
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Statement_Pdo_Oci extends Zend_Db_Statement_Pdo
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the result set rows.
|
||||
*
|
||||
* Behaves like parent, but if limit()
|
||||
* is used, the final result removes the extra column
|
||||
* 'zend_db_rownum'
|
||||
*
|
||||
* @param int $style OPTIONAL Fetch mode.
|
||||
* @param int $col OPTIONAL Column number, if fetch mode is by column.
|
||||
* @return array Collection of rows, each in a format by the fetch mode.
|
||||
* @throws Zend_Db_Statement_Exception
|
||||
*/
|
||||
public function fetchAll($style = null, $col = null)
|
||||
{
|
||||
$data = parent::fetchAll($style, $col);
|
||||
$results = array();
|
||||
$remove = $this->_adapter->foldCase('zend_db_rownum');
|
||||
|
||||
foreach ($data as $row) {
|
||||
if (is_array($row) && array_key_exists($remove, $row)) {
|
||||
unset($row[$remove]);
|
||||
}
|
||||
$results[] = $row;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
@ -325,6 +325,37 @@ abstract class Zend_Db_Table_Abstract
|
||||
return $this->_rowsetClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reference to the reference map
|
||||
*
|
||||
* @param string $ruleKey
|
||||
* @param string|array $columns
|
||||
* @param string $refTableClass
|
||||
* @param string|array $refColumns
|
||||
* @param string $onDelete
|
||||
* @param string $onUpdate
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
public function addReference($ruleKey, $columns, $refTableClass, $refColumns,
|
||||
$onDelete = null, $onUpdate = null)
|
||||
{
|
||||
$reference = array(self::COLUMNS => (array) $columns,
|
||||
self::REF_TABLE_CLASS => $refTableClass,
|
||||
self::REF_COLUMNS => (array) $refColumns);
|
||||
|
||||
if (!empty($onDelete)) {
|
||||
$reference[self::ON_DELETE] = $onDelete;
|
||||
}
|
||||
|
||||
if (!empty($onUpdate)) {
|
||||
$reference[self::ON_UPDATE] = $onUpdate;
|
||||
}
|
||||
|
||||
$this->_referenceMap[$ruleKey] = $reference;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $referenceMap
|
||||
* @return Zend_Db_Table_Abstract Provides a fluent interface
|
||||
@ -546,10 +577,10 @@ abstract class Zend_Db_Table_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether metadata should be cached in the class for the duration
|
||||
* Indicate whether metadata should be cached in the class for the duration
|
||||
* of the instance
|
||||
*
|
||||
* @param bool $flag
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
public function setMetadataCacheInClass($flag)
|
||||
@ -559,9 +590,9 @@ abstract class Zend_Db_Table_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve flag indicating if metadata should be cached for duration of
|
||||
* Retrieve flag indicating if metadata should be cached for duration of
|
||||
* instance
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function metadataCacheInClass()
|
||||
@ -713,7 +744,7 @@ abstract class Zend_Db_Table_Abstract
|
||||
|
||||
/**
|
||||
* Retrieve table columns
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getCols()
|
||||
@ -945,6 +976,29 @@ abstract class Zend_Db_Table_Abstract
|
||||
return $pkData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided column is an identity of the table
|
||||
*
|
||||
* @param string $column
|
||||
* @throws Zend_Db_Table_Exception
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIdentity($column)
|
||||
{
|
||||
$this->_setupPrimaryKey();
|
||||
|
||||
if (!isset($this->_metadata[$column])) {
|
||||
/**
|
||||
* @see Zend_Db_Table_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Table/Exception.php';
|
||||
|
||||
throw new Zend_Db_Table_Exception('Column "' . $column . '" not found in table.');
|
||||
}
|
||||
|
||||
return (bool) $this->_metadata[$column]['IDENTITY'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates existing rows.
|
||||
*
|
||||
@ -1105,11 +1159,11 @@ abstract class Zend_Db_Table_Abstract
|
||||
$whereClause = null;
|
||||
if (count($whereList)) {
|
||||
$whereOrTerms = array();
|
||||
$tableName = $this->_db->quoteTableAs($this->_name, null, true);
|
||||
foreach ($whereList as $keyValueSets) {
|
||||
$whereAndTerms = array();
|
||||
foreach ($keyValueSets as $keyPosition => $keyValue) {
|
||||
$type = $this->_metadata[$keyNames[$keyPosition]]['DATA_TYPE'];
|
||||
$tableName = $this->_db->quoteTableAs($this->_name, null, true);
|
||||
$columnName = $this->_db->quoteIdentifier($keyNames[$keyPosition], true);
|
||||
$whereAndTerms[] = $this->_db->quoteInto(
|
||||
$tableName . '.' . $columnName . ' = ?',
|
||||
@ -1165,17 +1219,20 @@ abstract class Zend_Db_Table_Abstract
|
||||
'stored' => true
|
||||
);
|
||||
|
||||
@Zend_Loader::loadClass($this->_rowsetClass);
|
||||
if (!class_exists($this->_rowsetClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_rowsetClass);
|
||||
}
|
||||
return new $this->_rowsetClass($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches one row in an object of type Zend_Db_Table_Row_Abstract,
|
||||
* or returns Boolean false if no row matches the specified criteria.
|
||||
* or returns null if no row matches the specified criteria.
|
||||
*
|
||||
* @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
|
||||
* @param string|array $order OPTIONAL An SQL ORDER clause.
|
||||
* @return Zend_Db_Table_Row_Abstract The row results per the
|
||||
* @return Zend_Db_Table_Row_Abstract|null The row results per the
|
||||
* Zend_Db_Adapter fetch mode, or null if no row found.
|
||||
*/
|
||||
public function fetchRow($where = null, $order = null)
|
||||
@ -1210,7 +1267,10 @@ abstract class Zend_Db_Table_Abstract
|
||||
'stored' => true
|
||||
);
|
||||
|
||||
@Zend_Loader::loadClass($this->_rowClass);
|
||||
if (!class_exists($this->_rowClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_rowClass);
|
||||
}
|
||||
return new $this->_rowClass($data);
|
||||
}
|
||||
|
||||
@ -1269,7 +1329,10 @@ abstract class Zend_Db_Table_Abstract
|
||||
'stored' => false
|
||||
);
|
||||
|
||||
@Zend_Loader::loadClass($this->_rowClass);
|
||||
if (!class_exists($this->_rowClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_rowClass);
|
||||
}
|
||||
$row = new $this->_rowClass($config);
|
||||
$row->setFromArray($data);
|
||||
return $row;
|
||||
|
@ -25,11 +25,6 @@
|
||||
*/
|
||||
require_once 'Zend/Db.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
@ -121,6 +116,12 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
|
||||
$this->_table = $config['table'];
|
||||
$this->_tableClass = get_class($this->_table);
|
||||
} else if ($this->_tableClass !== null) {
|
||||
if (!class_exists($this->_tableClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_tableClass);
|
||||
}
|
||||
$this->_table = new $this->_tableClass();
|
||||
}
|
||||
|
||||
if (isset($config['data'])) {
|
||||
@ -203,6 +204,28 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$this->_modifiedFields[$columnName] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset row field value
|
||||
*
|
||||
* @param string $columnName The column key.
|
||||
* @return Zend_Db_Table_Row_Abstract
|
||||
* @throws Zend_Db_Table_Row_Exception
|
||||
*/
|
||||
public function __unset($columnName)
|
||||
{
|
||||
$columnName = $this->_transformColumn($columnName);
|
||||
if (!array_key_exists($columnName, $this->_data)) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
|
||||
}
|
||||
if ($this->isConnected() && in_array($columnName, $this->_table->info('primary'))) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is a primary key and should not be unset");
|
||||
}
|
||||
unset($this->_data[$columnName]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test existence of row field
|
||||
*
|
||||
@ -453,7 +476,9 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (is_array($primaryKey)) {
|
||||
$newPrimaryKey = $primaryKey;
|
||||
} else {
|
||||
$newPrimaryKey = array(current((array) $this->_primary) => $primaryKey);
|
||||
//ZF-6167 Use tempPrimaryKey temporary to avoid that zend encoding fails.
|
||||
$tempPrimaryKey = (array) $this->_primary;
|
||||
$newPrimaryKey = array(current($tempPrimaryKey) => $primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -524,11 +549,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$pkNew = $this->_getPrimaryKey(true);
|
||||
$pkOld = $this->_getPrimaryKey(false);
|
||||
foreach ($depTables as $tableClass) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
|
||||
@ -602,11 +630,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
$pk = $this->_getPrimaryKey();
|
||||
foreach ($depTables as $tableClass) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t->_cascadeDelete($this->getTableClass(), $pk);
|
||||
@ -855,11 +886,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($dependentTable)) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($dependentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($dependentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($dependentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$dependentTable = new $dependentTable(array('db' => $db));
|
||||
}
|
||||
@ -900,6 +934,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
*
|
||||
* @param string|Zend_Db_Table_Abstract $parentTable
|
||||
* @param string OPTIONAL $ruleKey
|
||||
* @param Zend_Db_Table_Select OPTIONAL $select
|
||||
* @return Zend_Db_Table_Row_Abstract Query result from $parentTable
|
||||
* @throws Zend_Db_Table_Row_Exception If $parentTable is not a table or is not loadable.
|
||||
*/
|
||||
@ -908,11 +943,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($parentTable)) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($parentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($parentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($parentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$parentTable = new $parentTable(array('db' => $db));
|
||||
}
|
||||
@ -951,8 +989,9 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
/**
|
||||
* @param string|Zend_Db_Table_Abstract $matchTable
|
||||
* @param string|Zend_Db_Table_Abstract $intersectionTable
|
||||
* @param string OPTIONAL $primaryRefRule
|
||||
* @param string OPTIONAL $callerRefRule
|
||||
* @param string OPTIONAL $matchRefRule
|
||||
* @param Zend_Db_Table_Select OPTIONAL $select
|
||||
* @return Zend_Db_Table_Rowset_Abstract Query result from $matchTable
|
||||
* @throws Zend_Db_Table_Row_Exception If $matchTable or $intersectionTable is not a table class or is not loadable.
|
||||
*/
|
||||
@ -962,11 +1001,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($intersectionTable)) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($intersectionTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($intersectionTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($intersectionTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$intersectionTable = new $intersectionTable(array('db' => $db));
|
||||
}
|
||||
@ -980,11 +1022,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
}
|
||||
|
||||
if (is_string($matchTable)) {
|
||||
try {
|
||||
@Zend_Loader::loadClass($matchTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($matchTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($matchTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$matchTable = new $matchTable(array('db' => $db));
|
||||
}
|
||||
@ -1007,8 +1052,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$interInfo = $intersectionTable->info();
|
||||
$interDb = $intersectionTable->getAdapter();
|
||||
$interName = $interInfo['name'];
|
||||
$interSchema = isset($interInfo['schema']) ? $interInfo['schema'] : null;
|
||||
$matchInfo = $matchTable->info();
|
||||
$matchName = $matchInfo['name'];
|
||||
$matchSchema = isset($matchInfo['schema']) ? $matchInfo['schema'] : null;
|
||||
|
||||
$matchMap = $this->_prepareReference($intersectionTable, $matchTable, $matchRefRule);
|
||||
|
||||
@ -1019,8 +1066,8 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
}
|
||||
$joinCond = implode(' AND ', $joinCond);
|
||||
|
||||
$select->from(array('i' => $interName))
|
||||
->joinInner(array('m' => $matchName), $joinCond)
|
||||
$select->from(array('i' => $interName), Zend_Db_Select::SQL_WILDCARD, $interSchema)
|
||||
->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
|
||||
->setIntegrityCheck(false);
|
||||
|
||||
$callerMap = $this->_prepareReference($intersectionTable, $this->_getTable(), $callerRefRule);
|
||||
@ -1046,11 +1093,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
);
|
||||
|
||||
$rowsetClass = $matchTable->getRowsetClass();
|
||||
try {
|
||||
@Zend_Loader::loadClass($rowsetClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
if (!class_exists($rowsetClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($rowsetClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$rowset = new $rowsetClass($config);
|
||||
return $rowset;
|
||||
|
@ -20,11 +20,6 @@
|
||||
* @version $Id: Abstract.php 5896 2007-07-27 20:04:24Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
@ -116,7 +111,10 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
if (isset($config['rowClass'])) {
|
||||
$this->_rowClass = $config['rowClass'];
|
||||
}
|
||||
@Zend_Loader::loadClass($this->_rowClass);
|
||||
if (!class_exists($this->_rowClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_rowClass);
|
||||
}
|
||||
if (isset($config['data'])) {
|
||||
$this->_data = $config['data'];
|
||||
}
|
||||
@ -129,7 +127,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
|
||||
// set the count of rows
|
||||
$this->_count = count($this->_data);
|
||||
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
@ -310,7 +308,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
{
|
||||
return $this->_count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Take the Iterator to position $position
|
||||
* Required by interface SeekableIterator.
|
||||
@ -322,14 +320,14 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
public function seek($position)
|
||||
{
|
||||
$position = (int) $position;
|
||||
if ($position < 0 || $position > $this->_count) {
|
||||
if ($position < 0 || $position >= $this->_count) {
|
||||
require_once 'Zend/Db/Table/Rowset/Exception.php';
|
||||
throw new Zend_Db_Table_Rowset_Exception("Illegal index $position");
|
||||
}
|
||||
$this->_pointer = $position;
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an offset exists
|
||||
* Required by the ArrayAccess implementation
|
||||
@ -341,7 +339,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
{
|
||||
return isset($this->_data[(int) $offset]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the row for the given offset
|
||||
* Required by the ArrayAccess implementation
|
||||
@ -355,7 +353,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
|
||||
return $this->current();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
* Required by the ArrayAccess implementation
|
||||
@ -366,7 +364,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
* Required by the ArrayAccess implementation
|
||||
|
@ -65,7 +65,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
* @var Zend_Db_Table_Abstract
|
||||
*/
|
||||
protected $_table;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@ -74,6 +74,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
public function __construct(Zend_Db_Table_Abstract $table)
|
||||
{
|
||||
parent::__construct($table->getAdapter());
|
||||
|
||||
$this->setTable($table);
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
{
|
||||
return $this->_table;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the primary table name and retrieves the table schema.
|
||||
*
|
||||
@ -98,7 +99,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
$this->_adapter = $table->getAdapter();
|
||||
$this->_info = $table->info();
|
||||
$this->_table = $table;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -139,7 +140,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
if ($alias !== null) {
|
||||
$column = $alias;
|
||||
}
|
||||
|
||||
|
||||
switch (true) {
|
||||
case ($column == self::SQL_WILDCARD):
|
||||
break;
|
||||
@ -159,8 +160,8 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
*
|
||||
* The table name can be expressed
|
||||
*
|
||||
* @param array|string|Zend_Db_Expr|Zend_Db_Table_Abstract $name The table name or an
|
||||
associative array relating
|
||||
* @param array|string|Zend_Db_Expr|Zend_Db_Table_Abstract $name The table name or an
|
||||
associative array relating
|
||||
table name to correlation
|
||||
name.
|
||||
* @param array|string|Zend_Db_Expr $cols The columns to select from this table.
|
||||
@ -203,7 +204,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
if ($this->_integrityCheck !== false) {
|
||||
foreach ($fields as $columnEntry) {
|
||||
list($table, $column) = $columnEntry;
|
||||
|
||||
|
||||
// Check each column to ensure it only references the primary table
|
||||
if ($column) {
|
||||
if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {
|
||||
@ -216,4 +217,4 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
|
||||
return parent::assemble();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user