mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes into the trunk.
Revision: [2629] Fixed recursive associations when set to 0, did not add the hasOne or belongsTo in the query. Changed scaffold to use recursive setting of 0 in all methods that call Model::findAll() Fixed Invalid argument supplied for foreach() notice in show.thtml Removed 500 record limit in Controller::generateFieldNames() Revision: [2628] Merging changes from model_php5.php Revision: [2627] Fixing messed up characters in dbo_odbc, adding docstrings, and giving connect() a return value Revision: [2625] Bringing all DB drivers up to date Revision: [2624] Changed fixed for Ticket #609 so and empty array is set instead of null. This is more consistent with the other arrays that are returned if an association is found Revision: [2623] Adding fix for Ticket #712 git-svn-id: https://svn.cakephp.org/repo/trunk/cake/1.x.x.x@2630 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
4a8c03ef1c
commit
0c0dec8bc0
11 changed files with 829 additions and 538 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
1.0.0.2620
|
||||
1.0.0.2630
|
|
@ -767,7 +767,8 @@ class Controller extends Object
|
|||
if ($doCreateOptions)
|
||||
{
|
||||
$otherDisplayField = $otherModel->getDisplayField();
|
||||
$rec = $otherModel->findAll(null, null, null, 500);
|
||||
$otherModel->recursive = 0;
|
||||
$rec = $otherModel->findAll();
|
||||
foreach ($rec as $pass)
|
||||
{
|
||||
foreach ($pass as $key => $value)
|
||||
|
@ -807,7 +808,8 @@ class Controller extends Object
|
|||
if( $doCreateOptions )
|
||||
{
|
||||
$otherDisplayField = $otherModel->getDisplayField();
|
||||
$rec = $otherModel->findAll(null, null, null, 500);
|
||||
$otherModel->recursive = 0;
|
||||
$rec = $otherModel->findAll();
|
||||
foreach ($rec as $pass)
|
||||
{
|
||||
foreach($pass as $key => $value)
|
||||
|
@ -870,7 +872,8 @@ class Controller extends Object
|
|||
$fieldNames[$modelKeyM]['prompt'] = "Related ".Inflector::humanize(Inflector::pluralize($modelName));
|
||||
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
||||
$fieldNames[$modelKeyM]['tagName'] = $manyAssociation.'/'.$manyAssociation;
|
||||
$rec = $modelObject->findAll(null, null, null, 500);
|
||||
$modelObject->recursive = 0;
|
||||
$rec = $modelObject->findAll();
|
||||
foreach ($rec as $pass)
|
||||
{
|
||||
foreach($pass as $key=>$value)
|
||||
|
|
|
@ -148,6 +148,7 @@ class Scaffold extends Object {
|
|||
if($this->controllerClass->_beforeScaffold('index'))
|
||||
{
|
||||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames(null,false) );
|
||||
$this->controllerClass->{$this->modelKey}->recursive = 0;
|
||||
$this->controllerClass->set('data', $this->controllerClass->{$this->modelKey}->findAll());
|
||||
if(file_exists(APP.'views'.DS.$this->viewPath.DS.'scaffold.list.thtml'))
|
||||
{
|
||||
|
@ -252,7 +253,6 @@ class Scaffold extends Object {
|
|||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() );
|
||||
$this->controllerClass->cleanUpFields();
|
||||
|
||||
|
||||
if($type == 'create')
|
||||
{
|
||||
$this->controllerClass->{$this->modelKey}->create();
|
||||
|
|
|
@ -564,30 +564,27 @@ class DboSource extends DataSource
|
|||
$this->__bypass = true;
|
||||
}
|
||||
|
||||
if ($model->recursive > 0)
|
||||
foreach($model->__associations as $type)
|
||||
{
|
||||
foreach($model->__associations as $type)
|
||||
foreach($model->{$type} as $assoc => $assocData)
|
||||
{
|
||||
foreach($model->{$type} as $assoc => $assocData)
|
||||
$linkModel =& $model->{$assocData['className']};
|
||||
if($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany')
|
||||
{
|
||||
$linkModel =& $model->{$assocData['className']};
|
||||
if($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany')
|
||||
if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
$linkedModels[] = $type.'/'.$assoc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($model->useDbConfig == $linkModel->useDbConfig)
|
||||
{
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
$linkedModels[] = $type.'/'.$assoc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($model->useDbConfig == $linkModel->useDbConfig)
|
||||
{
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
$linkedModels[] = $type.'/'.$assoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -791,7 +788,7 @@ class DboSource extends DataSource
|
|||
{
|
||||
if($merge[0][$association] === false)
|
||||
{
|
||||
$data[$association] = null;
|
||||
$data[$association] = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -120,6 +120,7 @@ class DboMysql extends DboSource
|
|||
{
|
||||
$this->connected = true;
|
||||
}
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -279,14 +280,14 @@ class DboMysql extends DboSource
|
|||
{
|
||||
case 'boolean':
|
||||
$data = $this->boolean((bool)$data);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
|
||||
$data = mysql_real_escape_string($data, $this->connection);
|
||||
break;
|
||||
}
|
||||
|
||||
return "'" . $data . "'";
|
||||
|
|
|
@ -34,157 +34,145 @@
|
|||
*/
|
||||
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||
|
||||
classÊDboOdbcÊextendsÊDboSource
|
||||
class DboOdbc extends DboSource
|
||||
{
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@varÊunknown_type
|
||||
Ê*/
|
||||
ÊÊÊÊvarÊ$descriptionÊ=Ê"ODBCÊDBOÊDriver";
|
||||
* Driver description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $description = "ODBC DBO Driver";
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@varÊunknown_type
|
||||
Ê*/
|
||||
ÊÊÊÊvarÊ$startQuoteÊ=Ê"`";
|
||||
* Table/column starting quote
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $startQuote = "`";
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@varÊunknown_type
|
||||
Ê*/
|
||||
ÊÊÊÊvarÊ$endQuoteÊ=Ê"`";
|
||||
* Table/column end quote
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $endQuote = "`";
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@varÊunknown_type
|
||||
Ê*/
|
||||
ÊÊÊÊvarÊ$_baseConfigÊ=Êarray('persistent'Ê=>Êtrue,
|
||||
ÊÊÊÊ 'login'ÊÊÊÊÊÊ=>Ê'root',
|
||||
ÊÊ ÊÊ'password'ÊÊÊÊ=>Ê'',
|
||||
ÊÊÊÊ 'database'ÊÊÊÊ=>Ê'cake');
|
||||
* Driver base configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'login' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'cake');
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@varÊunknown_type
|
||||
Ê*/
|
||||
ÊÊÊÊ
|
||||
ÊÊÊÊvarÊ$columnsÊ=Êarray();
|
||||
ÊÊÊÊ
|
||||
//ÊÊÊÊ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',Ê'formatter'Ê=>Ê'date'),
|
||||
//ÊÊÊÊ'timestamp'ÊÊÊ=>Êarray('name'Ê=>Ê'datetime',Ê'format'Ê=>Ê'Y-m-dÊh:i:s',Ê'formatter'Ê=>Ê'date'),
|
||||
//ÊÊÊÊ'time'ÊÊÊÊÊÊÊÊ=>Êarray('name'Ê=>Ê'time',Ê'format'Ê=>Ê'h:i:s',Ê'formatter'Ê=>Ê'date'),
|
||||
//ÊÊÊÊ'date'ÊÊÊÊÊÊÊÊ=>Êarray('name'Ê=>Ê'date',Ê'format'Ê=>Ê'Y-m-d',Ê'formatter'Ê=>Ê'date'),
|
||||
//ÊÊÊÊ'binary'ÊÊÊÊÊÊ=>Êarray('name'Ê=>Ê'blob'),
|
||||
//ÊÊÊÊ'boolean'ÊÊÊÊÊ=>Êarray('name'Ê=>Ê'tinyint',Ê'limit'Ê=>Ê'1'));
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
|
||||
var $columns = array();
|
||||
|
||||
// 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', 'formatter' => 'date'),
|
||||
// 'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
|
||||
// 'time' => array('name' => 'time', 'format' => 'h:i:s', 'formatter' => 'date'),
|
||||
// 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
|
||||
// 'binary' => array('name' => 'blob'),
|
||||
// 'boolean' => array('name' => 'tinyint', 'limit' => '1'));
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@paramÊunknown_typeÊ$config
|
||||
Ê*Ê@returnÊunknown
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊ__constructÊ($config)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊreturn parent::__construct($config);
|
||||
ÊÊÊÊ}
|
||||
* 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['database'], $config['login'], $config['password']);
|
||||
|
||||
if ($this->connection)
|
||||
{
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*Ê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['database'],Ê$config['login'],Ê$config['password']);
|
||||
ÊÊÊÊÊÊÊÊifÊ($this->connection)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$this->connectedÊ=Êtrue;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊelse
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ//die('CouldÊnotÊconnectÊtoÊDB.');
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊ}
|
||||
* Disconnects from database.
|
||||
*
|
||||
* @return boolean True if the database could be disconnected, else false
|
||||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return @odbc_close($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊDisconnectsÊfromÊdatabase.
|
||||
Ê*
|
||||
Ê*Ê@returnÊbooleanÊTrueÊifÊtheÊdatabaseÊcouldÊbeÊdisconnected,ÊelseÊfalse
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊdisconnectÊ()
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊreturnÊ@odbc_close($this->connection);
|
||||
ÊÊÊÊ}
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
* @access protected
|
||||
*/
|
||||
function _execute ($sql)
|
||||
{
|
||||
return odbc_exec($this->connection, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊExecutesÊgivenÊSQLÊstatement.
|
||||
Ê*
|
||||
Ê*Ê@paramÊstringÊ$sqlÊSQLÊstatement
|
||||
Ê*Ê@returnÊresourceÊResultÊresourceÊidentifier
|
||||
Ê*Ê@accessÊprotected
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊ_executeÊ($sql)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊreturnÊodbc_exec($this->connection,Ê$sql);
|
||||
ÊÊÊÊ}
|
||||
* 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Ê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Ê=Êodbc_tables($this->connection);
|
||||
ÊÊÊÊÊÊÊÊifÊ(!$result)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊarray();
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊelse
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$tablesÊ=Êarray();
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊwhileÊ($lineÊ=Êodbc_fetch_array($result))
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ$tables[]Ê=Êstrtolower($line['TABLE_NAME']);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊ$tables;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊ}
|
||||
* Returns an array of sources (tables) in the database.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function listSources ()
|
||||
{
|
||||
$result = odbc_tables($this->connection);
|
||||
if (!$result)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
while ($line = odbc_fetch_array($result))
|
||||
{
|
||||
$tables[] = strtolower($line['TABLE_NAME']);
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
|
@ -192,236 +180,236 @@ class
|
|||
* @param Model $model Model object to describe
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
ÊÊÊÊfunctionÊ&describeÊ(&$model)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊ$cacheÊ=Êparent::describe($model);
|
||||
ÊÊÊÊÊÊÊÊifÊ($cacheÊ!=Ênull)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊ$cache;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
function &describe (&$model)
|
||||
{
|
||||
$cache = parent::describe($model);
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
ÊÊÊÊÊÊÊÊ$fieldsÊ=Êarray();
|
||||
ÊÊÊÊÊÊÊÊ$sqlÊ=Ê'SELECTÊ*ÊFROMÊ'Ê.Ê$this->name($model->table) . ' LIMIT 1';
|
||||
ÊÊÊÊÊÊÊÊ$resultÊ=Êodbc_exec($this->connection,Ê$sql);
|
||||
$fields = array();
|
||||
$sql = 'SELECT * FROM ' . $this->name($model->table) . ' LIMIT 1';
|
||||
$result = odbc_exec($this->connection, $sql);
|
||||
|
||||
$count = odbc_num_fields($result);
|
||||
|
||||
ÊÊÊÊÊÊÊÊforÊ($i = 1;Ê$iÊ<=Ê$count;Ê$i++)
|
||||
for ($i = 1; $i <= $count; $i++)
|
||||
{
|
||||
$cols[$i - 1]Ê=Êodbc_field_name($result,Ê$i);
|
||||
$cols[$i - 1] = odbc_field_name($result, $i);
|
||||
}
|
||||
|
||||
ÊÊÊÊÊÊÊÊforeachÊ($colsÊasÊ$column)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$typeÊ=Êodbc_field_type(odbc_exec($this->connection,"SELECTÊ"Ê.Ê$columnÊ.Ê"ÊFROMÊ"Ê.Ê$model->table),Ê1);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊarray_push($fields,Êarray('name'Ê=>Ê$column,Ê'type'Ê=>Ê$type));
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
foreach ($cols as $column)
|
||||
{
|
||||
$type = odbc_field_type(odbc_exec($this->connection,"SELECT " . $column . " FROM " . $model->table), 1);
|
||||
array_push($fields, array('name' => $column, 'type' => $type));
|
||||
}
|
||||
|
||||
ÊÊÊÊÊÊÊÊ$this->__cacheDescription($model->table,Ê$fields);
|
||||
ÊÊÊÊÊÊÊÊreturnÊ$fields;
|
||||
ÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊ
|
||||
$this->__cacheDescription($model->table, $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
ÊÊÊÊfunctionÊnameÊ($data)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊifÊ($dataÊ==Ê'*')
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊ'*';
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊÊ$posÊ=Êstrpos($data,Ê'`');
|
||||
ÊÊÊÊÊÊÊÊifÊ($posÊ===Êfalse)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$dataÊ=Ê''Ê.Êstr_replace('.',Ê'.',Ê$data)Ê.'';
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ//$dataÊ=Ê'`'.Êstr_replace('.',Ê'`.`',Ê$data)Ê.'`';
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊ$data;
|
||||
ÊÊÊÊ}
|
||||
function name ($data)
|
||||
{
|
||||
if ($data == '*')
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
$pos = strpos($data, '`');
|
||||
if ($pos === false)
|
||||
{
|
||||
$data = '' . str_replace('.', '.', $data) .'';
|
||||
//$data = '`'. str_replace('.', '`.`', $data) .'`';
|
||||
}
|
||||
return $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Ê($dataÊ===Ênull)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊ'NULL';
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊifÊ(ini_get('magic_quotes_gpc')Ê==Ê1)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$dataÊ=Êstripslashes($data);
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊ//Ê$dataÊ=Êmysql_real_escape_string($data,Ê$this->connection);
|
||||
* 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 ($data === null)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
// $data = mysql_real_escape_string($data, $this->connection);
|
||||
|
||||
ÊÊÊÊÊÊÊÊif(!is_numeric($data))
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$returnÊ=Ê"'"Ê.Ê$dataÊ.Ê"'";
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊelse
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$returnÊ=Ê$data;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊ$return;
|
||||
ÊÊÊÊ}
|
||||
if(!is_numeric($data))
|
||||
{
|
||||
$return = "'" . $data . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = $data;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊNotÊsureÊaboutÊthisÊone,ÊMySQLÊneedsÊitÊbutÊdoesÊODBC?ÊÊSaferÊjustÊtoÊleaveÊit
|
||||
Ê*Ê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;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊ}
|
||||
|
||||
/**
|
||||
Ê*Ê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))
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊifÊ(odbc_autocommit($this->connection, false))
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ$this->__transactionStartedÊ=Êtrue;
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊreturnÊtrue;
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊfalse;
|
||||
ÊÊÊÊ}
|
||||
|
||||
/**
|
||||
Ê*Ê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))
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
if (odbc_commit($this->connection))
|
||||
* Not sure about this one, MySQL needs it but does ODBC? Safer just to leave it
|
||||
* 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))
|
||||
{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ $this->__transactionStarted = false;
|
||||
return true;
|
||||
}
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊfalse;
|
||||
ÊÊÊÊ}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*Ê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))
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$this->__transactionStarted = false;
|
||||
returnÊodbc_rollback($this->connection);
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊfalse;
|
||||
ÊÊÊÊ}
|
||||
* 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))
|
||||
{
|
||||
if (odbc_autocommit($this->connection, false))
|
||||
{
|
||||
$this->__transactionStarted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊReturnsÊaÊformattedÊerrorÊmessageÊfromÊpreviousÊdatabaseÊoperation.
|
||||
Ê*
|
||||
Ê*Ê@returnÊstringÊErrorÊmessageÊwithÊerrorÊnumber
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊlastErrorÊ()
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊifÊ(odbc_error($this->connection))
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊreturnÊodbc_error($this->connection).':Ê'.odbc_errormsg($this->connection);
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊnull;
|
||||
ÊÊÊÊ}
|
||||
* 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))
|
||||
{
|
||||
if (odbc_commit($this->connection))
|
||||
{
|
||||
$this->__transactionStarted = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*Ê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Ênull;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊnull;
|
||||
ÊÊÊÊ}
|
||||
* 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))
|
||||
{
|
||||
$this->__transactionStarted = false;
|
||||
return odbc_rollback($this->connection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*Ê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Ê@odbc_num_rows($this->_result);
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊreturnÊnull;
|
||||
ÊÊÊÊ}
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message with error number
|
||||
*/
|
||||
function lastError ()
|
||||
{
|
||||
if (odbc_error($this->connection))
|
||||
{
|
||||
return odbc_error($this->connection).': '.odbc_errormsg($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊReturnsÊtheÊIDÊgeneratedÊfromÊtheÊpreviousÊINSERTÊoperation.
|
||||
Ê*
|
||||
Ê*Ê@paramÊunknown_typeÊ$source
|
||||
Ê*Ê@returnÊint
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊlastInsertIdÊ($sourceÊ=Ê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 null;
|
||||
}
|
||||
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 @odbc_num_rows($this->_result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @param unknown_type $source
|
||||
* @return int
|
||||
*/
|
||||
function lastInsertId ($source = null)
|
||||
{
|
||||
$result = $this->fetchAll('SELECT @@IDENTITY');
|
||||
return $result[0];
|
||||
ÊÊÊÊ}
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@paramÊstringÊ$realÊRealÊdatabase-layerÊcolumnÊtypeÊ(i.e.Ê"varchar(255)")
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊcolumn($real)
|
||||
ÊÊÊÊ{
|
||||
* Enter description here...
|
||||
*
|
||||
* @param string $real Real database-layer column type (i.e. "varchar(255)")
|
||||
*/
|
||||
function column($real)
|
||||
{
|
||||
if (is_array($real))
|
||||
{
|
||||
$col = $real['name'];
|
||||
|
@ -432,72 +420,72 @@ class
|
|||
return $col;
|
||||
}
|
||||
|
||||
ÊÊÊÊÊÊÊÊreturnÊ$real;
|
||||
ÊÊÊÊ}
|
||||
return $real;
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊEnterÊdescriptionÊhere...
|
||||
Ê*
|
||||
Ê*Ê@paramÊunknown_typeÊ$results
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊresultSet(&$results)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊ$this->resultsÊ=&Ê$results;
|
||||
ÊÊÊÊÊÊÊÊ$this->mapÊ=Êarray();
|
||||
ÊÊÊÊÊÊÊÊ$num_fieldsÊ=Êodbc_num_fields($results);
|
||||
ÊÊÊÊÊÊÊÊ$indexÊ=Ê0;
|
||||
ÊÊÊÊÊÊÊÊ$jÊ=Ê0;
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
function resultSet(&$results)
|
||||
{
|
||||
$this->results =& $results;
|
||||
$this->map = array();
|
||||
$num_fields = odbc_num_fields($results);
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
ÊÊÊÊÊÊÊÊwhileÊ($jÊ<Ê$num_fields)
|
||||
ÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$columnÊ=Êodbc_fetch_array($results,$j);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊifÊ(!empty($column->table))
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ$this->map[$index++]Ê=Êarray($column->table,Ê$column->name);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊelse
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊechoÊarray(0,Ê$column->name);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ$this->map[$index++]Ê=Êarray(0,Ê$column->name);
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊÊÊÊÊÊÊÊÊ$j++;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊ}
|
||||
while ($j < $num_fields)
|
||||
{
|
||||
$column = odbc_fetch_array($results,$j);
|
||||
if (!empty($column->table))
|
||||
{
|
||||
$this->map[$index++] = array($column->table, $column->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo array(0, $column->name);
|
||||
$this->map[$index++] = array(0, $column->name);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Ê*ÊFetchesÊtheÊnextÊrowÊfromÊtheÊcurrentÊresultÊset
|
||||
Ê*
|
||||
Ê*Ê@returnÊunknown
|
||||
Ê*/
|
||||
ÊÊÊÊfunctionÊfetchResult()
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊifÊ($rowÊ=Êodbc_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;
|
||||
ÊÊÊÊÊÊÊÊ}
|
||||
ÊÊÊÊ}
|
||||
* Fetches the next row from the current result set
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchResult()
|
||||
{
|
||||
if ($row = odbc_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ÊbuildSchemaQuery($schema)
|
||||
ÊÊÊÊ{
|
||||
ÊÊÊÊÊÊÊÊ$searchÊÊ=Êarray('{AUTOINCREMENT}',Ê'{PRIMARY}',Ê'{UNSIGNED}',Ê'{FULLTEXT}',
|
||||
ÊÊÊÊÊÊÊÊ'{FULLTEXT_MYSQL}',Ê'{BOOLEAN}',Ê'{UTF_8}');
|
||||
ÊÊÊÊÊÊÊÊ$replaceÊ=Êarray('int(11)ÊnotÊnullÊauto_increment',Ê'primaryÊkey',Ê'unsigned',
|
||||
ÊÊÊÊÊÊÊÊ'FULLTEXT',Ê'FULLTEXT',Ê'enumÊ(\'true\',Ê\'false\')ÊNOTÊNULLÊdefaultÊ\'true\'',
|
||||
ÊÊÊÊÊÊÊÊ'/*!40100ÊCHARACTERÊSETÊutf8ÊCOLLATEÊutf8_unicode_ciÊ*/');
|
||||
ÊÊÊÊÊÊÊÊ$queryÊ=Êtrim(str_replace($search,Ê$replace,Ê$schema));
|
||||
ÊÊÊÊÊÊÊÊreturnÊ$query;
|
||||
ÊÊÊÊ}
|
||||
function buildSchemaQuery($schema)
|
||||
{
|
||||
$search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}',
|
||||
'{FULLTEXT_MYSQL}', '{BOOLEAN}', '{UTF_8}');
|
||||
$replace = array('int(11) not null auto_increment', 'primary key', 'unsigned',
|
||||
'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'',
|
||||
'/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */');
|
||||
$query = trim(str_replace($search, $replace, $schema));
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -102,7 +102,8 @@ class DboPostgres extends DboSource
|
|||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return pg_close($this->connection);
|
||||
$this->connected = !@pg_close($this->connection);
|
||||
return !$this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,65 +168,6 @@ class DboPostgres extends DboSource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the fields list of an SQL query.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $alias Alias tablename
|
||||
* @param mixed $fields
|
||||
* @return array
|
||||
*/
|
||||
function fields (&$model, $alias, $fields)
|
||||
{
|
||||
if (is_array($fields))
|
||||
{
|
||||
$fields = $fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields != null)
|
||||
{
|
||||
if (strpos($fields, ','))
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields = array($fields);
|
||||
}
|
||||
$fields = array_map('trim', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($model->_tableInfo->value as $field)
|
||||
{
|
||||
$fields[]= $field['name'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($fields);
|
||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false)
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]) . ' AS ' . $this->name($alias . '__' . $fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]) . ' AS ' . $this->name($build[0] . '__' . $build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
|
@ -444,6 +386,65 @@ class DboPostgres extends DboSource
|
|||
return $data[0]['max'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the fields list of an SQL query.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $alias Alias tablename
|
||||
* @param mixed $fields
|
||||
* @return array
|
||||
*/
|
||||
function fields (&$model, $alias, $fields)
|
||||
{
|
||||
if (is_array($fields))
|
||||
{
|
||||
$fields = $fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields != null)
|
||||
{
|
||||
if (strpos($fields, ','))
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields = array($fields);
|
||||
}
|
||||
$fields = array_map('trim', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($model->_tableInfo->value as $field)
|
||||
{
|
||||
$fields[]= $field['name'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($fields);
|
||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false)
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]) . ' AS ' . $this->name($alias . '__' . $fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]) . ' AS ' . $this->name($build[0] . '__' . $build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
|
@ -520,7 +521,7 @@ class DboPostgres extends DboSource
|
|||
{
|
||||
return 'binary';
|
||||
}
|
||||
if (in_array($col, array('float', 'float4', 'float8', 'double', 'decimal', 'real')))
|
||||
if (in_array($col, array('float', 'float4', 'float8', 'double', 'decimal', 'real', 'numeric')))
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
|
|
@ -42,8 +42,54 @@ uses('model'.DS.'datasources'.DS.'dbo_source');
|
|||
* @subpackage cake.cake.libs.model.dbo
|
||||
* @since CakePHP v 0.9.0
|
||||
*/
|
||||
class DBO_SQLite extends DboSource
|
||||
class DboSqlite extends DboSource
|
||||
{
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $description = "SQLite DBO Driver";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $startQuote = '"';
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $endQuote = '"';
|
||||
|
||||
/**
|
||||
* Base configuration settings for SQLite driver
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'database' => 'cake',
|
||||
'connect' => 'sqlite_popen');
|
||||
|
||||
/**
|
||||
* SQLite column definition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $columns = array('primary_key' => array('name' => 'integer primary key'),
|
||||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||
'text' => array('name' => 'text'),
|
||||
'integer' => array('name' => 'integer', 'limit' => '11', 'formatter' => 'intval'),
|
||||
'float' => array('name' => 'float', 'formatter' => 'floatval'),
|
||||
'datetime' => array('name' => 'timestamp', 'format' => 'YmdHis', 'formatter' => 'date'),
|
||||
'timestamp' => array('name' => 'timestamp', 'format' => 'YmdHis', 'formatter' => 'date'),
|
||||
'time' => array('name' => 'timestamp', 'format' => 'His', 'formatter' => 'date'),
|
||||
'date' => array('name' => 'date', 'format' => 'Ymd', 'formatter' => 'date'),
|
||||
'binary' => array('name' => 'blob'),
|
||||
'boolean' => array('name' => 'integer', 'limit' => '1'));
|
||||
|
||||
/**
|
||||
* Connects to the database using config['file'] as a filename.
|
||||
|
@ -51,23 +97,13 @@ class DBO_SQLite extends DboSource
|
|||
* @param array $config Configuration array for connecting
|
||||
* @return mixed
|
||||
*/
|
||||
function connect($config)
|
||||
function connect()
|
||||
{
|
||||
if ($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->_conn = $config['connect']($config['file']);
|
||||
}
|
||||
$this->connected = $this->_conn? true: false;
|
||||
$config = $this->config;
|
||||
$this->connection = $config['connect']($config['database']);
|
||||
$this->connected = is_resource($this->connection);
|
||||
|
||||
if($this->connected)
|
||||
{
|
||||
return $this->_conn;
|
||||
}
|
||||
else
|
||||
{
|
||||
//die('Could not connect to DB.');
|
||||
}
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +113,8 @@ class DBO_SQLite extends DboSource
|
|||
*/
|
||||
function disconnect()
|
||||
{
|
||||
return sqlite_close($this->_conn);
|
||||
$this->connected = !@sqlite_close($this->connection);
|
||||
return !$this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,19 +123,28 @@ class DBO_SQLite extends DboSource
|
|||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
*/
|
||||
function execute($sql)
|
||||
function _execute($sql)
|
||||
{
|
||||
return sqlite_query($this->_conn, $sql);
|
||||
return sqlite_query($this->connection, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array.
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
function fetchRow()
|
||||
function fetchRow ($assoc = false)
|
||||
{
|
||||
return sqlite_fetch_array($this->_result);
|
||||
if(is_resource($this->_result))
|
||||
{
|
||||
$this->resultSet($this->_result);
|
||||
$resultRow = $this->fetchResult();
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,24 +152,37 @@ class DBO_SQLite extends DboSource
|
|||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function tablesList()
|
||||
function listSources()
|
||||
{
|
||||
$result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
|
||||
$db = $this->config['database'];
|
||||
$this->config['database'] = basename($this->config['database']);
|
||||
|
||||
$cache = parent::listSources();
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
while ($line = sqlite_fetch_array($result))
|
||||
{
|
||||
$tables[] = $line[0];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
|
||||
|
||||
if (!$result || empty($result))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
foreach ($result as $table)
|
||||
{
|
||||
$tables[] = $table[0]['name'];
|
||||
}
|
||||
parent::listSources($tables);
|
||||
|
||||
$this->config['database'] = $db;
|
||||
return $tables;
|
||||
}
|
||||
$this->config['database'] = $db;
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,17 +191,43 @@ class DBO_SQLite extends DboSource
|
|||
* @param string $tableName Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function fields($tableName)
|
||||
function describe(&$model)
|
||||
{
|
||||
$fields = false;
|
||||
$cols = sqlite_fetch_column_types($tableName, $this->_conn);
|
||||
$cache = parent::describe($model);
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
$fields = false;
|
||||
$cols = sqlite_fetch_column_types($model->table, $this->connection);
|
||||
|
||||
foreach ($cols as $column => $type)
|
||||
{
|
||||
$fields[] = array('name'=>$column, 'type'=>$type);
|
||||
}
|
||||
foreach ($cols as $column => $type)
|
||||
{
|
||||
$fields[] = array('name' => $column, 'type' => $this->column($type), 'null' => true);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
$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 SQLite
|
||||
*/
|
||||
function name ($data)
|
||||
{
|
||||
if ($data == '*')
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
$pos = strpos($data, '"');
|
||||
if ($pos === false)
|
||||
{
|
||||
$data = '"'. str_replace('.', '"."', $data) .'"';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,9 +236,94 @@ class DBO_SQLite extends DboSource
|
|||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @return string Quoted and escaped
|
||||
*/
|
||||
function prepareValue($data)
|
||||
function value ($data, $column = null, $safe = false)
|
||||
{
|
||||
return "'" . sqlite_escape_string($data) . "'";
|
||||
$parent = parent::value($data, $column, $safe);
|
||||
|
||||
if ($parent != null)
|
||||
{
|
||||
return $parent;
|
||||
}
|
||||
|
||||
if ($data === null)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if($data == '')
|
||||
{
|
||||
return "''";
|
||||
}
|
||||
|
||||
switch ($column)
|
||||
{
|
||||
case 'boolean':
|
||||
$data = $this->boolean((bool)$data);
|
||||
break;
|
||||
default:
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
$data = sqlite_escape_string($data);
|
||||
break;
|
||||
}
|
||||
return "'" . $data . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
if ($this->execute('BEGIN'))
|
||||
{
|
||||
$this->__transactionStarted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
$this->__transactionStarted;
|
||||
return $this->execute('COMMIT');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
return $this->execute('ROLLBACK');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +333,12 @@ class DBO_SQLite extends DboSource
|
|||
*/
|
||||
function lastError()
|
||||
{
|
||||
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): null;
|
||||
$error = sqlite_last_error($this->connection);
|
||||
if ($error)
|
||||
{
|
||||
return $error.': '.sqlite_error_string($error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,7 +348,11 @@ class DBO_SQLite extends DboSource
|
|||
*/
|
||||
function lastAffected()
|
||||
{
|
||||
return $this->_result? sqlite_changes($this->_conn): false;
|
||||
if ($this->_result)
|
||||
{
|
||||
return sqlite_changes($this->connection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,7 +363,11 @@ class DBO_SQLite extends DboSource
|
|||
*/
|
||||
function lastNumRows()
|
||||
{
|
||||
return $this->_result? sqlite_num_rows($this->_result): false;
|
||||
if ($this->_result)
|
||||
{
|
||||
sqlite_num_rows($this->_result);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +377,111 @@ class DBO_SQLite extends DboSource
|
|||
*/
|
||||
function lastInsertId()
|
||||
{
|
||||
return sqlite_last_insert_rowid($this->_conn);
|
||||
return sqlite_last_insert_rowid($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts database-layer column types to basic types
|
||||
*
|
||||
* @param string $real Real database-layer column type (i.e. "varchar(255)")
|
||||
* @return string Abstract column type (i.e. "string")
|
||||
*/
|
||||
function column($real)
|
||||
{
|
||||
if (is_array($real))
|
||||
{
|
||||
$col = $real['name'];
|
||||
if (isset($real['limit']))
|
||||
{
|
||||
$col .= '('.$real['limit'].')';
|
||||
}
|
||||
return $col;
|
||||
}
|
||||
|
||||
$col = low(r(')', '', $real));
|
||||
$limit = null;
|
||||
@list($col, $limit) = explode('(', $col);
|
||||
|
||||
if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp')))
|
||||
{
|
||||
return $col;
|
||||
}
|
||||
if (strpos($col, 'varchar') !== false)
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
if (in_array($col, array('blob', 'clob')))
|
||||
{
|
||||
return 'binary';
|
||||
}
|
||||
if (strpos($col, 'numeric') !== false)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
function resultSet(&$results)
|
||||
{
|
||||
$this->results =& $results;
|
||||
$this->map = array();
|
||||
$num_fields = sqlite_num_fields($results);
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
while ($j < $num_fields)
|
||||
{
|
||||
$columnName = str_replace('"', '', sqlite_field_name($results, $j));
|
||||
|
||||
if (strpos($columnName, '.'))
|
||||
{
|
||||
$parts = explode('.', $columnName);
|
||||
$this->map[$index++] = array($parts[0], $parts[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->map[$index++] = array(0, $columnName);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row from the current result set
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchResult()
|
||||
{
|
||||
if ($row = sqlite_fetch_array($this->results, SQLITE_ASSOC))
|
||||
{
|
||||
$resultRow = array();
|
||||
$i = 0;
|
||||
foreach ($row as $index => $field)
|
||||
{
|
||||
if (strpos($index, '.'))
|
||||
{
|
||||
list($table, $column) = explode('.', str_replace('"', '', $index));
|
||||
$resultRow[$table][$column] = $row[$index];
|
||||
}
|
||||
else
|
||||
{
|
||||
$resultRow[0][str_replace('"', '', $index)] = $row[$index];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,9 +491,23 @@ class DBO_SQLite extends DboSource
|
|||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
function selectLimit($limit, $offset=null)
|
||||
function limit ($limit, $offset = null)
|
||||
{
|
||||
return " LIMIT {$limit}".($offset? ", {$offset}": null);
|
||||
if ($limit)
|
||||
{
|
||||
$rt = '';
|
||||
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0)
|
||||
{
|
||||
$rt = ' LIMIT';
|
||||
}
|
||||
$rt .= ' ' . $limit;
|
||||
if ($offset)
|
||||
{
|
||||
$rt .= ', ' . $offset;
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -638,10 +638,10 @@ class Model extends Object
|
|||
{
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
if (!is_object($this->_tableInfo) && $db->isInterfaceSupported('describe'))
|
||||
{
|
||||
$this->_tableInfo = new NeatArray($db->describe($this));
|
||||
}
|
||||
return $this->_tableInfo;
|
||||
{
|
||||
$this->_tableInfo = new NeatArray($db->describe($this));
|
||||
}
|
||||
return $this->_tableInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -634,10 +634,10 @@ class Model extends Object
|
|||
{
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
if (!is_object($this->_tableInfo) && $db->isInterfaceSupported('describe'))
|
||||
{
|
||||
$this->_tableInfo = new NeatArray($db->describe($this));
|
||||
}
|
||||
return $this->_tableInfo;
|
||||
{
|
||||
$this->_tableInfo = new NeatArray($db->describe($this));
|
||||
}
|
||||
return $this->_tableInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -158,7 +158,7 @@ foreach($relations as $association => $relation)
|
|||
$controller = Inflector::pluralize($model);
|
||||
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($association))."</H2>";
|
||||
if(isset($data[$association]) && is_array($data[$association]))
|
||||
if(isset($data[$association][0]) && is_array($data[$association]))
|
||||
{
|
||||
?>
|
||||
<table class="inav" cellspacing="0">
|
||||
|
|
Loading…
Reference in a new issue