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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user