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

View file

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

View file

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