issue 2119. supporting php 5.4. db classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12686 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-04 09:36:46 +00:00
parent 7fe03148f0
commit 41fdaf00c3
29 changed files with 1846 additions and 798 deletions

View file

@ -1,4 +1,5 @@
<?php
/**
* @author NHN (developers@xpressengine.com)
* @package /classes/db/queryparts
@ -6,16 +7,19 @@
*/
class Query extends Object
{
/**
* Query id, defined in query xml file
* @var string
*/
var $queryID;
/**
* DML type, ex) INSERT, DELETE, UPDATE, SELECT
* @var string
*/
var $action;
/**
* priority level ex)LOW_PRIORITY, HIGHT_PRIORITY
* @var string
@ -27,26 +31,31 @@ class Query extends Object
* @var string|array
*/
var $columns;
/**
* table list
* @var string|array
*/
var $tables;
/**
* condition list
* @var string|array
*/
var $conditions;
/**
* group list
* @var string|array
*/
var $groups;
/**
* order list
* @var array
*/
var $orderby;
/**
* limit count
* @var int
@ -85,20 +94,24 @@ class Query extends Object
* @return void
*/
function Query($queryID = NULL
, $action = NULL
, $columns = NULL
, $tables = NULL
, $conditions = NULL
, $groups = NULL
, $orderby = NULL
, $limit = NULL
, $priority = NULL)
, $action = NULL
, $columns = NULL
, $tables = NULL
, $conditions = NULL
, $groups = NULL
, $orderby = NULL
, $limit = NULL
, $priority = NULL)
{
$this->queryID = $queryID;
$this->action = $action;
$this->priority = $priority;
if(!isset($tables)) return;
if(!isset($tables))
{
return;
}
$this->columns = $this->setColumns($columns);
$this->tables = $this->setTables($tables);
$this->conditions = $this->setConditions($conditions);
@ -153,7 +166,10 @@ class Query extends Object
return;
}
if(!is_array($columns)) $columns = array($columns);
if(!is_array($columns))
{
$columns = array($columns);
}
$this->columns = $columns;
}
@ -167,7 +183,10 @@ class Query extends Object
return;
}
if(!is_array($tables)) $tables = array($tables);
if(!is_array($tables))
{
$tables = array($tables);
}
$this->tables = $tables;
}
@ -180,34 +199,58 @@ class Query extends Object
function setConditions($conditions)
{
$this->conditions = array();
if(!isset($conditions) || count($conditions) === 0) return;
if(!is_array($conditions)) $conditions = array($conditions);
if(!isset($conditions) || count($conditions) === 0)
{
return;
}
if(!is_array($conditions))
{
$conditions = array($conditions);
}
foreach($conditions as $conditionGroup)
{
if($conditionGroup->show()) $this->conditions[] = $conditionGroup;
if($conditionGroup->show())
{
$this->conditions[] = $conditionGroup;
}
}
}
function setGroups($groups)
{
if(!isset($groups) || count($groups) === 0) return;
if(!is_array($groups)) $groups = array($groups);
if(!isset($groups) || count($groups) === 0)
{
return;
}
if(!is_array($groups))
{
$groups = array($groups);
}
$this->groups = $groups;
}
function setOrder($order)
{
if(!isset($order) || count($order) === 0) return;
if(!is_array($order)) $order = array($order);
if(!isset($order) || count($order) === 0)
{
return;
}
if(!is_array($order))
{
$order = array($order);
}
$this->orderby = $order;
}
function setLimit($limit = NULL)
{
if(!isset($limit)) return;
if(!isset($limit))
{
return;
}
$this->limit = $limit;
}
@ -217,7 +260,7 @@ class Query extends Object
* @param string|array $columns
* @return Query return Query instance
*/
function select($columns= NULL)
function select($columns = NULL)
{
$this->action = 'select';
$this->setColumns($columns);
@ -278,6 +321,7 @@ class Query extends Object
$this->setLimit($limit);
return $this;
}
// END Fluent interface
function getAction()
@ -287,7 +331,7 @@ class Query extends Object
function getPriority()
{
return $this->priority?'LOW_PRIORITY':'';
return $this->priority ? 'LOW_PRIORITY' : '';
}
/**
@ -304,9 +348,12 @@ class Query extends Object
function getClickCountColumns()
{
$click_count_columns = array();
foreach($this->columns as $column){
foreach($this->columns as $column)
{
if($column->show() && is_a($column, 'ClickCountExpression'))
{
$click_count_columns[] = $column;
}
}
return $click_count_columns;
}
@ -321,12 +368,16 @@ class Query extends Object
foreach($this->columns as $column)
{
if($column->show())
{
if($column->isSubquery())
{
$select[] = $column->toString($with_values) . ' as '. $column->getAlias();
$select[] = $column->toString($with_values) . ' as ' . $column->getAlias();
}
else
{
$select[] = $column->getExpression($with_values);
}
}
}
return trim(implode($select, ', '));
}
@ -341,7 +392,9 @@ class Query extends Object
foreach($this->columns as $column)
{
if($column->show())
{
$update[] = $column->getExpression($with_values);
}
}
return trim(implode($update, ', '));
}
@ -401,14 +454,26 @@ class Query extends Object
$simple_table_count = 0;
foreach($this->tables as $table)
{
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
else $from .= ', '.$table->toString($with_values) . ' ';
if($table->isJoinTable() || !$simple_table_count)
{
$from .= $table->toString($with_values) . ' ';
}
else
{
$from .= ', ' . $table->toString($with_values) . ' ';
}
if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
if(is_a($table, 'Subquery'))
{
$from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
}
$simple_table_count++;
}
if(trim($from) == '') return '';
if(trim($from) == '')
{
return '';
}
return $from;
}
@ -435,11 +500,13 @@ class Query extends Object
}
if($with_optimization &&
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order')))
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order')))
{
if($condition_count !== 0)
{
$where = '(' . $where . ') ';
}
foreach($this->orderby as $order)
{
@ -448,7 +515,9 @@ class Query extends Object
{
$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
if($condition_count === 0)
{
$opt_condition->setPipe("");
}
$where .= $opt_condition->toString($with_values) . ' ';
$condition_count++;
}
@ -465,8 +534,13 @@ class Query extends Object
function getGroupByString()
{
$groupBy = '';
if($this->groups) if($this->groups[0] !== "")
$groupBy = implode(', ', $this->groups);
if($this->groups)
{
if($this->groups[0] !== "")
{
$groupBy = implode(', ', $this->groups);
}
}
return $groupBy;
}
@ -478,11 +552,14 @@ class Query extends Object
{
if(!$this->_orderByString)
{
if(count($this->orderby) === 0) return '';
if(count($this->orderby) === 0)
{
return '';
}
$orderBy = '';
foreach($this->orderby as $order)
{
$orderBy .= $order->toString() .', ';
$orderBy .= $order->toString() . ', ';
}
$orderBy = substr($orderBy, 0, -2);
$this->_orderByString = $orderBy;
@ -533,7 +610,10 @@ class Query extends Object
if($table->isJoinTable() || is_a($table, 'Subquery'))
{
$args = $table->getArguments();
if($args) $this->arguments = array_merge($this->arguments, $args);
if($args)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
}
@ -547,30 +627,43 @@ class Query extends Object
if($column->show())
{
$args = $column->getArguments();
if($args) $this->arguments = array_merge($this->arguments, $args);
if($args)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
}
// Condition arguments
if(count($this->conditions) > 0)
{
foreach($this->conditions as $conditionGroup)
{
$args = $conditionGroup->getArguments();
if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
if(count($args) > 0)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
// Navigation arguments
if(count($this->orderby) > 0)
{
foreach($this->orderby as $order)
{
$args = $order->getArguments();
if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
if(count($args) > 0)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
}
return $this->arguments;
}
}
}
/* End of file Query.class.php */
/* Location: ./classes/db/queryparts/Query.class.php */