mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes to trunk
Revision: [1819] Added fix for undefined index in Form::generateFields() Adding missing doc blocks. Adding fix for Ticket #290. Added fix to allow setting fields for models. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1820 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f718229a04
commit
ee6ccf15b6
9 changed files with 719 additions and 494 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.6.1818 RC 1
|
||||
0.10.6.1820 RC 1
|
|
@ -59,10 +59,10 @@ class ConnectionManager extends Object
|
|||
*/
|
||||
var $_dataSources = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
if(class_exists('DATABASE_CONFIG'))
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.datasources
|
||||
* @since CakePHP v 0.10.x.1379
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
|
@ -35,7 +35,7 @@
|
|||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.datasources
|
||||
* @since CakePHP v 0.10.x.1379
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
*
|
||||
*/
|
||||
class DataSource extends Object
|
||||
|
@ -188,6 +188,10 @@ class DataSource extends Object
|
|||
var $__transactionStarted = false;
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
function __construct ()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -198,11 +202,11 @@ class DataSource extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns true if the DataSource supports the given interface (method)
|
||||
*
|
||||
* @param string $interface The name of the interface (method)
|
||||
* @return boolean True on success
|
||||
*/
|
||||
* Returns true if the DataSource supports the given interface (method)
|
||||
*
|
||||
* @param string $interface The name of the interface (method)
|
||||
* @return boolean True on success
|
||||
*/
|
||||
function isInterfaceSupported ($interface)
|
||||
{
|
||||
$methods = get_class_methods(get_class($this));
|
||||
|
@ -212,11 +216,11 @@ class DataSource extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration for the DataSource
|
||||
*
|
||||
* @param array $config The configuration array
|
||||
* @return void
|
||||
*/
|
||||
* Sets the configuration for the DataSource
|
||||
*
|
||||
* @param array $config The configuration array
|
||||
* @return void
|
||||
*/
|
||||
function setConfig ($config)
|
||||
{
|
||||
if(is_array($this->_baseConfig))
|
||||
|
@ -230,12 +234,12 @@ class DataSource extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return void
|
||||
*/
|
||||
* 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
|
||||
* @return void
|
||||
*/
|
||||
function __cacheDescription ($object, $data = null)
|
||||
{
|
||||
if (DEBUG > 0)
|
||||
|
@ -270,16 +274,34 @@ class DataSource extends Object
|
|||
return $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
*/
|
||||
function name ($name)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $value
|
||||
* @return unknown
|
||||
*/
|
||||
function value ($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return unknown
|
||||
*/
|
||||
function describe ($model)
|
||||
{
|
||||
if (isset($this->__descriptions[$model->table]))
|
||||
|
@ -296,21 +318,50 @@ class DataSource extends Object
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function create (&$model, $fields = null, $values = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $queryData
|
||||
* @return unknown
|
||||
*/
|
||||
function read (&$model, $queryData = array())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function update (&$model, $fields = null, $values = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $id
|
||||
*/
|
||||
function delete (&$model, $id = null)
|
||||
{
|
||||
if ($id == null)
|
||||
|
@ -319,16 +370,41 @@ class DataSource extends Object
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $fields
|
||||
* @return unknown
|
||||
*/
|
||||
function fields ($fields)
|
||||
{
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @return unknown
|
||||
*/
|
||||
function getColumnType (&$model, $fields)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $query
|
||||
* @param unknown_type $data
|
||||
* @param unknown_type $association
|
||||
* @param unknown_type $assocData
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $linkModel
|
||||
* @param unknown_type $index
|
||||
* @return unknown
|
||||
*/
|
||||
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $index)
|
||||
{
|
||||
$keys = array('{$__cake_id__$}', '{$__cake_foreignKey__$}');
|
||||
|
@ -362,11 +438,25 @@ class DataSource extends Object
|
|||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $key
|
||||
* @return unknown
|
||||
*/
|
||||
function resolveKey($model, $key)
|
||||
{
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $data
|
||||
* @param unknown_type $path
|
||||
* @return unknown
|
||||
*/
|
||||
function getFieldValue ($data, $path)
|
||||
{
|
||||
if (!is_array($path))
|
||||
|
@ -418,6 +508,10 @@ class DataSource extends Object
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
function __destruct ()
|
||||
{
|
||||
if ($this->connected)
|
||||
|
|
|
@ -46,9 +46,24 @@ uses('model'.DS.'datasources'.DS.'datasource');
|
|||
*/
|
||||
class DboSource extends DataSource
|
||||
{
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $description = "Database Data Source";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $__bypass = false;
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $__assocJoins = null;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -84,6 +99,11 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function sources ()
|
||||
{
|
||||
return array_map('strtolower', $this->listSources());
|
||||
|
@ -303,6 +323,14 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function create(&$model, $fields = null, $values = null)
|
||||
{
|
||||
if ($fields == null)
|
||||
|
@ -324,6 +352,14 @@ class DboSource extends DataSource
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $queryData
|
||||
* @param unknown_type $recursive
|
||||
* @return unknown
|
||||
*/
|
||||
function read (&$model, $queryData = array(), $recursive = 1)
|
||||
{
|
||||
$this->__scrubQueryData($queryData);
|
||||
|
@ -331,6 +367,11 @@ class DboSource extends DataSource
|
|||
$array = array();
|
||||
$linkedModels = array();
|
||||
|
||||
if(!empty($queryData['fields']))
|
||||
{
|
||||
$this->__bypass = true;
|
||||
}
|
||||
|
||||
if ($recursive > 0)
|
||||
{
|
||||
foreach($model->__associations as $type)
|
||||
|
@ -377,6 +418,19 @@ class DboSource extends DataSource
|
|||
return $resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $linkModel
|
||||
* @param unknown_type $type
|
||||
* @param unknown_type $association
|
||||
* @param unknown_type $assocData
|
||||
* @param unknown_type $queryData
|
||||
* @param unknown_type $external
|
||||
* @param unknown_type $resultSet
|
||||
* @param unknown_type $recursive
|
||||
*/
|
||||
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive = 1)
|
||||
{
|
||||
//$external = (($linkModel->db === $this) && $resultSet == null);
|
||||
|
@ -411,6 +465,19 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $linkModel
|
||||
* @param unknown_type $type
|
||||
* @param unknown_type $association
|
||||
* @param unknown_type $assocData
|
||||
* @param unknown_type $queryData
|
||||
* @param unknown_type $external
|
||||
* @param unknown_type $resultSet
|
||||
* @return unknown
|
||||
*/
|
||||
function generateSelfAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
|
||||
{
|
||||
$alias = $association;
|
||||
|
@ -433,10 +500,10 @@ class DboSource extends DataSource
|
|||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->joinFieldJoin))
|
||||
if(isset($this->__assocJoins))
|
||||
{
|
||||
$replace = ', ';
|
||||
$replace .= join(', ', $this->joinFieldJoin['fields']);
|
||||
$replace .= join(', ', $this->__assocJoins['fields']);
|
||||
$replace .= ' FROM';
|
||||
}
|
||||
else
|
||||
|
@ -451,9 +518,24 @@ class DboSource extends DataSource
|
|||
return $result;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $linkModel
|
||||
* @param unknown_type $type
|
||||
* @param unknown_type $association
|
||||
* @param unknown_type $assocData
|
||||
* @param unknown_type $queryData
|
||||
* @param unknown_type $external
|
||||
* @param unknown_type $resultSet
|
||||
* @return unknown
|
||||
*/
|
||||
function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
|
||||
{
|
||||
$this->__scrubQueryData($queryData);
|
||||
$joinedOnSelf = false;
|
||||
$fields = null;
|
||||
if ($linkModel == null)
|
||||
{
|
||||
if(array_key_exists('selfJoin', $queryData))
|
||||
|
@ -462,10 +544,10 @@ class DboSource extends DataSource
|
|||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->joinFieldJoin))// && !isset($queryData['fields']))
|
||||
if(isset($this->__assocJoins['fields']))
|
||||
{
|
||||
$joinFields = ', ';
|
||||
$joinFields .= join(', ', $this->joinFieldJoin['fields']);
|
||||
$joinFields .= join(', ', $this->__assocJoins['fields']);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -486,10 +568,6 @@ class DboSource extends DataSource
|
|||
{
|
||||
$joinedOnSelf = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$joinedOnSelf = false;
|
||||
}
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
|
@ -519,26 +597,23 @@ class DboSource extends DataSource
|
|||
}
|
||||
$sql .= $this->conditions($queryData['conditions']) . $this->order($queryData['order']);
|
||||
$sql .= $this->limit($queryData['limit']);
|
||||
return $sql;
|
||||
}
|
||||
else
|
||||
else if($joinedOnSelf != true)
|
||||
{
|
||||
if($joinedOnSelf == true)
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
else
|
||||
if($this->__bypass == false)
|
||||
{
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
|
||||
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
||||
$sql .= $this->order($assocData['order']);
|
||||
}
|
||||
$this->joinFieldJoin['fields'][] = $fields;
|
||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
|
||||
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
||||
$sql .= $this->order($assocData['order']);
|
||||
$this->__assocJoins['fields'][] = $fields;
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
@ -571,24 +646,21 @@ class DboSource extends DataSource
|
|||
$sql .= $this->limit($queryData['limit']);
|
||||
return $sql;
|
||||
}
|
||||
else
|
||||
else if($joinedOnSelf != true)
|
||||
{
|
||||
if($joinedOnSelf == true)
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
else
|
||||
if($this->__bypass == false)
|
||||
{
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||
}
|
||||
$this->joinFieldJoin['fields'][] = $fields;
|
||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||
$this->__assocJoins['fields'][] = $fields;
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
@ -652,6 +724,14 @@ class DboSource extends DataSource
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function update (&$model, $fields = null, $values = null)
|
||||
{
|
||||
$updates = array();
|
||||
|
@ -667,6 +747,13 @@ class DboSource extends DataSource
|
|||
return $this->execute($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $id
|
||||
* @return unknown
|
||||
*/
|
||||
function delete (&$model, $id = null)
|
||||
{
|
||||
$_id = $model->id;
|
||||
|
@ -689,6 +776,14 @@ class DboSource extends DataSource
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $key
|
||||
* @param unknown_type $assoc
|
||||
* @return unknown
|
||||
*/
|
||||
function resolveKey($model, $key, $assoc = null)
|
||||
{
|
||||
if ($assoc == null)
|
||||
|
@ -703,11 +798,22 @@ class DboSource extends DataSource
|
|||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $field
|
||||
*/
|
||||
function getColumnType (&$model, $field)
|
||||
{
|
||||
$columns = $model->loadInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $data
|
||||
*/
|
||||
function __scrubQueryData(&$data)
|
||||
{
|
||||
if (!isset($data['conditions']))
|
||||
|
@ -732,6 +838,14 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $alias
|
||||
* @param unknown_type $fields
|
||||
* @return unknown
|
||||
*/
|
||||
function fields (&$model, $alias, $fields)
|
||||
{
|
||||
if (is_array($fields))
|
||||
|
@ -774,8 +888,9 @@ class DboSource extends DataSource
|
|||
|
||||
/**
|
||||
* Parses conditions array (or just passes it if it's a string)
|
||||
* @return string
|
||||
*
|
||||
* @param unknown_type $conditions
|
||||
* @return string
|
||||
*/
|
||||
function conditions ($conditions)
|
||||
{
|
||||
|
@ -833,10 +948,21 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
function limit ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $key
|
||||
* @param unknown_type $dir
|
||||
* @return unknown
|
||||
*/
|
||||
function order ($key, $dir = '')
|
||||
{
|
||||
if (trim($key) == '')
|
||||
|
@ -847,7 +973,8 @@ class DboSource extends DataSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Disconnects database, kills the connection and says the connection is closed, and if DEBUG is turned on, the log for this object is shown.
|
||||
* Disconnects database, kills the connection and says the connection is closed,
|
||||
* and if DEBUG is turned on, the log for this object is shown.
|
||||
*
|
||||
*/
|
||||
function close ()
|
||||
|
@ -888,6 +1015,4 @@ class DboSource extends DataSource
|
|||
return is_array($out)? $out[0]['count']: false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -20,8 +20,8 @@
|
|||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||
* @since CakePHP v 0.2.9
|
||||
* @subpackage cake.cake.libs.model.dbo
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
|
@ -30,8 +30,8 @@
|
|||
|
||||
|
||||
/**
|
||||
* Include DBO.
|
||||
*/
|
||||
* Include DBO.
|
||||
*/
|
||||
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||
|
||||
/**
|
||||
|
@ -40,292 +40,313 @@ uses('model'.DS.'datasources'.DS.'dbo_source');
|
|||
* Long description for class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||
* @since CakePHP v 0.2.9
|
||||
* @subpackage cake.cake.libs.model.dbo
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
*/
|
||||
class DboMysql extends DboSource
|
||||
{
|
||||
|
||||
var $description = "MySQL DBO Driver";
|
||||
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'host' => 'localhost',
|
||||
'login' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'cake',
|
||||
'port' => 3306
|
||||
);
|
||||
|
||||
var $columns = array(
|
||||
'primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||
'text' => array('name' => 'text'),
|
||||
'integer' => array('name' => 'int', 'limit' => '11'),
|
||||
'float' => array('name' => 'float'),
|
||||
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||
'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||
'time' => array('name' => 'time', 'format' => 'h:i:s'),
|
||||
'date' => array('name' => 'date', 'format' => 'Y-m-d'),
|
||||
'binary' => array('name' => 'blob'),
|
||||
'boolean' => array('name' => 'tinyint', 'limit' => '1')
|
||||
);
|
||||
|
||||
function __construct ($config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
return $this->connect();
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $description = "MySQL DBO Driver";
|
||||
|
||||
/**
|
||||
* Connects to the database using options in the given configuration array.
|
||||
*
|
||||
* @return boolean True if the database could be connected, else false
|
||||
*/
|
||||
function connect ()
|
||||
{
|
||||
$config = $this->config;
|
||||
if ($config['persistent'])
|
||||
{
|
||||
$connect = 'mysql_pconnect';
|
||||
}
|
||||
else
|
||||
{
|
||||
$connect = 'mysql_connect';
|
||||
}
|
||||
|
||||
$this->connected = false;
|
||||
$this->connection = $connect($config['host'], $config['login'], $config['password']);
|
||||
if ($this->connection)
|
||||
{
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
if ($this->connected)
|
||||
{
|
||||
return mysql_select_db($config['database'], $this->connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
//die('Could not connect to DB.');
|
||||
}
|
||||
}
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'host' => 'localhost',
|
||||
'login' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'cake',
|
||||
'port' => 3306);
|
||||
|
||||
/**
|
||||
* Disconnects from database.
|
||||
*
|
||||
* @return boolean True if the database could be disconnected, else false
|
||||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return mysql_close($this->connection);
|
||||
}
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $columns = array('primary_key' =>array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||
'text' => array('name' => 'text'),
|
||||
'integer' => array('name' => 'int', 'limit' => '11'),
|
||||
'float' => array('name' => 'float'),
|
||||
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||
'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||
'time' => array('name' => 'time', 'format' => 'h:i:s'),
|
||||
'date' => array('name' => 'date', 'format' => 'Y-m-d'),
|
||||
'binary' => array('name' => 'blob'),
|
||||
'boolean' => array('name' => 'tinyint', 'limit' => '1'));
|
||||
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
* @access protected
|
||||
*/
|
||||
function _execute ($sql)
|
||||
{
|
||||
return mysql_query($sql, $this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL query abstraction
|
||||
*
|
||||
* @param string $method Method name
|
||||
* @param array $params Parameters
|
||||
* @return resource Result resource identifier
|
||||
*/
|
||||
function query ()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (count($args) == 1)
|
||||
{
|
||||
return $this->fetchAll($args[0]);
|
||||
}
|
||||
elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->find($query);
|
||||
}
|
||||
elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findAllBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->findAll($query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @param bool $assoc Associative array only, or both?
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
function fetchRow ($assoc = false)
|
||||
{
|
||||
if(is_resource($this->_result))
|
||||
{
|
||||
$this->resultSet($this->_result);
|
||||
$resultRow = $this->fetchResult();
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of sources (tables) in the database.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function listSources ()
|
||||
{
|
||||
$result = mysql_list_tables($this->config['database'], $this->connection);
|
||||
if (!$result)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
while ($line = mysql_fetch_array($result))
|
||||
{
|
||||
$tables[] = $line[0];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $tableName Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function &describe (&$model)
|
||||
{
|
||||
$cache = parent::describe($model);
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$fields = false;
|
||||
$cols = $this->query('DESC ' . $this->name($model->table));
|
||||
|
||||
foreach ($cols as $column)
|
||||
{
|
||||
$colKey = array_keys($column);
|
||||
if (isset($column[$colKey[0]]) && !isset($column[0]))
|
||||
{
|
||||
$column[0] = $column[$colKey[0]];
|
||||
}
|
||||
|
||||
if (isset($column[0]))
|
||||
{
|
||||
$fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->__cacheDescription($model->table, $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted name of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data Name (table/field) to be prepared for use in an SQL statement
|
||||
* @return string Quoted for MySQL
|
||||
*/
|
||||
function name ($data)
|
||||
{
|
||||
if ($data == '*')
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
return '`'. ereg_replace('\.', '`.`', $data) .'`';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @param string $column The column into which this data will be inserted
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
function value ($data, $column = null)
|
||||
{
|
||||
$parent = parent::value($data, $column);
|
||||
if ($parent != null)
|
||||
{
|
||||
return $parent;
|
||||
}
|
||||
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
if (version_compare(phpversion(),"4.3.0") == "-1")
|
||||
{
|
||||
$data = mysql_escape_string($data, $this->connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = mysql_real_escape_string($data, $this->connection);
|
||||
}
|
||||
return "'" . $data . "'";
|
||||
// TODO: Add logic that formats/escapes data based on column type
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates between PHP boolean values and MySQL (faked) boolean values
|
||||
*
|
||||
* @param mixed $data Value to be translated
|
||||
* @return mixed Converted boolean value
|
||||
*/
|
||||
function boolean ($data)
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $config
|
||||
* @return unknown
|
||||
*/
|
||||
function __construct ($config)
|
||||
{
|
||||
if ($data === true || $data === false)
|
||||
{
|
||||
if ($data === true)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (intval($data !== 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
parent::__construct($config);
|
||||
return $this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the database using options in the given configuration array.
|
||||
*
|
||||
* @return boolean True if the database could be connected, else false
|
||||
*/
|
||||
function connect ()
|
||||
{
|
||||
$config = $this->config;
|
||||
$connect = $config['connect'];
|
||||
|
||||
$this->connected = false;
|
||||
$this->connection = $connect($config['host'], $config['login'], $config['password']);
|
||||
if ($this->connection)
|
||||
{
|
||||
$this->connected = true;
|
||||
}
|
||||
if ($this->connected)
|
||||
{
|
||||
return mysql_select_db($config['database'], $this->connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
//die('Could not connect to DB.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from database.
|
||||
*
|
||||
* @return boolean True if the database could be disconnected, else false
|
||||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return mysql_close($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
* @access protected
|
||||
*/
|
||||
function _execute ($sql)
|
||||
{
|
||||
return mysql_query($sql, $this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL query abstraction
|
||||
*
|
||||
* @return resource Result resource identifier
|
||||
*/
|
||||
function query ()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (count($args) == 1)
|
||||
{
|
||||
return $this->fetchAll($args[0]);
|
||||
}
|
||||
elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->find($query);
|
||||
}
|
||||
elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findAllBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->findAll($query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @param bool $assoc Associative array only, or both?
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
function fetchRow ($assoc = false)
|
||||
{
|
||||
if(is_resource($this->_result))
|
||||
{
|
||||
$this->resultSet($this->_result);
|
||||
$resultRow = $this->fetchResult();
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of sources (tables) in the database.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function listSources ()
|
||||
{
|
||||
$result = mysql_list_tables($this->config['database'], $this->connection);
|
||||
if (!$result)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
while ($line = mysql_fetch_array($result))
|
||||
{
|
||||
$tables[] = $line[0];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $tableName Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function &describe (&$model)
|
||||
{
|
||||
$cache = parent::describe($model);
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$fields = false;
|
||||
$cols = $this->query('DESC ' . $this->name($model->table));
|
||||
|
||||
foreach ($cols as $column)
|
||||
{
|
||||
$colKey = array_keys($column);
|
||||
if (isset($column[$colKey[0]]) && !isset($column[0]))
|
||||
{
|
||||
$column[0] = $column[$colKey[0]];
|
||||
}
|
||||
if (isset($column[0]))
|
||||
{
|
||||
$fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']);
|
||||
}
|
||||
}
|
||||
$this->__cacheDescription($model->table, $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted name of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data Name (table.field) to be prepared for use in an SQL statement
|
||||
* @return string Quoted for MySQL
|
||||
*/
|
||||
function name ($data)
|
||||
{
|
||||
if ($data == '*')
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
return '`'. ereg_replace('\.', '`.`', $data) .'`';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @param string $column The column into which this data will be inserted
|
||||
* @return string Quoted and escaped
|
||||
* @todo Add logic that formats/escapes data based on column type
|
||||
*/
|
||||
function value ($data, $column = null)
|
||||
{
|
||||
$parent = parent::value($data, $column);
|
||||
if ($parent != null)
|
||||
{
|
||||
return $parent;
|
||||
}
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
if (version_compare(phpversion(),"4.3.0") == "-1")
|
||||
{
|
||||
$data = mysql_escape_string($data, $this->connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = mysql_real_escape_string($data, $this->connection);
|
||||
}
|
||||
return "'" . $data . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates between PHP boolean values and MySQL (faked) boolean values
|
||||
*
|
||||
* @param mixed $data Value to be translated
|
||||
* @return mixed Converted boolean value
|
||||
*/
|
||||
function boolean ($data)
|
||||
{
|
||||
if ($data === true || $data === false)
|
||||
{
|
||||
if ($data === true)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (intval($data !== 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function create(&$model, $fields = null, $values = null)
|
||||
{
|
||||
return parent::create($model, $fields, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @param unknown_type $fields
|
||||
* @param unknown_type $values
|
||||
* @return unknown
|
||||
*/
|
||||
function update(&$model, $fields = null, $values = null)
|
||||
{
|
||||
return parent::update($model, $fields, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a transaction
|
||||
*
|
||||
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions).
|
||||
*/
|
||||
* Begin a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions).
|
||||
*/
|
||||
function begin (&$model)
|
||||
{
|
||||
if (parent::begin($model))
|
||||
|
@ -340,10 +361,13 @@ class DboMysql extends DboSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Commit a transaction
|
||||
*
|
||||
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
|
||||
*/
|
||||
* Commit a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
function commit (&$model)
|
||||
{
|
||||
if (parent::commit($model))
|
||||
|
@ -355,10 +379,13 @@ class DboMysql extends DboSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Rollback a transaction
|
||||
*
|
||||
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
|
||||
*/
|
||||
* Rollback a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
function rollback (&$model)
|
||||
{
|
||||
if (parent::rollback($model))
|
||||
|
@ -369,58 +396,59 @@ class DboMysql extends DboSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message with error number
|
||||
*/
|
||||
function lastError ()
|
||||
{
|
||||
if (mysql_errno($this->connection))
|
||||
{
|
||||
return mysql_errno($this->connection).': '.mysql_error($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message with error number
|
||||
*/
|
||||
function lastError ()
|
||||
{
|
||||
if (mysql_errno($this->connection))
|
||||
{
|
||||
return mysql_errno($this->connection).': '.mysql_error($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
function lastAffected ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return mysql_affected_rows($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
function lastAffected ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return mysql_affected_rows($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return @mysql_num_rows($this->_result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return @mysql_num_rows($this->_result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function lastInsertId ($source = null)
|
||||
{
|
||||
return mysql_insert_id($this->connection);
|
||||
}
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @param unknown_type $source
|
||||
* @return in
|
||||
*/
|
||||
function lastInsertId ($source = null)
|
||||
{
|
||||
return mysql_insert_id($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
|
@ -429,78 +457,76 @@ class DboMysql extends DboSource
|
|||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
function limit ($limit, $offset = null)
|
||||
{
|
||||
if ($limit)
|
||||
{
|
||||
$rt = '';
|
||||
if (!strpos(low($limit), 'limit') || strpos(low($limit), 'limit') === 0)
|
||||
{
|
||||
$rt = ' LIMIT';
|
||||
}
|
||||
if ($offset)
|
||||
{
|
||||
$rt .= ' ' . $offset. ',';
|
||||
}
|
||||
$rt .= ' ' . $limit;
|
||||
return $rt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function limit ($limit, $offset = null)
|
||||
{
|
||||
if ($limit)
|
||||
{
|
||||
$rt = '';
|
||||
if (!strpos(low($limit), 'limit') || strpos(low($limit), 'limit') === 0)
|
||||
{
|
||||
$rt = ' LIMIT';
|
||||
}
|
||||
if ($offset)
|
||||
{
|
||||
$rt .= ' ' . $offset. ',';
|
||||
}
|
||||
$rt .= ' ' . $limit;
|
||||
return $rt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
function resultSet(&$results)
|
||||
{
|
||||
$this->results =& $results;
|
||||
$this->map = array();
|
||||
$num_fields = mysql_num_fields($results);
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
function resultSet(&$results)
|
||||
{
|
||||
$this->results =& $results;
|
||||
$this->map = array();
|
||||
$num_fields = mysql_num_fields($results);
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
while ($j < $num_fields)
|
||||
{
|
||||
$column = mysql_fetch_field($results,$j);
|
||||
|
||||
if (!empty($column->table))
|
||||
{
|
||||
$this->map[$index++] = array($column->table, $column->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->map[$index++] = array(0, $column->name);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
while ($j < $num_fields)
|
||||
{
|
||||
$column = mysql_fetch_field($results,$j);
|
||||
if (!empty($column->table))
|
||||
{
|
||||
$this->map[$index++] = array($column->table, $column->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->map[$index++] = array(0, $column->name);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row from the current result set
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchResult()
|
||||
{
|
||||
if ($row = mysql_fetch_row($this->results))
|
||||
{
|
||||
$resultRow = array();
|
||||
$i =0;
|
||||
foreach ($row as $index => $field)
|
||||
{
|
||||
list($table, $column) = $this->map[$index];
|
||||
$resultRow[$table][$column] = $row[$index];
|
||||
$i++;
|
||||
}
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function fetchResult()
|
||||
{
|
||||
if ($row = mysql_fetch_row($this->results))
|
||||
{
|
||||
$resultRow = array();
|
||||
$i =0;
|
||||
foreach ($row as $index => $field)
|
||||
{
|
||||
list($table, $column) = $this->map[$index];
|
||||
$resultRow[$table][$column] = $row[$index];
|
||||
$i++;
|
||||
}
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -80,14 +80,7 @@ class DboPostgres extends DboSource
|
|||
function connect ()
|
||||
{
|
||||
$config = $this->config;
|
||||
if ($config['persistent'])
|
||||
{
|
||||
$connect = 'pg_pconnect';
|
||||
}
|
||||
else
|
||||
{
|
||||
$connect = 'pg_connect';
|
||||
}
|
||||
$connect = $config['connect'];
|
||||
|
||||
$this->connection = $connect("dbname={$config['database']} user={$config['login']} password={$config['password']}");
|
||||
if ($this->connection)
|
||||
|
|
|
@ -28,11 +28,17 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Load the model class based on the version of PHP.
|
||||
*
|
||||
*/
|
||||
if (phpversion() < 5)
|
||||
{
|
||||
require_once(LIBS.'model'.DS.'model_php4.php');
|
||||
if (function_exists("overload")) {
|
||||
overload("Model");
|
||||
if (function_exists("overload"))
|
||||
{
|
||||
overload("Model");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -350,19 +350,25 @@ class Model extends Object
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PHP4 Only
|
||||
*
|
||||
* Handles custom method calls, like findBy<field> for DB models,
|
||||
* and custom RPC calls for remote data sources.
|
||||
*
|
||||
* @param unknown_type $method
|
||||
* @param unknown_type $params
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @access protected
|
||||
*/
|
||||
// --- PHP4 Only
|
||||
function __call($method, $params, &$return)
|
||||
{
|
||||
$return = $this->db->query($method, $params, $this);
|
||||
return true;
|
||||
}
|
||||
// --- PHP4 Only
|
||||
|
||||
/**
|
||||
* Private helper method to create a set of associations.
|
||||
|
@ -435,6 +441,7 @@ class Model extends Object
|
|||
* @param string $type "Belongs", "One", "Many", "ManyTo"
|
||||
* @param string $assoc
|
||||
* @param string $model
|
||||
* @access private
|
||||
*/
|
||||
function __generateAssociation ($type, $assoc)
|
||||
{
|
||||
|
@ -651,6 +658,7 @@ class Model extends Object
|
|||
*
|
||||
* @param string $name Name of field to get
|
||||
* @param string $conditions SQL conditions (defaults to NULL)
|
||||
* @param string $order (defaults to NULL)
|
||||
* @return field contents
|
||||
*/
|
||||
function field ($name, $conditions = null, $order = null)
|
||||
|
@ -929,9 +937,11 @@ class Model extends Object
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if a record that meets given conditions exists
|
||||
*
|
||||
* @param unknown_type $conditions
|
||||
* @return boolean True if such a record exists
|
||||
*/
|
||||
function hasAny ($conditions = null)
|
||||
|
@ -998,44 +1008,6 @@ class Model extends Object
|
|||
return $this->afterFind($this->db->read($this, $queryData, $recursive));
|
||||
}
|
||||
|
||||
|
||||
//////////////
|
||||
|
||||
/* $joins[] = $join;
|
||||
|
||||
if (count($joins))
|
||||
{
|
||||
$joins = join(' ', $joins);
|
||||
}
|
||||
else
|
||||
{
|
||||
$joins = null;
|
||||
}
|
||||
|
||||
if (count($whers))
|
||||
{
|
||||
$whers = '(' . join(' AND ', $whers) . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$whers = null;
|
||||
}
|
||||
|
||||
if ($conditions && $whers)
|
||||
{
|
||||
$conditions .= ' AND ';
|
||||
}
|
||||
$conditions .= $whers;
|
||||
|
||||
////////// conditions & order
|
||||
|
||||
$sql .= $limit_str;
|
||||
|
||||
$data = $this->db->fetchAll($sql);
|
||||
|
||||
return $data;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Runs a direct query against the bound DataSource, and returns the result
|
||||
*
|
||||
|
@ -1066,6 +1038,7 @@ class Model extends Object
|
|||
* Returns number of rows matching given SQL condition.
|
||||
*
|
||||
* @param string $conditions SQL conditions (WHERE clause conditions)
|
||||
* @param int $recursize The number of levels deep to fetch associated records
|
||||
* @return int Number of matching rows
|
||||
*/
|
||||
function findCount ($conditions = null, $recursive = 0)
|
||||
|
@ -1082,11 +1055,11 @@ class Model extends Object
|
|||
* Special findAll variation for tables joined to themselves.
|
||||
* The table needs fields id and parent_id to work.
|
||||
*
|
||||
* @todo Perhaps create a Component with this logic, according to a thought from Michal, its author. -OJ 22 nov 2005
|
||||
* @param array $conditions Conditions for the findAll() call
|
||||
* @param array $fields Fields for the findAll() call
|
||||
* @param string $sort SQL ORDER BY statement
|
||||
* @return unknown
|
||||
* @todo Perhaps create a Component with this logic
|
||||
*/
|
||||
function findAllThreaded ($conditions=null, $fields=null, $sort=null)
|
||||
{
|
||||
|
@ -1287,15 +1260,18 @@ class Model extends Object
|
|||
/**
|
||||
* Escapes the field name and prepends the model name
|
||||
*
|
||||
* @param unknown_type $field
|
||||
* @return string The name of the escaped field for this Model (i.e. id becomes `Post`.`id`).
|
||||
*/
|
||||
function escapeField($field)
|
||||
{
|
||||
return $this->db->name($this->name).'.'.$this->db->name($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current record's ID
|
||||
*
|
||||
* @param unknown_type $list
|
||||
* @return mixed The ID of the current record
|
||||
*/
|
||||
function getID($list = 0)
|
||||
|
@ -1383,6 +1359,7 @@ class Model extends Object
|
|||
/**
|
||||
* Before find callback
|
||||
*
|
||||
* @param unknown_type $conditions
|
||||
* @return boolean True if the operation should continue, false if it should abort
|
||||
*/
|
||||
function beforeFind($conditions)
|
||||
|
|
|
@ -428,6 +428,10 @@ class FormHelper extends Helper
|
|||
{
|
||||
$field['selectAttr']['DISABLED'] = true;
|
||||
}
|
||||
if(!isset( $field['options']))
|
||||
{
|
||||
$field['options'] = null;
|
||||
}
|
||||
$strFormFields = $strFormFields.$this->generateSelectDiv( $field['tagName'], $field['prompt'], $field['options'], $field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg'] );
|
||||
break;
|
||||
case "area";
|
||||
|
|
Loading…
Reference in a new issue