Reverting changes made by gwoo

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3284 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-07-22 16:45:18 +00:00
parent ceb72b3415
commit 4347f25025
3 changed files with 79 additions and 92 deletions

View file

@ -103,8 +103,8 @@ class DboMysqli extends DboSource {
if (mysqli_select_db($this->connection, $config['database'])) { if (mysqli_select_db($this->connection, $config['database'])) {
$this->connected = true; $this->connected = true;
} }
return $this->connected; return $this->connected;
} }
/** /**
@ -123,19 +123,19 @@ class DboMysqli extends DboSource {
* @return resource Result resource identifier * @return resource Result resource identifier
* @access protected * @access protected
*/ */
function _execute($sql) { function _execute($sql) {
return mysqli_query($this->connection, $sql); return mysqli_query($this->connection, $sql);
} }
/** /**
* Returns an array of sources (tables) in the database. * Returns an array of sources (tables) in the database.
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function listSources() { function listSources() {
$cache = parent::listSources(); $cache = parent::listSources();
if ($cache != null) { if ($cache != null) {
return $cache; return $cache;
} }
$result = $this->_execute('SHOW TABLES FROM ' . $this->config['database'] . ';'); $result = $this->_execute('SHOW TABLES FROM ' . $this->config['database'] . ';');
if (!$result) { if (!$result) {
return array(); return array();
@ -145,7 +145,7 @@ class DboMysqli extends DboSource {
while ($line = mysqli_fetch_array($result)) { while ($line = mysqli_fetch_array($result)) {
$tables[] = $line[0]; $tables[] = $line[0];
} }
parent::listSources($tables); parent::listSources($tables);
return $tables; return $tables;
} }
@ -156,16 +156,16 @@ class DboMysqli extends DboSource {
* @param string $tableName Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function describe(&$model) { function describe(&$model) {
$cache = parent::describe($model); $cache = parent::describe($model);
if ($cache != null) { if ($cache != null) {
return $cache; return $cache;
} }
$fields = false; $fields = false;
$cols = $this->query('DESCRIBE ' . $this->fullTableName($model)); $cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
foreach ($cols as $column) { foreach ($cols as $column) {
$colKey = array_keys($column); $colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) { if (isset($column[$colKey[0]]) && !isset($column[0])) {
@ -179,8 +179,8 @@ class DboMysqli extends DboSource {
'default' => $column[0]['Default'] 'default' => $column[0]['Default']
); );
} }
} }
$this->__cacheDescription($model->tablePrefix.$model->table, $fields); $this->__cacheDescription($model->tablePrefix.$model->table, $fields);
return $fields; return $fields;
} }
@ -388,36 +388,36 @@ class DboMysqli extends DboSource {
* *
* @param unknown_type $results * @param unknown_type $results
*/ */
function resultSet(&$results) { function resultSet(&$results) {
$this->results =& $results; $this->results =& $results;
$this->map = array(); $this->map = array();
$num_fields = mysqli_num_fields($results); $num_fields = mysqli_num_fields($results);
$index = 0; $index = 0;
$j = 0; $j = 0;
while ($j < $num_fields) { while ($j < $num_fields) {
$column = mysqli_fetch_field_direct($results, $j); $column = mysqli_fetch_field_direct($results, $j);
if (!empty($column->table)) { if (!empty($column->table)) {
$this->map[$index++] = array($column->table, $column->name); $this->map[$index++] = array($column->table, $column->name);
} else { } else {
$this->map[$index++] = array(0, $column->name); $this->map[$index++] = array(0, $column->name);
} }
$j++; $j++;
} }
} }
/** /**
* Fetches the next row from the current result set * Fetches the next row from the current result set
* *
* @return unknown * @return unknown
*/ */
function fetchResult() { function fetchResult() {
if ($row = mysqli_fetch_row($this->results)) { if ($row = mysqli_fetch_row($this->results)) {
$resultRow = array(); $resultRow = array();
$i = 0; $i = 0;
foreach ($row as $index => $field) { foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index]; @list($table, $column) = $this->map[$index];
$resultRow[$table][$column] = $row[$index]; $resultRow[$table][$column] = $row[$index];
$i++; $i++;
} }
return $resultRow; return $resultRow;
} else { } else {
return false; return false;
@ -428,8 +428,8 @@ class DboMysqli extends DboSource {
* *
* @param bool $assoc Associative array only, or both? * @param bool $assoc Associative array only, or both?
* @return array The fetched row as an array * @return array The fetched row as an array
*/ */
function fetchRow($assoc = false) { function fetchRow($assoc = false) {
if (is_object($this->_result)) { if (is_object($this->_result)) {
$this->resultSet($this->_result); $this->resultSet($this->_result);
$resultRow = $this->fetchResult(); $resultRow = $this->fetchResult();

View file

@ -182,7 +182,7 @@ class DboSource extends DataSource {
$all = true; $all = true;
$field = Inflector::underscore(preg_replace('/findAllBy/i', '', $args[0])); $field = Inflector::underscore(preg_replace('/findAllBy/i', '', $args[0]));
} }
$or = (strpos($field, '_or_') !== false); $or = (strpos($field, '_or_') !== false);
if ($or) { if ($or) {
$field = explode('_or_', $field); $field = explode('_or_', $field);
@ -210,7 +210,7 @@ class DboSource extends DataSource {
} }
if ($all) { if ($all) {
if (isset($params[3 + $off])) { if (isset($params[3 + $off])) {
$limit = $params[3 + $off]; $limit = $params[3 + $off];
} }
@ -543,12 +543,12 @@ class DboSource extends DataSource {
// Build final query SQL // Build final query SQL
$query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null); $query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null);
$resultSet = $this->fetchAll($query, $model->cacheQueries, $model->name); $resultSet = $this->fetchAll($query, $model->cacheQueries, $model->name);
if ($resultSet === false) { if ($resultSet === false) {
$model->onError(); $model->onError();
return false; return false;
} }
$filtered = $this->__filterResults($resultSet, $model); $filtered = $this->__filterResults($resultSet, $model);
if ($model->recursive > 0) { if ($model->recursive > 0) {
@ -667,11 +667,11 @@ class DboSource extends DataSource {
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($q, $model->cacheQueries, $model->name);
if (!empty($fetch) && is_array($fetch)) { if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) { if ($recursive > 0) {
foreach($linkModel->__associations as $type1) { foreach($linkModel->__associations as $type1) {
foreach($linkModel->{$type1} as $assoc1 => $assocData1) { foreach($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assocData1['className']}; $deepModel =& $linkModel->{$assocData1['className']};
if ($deepModel->alias != $model->name) { if ($deepModel->alias != $model->name) {
$tmpStack = $stack; $tmpStack = $stack;
@ -829,22 +829,6 @@ class DboSource extends DataSource {
} }
} }
return $sql; return $sql;
} else {
if (isset($linkModel->assoc['conditions']) && !empty($linkModel->assoc['conditions'])) {
$assocData['conditions'] = $linkModel->assoc['conditions'];
}
if (isset($linkModel->assoc['fields']) && !empty($linkModel->assoc['fields'])) {
$assocData['fields'] = $linkModel->assoc['fields'];
}
if (isset($linkModel->assoc['order']) && !empty($linkModel->assoc['order'])) {
$assocData['order'] = $linkModel->assocData['order'];
}
if (isset($linkModel->assoc['limit']) && !empty($linkModel->assoc['limit'])) {
$assocData['limit'] = $linkModel->assocData['limit'];
}
if (isset($linkModel->assoc['offset']) && !empty($linkModel->assoc['offset'])) {
$assocData['offset'] = $linkModel->assocData['offset'];
}
} }
$alias = $association; $alias = $association;
@ -855,18 +839,19 @@ class DboSource extends DataSource {
switch($type) { switch($type) {
case 'hasOne': case 'hasOne':
if ($external || isset($assocData['external'])) { if ($external || isset($assocData['external'])) {
if (isset($assocData['finderQuery'])) { if (isset($assocData['finderQuery'])) {
return $assocData['finderQuery']; return $assocData['finderQuery'];
} }
if (!isset($assocData['limit'])) { if (!isset($assocData['fields'])) {
$assocData['limit'] = $queryData['limit']; $assocData['fields'] = '';
} }
if (!isset($assocData['offset'])) {
$assocData['offset'] = $queryData['offset']; $limit = '';
if (isset($queryData['limit']) && !empty($queryData['limit'])) {
$limit = $this->limit($queryData['limit'], $queryData['offset']);
} }
$limit = $this->limit($assocData['limit'], $assocData['offset']);
$sql = 'SELECT '; $sql = 'SELECT ';
if ($this->goofyLimit) { if ($this->goofyLimit) {
@ -900,6 +885,9 @@ class DboSource extends DataSource {
return $sql; return $sql;
} else { } else {
if (!isset($assocData['fields'])) {
$assocData['fields'] = '';
}
if ($this->__bypass === false) { if ($this->__bypass === false) {
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields'])); $fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
@ -932,14 +920,14 @@ class DboSource extends DataSource {
break; break;
case 'belongsTo': case 'belongsTo':
if ($external || isset($assocData['external'])) { if ($external || isset($assocData['external'])) {
$limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
if (!isset($assocData['limit'])) { if (!isset($assocData['fields'])) {
$assocData['limit'] = $queryData['limit']; $assocData['fields'] = '';
} }
if (!isset($assocData['offset'])) {
$assocData['offset'] = $queryData['offset'];
}
$limit = $this->limit($assocData['limit'], $assocData['offset']);
$sql = 'SELECT '; $sql = 'SELECT ';
if ($this->goofyLimit) { if ($this->goofyLimit) {
@ -970,6 +958,9 @@ class DboSource extends DataSource {
return $sql; return $sql;
} else { } else {
if (!isset($assocData['fields'])) {
$assocData['fields'] = '';
}
if ($this->__bypass === false) { if ($this->__bypass === false) {
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields'])); $fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
@ -1012,10 +1003,12 @@ class DboSource extends DataSource {
$sql = $assocData['finderQuery']; $sql = $assocData['finderQuery'];
} else { } else {
$limit = $this->limit($assocData['limit'], $assocData['offset']); $limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
$conditions = $assocData['conditions']; $conditions = $assocData['conditions'];
$sql = 'SELECT '; $sql = 'SELECT ';
if ($this->goofyLimit) { if ($this->goofyLimit) {
@ -1037,7 +1030,6 @@ class DboSource extends DataSource {
} }
$sql .= $this->conditions($conditions); $sql .= $this->conditions($conditions);
$sql .= $this->order($assocData['order']); $sql .= $this->order($assocData['order']);
if (!$this->goofyLimit) { if (!$this->goofyLimit) {
@ -1052,7 +1044,10 @@ class DboSource extends DataSource {
} else { } else {
$joinTbl = $this->fullTableName($assocData['joinTable']); $joinTbl = $this->fullTableName($assocData['joinTable']);
$limit = $this->limit($assocData['limit'], $assocData['offset']); $limit = '';
if (isset($assocData['limit'])) {
$limit = $this->limit($assocData['limit'], $queryData['offset']);
}
$sql = 'SELECT '; $sql = 'SELECT ';
@ -1088,7 +1083,6 @@ class DboSource extends DataSource {
$sql .= ' = ' . $this->name($alias) . '.' . $this->name($linkModel->primaryKey); $sql .= ' = ' . $this->name($alias) . '.' . $this->name($linkModel->primaryKey);
$sql .= $this->conditions($assocData['conditions']); $sql .= $this->conditions($assocData['conditions']);
$sql .= $this->order($assocData['order']); $sql .= $this->order($assocData['order']);
if (!$this->goofyLimit) { if (!$this->goofyLimit) {

View file

@ -288,27 +288,20 @@ class Model extends Object {
* Default association keys * Default association keys
* *
* @var array * @var array
* @access protected * @access protected
*/ */
var $__associationKeys = array( var $__associationKeys = array(
'belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'), 'belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'),
'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'), 'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'),
'hasMany' => array('className', 'conditions', 'order','limit','offset', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'), 'hasMany' => array('className', 'conditions', 'order', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
'hasAndBelongsToMany' => array('className', 'joinTable', 'fields', 'foreignKey', 'associationForeignKey', 'conditions', 'order','limit','offset', 'uniq', 'finderQuery', 'deleteQuery', 'insertQuery', 'with') 'hasAndBelongsToMany' => array('className', 'joinTable', 'fields', 'foreignKey', 'associationForeignKey', 'conditions', 'order', 'uniq', 'finderQuery', 'deleteQuery', 'insertQuery', 'with')
); );
/**
* Access to the association property keys
*
* @var array
* @access public
*/
var $assoc = array('conditions', 'fields', 'order', 'limit','offset');
/** /**
* Holds provided/generated association key names and other data for all associations * Holds provided/generated association key names and other data for all associations
* *
* @var array * @var array
* @access protected * @access protected
*/ */
var $__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); var $__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
@ -316,7 +309,7 @@ class Model extends Object {
* The last inserted ID of the data that this model created * The last inserted ID of the data that this model created
* *
* @var integer * @var integer
* @access protected * @access protected
*/ */
var $__insertID = null; var $__insertID = null;
@ -324,7 +317,7 @@ class Model extends Object {
* The number of records returned by the last query * The number of records returned by the last query
* *
* @var integer * @var integer
* @access protected * @access protected
*/ */
var $__numRows = null; var $__numRows = null;
@ -332,7 +325,7 @@ class Model extends Object {
* The number of records affected by the last query * The number of records affected by the last query
* *
* @var integer * @var integer
* @access protected * @access protected
*/ */
var $__affectedRows = null; var $__affectedRows = null;
@ -431,14 +424,14 @@ class Model extends Object {
* Handles custom method calls, like findBy<field> for DB models, * Handles custom method calls, like findBy<field> for DB models,
* and custom RPC calls for remote data sources. * and custom RPC calls for remote data sources.
* *
* @param string $method Name of method to call. * @param string $method Name of method to call.
* @param array $params Parameters for the method. * @param array $params Parameters for the method.
* @return unknown * @return unknown
* @access protected * @access protected
*/ */
function __call($method, $params) { function __call($method, $params) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$methods = array_keys($this->__behaviorMethods); $methods = array_keys($this->__behaviorMethods);
$call = array_values($this->__behaviorMethods); $call = array_values($this->__behaviorMethods);
$count = count($call); $count = count($call);
@ -485,12 +478,12 @@ class Model extends Object {
/** /**
* Turn off associations on the fly. * Turn off associations on the fly.
* *
* Example: Turn off the associated Model Supportrequest, * Example: Turn off the associated Model Supportrequest,
* to temporarily lighten the User model: * to temporarily lighten the User model:
* <code> * <code>
* $this->User->unbindModel( array('hasMany' => array('Supportrequest')) ); * $this->User->unbindModel( array('hasMany' => array('Supportrequest')) );
* </code> * </code>
* *
* @link http://cakebaker.wordpress.com/2006/02/22/new-feature-bindmodelunbindmodel/ * @link http://cakebaker.wordpress.com/2006/02/22/new-feature-bindmodelunbindmodel/
* @param array $params * @param array $params
* @return boolean Always true * @return boolean Always true
@ -775,7 +768,7 @@ class Model extends Object {
$this->id = false; $this->id = false;
unset ($this->data); unset ($this->data);
$this->data = array(); $this->data = array();
$cols = $this->loadInfo(); $cols = $this->loadInfo();
if (array_key_exists('default', $cols->value[0])) { if (array_key_exists('default', $cols->value[0])) {
$count = count($cols->value); $count = count($cols->value);
@ -1253,7 +1246,7 @@ class Model extends Object {
$this->behaviors[$b[$i]]->afterFind($this, $results); $this->behaviors[$b[$i]]->afterFind($this, $results);
} }
} }
$return = $this->afterFind($results); $return = $this->afterFind($results);
if (isset($this->__backAssociation)) { if (isset($this->__backAssociation)) {