mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes into the trunk.
Revision: [2618] Adding fix for Ticket #609 Revision: [2617] Added fix for Ticket #684 Revision: [2616] Adding patch from Ticket #649 Revision: [2615] Adding fix for Ticket #608 Revision: [2614] Additional fix for Ticket #584 Revision: [2613] Adding fix for Ticket #584 Revision: [2612] Added fix for undefined index notices Revision: [2609] Adding fix for Ticket #658 Revision: [2608] Adding fix for Ticket #635, and code formatting fixes in FormHelper Revision: [2607] Adding fix for Ticket #636 Revision: [2606] Adding fix to allow associations to be defined through non-associative arrays Revision: [2605] Adding fix for Ticket #672 Revision: [2604] Adding fix for Ticket #708 Revision: [2603] Adding fix for Ticket #687 Revision: [2602] Refactoring database drivers, and adding fix for Ticket #398 Revision: [2601] Merging change from model_php5.php Revision: [2600] Adding ODBC driver Revision: [2599] Adding fix for Ticket #702 Revision: [2598] Adding fix for Ticket #699 Revision: [2597] Fixing an issue in Model::set(), and moving limit() to DboSource Revision: [2595] Fixing unit test download URL in Bake Revision: [2594] Adding fix for Ticket #698 Revision: [2593] Adding fox for Ticket #231 Revision: [2592] Adding fix for Ticket #630, and updating MS SQL driver docstring Revision: [2577] Adding $alias property to enable future Oracle support Revision: [2568] Merging changes to bake from old sandboxes git-svn-id: https://svn.cakephp.org/repo/trunk/cake/1.x.x.x@2620 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
1707fd8582
commit
4a8c03ef1c
20 changed files with 1507 additions and 633 deletions
|
@ -6,4 +6,4 @@
|
||||||
// +---------------------------------------------------------------------------------------------------+ //
|
// +---------------------------------------------------------------------------------------------------+ //
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
1.0.0.2560
|
1.0.0.2620
|
|
@ -75,23 +75,26 @@ table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border: 1px solid #333;
|
border: 1px solid #333;
|
||||||
|
border-collapse: collapse;
|
||||||
clear:both;
|
clear:both;
|
||||||
margin: 0 0 2em 0;
|
margin: 0 0 2em 0;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
|
tbody {
|
||||||
|
height: 400px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
th {
|
th {
|
||||||
background-color: #ccc;
|
border: 1px solid #666;
|
||||||
border-top: 1px solid #fff;
|
|
||||||
border-right: 1px solid #666;
|
|
||||||
border-bottom: 1px solid #666;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding:3px;
|
padding:3px;
|
||||||
|
border-bottom: 1px solid #666;
|
||||||
}
|
}
|
||||||
table tr td {
|
table tr td {
|
||||||
border-right: 1px solid #ccc;
|
|
||||||
padding:4px 4px;
|
padding:4px 4px;
|
||||||
vertical-align:top;
|
vertical-align:top;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
border-bottom: 1px solid #666;
|
||||||
}
|
}
|
||||||
table tr.altRow td {
|
table tr.altRow td {
|
||||||
background: #f4f4f4;
|
background: #f4f4f4;
|
||||||
|
|
|
@ -44,16 +44,6 @@ class AclNode extends AppModel
|
||||||
|
|
||||||
var $cacheQueries = false;
|
var $cacheQueries = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
$this->setSource();
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
|
@ -262,7 +252,7 @@ class AclNode extends AppModel
|
||||||
function _resolveID($id)
|
function _resolveID($id)
|
||||||
{
|
{
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
$key = (is_string($id) ? 'alias' : $secondary_id);
|
$key = (is_numeric($id) ? $secondary_id : 'alias');
|
||||||
return array($this->name.'.'.$key => $id);
|
return array($this->name.'.'.$key => $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,15 +312,6 @@ class AclNode extends AppModel
|
||||||
$vars['class'] = ucwords($class);
|
$vars['class'] = ucwords($class);
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function setSource()
|
|
||||||
{
|
|
||||||
$this->table = strtolower(get_class($this)) . "s";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -76,14 +76,35 @@ class PagesController extends AppController{
|
||||||
{
|
{
|
||||||
$this->redirect('/');
|
$this->redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = func_get_args();
|
$path = func_get_args();
|
||||||
|
|
||||||
if (!count($path))
|
if (!count($path))
|
||||||
{
|
{
|
||||||
$this->redirect('/');
|
$this->redirect('/');
|
||||||
}
|
}
|
||||||
$this->set('page', $path[0]);
|
|
||||||
$this->set('subpage', empty($path[1])? null: $path[1]);
|
$count = count($path);
|
||||||
$this->set('title', ucfirst($path[count($path)-1]));
|
$page = null;
|
||||||
|
$subpage = null;
|
||||||
|
$title = null;
|
||||||
|
|
||||||
|
if(!empty($path[0]))
|
||||||
|
{
|
||||||
|
$page = $path[0];
|
||||||
|
}
|
||||||
|
if(!empty($path[1]))
|
||||||
|
{
|
||||||
|
$subpage = $path[1];
|
||||||
|
}
|
||||||
|
if(!empty($path[$count-1]))
|
||||||
|
{
|
||||||
|
$title = ucfirst($path[$count-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->set('page', $page);
|
||||||
|
$this->set('subpage', $subpage);
|
||||||
|
$this->set('title', $title);
|
||||||
$this->render(join('/', $path));
|
$this->render(join('/', $path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,16 +72,30 @@ class DboSource extends DataSource
|
||||||
*/
|
*/
|
||||||
var $endQuote = null;
|
var $endQuote = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $alias = 'AS ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $goofyLimit = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct($config = null)
|
function __construct($config = null)
|
||||||
{
|
{
|
||||||
$this->debug = DEBUG > 0;
|
$this->debug = DEBUG > 0;
|
||||||
$this->fullDebug = DEBUG > 1;
|
$this->fullDebug = DEBUG > 1;
|
||||||
parent::__construct($config);
|
parent::__construct($config);
|
||||||
return $this->connect();
|
return $this->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +109,7 @@ class DboSource extends DataSource
|
||||||
$this->disconnect();
|
$this->disconnect();
|
||||||
if ($config != null)
|
if ($config != null)
|
||||||
{
|
{
|
||||||
$this->config = am($this->config, $config);
|
$this->config = am($this->_baseConfig, $config);
|
||||||
}
|
}
|
||||||
return $this->connect();
|
return $this->connect();
|
||||||
}
|
}
|
||||||
|
@ -326,7 +340,7 @@ class DboSource extends DataSource
|
||||||
* @param boolean $cache Enables returning/storing cached query results
|
* @param boolean $cache Enables returning/storing cached query results
|
||||||
* @return array Array of resultset rows, or false if no rows matched
|
* @return array Array of resultset rows, or false if no rows matched
|
||||||
*/
|
*/
|
||||||
function fetchAll ($sql, $cache = true)
|
function fetchAll ($sql, $cache = true, $modelName = null)
|
||||||
{
|
{
|
||||||
if ($cache && isset($this->_queryCache[$sql]))
|
if ($cache && isset($this->_queryCache[$sql]))
|
||||||
{
|
{
|
||||||
|
@ -409,8 +423,8 @@ class DboSource extends DataSource
|
||||||
{
|
{
|
||||||
$text = 'query';
|
$text = 'query';
|
||||||
}
|
}
|
||||||
print("<table border=\"1\">\n<tr><th colspan=\"7\">{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</th></tr>\n");
|
print("<table border=\"0\">\n<caption>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n");
|
||||||
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
|
print("<thead>\n<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>\n</thead>\n<tbody>\n");
|
||||||
|
|
||||||
foreach($log as $k => $i)
|
foreach($log as $k => $i)
|
||||||
{
|
{
|
||||||
|
@ -580,7 +594,7 @@ 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);
|
$resultSet = $this->fetchAll($query, $model->cacheQueries, $model->name );
|
||||||
$filtered = $this->__filterResults($resultSet, $model);
|
$filtered = $this->__filterResults($resultSet, $model);
|
||||||
|
|
||||||
if ($model->recursive > 0)
|
if ($model->recursive > 0)
|
||||||
|
@ -613,7 +627,7 @@ class DboSource extends DataSource
|
||||||
}
|
}
|
||||||
if (isset($db) && $db != null)
|
if (isset($db) && $db != null)
|
||||||
{
|
{
|
||||||
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive);
|
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1);
|
||||||
unset($db);
|
unset($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -628,12 +642,14 @@ class DboSource extends DataSource
|
||||||
return $resultSet;
|
return $resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private method
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $linkModel
|
* @param unknown_type $results
|
||||||
* @param Model $model
|
* @param unknown_type $model
|
||||||
* @return array
|
* @param unknown_type $filtered
|
||||||
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function __filterResults(&$results, &$model, $filtered = array())
|
function __filterResults(&$results, &$model, $filtered = array())
|
||||||
{
|
{
|
||||||
|
@ -706,7 +722,7 @@ class DboSource extends DataSource
|
||||||
{
|
{
|
||||||
$row =& $resultSet[$i];
|
$row =& $resultSet[$i];
|
||||||
$q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i);
|
$q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i);
|
||||||
$fetch = $this->fetchAll($q, $model->cacheQueries);
|
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name);
|
||||||
|
|
||||||
if (!empty($fetch) && is_array($fetch))
|
if (!empty($fetch) && is_array($fetch))
|
||||||
{
|
{
|
||||||
|
@ -726,10 +742,23 @@ class DboSource extends DataSource
|
||||||
}
|
}
|
||||||
$this->__mergeAssociation($resultSet[$i], $fetch, $association, $type);
|
$this->__mergeAssociation($resultSet[$i], $fetch, $association, $type);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tempArray[0][$association] = false;
|
||||||
|
$this->__mergeAssociation($resultSet[$i], $tempArray, $association, $type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $data
|
||||||
|
* @param unknown_type $merge
|
||||||
|
* @param unknown_type $association
|
||||||
|
* @param unknown_type $type
|
||||||
|
*/
|
||||||
function __mergeAssociation(&$data, $merge, $association, $type)
|
function __mergeAssociation(&$data, $merge, $association, $type)
|
||||||
{
|
{
|
||||||
if (isset($merge[0]) && !isset($merge[0][$association]))
|
if (isset($merge[0]) && !isset($merge[0][$association]))
|
||||||
|
@ -760,17 +789,24 @@ class DboSource extends DataSource
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach ($merge as $i => $row)
|
if($merge[0][$association] === false)
|
||||||
{
|
{
|
||||||
if (count($row) == 1)
|
$data[$association] = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($merge as $i => $row)
|
||||||
{
|
{
|
||||||
$data[$association][] = $row[$association];
|
if (count($row) == 1)
|
||||||
}
|
{
|
||||||
else
|
$data[$association][] = $row[$association];
|
||||||
{
|
}
|
||||||
$tmp = array_merge($row[$association], $row);
|
else
|
||||||
unset($tmp[$association]);
|
{
|
||||||
$data[$association][] = $tmp;
|
$tmp = array_merge($row[$association], $row);
|
||||||
|
unset($tmp[$association]);
|
||||||
|
$data[$association][] = $tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -798,8 +834,8 @@ class DboSource extends DataSource
|
||||||
|
|
||||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])). ', ';
|
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])). ', ';
|
||||||
$sql .= join(', ', $this->fields($linkModel, $alias, ''));
|
$sql .= join(', ', $this->fields($linkModel, $alias, ''));
|
||||||
$sql .= ' FROM '.$this->name($model->table).' AS ' . $this->name($model->name);
|
$sql .= ' FROM '.$this->name($model->table).' '.$this->alias.$this->name($model->name);
|
||||||
$sql .= ' LEFT JOIN '.$this->name($linkModel->table).' AS ' . $this->name($alias);
|
$sql .= ' LEFT JOIN '.$this->name($linkModel->table).' '.$this->alias.$this->name($alias);
|
||||||
$sql .= ' ON ';
|
$sql .= ' ON ';
|
||||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||||
$sql .= ' = '.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
$sql .= ' = '.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||||
|
@ -868,12 +904,21 @@ class DboSource extends DataSource
|
||||||
{
|
{
|
||||||
$joinFields = null;
|
$joinFields = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates primary query
|
// Generates primary query
|
||||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) .$joinFields. ' FROM ';
|
$sql = 'SELECT ';
|
||||||
$sql .= $this->name($model->table).' AS ';
|
if ($this->goofyLimit)
|
||||||
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
|
{
|
||||||
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
|
$sql .= $this->limit($queryData['limit']);
|
||||||
$sql .= ' '.$this->limit($queryData['limit']);
|
}
|
||||||
|
$sql .= ' ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) .$joinFields. ' FROM ';
|
||||||
|
$sql .= $this->name($model->table).' '.$this->alias;
|
||||||
|
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
|
||||||
|
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
|
||||||
|
if (!$this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= ' '.$this->limit($queryData['limit']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
@ -897,8 +942,18 @@ class DboSource extends DataSource
|
||||||
{
|
{
|
||||||
$assocData['fields'] = '';
|
$assocData['fields'] = '';
|
||||||
}
|
}
|
||||||
$sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
$limit = '';
|
||||||
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$this->name($alias).' ';
|
if (isset($queryData['limit']) && !empty($queryData['limit']))
|
||||||
|
{
|
||||||
|
$limit = $this->limit($queryData['limit']);
|
||||||
|
}
|
||||||
|
$sql = 'SELECT ';
|
||||||
|
if ($this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= $limit;
|
||||||
|
}
|
||||||
|
$sql .= ' '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||||
|
$sql .= ' FROM '.$this->name($linkModel->table).' '.$this->alias.$this->name($alias).' ';
|
||||||
|
|
||||||
$conditions = $queryData['conditions'];
|
$conditions = $queryData['conditions'];
|
||||||
$condition = $this->name($alias).'.'.$this->name($assocData['foreignKey']);
|
$condition = $this->name($alias).'.'.$this->name($assocData['foreignKey']);
|
||||||
|
@ -920,7 +975,11 @@ class DboSource extends DataSource
|
||||||
$conditions .= $cond;
|
$conditions .= $cond;
|
||||||
}
|
}
|
||||||
$sql .= $this->conditions($conditions) . $this->order($queryData['order']);
|
$sql .= $this->conditions($conditions) . $this->order($queryData['order']);
|
||||||
$sql .= $this->limit($queryData['limit']);
|
|
||||||
|
if (!$this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= $limit;
|
||||||
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -939,7 +998,7 @@ class DboSource extends DataSource
|
||||||
$this->__assocJoins = null;
|
$this->__assocJoins = null;
|
||||||
}
|
}
|
||||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||||
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
|
$sql .= ' '.$this->alias.$this->name($alias).' ON '.$this->name($alias).'.';
|
||||||
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
||||||
|
|
||||||
if ($assocData['order'] != null)
|
if ($assocData['order'] != null)
|
||||||
|
@ -969,12 +1028,23 @@ class DboSource extends DataSource
|
||||||
case 'belongsTo':
|
case 'belongsTo':
|
||||||
if ($external)
|
if ($external)
|
||||||
{
|
{
|
||||||
|
$limit = '';
|
||||||
|
if (isset($assocData['limit']))
|
||||||
|
{
|
||||||
|
$limit = $this->limit($assocData['limit']);
|
||||||
|
}
|
||||||
if(!isset($assocData['fields']))
|
if(!isset($assocData['fields']))
|
||||||
{
|
{
|
||||||
$assocData['fields'] = '';
|
$assocData['fields'] = '';
|
||||||
}
|
}
|
||||||
$sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
|
||||||
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$this->name($alias).' ';
|
$sql = 'SELECT ';
|
||||||
|
if ($this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= $limit;
|
||||||
|
}
|
||||||
|
$sql .= ' '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||||
|
$sql .= ' FROM '.$this->name($linkModel->table).' '.$this->alias.$this->name($alias).' ';
|
||||||
|
|
||||||
$conditions = $assocData['conditions'];
|
$conditions = $assocData['conditions'];
|
||||||
|
|
||||||
|
@ -994,9 +1064,9 @@ class DboSource extends DataSource
|
||||||
$conditions .= $condition;
|
$conditions .= $condition;
|
||||||
}
|
}
|
||||||
$sql .= $this->conditions($conditions) . $this->order($assocData['order']);
|
$sql .= $this->conditions($conditions) . $this->order($assocData['order']);
|
||||||
if (isset($assocData['limit']))
|
if (!$this->goofyLimit)
|
||||||
{
|
{
|
||||||
$sql .= $this->limit($assocData['limit']);
|
$sql .= $limit;
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
@ -1016,7 +1086,7 @@ class DboSource extends DataSource
|
||||||
$this->__assocJoins = null;
|
$this->__assocJoins = null;
|
||||||
}
|
}
|
||||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||||
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
$sql .= ' '.$this->alias . $this->name($alias) . ' ON ';
|
||||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||||
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||||
|
|
||||||
|
@ -1046,9 +1116,20 @@ class DboSource extends DataSource
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$limit = '';
|
||||||
|
if (isset($assocData['limit']))
|
||||||
|
{
|
||||||
|
$limit = $this->limit($assocData['limit']);
|
||||||
|
}
|
||||||
|
|
||||||
$conditions = $assocData['conditions'];
|
$conditions = $assocData['conditions'];
|
||||||
$sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
$sql = 'SELECT ';
|
||||||
$sql .= ' FROM '.$this->name($linkModel->table).' AS '. $this->name($alias);
|
if ($this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= $limit;
|
||||||
|
}
|
||||||
|
$sql .= ' '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||||
|
$sql .= ' FROM '.$this->name($linkModel->table).' '.$this->alias. $this->name($alias);
|
||||||
|
|
||||||
if (is_array($conditions))
|
if (is_array($conditions))
|
||||||
{
|
{
|
||||||
|
@ -1068,9 +1149,9 @@ class DboSource extends DataSource
|
||||||
$sql .= $this->conditions($conditions);
|
$sql .= $this->conditions($conditions);
|
||||||
$sql .= $this->order($assocData['order']);
|
$sql .= $this->order($assocData['order']);
|
||||||
|
|
||||||
if (isset($assocData['limit']))
|
if (!$this->goofyLimit)
|
||||||
{
|
{
|
||||||
$sql .= $this->limit($assocData['limit']);
|
$sql .= $limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
|
@ -1084,8 +1165,18 @@ class DboSource extends DataSource
|
||||||
{
|
{
|
||||||
$joinTbl = $this->name($assocData['joinTable']);
|
$joinTbl = $this->name($assocData['joinTable']);
|
||||||
|
|
||||||
$sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
$limit = '';
|
||||||
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$this->name($alias);
|
if (isset($assocData['limit']))
|
||||||
|
{
|
||||||
|
$limit = $this->limit($assocData['limit']);
|
||||||
|
}
|
||||||
|
$sql = 'SELECT ';
|
||||||
|
if ($this->goofyLimit)
|
||||||
|
{
|
||||||
|
$sql .= $limit;
|
||||||
|
}
|
||||||
|
$sql .= ' '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
|
||||||
|
$sql .= ' FROM '.$this->name($linkModel->table).' '.$this->alias.$this->name($alias);
|
||||||
$sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl;
|
$sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl;
|
||||||
$sql .= '.'.$this->name($assocData['foreignKey']).'={$__cakeID__$}';
|
$sql .= '.'.$this->name($assocData['foreignKey']).'={$__cakeID__$}';
|
||||||
$sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']);
|
$sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']);
|
||||||
|
@ -1093,9 +1184,9 @@ class DboSource extends DataSource
|
||||||
|
|
||||||
$sql .= $this->conditions($assocData['conditions']);
|
$sql .= $this->conditions($assocData['conditions']);
|
||||||
$sql .= $this->order($assocData['order']);
|
$sql .= $this->order($assocData['order']);
|
||||||
if (isset($assocData['limit']))
|
if (!$this->goofyLimit)
|
||||||
{
|
{
|
||||||
$sql .= $this->limit($assocData['limit']);
|
$sql .= $limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
|
@ -1112,7 +1203,7 @@ class DboSource extends DataSource
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function update (&$model, $fields = null, $values = null)
|
function update (&$model, $fields = array(), $values = array())
|
||||||
{
|
{
|
||||||
$updates = array();
|
$updates = array();
|
||||||
$combined = array_combine($fields, $values);
|
$combined = array_combine($fields, $values);
|
||||||
|
@ -1413,13 +1504,30 @@ class DboSource extends DataSource
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be overridden in subclasses.
|
* Returns a limit statement in the correct format for the particular database.
|
||||||
*
|
*
|
||||||
|
* @param int $limit Limit of results returned
|
||||||
|
* @param int $offset Offset from which to start results
|
||||||
|
* @return string SQL limit/offset statement
|
||||||
*/
|
*/
|
||||||
function limit ()
|
function limit ($limit, $offset = null)
|
||||||
{
|
{
|
||||||
|
if ($limit)
|
||||||
|
{
|
||||||
|
$rt = '';
|
||||||
|
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0)
|
||||||
|
{
|
||||||
|
$rt = ' LIMIT';
|
||||||
|
}
|
||||||
|
if ($offset)
|
||||||
|
{
|
||||||
|
$rt .= ' ' . $offset. ',';
|
||||||
|
}
|
||||||
|
$rt .= ' ' . $limit;
|
||||||
|
return $rt;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1565,8 +1673,8 @@ class DboSource extends DataSource
|
||||||
*/
|
*/
|
||||||
function hasAny($table, $sql)
|
function hasAny($table, $sql)
|
||||||
{
|
{
|
||||||
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
|
$out = $this->one("SELECT COUNT(*) ".$this->alias."count FROM {$table}".($sql? " WHERE {$sql}":""));
|
||||||
return is_array($out)? $out[0]['count']: false;
|
return is_array($out)? $out[0]['count']: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -61,6 +61,23 @@ class DboAdodb extends DboSource
|
||||||
*/
|
*/
|
||||||
var $_adodb = null;
|
var $_adodb = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array translating ADOdb column MetaTypes to cake-supported metatypes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_adodb_column_types = array(
|
||||||
|
'C' => 'string',
|
||||||
|
'X' => 'text',
|
||||||
|
'D' => 'date',
|
||||||
|
'T' => 'timestamp',
|
||||||
|
'L' => 'boolean',
|
||||||
|
'N' => 'float',
|
||||||
|
'I' => 'integer',
|
||||||
|
'R' => 'integer', // denotes auto-increment or counter field
|
||||||
|
'B' => 'binary');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to the database using options in the given configuration array.
|
* Connects to the database using options in the given configuration array.
|
||||||
*
|
*
|
||||||
|
@ -106,7 +123,7 @@ class DboAdodb extends DboSource
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function _execute ($sql)
|
||||||
{
|
{
|
||||||
return $this->_adodb->execute($sql);
|
return $this->_adodb->execute($sql);
|
||||||
}
|
}
|
||||||
|
@ -116,10 +133,14 @@ class DboAdodb extends DboSource
|
||||||
*
|
*
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow ()
|
function fetchRow ()
|
||||||
{
|
{
|
||||||
return $this->_result->FetchRow();
|
if($this->_result->EOF)
|
||||||
}
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->_result->FetchRow();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin a transaction
|
* Begin a transaction
|
||||||
|
@ -193,20 +214,27 @@ class DboAdodb extends DboSource
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of the fields in given table name.
|
* Returns an array of the fields in the table used by the given model.
|
||||||
*
|
*
|
||||||
* @param string $tableName Name of database table to inspect
|
*
|
||||||
|
* @param AppModel $model Model object
|
||||||
* @return array Fields in table. Keys are name and type
|
* @return array Fields in table. Keys are name and type
|
||||||
*/
|
*/
|
||||||
function fields ($tableName)
|
function describe (&$model)
|
||||||
{
|
{
|
||||||
$data = $this->_adodb->MetaColumns($tableName);
|
$cache = parent::describe($model);
|
||||||
$fields = false;
|
if ($cache != null)
|
||||||
|
{
|
||||||
foreach ($data as $item)
|
return $cache;
|
||||||
$fields[] = array('name'=>$item->name, 'type'=>$item->type);
|
}
|
||||||
|
$fields = false;
|
||||||
return $fields;
|
$cols = $this->_adodb->MetaColumns($model->table);
|
||||||
|
foreach ($cols as $column)
|
||||||
|
{
|
||||||
|
$fields[] = array('name'=>$column->name, 'type'=>$column->type);
|
||||||
|
}
|
||||||
|
$this->__cacheDescription($model->table, $fields);
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,6 +307,87 @@ class DboAdodb extends DboSource
|
||||||
// adodb doesn't allow us to get the correct limit string out of it
|
// adodb doesn't allow us to get the correct limit string out of it
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* 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 ( isset( $this->_result ))
|
||||||
|
{
|
||||||
|
$adodb_metatyper = & $this->_result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$adodb_metatyper = & $this->_adodb->execute('Select 1');
|
||||||
|
}
|
||||||
|
$interpreted_type = $adodb_metatyper->MetaType($real);
|
||||||
|
|
||||||
|
if (!isset($this->_adodb_column_types[$interpreted_type]))
|
||||||
|
{
|
||||||
|
return 'text';
|
||||||
|
}
|
||||||
|
return $this->_adodb_column_types[ $interpreted_type ] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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_type The type of the column into which this data will be inserted
|
||||||
|
* @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
|
||||||
|
* @return string Quoted and escaped data
|
||||||
|
*/
|
||||||
|
function value ($data, $column = null, $safe = false)
|
||||||
|
{
|
||||||
|
$parent = parent::value($data, $column, $safe);
|
||||||
|
|
||||||
|
if ($parent != null)
|
||||||
|
{
|
||||||
|
return $parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data === null)
|
||||||
|
{
|
||||||
|
return 'NULL';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($data == '')
|
||||||
|
{
|
||||||
|
return "''";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini_get('magic_quotes_gpc') == 1)
|
||||||
|
{
|
||||||
|
$data = stripslashes($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_adodb->qstr( $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of all result rows for a given SQL query.
|
||||||
|
* Returns false if no rows matched.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @param boolean $cache Enables returning/storing cached query results
|
||||||
|
* @param string $modelName Name of model for first array dimension of results
|
||||||
|
* @return array Array of resultset rows, or false if no rows matched
|
||||||
|
*/
|
||||||
|
function fetchAll ($sql, $cache = true, $modelName = null)
|
||||||
|
{
|
||||||
|
$result = parent::fetchAll( $sql, $cache );
|
||||||
|
if (!$result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach($result as $key => $value)
|
||||||
|
{
|
||||||
|
$return[$key][$modelName] = $value;
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -66,6 +66,13 @@ class DboMssql extends DboSource
|
||||||
*/
|
*/
|
||||||
var $endQuote = "]";
|
var $endQuote = "]";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $goofyLimit = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base configuration settings for MS SQL driver
|
* Base configuration settings for MS SQL driver
|
||||||
*
|
*
|
||||||
|
@ -84,7 +91,7 @@ class DboMssql extends DboSource
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||||
'text' => array('name' => 'text'),
|
'text' => array('name' => 'text'),
|
||||||
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
|
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
|
||||||
|
@ -196,7 +203,7 @@ class DboMssql extends DboSource
|
||||||
|
|
||||||
if (!$result || empty($result))
|
if (!$result || empty($result))
|
||||||
{
|
{
|
||||||
return null;
|
return array();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -213,7 +220,7 @@ class DboMssql extends DboSource
|
||||||
/**
|
/**
|
||||||
* Returns an array of the fields in given table name.
|
* Returns an array of the fields in given table name.
|
||||||
*
|
*
|
||||||
* @param string $tableName Name of database table to inspect
|
* @param Model $model Model object to describe
|
||||||
* @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)
|
||||||
|
@ -414,6 +421,28 @@ class DboMssql extends DboSource
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes Identity (primary key) column from update data before returning to parent
|
||||||
|
*
|
||||||
|
* @param Model $model
|
||||||
|
* @param array $fields
|
||||||
|
* @param array $values
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function update (&$model, $fields = array(), $values = array())
|
||||||
|
{
|
||||||
|
foreach ($fields as $i => $field)
|
||||||
|
{
|
||||||
|
if ($field == $model->primaryKey)
|
||||||
|
{
|
||||||
|
unset($fields[$i]);
|
||||||
|
unset($values[$i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parent::update($model, $fields, $values);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a formatted error message from previous database operation.
|
* Returns a formatted error message from previous database operation.
|
||||||
*
|
*
|
||||||
|
@ -486,13 +515,9 @@ class DboMssql extends DboSource
|
||||||
if ($limit)
|
if ($limit)
|
||||||
{
|
{
|
||||||
$rt = '';
|
$rt = '';
|
||||||
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0)
|
if (!strpos(strtolower($limit), 'top') || strpos(strtolower($limit), 'top') === 0)
|
||||||
{
|
{
|
||||||
$rt = ' LIMIT';
|
$rt = ' TOP';
|
||||||
}
|
|
||||||
if ($offset)
|
|
||||||
{
|
|
||||||
$rt .= ' ' . $offset. ',';
|
|
||||||
}
|
}
|
||||||
$rt .= ' ' . $limit;
|
$rt .= ' ' . $limit;
|
||||||
return $rt;
|
return $rt;
|
||||||
|
@ -508,6 +533,16 @@ class DboMssql extends DboSource
|
||||||
*/
|
*/
|
||||||
function column($real)
|
function column($real)
|
||||||
{
|
{
|
||||||
|
if (is_array($real))
|
||||||
|
{
|
||||||
|
$col = $real['name'];
|
||||||
|
if (isset($real['limit']))
|
||||||
|
{
|
||||||
|
$col .= '('.$real['limit'].')';
|
||||||
|
}
|
||||||
|
return $col;
|
||||||
|
}
|
||||||
|
|
||||||
$col = r(')', '', $real);
|
$col = r(')', '', $real);
|
||||||
$limit = null;
|
$limit = null;
|
||||||
@list($col, $limit) = explode('(', $col);
|
@list($col, $limit) = explode('(', $col);
|
||||||
|
|
|
@ -181,7 +181,7 @@ class DboMysql extends DboSource
|
||||||
$result = mysql_list_tables($this->config['database'], $this->connection);
|
$result = mysql_list_tables($this->config['database'], $this->connection);
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
return null;
|
return array();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -402,32 +402,6 @@ class DboMysql extends DboSource
|
||||||
return mysql_insert_id($this->connection);
|
return mysql_insert_id($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a limit statement in the correct format for the particular database.
|
|
||||||
*
|
|
||||||
* @param int $limit Limit of results returned
|
|
||||||
* @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(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0)
|
|
||||||
{
|
|
||||||
$rt = ' LIMIT';
|
|
||||||
}
|
|
||||||
if ($offset)
|
|
||||||
{
|
|
||||||
$rt .= ' ' . $offset. ',';
|
|
||||||
}
|
|
||||||
$rt .= ' ' . $limit;
|
|
||||||
return $rt;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts database-layer column types to basic types
|
* Converts database-layer column types to basic types
|
||||||
*
|
*
|
||||||
|
@ -436,6 +410,16 @@ class DboMysql extends DboSource
|
||||||
*/
|
*/
|
||||||
function column($real)
|
function column($real)
|
||||||
{
|
{
|
||||||
|
if (is_array($real))
|
||||||
|
{
|
||||||
|
$col = $real['name'];
|
||||||
|
if (isset($real['limit']))
|
||||||
|
{
|
||||||
|
$col .= '('.$real['limit'].')';
|
||||||
|
}
|
||||||
|
return $col;
|
||||||
|
}
|
||||||
|
|
||||||
$col = r(')', '', $real);
|
$col = r(')', '', $real);
|
||||||
$limit = null;
|
$limit = null;
|
||||||
@list($col, $limit) = explode('(', $col);
|
@list($col, $limit) = explode('(', $col);
|
||||||
|
|
503
cake/libs/model/dbo/dbo_odbc.php
Normal file
503
cake/libs/model/dbo/dbo_odbc.php
Normal file
|
@ -0,0 +1,503 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ODBC for DBO
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.dbo
|
||||||
|
* @since CakePHP v 0.10.5.1790
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include DBO.
|
||||||
|
*/
|
||||||
|
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||||
|
|
||||||
|
classÊDboOdbcÊextendsÊDboSource
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*ÊEnterÊdescriptionÊhere...
|
||||||
|
Ê*
|
||||||
|
Ê*Ê@varÊunknown_type
|
||||||
|
Ê*/
|
||||||
|
ÊÊÊÊvarÊ$descriptionÊ=Ê"ODBCÊDBOÊDriver";
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*ÊEnterÊdescriptionÊhere...
|
||||||
|
Ê*
|
||||||
|
Ê*Ê@varÊunknown_type
|
||||||
|
Ê*/
|
||||||
|
ÊÊÊÊvarÊ$startQuoteÊ=Ê"`";
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*ÊEnterÊdescriptionÊhere...
|
||||||
|
Ê*
|
||||||
|
Ê*Ê@varÊunknown_type
|
||||||
|
Ê*/
|
||||||
|
ÊÊÊÊvarÊ$endQuoteÊ=Ê"`";
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*ÊEnterÊdescriptionÊhere...
|
||||||
|
Ê*
|
||||||
|
Ê*Ê@varÊunknown_type
|
||||||
|
Ê*/
|
||||||
|
ÊÊÊÊ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...
|
||||||
|
Ê*
|
||||||
|
Ê*Ê@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;
|
||||||
|
ÊÊÊÊÊÊÊÊ}
|
||||||
|
ÊÊÊÊÊÊÊÊ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);
|
||||||
|
ÊÊÊÊ}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*Ê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Ê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.
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
ÊÊÊÊÊÊÊÊ}
|
||||||
|
|
||||||
|
ÊÊÊÊÊÊÊÊ$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++)
|
||||||
|
{
|
||||||
|
$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));
|
||||||
|
ÊÊÊÊÊÊÊÊ}
|
||||||
|
|
||||||
|
ÊÊÊÊÊÊÊÊ$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;
|
||||||
|
ÊÊÊÊ}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*Ê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;
|
||||||
|
ÊÊÊÊ}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*Ê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))
|
||||||
|
{
|
||||||
|
ÊÊÊÊÊÊÊÊÊÊÊÊ $this->__transactionStarted = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ÊÊÊÊÊÊÊÊ}
|
||||||
|
ÊÊÊÊÊÊÊÊ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;
|
||||||
|
ÊÊÊÊ}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ê*Ê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Ê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)
|
||||||
|
ÊÊÊÊ{
|
||||||
|
if (is_array($real))
|
||||||
|
{
|
||||||
|
$col = $real['name'];
|
||||||
|
if (isset($real['limit']))
|
||||||
|
{
|
||||||
|
$col .= '('.$real['limit'].')';
|
||||||
|
}
|
||||||
|
return $col;
|
||||||
|
}
|
||||||
|
|
||||||
|
ÊÊÊÊÊÊÊÊ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;
|
||||||
|
|
||||||
|
ÊÊÊÊÊÊÊÊ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;
|
||||||
|
ÊÊÊÊÊÊÊÊ}
|
||||||
|
ÊÊÊÊ}
|
||||||
|
|
||||||
|
ÊÊÊÊ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;
|
||||||
|
ÊÊÊÊ}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -55,13 +55,13 @@ class DboPostgres extends DboSource
|
||||||
'port' => 5432);
|
'port' => 5432);
|
||||||
|
|
||||||
var $columns = array(
|
var $columns = array(
|
||||||
'primary_key' => array('name' => 'serial primary key'),
|
'primary_key' => array('name' => 'serial NOT NULL'),
|
||||||
'string' => array('name' => 'character varying', 'limit' => '255'),
|
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||||
'text' => array('name' => 'text'),
|
'text' => array('name' => 'text'),
|
||||||
'integer' => array('name' => 'integer'),
|
'integer' => array('name' => 'integer'),
|
||||||
'float' => array('name' => 'float'),
|
'float' => array('name' => 'float'),
|
||||||
'datetime' => array('name' => 'timestamp'),
|
'datetime' => array('name' => 'timestamp'),
|
||||||
'timestamp' => array('name' => 'timestamp'),
|
'timestamp' => array('name' => 'timestamp'),
|
||||||
'time' => array('name' => 'time'),
|
'time' => array('name' => 'time'),
|
||||||
'date' => array('name' => 'date'),
|
'date' => array('name' => 'date'),
|
||||||
'binary' => array('name' => 'bytea'),
|
'binary' => array('name' => 'bytea'),
|
||||||
|
@ -82,7 +82,7 @@ class DboPostgres extends DboSource
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
$connect = $config['connect'];
|
$connect = $config['connect'];
|
||||||
|
|
||||||
$this->connection = $connect("dbname={$config['database']} user={$config['login']} password={$config['password']}");
|
$this->connection = $connect("host={$config['host']} port={$config['port']} dbname={$config['database']} user={$config['login']} password={$config['password']}");
|
||||||
if ($this->connection)
|
if ($this->connection)
|
||||||
{
|
{
|
||||||
$this->connected = true;
|
$this->connected = true;
|
||||||
|
@ -102,7 +102,7 @@ class DboPostgres extends DboSource
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
return pg_close($this->connection);
|
return pg_close($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,28 +113,7 @@ class DboPostgres extends DboSource
|
||||||
*/
|
*/
|
||||||
function _execute ($sql)
|
function _execute ($sql)
|
||||||
{
|
{
|
||||||
return pg_query($this->connection, $sql);
|
return pg_query($this->connection, $sql);
|
||||||
}
|
|
||||||
|
|
||||||
function query ()
|
|
||||||
{
|
|
||||||
$args = func_get_args();
|
|
||||||
if (count($args) == 1)
|
|
||||||
{
|
|
||||||
return $this->fetchAll($args[0]);
|
|
||||||
}
|
|
||||||
elseif (count($args) > 1 && strpos(strtolower($args[0]), 'findby') === 0)
|
|
||||||
{
|
|
||||||
$field = Inflector::underscore(preg_replace('/findBy/i', '', $args[0]));
|
|
||||||
$query = '"' . $args[2]->name . '"."' . $field . '" = ' . $this->value($args[1][0]);
|
|
||||||
return $args[2]->find($query);
|
|
||||||
}
|
|
||||||
elseif (count($args) > 1 && strpos(strtolower($args[0]), 'findallby') === 0)
|
|
||||||
{
|
|
||||||
$field = Inflector::underscore(preg_replace('/findAllBy/i', '', $args[0]));
|
|
||||||
$query = '"' . $args[2]->name . '"."' . $field . '" = ' . $this->value($args[1][0]);
|
|
||||||
return $args[2]->findAll($query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,23 +142,29 @@ class DboPostgres extends DboSource
|
||||||
*/
|
*/
|
||||||
function listSources ()
|
function listSources ()
|
||||||
{
|
{
|
||||||
$sql = "SELECT table_name as name FROM information_schema.tables WHERE table_schema = 'public';";
|
$cache = parent::listSources();
|
||||||
|
if ($cache != null)
|
||||||
|
{
|
||||||
|
return $cache;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->query($sql);
|
$sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'public';";
|
||||||
|
$result = $this->fetchAll($sql);
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
return null;
|
return array();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tables = array();
|
$tables = array();
|
||||||
foreach ($result as $item)
|
foreach ($result as $item)
|
||||||
{
|
{
|
||||||
$tables[] = $item[0]['name'];
|
$tables[] = $item[0]['name'];
|
||||||
}
|
}
|
||||||
return $tables;
|
parent::listSources($tables);
|
||||||
}
|
return $tables;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,7 +242,7 @@ class DboPostgres extends DboSource
|
||||||
|
|
||||||
$fields = false;
|
$fields = false;
|
||||||
|
|
||||||
$cols = $this->query("SELECT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default FROM information_schema.columns WHERE table_name =".$this->value($model->table)." ORDER BY ordinal_position");
|
$cols = $this->fetchAll("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default, ordinal_position FROM information_schema.columns WHERE table_name =".$this->value($model->table)." ORDER BY ordinal_position");
|
||||||
|
|
||||||
foreach ($cols as $column)
|
foreach ($cols as $column)
|
||||||
{
|
{
|
||||||
|
@ -316,19 +301,29 @@ class DboPostgres extends DboSource
|
||||||
}
|
}
|
||||||
switch ($column)
|
switch ($column)
|
||||||
{
|
{
|
||||||
|
case 'integer':
|
||||||
|
if ($data == '')
|
||||||
|
{
|
||||||
|
return 'DEFAULT';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = pg_escape_string($data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'binary':
|
case 'binary':
|
||||||
$data = pg_escape_bytea($data);
|
$data = pg_escape_bytea($data);
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$data = $this->boolean((bool)$data);
|
$data = $this->boolean((bool)$data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (ini_get('magic_quotes_gpc') == 1)
|
if (ini_get('magic_quotes_gpc') == 1)
|
||||||
{
|
{
|
||||||
$data = stripslashes($data);
|
$data = stripslashes($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = pg_escape_string($data);
|
$data = pg_escape_string($data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = "'" . $data . "'";
|
$return = "'" . $data . "'";
|
||||||
|
@ -443,10 +438,10 @@ class DboPostgres extends DboSource
|
||||||
*/
|
*/
|
||||||
function lastInsertId ($source, $field='id')
|
function lastInsertId ($source, $field='id')
|
||||||
{
|
{
|
||||||
$sql = "SELECT last_value AS max FROM {$source}_{$field}_seq";
|
$sql = "SELECT last_value AS max FROM {$source}_{$field}_seq";
|
||||||
$res = $this->rawQuery($sql);
|
$res = $this->rawQuery($sql);
|
||||||
$data = $this->fetchRow($res);
|
$data = $this->fetchRow($res);
|
||||||
return $data[0]['max'];
|
return $data[0]['max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,6 +478,16 @@ class DboPostgres extends DboSource
|
||||||
*/
|
*/
|
||||||
function column($real)
|
function column($real)
|
||||||
{
|
{
|
||||||
|
if (is_array($real))
|
||||||
|
{
|
||||||
|
$col = $real['name'];
|
||||||
|
if (isset($real['limit']))
|
||||||
|
{
|
||||||
|
$col .= '('.$real['limit'].')';
|
||||||
|
}
|
||||||
|
return $col;
|
||||||
|
}
|
||||||
|
|
||||||
$col = r(')', '', $real);
|
$col = r(')', '', $real);
|
||||||
$limit = null;
|
$limit = null;
|
||||||
@list($col, $limit) = explode('(', $col);
|
@list($col, $limit) = explode('(', $col);
|
||||||
|
@ -499,7 +504,7 @@ class DboPostgres extends DboSource
|
||||||
{
|
{
|
||||||
return 'boolean';
|
return 'boolean';
|
||||||
}
|
}
|
||||||
if (strpos($col, 'integer') !== false)
|
if (strpos($col, 'int') !== false && $col != 'interval')
|
||||||
{
|
{
|
||||||
return 'integer';
|
return 'integer';
|
||||||
}
|
}
|
||||||
|
@ -515,7 +520,7 @@ class DboPostgres extends DboSource
|
||||||
{
|
{
|
||||||
return 'binary';
|
return 'binary';
|
||||||
}
|
}
|
||||||
if (in_array($col, array('float', 'double', 'decimal', 'real')))
|
if (in_array($col, array('float', 'float4', 'float8', 'double', 'decimal', 'real')))
|
||||||
{
|
{
|
||||||
return 'float';
|
return 'float';
|
||||||
}
|
}
|
||||||
|
@ -645,7 +650,15 @@ class DboPostgres extends DboSource
|
||||||
{
|
{
|
||||||
$insert = $this->value($value, $model->getColumnType($fields[$count]));
|
$insert = $this->value($value, $model->getColumnType($fields[$count]));
|
||||||
}
|
}
|
||||||
$valueInsert[] = $insert;
|
|
||||||
|
if ($insert === '\'\'')
|
||||||
|
{
|
||||||
|
unset($fieldInsert[$count]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$valueInsert[] = $insert;
|
||||||
|
}
|
||||||
unset($insert);
|
unset($insert);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,8 +453,15 @@ class Model extends Object
|
||||||
|
|
||||||
foreach ($this->{$type} as $assoc => $value)
|
foreach ($this->{$type} as $assoc => $value)
|
||||||
{
|
{
|
||||||
|
if (is_numeric($assoc))
|
||||||
|
{
|
||||||
|
unset($this->{$type}[$assoc]);
|
||||||
|
$assoc = $value;
|
||||||
|
$value = array();
|
||||||
|
$this->{$type}[$assoc] = $value;
|
||||||
|
}
|
||||||
$className = $assoc;
|
$className = $assoc;
|
||||||
if (isset($value['className']) && $value['className'] !== null)
|
if (isset($value['className']) && !empty($value['className']))
|
||||||
{
|
{
|
||||||
$className = $value['className'];
|
$className = $value['className'];
|
||||||
}
|
}
|
||||||
|
@ -480,11 +487,11 @@ class Model extends Object
|
||||||
$colKey = Inflector::underscore($className);
|
$colKey = Inflector::underscore($className);
|
||||||
if(ClassRegistry::isKeySet($colKey))
|
if(ClassRegistry::isKeySet($colKey))
|
||||||
{
|
{
|
||||||
$this->{$className} =& ClassRegistry::getObject($colKey);
|
$this->{$className} = ClassRegistry::getObject($colKey);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->{$className} =& new $className();
|
$this->{$className} = new $className();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->alias[$assoc] = $this->{$className}->table;
|
$this->alias[$assoc] = $this->{$className}->table;
|
||||||
|
@ -590,15 +597,22 @@ class Model extends Object
|
||||||
* @param string $two Value string for the alternative indata method
|
* @param string $two Value string for the alternative indata method
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function set ($one, $two=null)
|
function set ($one, $two = null)
|
||||||
{
|
{
|
||||||
if (is_array($one))
|
if (is_array($one))
|
||||||
{
|
{
|
||||||
$data = $one;
|
if (countdim($one) == 1)
|
||||||
|
{
|
||||||
|
$data = array($this->name => $one);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = $one;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$data = array($one=>$two);
|
$data = array($this->name => array($one => $two));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $n => $v)
|
foreach ($data as $n => $v)
|
||||||
|
@ -823,6 +837,7 @@ class Model extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
||||||
|
$this->validationErrors = array();
|
||||||
|
|
||||||
if(!$this->beforeValidate())
|
if(!$this->beforeValidate())
|
||||||
{
|
{
|
||||||
|
@ -976,8 +991,8 @@ class Model extends Object
|
||||||
foreach ($y as $assoc => $value)
|
foreach ($y as $assoc => $value)
|
||||||
{
|
{
|
||||||
$joinTable[] = $this->hasAndBelongsToMany[$assoc]['joinTable'];
|
$joinTable[] = $this->hasAndBelongsToMany[$assoc]['joinTable'];
|
||||||
$mainKey = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
$mainKey[] = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
||||||
$keys[] = $mainKey;
|
$keys[] = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
||||||
$keys[] = $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
$keys[] = $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
||||||
$fields[] = join(',', $keys);
|
$fields[] = join(',', $keys);
|
||||||
unset($keys);
|
unset($keys);
|
||||||
|
@ -1005,7 +1020,7 @@ class Model extends Object
|
||||||
for ($count = 0; $count < $total; $count++)
|
for ($count = 0; $count < $total; $count++)
|
||||||
{
|
{
|
||||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
$db->execute("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
|
$db->execute("DELETE FROM {$joinTable[$count]} WHERE {$mainKey[$count]} = '{$id}'");
|
||||||
if(!empty($newValue[$count]))
|
if(!empty($newValue[$count]))
|
||||||
{
|
{
|
||||||
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
|
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
|
||||||
|
|
|
@ -449,8 +449,15 @@ class Model extends Object
|
||||||
|
|
||||||
foreach ($this->{$type} as $assoc => $value)
|
foreach ($this->{$type} as $assoc => $value)
|
||||||
{
|
{
|
||||||
|
if (is_numeric($assoc))
|
||||||
|
{
|
||||||
|
unset($this->{$type}[$assoc]);
|
||||||
|
$assoc = $value;
|
||||||
|
$value = array();
|
||||||
|
$this->{$type}[$assoc] = $value;
|
||||||
|
}
|
||||||
$className = $assoc;
|
$className = $assoc;
|
||||||
if (isset($value['className']) && $value['className'] !== null)
|
if (isset($value['className']) && !empty($value['className']))
|
||||||
{
|
{
|
||||||
$className = $value['className'];
|
$className = $value['className'];
|
||||||
}
|
}
|
||||||
|
@ -586,15 +593,22 @@ class Model extends Object
|
||||||
* @param string $two Value string for the alternative indata method
|
* @param string $two Value string for the alternative indata method
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function set ($one, $two=null)
|
function set ($one, $two = null)
|
||||||
{
|
{
|
||||||
if (is_array($one))
|
if (is_array($one))
|
||||||
{
|
{
|
||||||
$data = $one;
|
if (countdim($one) == 1)
|
||||||
|
{
|
||||||
|
$data = array($this->name => $one);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = $one;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$data = array($one=>$two);
|
$data = array($this->name => array($one => $two));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $n => $v)
|
foreach ($data as $n => $v)
|
||||||
|
@ -819,6 +833,7 @@ class Model extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
||||||
|
$this->validationErrors = array();
|
||||||
|
|
||||||
if(!$this->beforeValidate())
|
if(!$this->beforeValidate())
|
||||||
{
|
{
|
||||||
|
@ -972,8 +987,8 @@ class Model extends Object
|
||||||
foreach ($y as $assoc => $value)
|
foreach ($y as $assoc => $value)
|
||||||
{
|
{
|
||||||
$joinTable[] = $this->hasAndBelongsToMany[$assoc]['joinTable'];
|
$joinTable[] = $this->hasAndBelongsToMany[$assoc]['joinTable'];
|
||||||
$mainKey = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
$mainKey[] = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
||||||
$keys[] = $mainKey;
|
$keys[] = $this->hasAndBelongsToMany[$assoc]['foreignKey'];
|
||||||
$keys[] = $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
$keys[] = $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
||||||
$fields[] = join(',', $keys);
|
$fields[] = join(',', $keys);
|
||||||
unset($keys);
|
unset($keys);
|
||||||
|
@ -1001,7 +1016,7 @@ class Model extends Object
|
||||||
for ($count = 0; $count < $total; $count++)
|
for ($count = 0; $count < $total; $count++)
|
||||||
{
|
{
|
||||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
$db->execute("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
|
$db->execute("DELETE FROM {$joinTable[$count]} WHERE {$mainKey[$count]} = '{$id}'");
|
||||||
if(!empty($newValue[$count]))
|
if(!empty($newValue[$count]))
|
||||||
{
|
{
|
||||||
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
|
$db->execute("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Object
|
||||||
* Calls a controller's method from any location.
|
* Calls a controller's method from any location.
|
||||||
*
|
*
|
||||||
* @param string $url URL in the form of Cake URL ("/controller/method/parameter")
|
* @param string $url URL in the form of Cake URL ("/controller/method/parameter")
|
||||||
* @param array $extra If array includes the key "render" it sets the AutoRender to true.
|
* @param array $extra If array includes the key "return" it sets the AutoRender to true.
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function requestAction ($url, $extra = array())
|
function requestAction ($url, $extra = array())
|
||||||
|
|
|
@ -52,6 +52,23 @@ class Router extends Object {
|
||||||
*/
|
*/
|
||||||
var $routes = array();
|
var $routes = array();
|
||||||
|
|
||||||
|
function __construct ()
|
||||||
|
{
|
||||||
|
if(defined('CAKE_ADMIN'))
|
||||||
|
{
|
||||||
|
$admin = CAKE_ADMIN;
|
||||||
|
if(!empty($admin))
|
||||||
|
{
|
||||||
|
$this->routes[] = array (
|
||||||
|
'/:'.$admin.'/:controller/:action/* (default)',
|
||||||
|
'/^(?:\/(?:('.$admin.')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:[\\/\\?](.*))?)?)?))[\/]*$/',
|
||||||
|
array($admin, 'controller', 'action'),
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Better description. Returns this object's routes array. Returns false if there are no routes available.
|
* TODO: Better description. Returns this object's routes array. Returns false if there are no routes available.
|
||||||
*
|
*
|
||||||
|
@ -134,21 +151,6 @@ class Router extends Object {
|
||||||
array('controller', 'action'),
|
array('controller', 'action'),
|
||||||
array());
|
array());
|
||||||
|
|
||||||
if(defined('CAKE_ADMIN'))
|
|
||||||
{
|
|
||||||
$admin = CAKE_ADMIN;
|
|
||||||
if(!empty($admin))
|
|
||||||
{
|
|
||||||
$this->routes[] = array
|
|
||||||
(
|
|
||||||
'/:'.$admin.'/:controller/:action/* (default)',
|
|
||||||
'/^(?:\/(?:('.$admin.')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:[\\/\\?](.*))?)?)?))[\/]*$/',
|
|
||||||
array($admin, 'controller', 'action'),
|
|
||||||
array());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->connect('/bare/:controller/:action/*', array('bare'=>'1'));
|
$this->connect('/bare/:controller/:action/*', array('bare'=>'1'));
|
||||||
$this->connect('/ajax/:controller/:action/*', array('bare'=>'1'));
|
$this->connect('/ajax/:controller/:action/*', array('bare'=>'1'));
|
||||||
|
|
||||||
|
|
|
@ -334,18 +334,19 @@ class FormHelper extends Helper
|
||||||
*/
|
*/
|
||||||
function generateSelectDiv($tagName, $prompt, $options, $selected=null, $selectAttr=null, $optionAttr=null, $required=false, $errorMsg=null)
|
function generateSelectDiv($tagName, $prompt, $options, $selected=null, $selectAttr=null, $optionAttr=null, $required=false, $errorMsg=null)
|
||||||
{
|
{
|
||||||
$selectAttr['id'] = strtolower(str_replace('/', '_',$tagName));;
|
$selectAttr['id'] = strtolower(str_replace('/', '_',$tagName));
|
||||||
$str = $this->Html->selectTag( $tagName, $options, $selected, $selectAttr, $optionAttr );
|
$str = $this->Html->selectTag( $tagName, $options, $selected, $selectAttr, $optionAttr );
|
||||||
$strLabel = $this->labelTag( $tagName, $prompt );
|
$strLabel = $this->labelTag( $tagName, $prompt );
|
||||||
|
|
||||||
$divClass = "optional";
|
$divClass = "optional";
|
||||||
|
if($required)
|
||||||
if( $required )
|
{
|
||||||
$divClass = "required";
|
$divClass = "required";
|
||||||
|
}
|
||||||
|
|
||||||
$strError = "";// initialize the error to empty.
|
$strError = "";// initialize the error to empty.
|
||||||
|
|
||||||
if( $this->isFieldError( $tagName ) )
|
if($this->isFieldError($tagName))
|
||||||
{
|
{
|
||||||
// if it was an error that occured, then add the error message, and append " error" to the div tag.
|
// if it was an error that occured, then add the error message, and append " error" to the div tag.
|
||||||
$strError = $this->pTag( 'error', $errorMsg );
|
$strError = $this->pTag( 'error', $errorMsg );
|
||||||
|
|
|
@ -1083,7 +1083,7 @@ function url($url = null, $return = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do not display the select tag if no option elements are avaible
|
// do not display the select tag if no option elements are avaible
|
||||||
if (!is_array($optionElements) || count($optionElements) == 0)
|
if (!is_array($optionElements))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,33 +214,72 @@ class JavascriptHelper extends Helper
|
||||||
* @param string $q The type of quote to use
|
* @param string $q The type of quote to use
|
||||||
* @return string A JSON code block
|
* @return string A JSON code block
|
||||||
*/
|
*/
|
||||||
function object ($data = array(), $block = false, $prefix = '', $postfix = '', $stringKeys = array(), $quoteKeys = true, $q = "'")
|
function object ($data = array(), $block = false, $prefix = '', $postfix = '', $stringKeys = array(), $quoteKeys = true, $q = "\"")
|
||||||
{
|
{
|
||||||
|
if (is_object($data))
|
||||||
|
{
|
||||||
|
$data = get_object_vars($data);
|
||||||
|
}
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
$key = array();
|
||||||
|
if (is_array($data))
|
||||||
|
{
|
||||||
|
$keys = array_keys($data);
|
||||||
|
}
|
||||||
|
$numeric = true;
|
||||||
|
|
||||||
|
if (!empty($keys))
|
||||||
|
{
|
||||||
|
foreach ($keys as $key)
|
||||||
|
{
|
||||||
|
if (!is_numeric($key))
|
||||||
|
{
|
||||||
|
$numeric = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($data as $key => $val)
|
foreach($data as $key => $val)
|
||||||
{
|
{
|
||||||
if (is_array($val))
|
if (is_array($val) || is_object($val))
|
||||||
{
|
{
|
||||||
$out[] = $key.':'.$this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
|
$val = $this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
|
||||||
}
|
$out[] = $val;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys)))
|
{
|
||||||
{
|
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys)))
|
||||||
$val = $q.$val.$q;
|
{
|
||||||
}
|
$val = $q.$val.$q;
|
||||||
if (trim($val) == '')
|
}
|
||||||
{
|
if (trim($val) == '')
|
||||||
$val = 'null';
|
{
|
||||||
}
|
$val = 'null';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$out[] = $key.':'.$val;
|
if (!$numeric)
|
||||||
}
|
{
|
||||||
|
$val = $key.':'.$val;
|
||||||
|
}
|
||||||
|
$out[] = $val;
|
||||||
}
|
}
|
||||||
$rt = $prefix.'{'.join(', ', $out).'}'.$postfix;
|
|
||||||
|
if (!$numeric)
|
||||||
|
{
|
||||||
|
$rt = '{'.join(', ', $out).'}';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$rt = 'new Array('.join(', ', $out).')';
|
||||||
|
}
|
||||||
|
$rt = $prefix.$rt.$postfix;
|
||||||
|
|
||||||
if ($block)
|
if ($block)
|
||||||
{
|
{
|
||||||
return $this->codeBlock($rt);
|
$rt = $this->codeBlock($rt);
|
||||||
}
|
}
|
||||||
return $rt;
|
return $rt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ if(!empty($this->controller->{$model}->alias))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<table class="inav" cellspacing="0">
|
<table class="inav" cellpadding="1">
|
||||||
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<?php
|
<?php
|
||||||
foreach ($fieldNames as $fieldName)
|
foreach ($fieldNames as $fieldName)
|
||||||
|
@ -60,6 +61,8 @@ foreach ($fieldNames as $fieldName)
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
$iRowIndex = 0;
|
$iRowIndex = 0;
|
||||||
|
@ -116,6 +119,7 @@ if(is_array($data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
<li><?php echo $html->link('New '.$humanSingularName, $path.$this->viewPath.'/add'); ?></li>
|
<li><?php echo $html->link('New '.$humanSingularName, $path.$this->viewPath.'/add'); ?></li>
|
||||||
|
|
|
@ -33,15 +33,39 @@ ini_set('error_reporting', '7');
|
||||||
|
|
||||||
define ('DS', DIRECTORY_SEPARATOR);
|
define ('DS', DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
/**
|
$app = 'app';
|
||||||
* Change these setting only if your install
|
$core = null;
|
||||||
* is different from a distribution install.
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
*
|
$here = $argv[0];
|
||||||
*/
|
$dataSource = 'default';
|
||||||
define ('ROOT', dirname(dirname(dirname(__FILE__))).DS);
|
|
||||||
define ('APP_DIR', 'app');
|
for ($i = 1; $i < count($argv); $i += 2)
|
||||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
{
|
||||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH);
|
// Process command-line modifiers here
|
||||||
|
switch (strtolower($argv[$i]))
|
||||||
|
{
|
||||||
|
case '-app':
|
||||||
|
$app = $argv[$i + 1];
|
||||||
|
break;
|
||||||
|
case '-core':
|
||||||
|
$core = $argv[$i + 1];
|
||||||
|
break;
|
||||||
|
case '-root':
|
||||||
|
$root = $argv[$i + 1];
|
||||||
|
break;
|
||||||
|
case '-datasource':
|
||||||
|
$dataSource = $argv[$i + 1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
define ('ROOT', $root.DS);
|
||||||
|
define ('APP_DIR', $app);
|
||||||
|
define ('APP_PATH', $app.DS);
|
||||||
|
define ('DEBUG', 1);
|
||||||
|
define ('CORE_PATH', $core);
|
||||||
|
define ('CAKE_CORE_INCLUDE_PATH', ROOT);
|
||||||
|
define('DATASOURCE', $dataSource);
|
||||||
|
|
||||||
define ('DEBUG', 1);
|
define ('DEBUG', 1);
|
||||||
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
|
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
|
||||||
|
@ -49,7 +73,14 @@ ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_
|
||||||
require ('cake'.DS.'basics.php');
|
require ('cake'.DS.'basics.php');
|
||||||
require ('cake'.DS.'config'.DS.'paths.php');
|
require ('cake'.DS.'config'.DS.'paths.php');
|
||||||
require (CONFIGS.'core.php');
|
require (CONFIGS.'core.php');
|
||||||
require (CONFIGS.'database.php');
|
if (file_exists( CONFIGS.'database.php' ))
|
||||||
|
{
|
||||||
|
require_once (CONFIGS.'database.php');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
die("Unable to find /app/config/database.php. Please create it before continuing.\n\n");
|
||||||
|
}
|
||||||
uses ('neat_array');
|
uses ('neat_array');
|
||||||
uses ('object');
|
uses ('object');
|
||||||
uses ('session');
|
uses ('session');
|
||||||
|
@ -143,6 +174,7 @@ class AclCLI {
|
||||||
*/
|
*/
|
||||||
function __construct ($command, $args)
|
function __construct ($command, $args)
|
||||||
{
|
{
|
||||||
|
$this->dataSource = DATASOURCE;
|
||||||
$acl = new AclComponent();
|
$acl = new AclComponent();
|
||||||
$this->acl = $acl->getACL();
|
$this->acl = $acl->getACL();
|
||||||
|
|
||||||
|
@ -255,7 +287,7 @@ class AclCLI {
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
$node = &new $class;
|
$node = &new $class;
|
||||||
|
|
||||||
if (!$node->setParent(intval($this->args[2]), intval($this->args[1])))
|
if (!$node->setParent($this->args[2], $this->args[1]))
|
||||||
{
|
{
|
||||||
fwrite($this->stdout, "Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.\n");
|
fwrite($this->stdout, "Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.\n");
|
||||||
}
|
}
|
||||||
|
@ -377,37 +409,38 @@ class AclCLI {
|
||||||
$db =& ConnectionManager::getDataSource($this->dataSource);
|
$db =& ConnectionManager::getDataSource($this->dataSource);
|
||||||
fwrite($this->stdout, "Initializing Database...\n");
|
fwrite($this->stdout, "Initializing Database...\n");
|
||||||
fwrite($this->stdout, "Creating access control objects table (acos)...\n");
|
fwrite($this->stdout, "Creating access control objects table (acos)...\n");
|
||||||
$sql = " CREATE TABLE `acos` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
$sql = " CREATE TABLE ".$db->name('acos')." (
|
||||||
`object_id` int(11) default NULL,
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
||||||
`alias` varchar(255) NOT NULL default '',
|
".$db->name('object_id')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
`lft` int(11) default NULL,
|
".$db->name('alias')." ".$db->column($db->columns['string'])." NOT NULL default '',
|
||||||
`rght` int(11) default NULL,
|
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
PRIMARY KEY (`id`)
|
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
|
PRIMARY KEY (".$db->name('id').")
|
||||||
);";
|
);";
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
|
|
||||||
fwrite($this->stdout, "Creating access request objects table (aros)...\n");
|
fwrite($this->stdout, "Creating access request objects table (aros)...\n");
|
||||||
$sql2 = "CREATE TABLE `aros` (
|
$sql2 = "CREATE TABLE ".$db->name('aros')." (
|
||||||
`id` int(11) NOT NULL auto_increment,
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
||||||
`user_id` int(11) default NULL,
|
".$db->name('user_id')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
`alias` varchar(255) NOT NULL default '',
|
".$db->name('alias')." ".$db->column($db->columns['string'])." NOT NULL default '',
|
||||||
`lft` int(11) default NULL,
|
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
`rght` int(11) default NULL,
|
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (".$db->name('id').")
|
||||||
);";
|
);";
|
||||||
$db->query($sql2);
|
$db->query($sql2);
|
||||||
|
|
||||||
fwrite($this->stdout, "Creating relationships table (aros_acos)...\n");
|
fwrite($this->stdout, "Creating relationships table (aros_acos)...\n");
|
||||||
$sql3 = "CREATE TABLE `aros_acos` (
|
$sql3 = "CREATE TABLE ".$db->name('aros_acos')." (
|
||||||
`id` int(11) NOT NULL auto_increment,
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
||||||
`aro_id` int(11) default NULL,
|
".$db->name('aro_id')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
`aco_id` int(11) default NULL,
|
".$db->name('aco_id')." ".$db->column($db->columns['integer'])." default NULL,
|
||||||
`_create` int(1) NOT NULL default '0',
|
".$db->name('_create')." ".$db->column($db->columns['integer'])." NOT NULL default '0',
|
||||||
`_read` int(1) NOT NULL default '0',
|
".$db->name('_read')." ".$db->column($db->columns['integer'])." NOT NULL default '0',
|
||||||
`_update` int(1) NOT NULL default '0',
|
".$db->name('_update')." ".$db->column($db->columns['integer'])." NOT NULL default '0',
|
||||||
`_delete` int(11) NOT NULL default '0',
|
".$db->name('_delete')." ".$db->column($db->columns['integer'])." NOT NULL default '0',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (".$db->name('id').")
|
||||||
);";
|
);";
|
||||||
$db->query($sql3);
|
$db->query($sql3);
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,12 @@ define ('APP_DIR', $app);
|
||||||
define ('APP_PATH', $app.DS);
|
define ('APP_PATH', $app.DS);
|
||||||
define ('DEBUG', 1);
|
define ('DEBUG', 1);
|
||||||
define ('CORE_PATH', $core);
|
define ('CORE_PATH', $core);
|
||||||
|
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
||||||
|
|
||||||
|
if(function_exists('ini_set'))
|
||||||
|
{
|
||||||
|
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
|
||||||
|
}
|
||||||
|
|
||||||
require_once (ROOT.'cake'.DS.'basics.php');
|
require_once (ROOT.'cake'.DS.'basics.php');
|
||||||
require_once (ROOT.'cake'.DS.'config'.DS.'paths.php');
|
require_once (ROOT.'cake'.DS.'config'.DS.'paths.php');
|
||||||
|
@ -842,7 +848,7 @@ class Bake {
|
||||||
$editView .= "<form action=\"/{$temp->viewPath}/edit/<?php echo \$data['{$objModel->tableToModel[$objModel->table]}']['$id'] ?>\" method=\"post\">\n";
|
$editView .= "<form action=\"/{$temp->viewPath}/edit/<?php echo \$data['{$objModel->tableToModel[$objModel->table]}']['$id'] ?>\" method=\"post\">\n";
|
||||||
|
|
||||||
$fields = $this->generateFields($temp->generateFieldNames(null, true));
|
$fields = $this->generateFields($temp->generateFieldNames(null, true));
|
||||||
$fields .= "<?php echo \$html->hidden('{$objModel->table}/{$id}', array('value' => \$data['{$objModel->tableToModel[$objModel->table]}']['$id']))?>";
|
$fields .= "<?php echo \$html->hidden('{$objModel->name}/{$id}', array('value' => \$data['{$objModel->tableToModel[$objModel->table]}']['$id']))?>";
|
||||||
$fields .= $this->generateSubmitDiv('Save');
|
$fields .= $this->generateSubmitDiv('Save');
|
||||||
|
|
||||||
$editView .= $fields;
|
$editView .= $fields;
|
||||||
|
@ -972,7 +978,7 @@ class Bake {
|
||||||
$components = explode(',', $componentsListTrimmed);
|
$components = explode(',', $componentsListTrimmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
$wannaDoScaffolding = $this->getInput("Would to include some basic scaffolded actions (index, add, view, edit)?", array('y','n'), 'n');
|
$wannaDoScaffolding = $this->getInput("Would to include some basic class methods (index(), add(), view(), edit())?", array('y','n'), 'n');
|
||||||
|
|
||||||
if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes')
|
if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes')
|
||||||
{
|
{
|
||||||
|
@ -1019,6 +1025,8 @@ class Bake {
|
||||||
$actions .= "\t\t\t}\n";
|
$actions .= "\t\t\t}\n";
|
||||||
$actions .= "\t\t\telse\n";
|
$actions .= "\t\t\telse\n";
|
||||||
$actions .= "\t\t\t{\n";
|
$actions .= "\t\t\t{\n";
|
||||||
|
$actions .= "\t\t\t\t\$this->set('data', \$this->params['data']);\n";
|
||||||
|
$actions .= "\t\t\t\t\$this->validateErrors(\$this->{$controllerModel});\n";
|
||||||
$actions .= "\t\t\t\t\$this->render();\n";
|
$actions .= "\t\t\t\t\$this->render();\n";
|
||||||
$actions .= "\t\t\t}\n";
|
$actions .= "\t\t\t}\n";
|
||||||
$actions .= "\t\t}\n";
|
$actions .= "\t\t}\n";
|
||||||
|
@ -1131,7 +1139,7 @@ class Bake {
|
||||||
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
|
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$this->stdout("\nYou can download the Cake test suite from http://ww.cakephp.org/", true);
|
$this->stdout("\nYou can download the Cake test suite from http://cakeforge.org/frs/?group_id=62", true);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1268,7 +1276,7 @@ class Bake {
|
||||||
}
|
}
|
||||||
|
|
||||||
$out .= "}\n";
|
$out .= "}\n";
|
||||||
$out .= "?>\n";
|
$out .= "?>";
|
||||||
|
|
||||||
$inflect = new Inflector();
|
$inflect = new Inflector();
|
||||||
|
|
||||||
|
@ -1367,7 +1375,7 @@ class Bake {
|
||||||
$out .= $actions;
|
$out .= $actions;
|
||||||
|
|
||||||
$out .= "}\n";
|
$out .= "}\n";
|
||||||
$out .= "?>\n";
|
$out .= "?>";
|
||||||
|
|
||||||
$filename = CONTROLLERS . $inflect->underscore($controllerName) . '_controller.php';
|
$filename = CONTROLLERS . $inflect->underscore($controllerName) . '_controller.php';
|
||||||
|
|
||||||
|
@ -1471,7 +1479,7 @@ class Bake {
|
||||||
$this->stdout($prompt . " $print_options \n" . "[$default] > ", false);
|
$this->stdout($prompt . " $print_options \n" . "[$default] > ", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = trim(fgets(STDIN));
|
$result = trim(fgets($this->stdin));
|
||||||
|
|
||||||
if($default != null && empty($result))
|
if($default != null && empty($result))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue