2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DataSource base class
|
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:46 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2012-03-13 02:46:46 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Model.Datasource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.10.5.1790
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* DataSource base class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Model.Datasource
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class DataSource extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Are we connected to the DataSource?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $connected = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The default configuration of a specific DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_baseConfig = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds references to descriptions loaded by the DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-08-20 04:43:34 +00:00
|
|
|
protected $_descriptions = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds a list of sources (tables) contained in the DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_sources = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The DataSource configuration
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $config = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Whether or not this DataSource is in the middle of a transaction
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_transactionStarted = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Whether or not source data like available tables and schema descriptions
|
|
|
|
* should be cached
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheSources = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
2009-12-19 18:23:46 +00:00
|
|
|
*
|
|
|
|
* @param array $config Array of configuration information for the datasource.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-05-28 20:38:46 +00:00
|
|
|
public function __construct($config = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
parent::__construct();
|
2008-08-01 06:08:23 +00:00
|
|
|
$this->setConfig($config);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Caches/returns cached results for child instances
|
|
|
|
*
|
2009-12-19 18:23:46 +00:00
|
|
|
* @param mixed $data
|
|
|
|
* @return array Array of sources available in this datasource.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function listSources($data = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->cacheSources === false) {
|
|
|
|
return null;
|
|
|
|
}
|
2008-08-07 15:36:26 +00:00
|
|
|
|
|
|
|
if ($this->_sources !== null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_sources;
|
|
|
|
}
|
|
|
|
|
2008-08-12 21:08:51 +00:00
|
|
|
$key = ConnectionManager::getSourceName($this) . '_' . $this->config['database'] . '_list';
|
2008-08-14 16:52:29 +00:00
|
|
|
$key = preg_replace('/[^A-Za-z0-9_\-.+]/', '_', $key);
|
2008-05-30 11:40:08 +00:00
|
|
|
$sources = Cache::read($key, '_cake_model_');
|
|
|
|
|
2008-07-26 20:00:20 +00:00
|
|
|
if (empty($sources)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$sources = $data;
|
2008-07-26 20:00:20 +00:00
|
|
|
Cache::write($key, $data, '_cake_model_');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 00:41:27 +00:00
|
|
|
return $this->_sources = $sources;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a Model description (metadata) or null if none found.
|
|
|
|
*
|
2011-09-03 15:57:58 +00:00
|
|
|
* @param Model|string $model
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return array Array of Metadata for the $model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-09-03 15:57:58 +00:00
|
|
|
public function describe($model) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->cacheSources === false) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-09-03 15:57:58 +00:00
|
|
|
if (is_string($model)) {
|
|
|
|
$table = $model;
|
|
|
|
} else {
|
|
|
|
$table = $model->tablePrefix . $model->table;
|
|
|
|
}
|
2010-01-14 04:14:06 +00:00
|
|
|
|
2011-08-20 04:43:34 +00:00
|
|
|
if (isset($this->_descriptions[$table])) {
|
|
|
|
return $this->_descriptions[$table];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-08-20 05:39:30 +00:00
|
|
|
$cache = $this->_cacheDescription($table);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if ($cache !== null) {
|
2011-08-20 04:43:34 +00:00
|
|
|
$this->_descriptions[$table] =& $cache;
|
2008-05-30 11:40:08 +00:00
|
|
|
return $cache;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Begin a transaction
|
|
|
|
*
|
|
|
|
* @return boolean Returns true if a transaction is not in progress
|
|
|
|
*/
|
2010-12-04 19:15:32 +00:00
|
|
|
public function begin() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return !$this->_transactionStarted;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Commit a transaction
|
|
|
|
*
|
|
|
|
* @return boolean Returns true if a transaction is in progress
|
|
|
|
*/
|
2010-12-04 19:15:32 +00:00
|
|
|
public function commit() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_transactionStarted;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Rollback a transaction
|
|
|
|
*
|
|
|
|
* @return boolean Returns true if a transaction is in progress
|
|
|
|
*/
|
2010-12-04 19:15:32 +00:00
|
|
|
public function rollback() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_transactionStarted;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Converts column types to basic types
|
|
|
|
*
|
|
|
|
* @param string $real Real column type (i.e. "varchar(255)")
|
|
|
|
* @return string Abstract column type (i.e. "string")
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function column($real) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-20 01:09:47 +00:00
|
|
|
* Used to create new records. The "C" CRUD.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* To-be-overridden in subclasses.
|
|
|
|
*
|
2009-10-20 01:09:47 +00:00
|
|
|
* @param Model $model The Model to be created.
|
|
|
|
* @param array $fields An Array of fields to be saved.
|
|
|
|
* @param array $values An Array of values to save.
|
|
|
|
* @return boolean success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-02-25 00:41:27 +00:00
|
|
|
public function create(Model $model, $fields = null, $values = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-20 01:09:47 +00:00
|
|
|
* Used to read records from the Datasource. The "R" in CRUD
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* To-be-overridden in subclasses.
|
|
|
|
*
|
2009-10-20 01:09:47 +00:00
|
|
|
* @param Model $model The model being read.
|
|
|
|
* @param array $queryData An array of query data used to find the data you want
|
2012-08-19 21:00:26 +00:00
|
|
|
* @param integer $recursive Number of levels of association
|
2009-10-20 01:09:47 +00:00
|
|
|
* @return mixed
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-08-19 21:00:26 +00:00
|
|
|
public function read(Model $model, $queryData = array(), $recursive = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-20 01:09:47 +00:00
|
|
|
* Update a record(s) in the datasource.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* To-be-overridden in subclasses.
|
|
|
|
*
|
2009-10-20 01:09:47 +00:00
|
|
|
* @param Model $model Instance of the model class being updated
|
|
|
|
* @param array $fields Array of fields to be updated
|
|
|
|
* @param array $values Array of values to be update $fields to.
|
2012-08-19 21:00:26 +00:00
|
|
|
* @param mixed $conditions
|
2009-10-20 01:09:47 +00:00
|
|
|
* @return boolean Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-08-19 21:00:26 +00:00
|
|
|
public function update(Model $model, $fields = null, $values = null, $conditions = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-20 01:09:47 +00:00
|
|
|
* Delete a record(s) in the datasource.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* To-be-overridden in subclasses.
|
|
|
|
*
|
2009-10-20 01:09:47 +00:00
|
|
|
* @param Model $model The model class having record(s) deleted
|
2011-10-06 02:10:14 +00:00
|
|
|
* @param mixed $conditions The conditions to use for deleting.
|
2011-07-30 22:38:57 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-02-25 00:41:27 +00:00
|
|
|
public function delete(Model $model, $id = null) {
|
2011-10-06 02:10:14 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID generated from the previous INSERT operation.
|
|
|
|
*
|
2011-07-30 22:38:57 +00:00
|
|
|
* @param mixed $source
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return mixed Last ID key generated in previous INSERT
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function lastInsertId($source = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-11-23 02:21:55 +00:00
|
|
|
* Returns the number of rows returned by last operation.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-30 22:38:57 +00:00
|
|
|
* @param mixed $source
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return integer Number of rows returned by last operation
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function lastNumRows($source = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-11-23 02:21:55 +00:00
|
|
|
* Returns the number of rows affected by last query.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-30 22:38:57 +00:00
|
|
|
* @param mixed $source
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return integer Number of rows affected by last query.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function lastAffected($source = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-20 20:11:31 +00:00
|
|
|
/**
|
|
|
|
* Check whether the conditions for the Datasource being available
|
|
|
|
* are satisfied. Often used from connect() to check for support
|
|
|
|
* before establishing a connection.
|
|
|
|
*
|
|
|
|
* @return boolean Whether or not the Datasources conditions for use are met.
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function enabled() {
|
2009-10-20 20:11:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-23 02:21:55 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-12-19 18:23:46 +00:00
|
|
|
* Sets the configuration for the DataSource.
|
|
|
|
* Merges the $config information with the _baseConfig and the existing $config property.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param array $config The configuration array
|
2008-08-01 06:08:23 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setConfig($config = array()) {
|
2008-08-01 06:08:23 +00:00
|
|
|
$this->config = array_merge($this->_baseConfig, $this->config, $config);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Cache the DataSource description
|
|
|
|
*
|
|
|
|
* @param string $object The name of the object (model) to cache
|
|
|
|
* @param mixed $data The description of the model, usually a string or array
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return mixed
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _cacheDescription($object, $data = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->cacheSources === false) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($data !== null) {
|
2011-08-20 04:43:34 +00:00
|
|
|
$this->_descriptions[$object] =& $data;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$key = ConnectionManager::getSourceName($this) . '_' . $object;
|
|
|
|
$cache = Cache::read($key, '_cake_model_');
|
|
|
|
|
|
|
|
if (empty($cache)) {
|
|
|
|
$cache = $data;
|
2008-07-26 20:00:20 +00:00
|
|
|
Cache::write($key, $cache, '_cake_model_');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $cache;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-12-19 18:23:46 +00:00
|
|
|
* Replaces `{$__cakeID__$}` and `{$__cakeForeignKey__$}` placeholders in query data.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-12-19 18:23:46 +00:00
|
|
|
* @param string $query Query string needing replacements done.
|
|
|
|
* @param array $data Array of data with values that will be inserted in placeholders.
|
|
|
|
* @param string $association Name of association model being replaced
|
2011-07-30 22:38:57 +00:00
|
|
|
* @param array $assocData
|
2010-01-14 04:14:06 +00:00
|
|
|
* @param Model $model Instance of the model to replace $__cakeID__$
|
2009-12-19 18:23:46 +00:00
|
|
|
* @param Model $linkModel Instance of model to replace $__cakeForeignKey__$
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param array $stack
|
2009-12-19 18:23:46 +00:00
|
|
|
* @return string String of query data with placeholders replaced.
|
|
|
|
* @todo Remove and refactor $assocData, ensure uses of the method have the param removed too.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-05-28 20:38:46 +00:00
|
|
|
public function insertQueryData($query, $data, $association, $assocData, Model $model, Model $linkModel, $stack) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
|
|
|
|
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$val = null;
|
2010-12-22 01:40:19 +00:00
|
|
|
$type = null;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (strpos($query, $key) !== false) {
|
2008-10-23 00:10:44 +00:00
|
|
|
switch ($key) {
|
2008-05-30 11:40:08 +00:00
|
|
|
case '{$__cakeID__$}':
|
|
|
|
if (isset($data[$model->alias]) || isset($data[$association])) {
|
|
|
|
if (isset($data[$model->alias][$model->primaryKey])) {
|
|
|
|
$val = $data[$model->alias][$model->primaryKey];
|
|
|
|
} elseif (isset($data[$association][$model->primaryKey])) {
|
|
|
|
$val = $data[$association][$model->primaryKey];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$found = false;
|
|
|
|
foreach (array_reverse($stack) as $assoc) {
|
|
|
|
if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) {
|
|
|
|
$val = $data[$assoc][$model->primaryKey];
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
$val = '';
|
|
|
|
}
|
|
|
|
}
|
2010-12-22 01:40:19 +00:00
|
|
|
$type = $model->getColumnType($model->primaryKey);
|
2008-05-30 11:40:08 +00:00
|
|
|
break;
|
|
|
|
case '{$__cakeForeignKey__$}':
|
2010-04-04 08:17:43 +00:00
|
|
|
foreach ($model->associations() as $id => $name) {
|
2008-05-30 11:40:08 +00:00
|
|
|
foreach ($model->$name as $assocName => $assoc) {
|
|
|
|
if ($assocName === $association) {
|
|
|
|
if (isset($assoc['foreignKey'])) {
|
|
|
|
$foreignKey = $assoc['foreignKey'];
|
2010-12-22 01:40:19 +00:00
|
|
|
$assocModel = $model->$assocName;
|
|
|
|
$type = $assocModel->getColumnType($assocModel->primaryKey);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (isset($data[$model->alias][$foreignKey])) {
|
|
|
|
$val = $data[$model->alias][$foreignKey];
|
|
|
|
} elseif (isset($data[$association][$foreignKey])) {
|
|
|
|
$val = $data[$association][$foreignKey];
|
|
|
|
} else {
|
|
|
|
$found = false;
|
|
|
|
foreach (array_reverse($stack) as $assoc) {
|
|
|
|
if (isset($data[$assoc]) && isset($data[$assoc][$foreignKey])) {
|
|
|
|
$val = $data[$assoc][$foreignKey];
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
$val = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (empty($val) && $val !== '0') {
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-22 01:40:19 +00:00
|
|
|
$query = str_replace($key, $this->value($val, $type), $query);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* To-be-overridden in subclasses.
|
|
|
|
*
|
2009-12-19 18:23:46 +00:00
|
|
|
* @param Model $model Model instance
|
|
|
|
* @param string $key Key name to make
|
|
|
|
* @return string Key name for model.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-02-25 00:41:27 +00:00
|
|
|
public function resolveKey(Model $model, $key) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $model->alias . $key;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-05 10:57:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the schema name. Override this in subclasses.
|
|
|
|
*
|
|
|
|
* @return string schema name
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function getSchemaName() {
|
2011-12-29 12:18:37 +00:00
|
|
|
return null;
|
2011-11-05 10:57:08 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:51:18 +00:00
|
|
|
/**
|
|
|
|
* Closes a connection. Override in subclasses
|
2012-07-18 01:55:29 +00:00
|
|
|
*
|
2012-03-16 15:51:18 +00:00
|
|
|
* @return boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function close() {
|
|
|
|
return $this->connected = false;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Closes the current datasource.
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function __destruct() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->_transactionStarted) {
|
2011-02-25 00:41:27 +00:00
|
|
|
$this->rollback();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($this->connected) {
|
|
|
|
$this->close();
|
|
|
|
}
|
|
|
|
}
|
2012-03-04 19:18:04 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|