mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-28 15:49:57 +09:00
merge from 1.5.3 (~r10943)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@10951 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
7aa4798373
commit
54e3a72065
334 changed files with 13011 additions and 5561 deletions
|
|
@ -1,343 +1,497 @@
|
|||
<?php
|
||||
|
||||
class Query extends Object {
|
||||
var $queryID;
|
||||
var $action;
|
||||
var $priority;
|
||||
|
||||
var $columns;
|
||||
var $tables;
|
||||
var $conditions;
|
||||
var $groups;
|
||||
var $orderby;
|
||||
var $limit;
|
||||
|
||||
var $arguments = null;
|
||||
|
||||
var $columnList = null;
|
||||
|
||||
var $_orderByString;
|
||||
|
||||
function Query($queryID = 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;
|
||||
$this->columns = $this->setColumns($columns);
|
||||
$this->tables = $this->setTables($tables);
|
||||
$this->conditions = $this->setConditions($conditions);
|
||||
$this->groups = $this->setGroups($groups);
|
||||
$this->orderby = $this->setOrder($orderby);
|
||||
$this->limit = $this->setLimit($limit);
|
||||
}
|
||||
|
||||
function show(){
|
||||
return true;
|
||||
}
|
||||
|
||||
function setQueryId($queryID){
|
||||
$this->queryID = $queryID;
|
||||
}
|
||||
|
||||
function setAction($action){
|
||||
$this->action = $action;
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts
|
||||
* @version 0.1
|
||||
*/
|
||||
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
|
||||
*/
|
||||
var $priority;
|
||||
|
||||
/**
|
||||
* column list
|
||||
* @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
|
||||
*/
|
||||
var $limit;
|
||||
|
||||
/**
|
||||
* argument list
|
||||
* @var array
|
||||
*/
|
||||
var $arguments = null;
|
||||
|
||||
/**
|
||||
* column list
|
||||
* @var array
|
||||
*/
|
||||
var $columnList = null;
|
||||
|
||||
/**
|
||||
* order by text
|
||||
* @var string
|
||||
*/
|
||||
var $_orderByString;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $queryID
|
||||
* @param string $action
|
||||
* @param string|array $columns
|
||||
* @param string|array $tables
|
||||
* @param string|array $conditions
|
||||
* @param string|array $groups
|
||||
* @param string|array $orderby
|
||||
* @param int $limit
|
||||
* @param string $priority
|
||||
* @return void
|
||||
*/
|
||||
function Query($queryID = 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;
|
||||
$this->columns = $this->setColumns($columns);
|
||||
$this->tables = $this->setTables($tables);
|
||||
$this->conditions = $this->setConditions($conditions);
|
||||
$this->groups = $this->setGroups($groups);
|
||||
$this->orderby = $this->setOrder($orderby);
|
||||
$this->limit = $this->setLimit($limit);
|
||||
}
|
||||
|
||||
function show(){
|
||||
return true;
|
||||
}
|
||||
|
||||
function setQueryId($queryID){
|
||||
$this->queryID = $queryID;
|
||||
}
|
||||
|
||||
function setAction($action){
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
function setPriority($priority){
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
function setColumnList($columnList){
|
||||
$this->columnList = $columnList;
|
||||
if(count($this->columnList) > 0) {
|
||||
$selectColumns = array();
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
foreach($this->columnList as $columnName){
|
||||
$columnName = $dbParser->escapeColumn($columnName);
|
||||
$selectColumns[] = new SelectExpression($columnName);
|
||||
}
|
||||
unset($this->columns);
|
||||
$this->columns = $selectColumns;
|
||||
}
|
||||
}
|
||||
|
||||
function setColumns($columns){
|
||||
if(!isset($columns) || count($columns) === 0){
|
||||
$this->columns = array(new StarExpression());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($columns)) $columns = array($columns);
|
||||
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
function setTables($tables){
|
||||
if(!isset($tables) || count($tables) === 0){
|
||||
$this->setError(true);
|
||||
$this->setMessage("You must provide at least one table for the query.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
|
||||
$this->tables = $tables;
|
||||
}
|
||||
|
||||
function setPriority($priority){
|
||||
$this->priority = $priority;
|
||||
function setSubquery($subquery){
|
||||
$this->subquery = $subquery;
|
||||
}
|
||||
|
||||
function setColumnList($columnList){
|
||||
$this->columnList = $columnList;
|
||||
if(count($this->columnList) > 0) {
|
||||
$selectColumns = array();
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
foreach($this->columnList as $columnName){
|
||||
$columnName = $dbParser->escapeColumn($columnName);
|
||||
$selectColumns[] = new SelectExpression($columnName);
|
||||
}
|
||||
unset($this->columns);
|
||||
$this->columns = $selectColumns;
|
||||
}
|
||||
}
|
||||
|
||||
function setColumns($columns){
|
||||
if(!isset($columns) || count($columns) === 0){
|
||||
$this->columns = array(new StarExpression());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($columns)) $columns = array($columns);
|
||||
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
function setTables($tables){
|
||||
if(!isset($tables) || count($tables) === 0){
|
||||
$this->setError(true);
|
||||
$this->setMessage("You must provide at least one table for the query.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
|
||||
$this->tables = $tables;
|
||||
}
|
||||
|
||||
function setConditions($conditions){
|
||||
$this->conditions = array();
|
||||
if(!isset($conditions) || count($conditions) === 0) return;
|
||||
if(!is_array($conditions)) $conditions = array($conditions);
|
||||
|
||||
foreach($conditions as $conditionGroup){
|
||||
if($conditionGroup->show()) $this->conditions[] = $conditionGroup;
|
||||
}
|
||||
}
|
||||
|
||||
function setGroups($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);
|
||||
|
||||
$this->orderby = $order;
|
||||
}
|
||||
|
||||
function setLimit($limit = NULL){
|
||||
if(!isset($limit)) return;
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
// START Fluent interface
|
||||
function select($columns= null){
|
||||
$this->action = 'select';
|
||||
$this->setColumns($columns);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function from($tables){
|
||||
$this->setTables($tables);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function where($conditions){
|
||||
$this->setConditions($conditions);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function groupBy($groups){
|
||||
$this->setGroups($groups);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function orderBy($order){
|
||||
$this->setOrder($order);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function limit($limit){
|
||||
$this->setLimit($limit);
|
||||
return $this;
|
||||
}
|
||||
// END Fluent interface
|
||||
|
||||
function getAction(){
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
function getPriority(){
|
||||
return $this->priority?'LOW_PRIORITY':'';
|
||||
}
|
||||
|
||||
function getSelectString($with_values = true){
|
||||
foreach($this->columns as $column){
|
||||
if($column->show())
|
||||
if($column->isSubquery()){
|
||||
$select[] = $column->toString($with_values) . ' as '. $column->getAlias();
|
||||
}
|
||||
else
|
||||
$select[] = $column->getExpression($with_values);
|
||||
}
|
||||
return trim(implode($select, ', '));
|
||||
}
|
||||
|
||||
function getUpdateString($with_values = true){
|
||||
foreach($this->columns as $column){
|
||||
if($column->show())
|
||||
$update[] = $column->getExpression($with_values);
|
||||
}
|
||||
return trim(implode($update, ', '));
|
||||
}
|
||||
|
||||
function getInsertString($with_values = true){
|
||||
$columnsList = '';
|
||||
$valuesList = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$columnsList .= $column->getColumnName() . ', ';
|
||||
$valuesList .= $column->getValue($with_values) . ', ';
|
||||
}
|
||||
}
|
||||
$columnsList = substr($columnsList, 0, -2);
|
||||
$valuesList = substr($valuesList, 0, -2);
|
||||
|
||||
return "($columnsList) \n VALUES ($valuesList)";
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
// from table_a
|
||||
// from table_a inner join table_b on x=y
|
||||
// from (select * from table a) as x
|
||||
// from (select * from table t) as x inner join table y on y.x
|
||||
function getFromString($with_values = true){
|
||||
$from = '';
|
||||
$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(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
|
||||
|
||||
$simple_table_count++;
|
||||
}
|
||||
if(trim($from) == '') return '';
|
||||
return $from;
|
||||
}
|
||||
|
||||
function getWhereString($with_values = true, $with_optimization = true){
|
||||
$where = '';
|
||||
$condition_count = 0;
|
||||
|
||||
foreach ($this->conditions as $conditionGroup) {
|
||||
if ($condition_count === 0) {
|
||||
$conditionGroup->setPipe("");
|
||||
}
|
||||
$condition_string = $conditionGroup->toString($with_values);
|
||||
$where .= $condition_string;
|
||||
$condition_count++;
|
||||
}
|
||||
|
||||
if ($with_optimization &&
|
||||
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
|
||||
|
||||
if ($condition_count !== 0)
|
||||
$where = '(' . $where . ') ';
|
||||
|
||||
foreach ($this->orderby as $order) {
|
||||
$colName = $order->getColumnName();
|
||||
if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
|
||||
$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
|
||||
if ($condition_count === 0)
|
||||
$opt_condition->setPipe("");
|
||||
$where .= $opt_condition->toString($with_values) . ' ';
|
||||
$condition_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trim($where);
|
||||
}
|
||||
|
||||
function getGroupByString(){
|
||||
$groupBy = '';
|
||||
if($this->groups) if($this->groups[0] !== "")
|
||||
$groupBy = implode(', ', $this->groups);
|
||||
return $groupBy;
|
||||
}
|
||||
|
||||
function getOrderByString(){
|
||||
if(!$this->_orderByString){
|
||||
if(count($this->orderby) === 0) return '';
|
||||
$orderBy = '';
|
||||
foreach($this->orderby as $order){
|
||||
$orderBy .= $order->toString() .', ';
|
||||
}
|
||||
$orderBy = substr($orderBy, 0, -2);
|
||||
$this->_orderByString = $orderBy;
|
||||
}
|
||||
return $this->_orderByString;
|
||||
}
|
||||
|
||||
function getLimit(){
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
function getLimitString(){
|
||||
$limit = '';
|
||||
if(count($this->limit) > 0){
|
||||
$limit = '';
|
||||
$limit .= $this->limit->toString();
|
||||
}
|
||||
return $limit;
|
||||
}
|
||||
|
||||
function getFirstTableName(){
|
||||
return $this->tables[0]->getName();
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
if(!isset($this->arguments)){
|
||||
$this->arguments = array();
|
||||
|
||||
// Join table arguments
|
||||
if(count($this->tables) > 0)
|
||||
{
|
||||
foreach($this->tables as $table)
|
||||
{
|
||||
if($table->isJoinTable())
|
||||
{
|
||||
$args = $table->getArguments();
|
||||
if($args) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setConditions($conditions){
|
||||
$this->conditions = array();
|
||||
if(!isset($conditions) || count($conditions) === 0) return;
|
||||
if(!is_array($conditions)) $conditions = array($conditions);
|
||||
|
||||
foreach($conditions as $conditionGroup){
|
||||
if($conditionGroup->show()) $this->conditions[] = $conditionGroup;
|
||||
}
|
||||
}
|
||||
|
||||
function setGroups($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);
|
||||
|
||||
$this->orderby = $order;
|
||||
}
|
||||
|
||||
function setLimit($limit = NULL){
|
||||
if(!isset($limit)) return;
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
// START Fluent interface
|
||||
/**
|
||||
* seleect set
|
||||
* @param string|array $columns
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function select($columns= null){
|
||||
$this->action = 'select';
|
||||
$this->setColumns($columns);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* from set
|
||||
* @param string|array $tables
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function from($tables){
|
||||
$this->setTables($tables);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* where set
|
||||
* @param string|array $conditions
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function where($conditions){
|
||||
$this->setConditions($conditions);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* groupBy set
|
||||
* @param string|array $groups
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function groupBy($groups){
|
||||
$this->setGroups($groups);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* orderBy set
|
||||
* @param string|array $order
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function orderBy($order){
|
||||
$this->setOrder($order);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* limit set
|
||||
* @param int $limit
|
||||
* @return Query return Query instance
|
||||
*/
|
||||
function limit($limit){
|
||||
$this->setLimit($limit);
|
||||
return $this;
|
||||
}
|
||||
// END Fluent interface
|
||||
|
||||
function getAction(){
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
function getPriority(){
|
||||
return $this->priority?'LOW_PRIORITY':'';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return select sql
|
||||
* @param boolean $with_values
|
||||
* @return string
|
||||
*/
|
||||
function getSelectString($with_values = true){
|
||||
foreach($this->columns as $column){
|
||||
if($column->show())
|
||||
if($column->isSubquery()){
|
||||
$select[] = $column->toString($with_values) . ' as '. $column->getAlias();
|
||||
}
|
||||
else
|
||||
$select[] = $column->getExpression($with_values);
|
||||
}
|
||||
return trim(implode($select, ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return update sql
|
||||
* @param boolean $with_values
|
||||
* @return string
|
||||
*/
|
||||
function getUpdateString($with_values = true){
|
||||
foreach($this->columns as $column){
|
||||
if($column->show())
|
||||
$update[] = $column->getExpression($with_values);
|
||||
}
|
||||
return trim(implode($update, ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return insert sql
|
||||
* @param boolean $with_values
|
||||
* @return string
|
||||
*/
|
||||
function getInsertString($with_values = true){
|
||||
$columnsList = '';
|
||||
if($this->subquery){ // means we have insert-select
|
||||
|
||||
// Column arguments
|
||||
if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$args = $column->getArguments();
|
||||
if($args) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
foreach($this->columns as $column){
|
||||
$columnsList .= $column->getColumnName() . ', ';
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
$columnsList = substr($columnsList, 0, -2);
|
||||
|
||||
$selectStatement = $this->subquery->toString($with_values);
|
||||
$selectStatement = substr($selectStatement, 1, -1);
|
||||
|
||||
return "($columnsList) \n $selectStatement";
|
||||
}
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
$valuesList = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$columnsList .= $column->getColumnName() . ', ';
|
||||
$valuesList .= $column->getValue($with_values) . ', ';
|
||||
}
|
||||
}
|
||||
$columnsList = substr($columnsList, 0, -2);
|
||||
$valuesList = substr($valuesList, 0, -2);
|
||||
|
||||
return "($columnsList) \n VALUES ($valuesList)";
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* from table_a
|
||||
* from table_a inner join table_b on x=y
|
||||
* from (select * from table a) as x
|
||||
* from (select * from table t) as x inner join table y on y.x
|
||||
* @param boolean $with_values
|
||||
* @return string
|
||||
*/
|
||||
function getFromString($with_values = true){
|
||||
$from = '';
|
||||
$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(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
|
||||
|
||||
$simple_table_count++;
|
||||
}
|
||||
if(trim($from) == '') return '';
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return where sql
|
||||
* @param boolean $with_values
|
||||
* @param boolean $with_optimization
|
||||
* @return string
|
||||
*/
|
||||
function getWhereString($with_values = true, $with_optimization = true){
|
||||
$where = '';
|
||||
$condition_count = 0;
|
||||
|
||||
foreach ($this->conditions as $conditionGroup) {
|
||||
if ($condition_count === 0) {
|
||||
$conditionGroup->setPipe("");
|
||||
}
|
||||
$condition_string = $conditionGroup->toString($with_values);
|
||||
$where .= $condition_string;
|
||||
$condition_count++;
|
||||
}
|
||||
|
||||
if ($with_optimization &&
|
||||
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
|
||||
|
||||
if ($condition_count !== 0)
|
||||
$where = '(' . $where . ') ';
|
||||
|
||||
foreach ($this->orderby as $order) {
|
||||
$colName = $order->getColumnName();
|
||||
if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
|
||||
$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
|
||||
if ($condition_count === 0)
|
||||
$opt_condition->setPipe("");
|
||||
$where .= $opt_condition->toString($with_values) . ' ';
|
||||
$condition_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trim($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return groupby sql
|
||||
* @return string
|
||||
*/
|
||||
function getGroupByString(){
|
||||
$groupBy = '';
|
||||
if($this->groups) if($this->groups[0] !== "")
|
||||
$groupBy = implode(', ', $this->groups);
|
||||
return $groupBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return orderby sql
|
||||
* @return string
|
||||
*/
|
||||
function getOrderByString(){
|
||||
if(!$this->_orderByString){
|
||||
if(count($this->orderby) === 0) return '';
|
||||
$orderBy = '';
|
||||
foreach($this->orderby as $order){
|
||||
$orderBy .= $order->toString() .', ';
|
||||
}
|
||||
$orderBy = substr($orderBy, 0, -2);
|
||||
$this->_orderByString = $orderBy;
|
||||
}
|
||||
return $this->_orderByString;
|
||||
}
|
||||
|
||||
function getLimit(){
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return limit sql
|
||||
* @return string
|
||||
*/
|
||||
function getLimitString(){
|
||||
$limit = '';
|
||||
if(count($this->limit) > 0){
|
||||
$limit = '';
|
||||
$limit .= $this->limit->toString();
|
||||
}
|
||||
return $limit;
|
||||
}
|
||||
|
||||
function getFirstTableName(){
|
||||
return $this->tables[0]->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
* @return array
|
||||
*/
|
||||
function getArguments(){
|
||||
if(!isset($this->arguments)){
|
||||
$this->arguments = array();
|
||||
|
||||
// Join table arguments
|
||||
if(count($this->tables) > 0)
|
||||
{
|
||||
foreach($this->tables as $table)
|
||||
{
|
||||
if($table->isJoinTable() || is_a($table, 'Subquery'))
|
||||
{
|
||||
$args = $table->getArguments();
|
||||
if($args) $this->arguments = array_merge($this->arguments, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Column arguments
|
||||
if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$args = $column->getArguments();
|
||||
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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts
|
||||
* @version 0.1
|
||||
*/
|
||||
class Subquery extends Query {
|
||||
/**
|
||||
* table alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
/**
|
||||
* join type
|
||||
* @var string
|
||||
*/
|
||||
var $join_type;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $alias
|
||||
* @param string|array $columns
|
||||
* @param string|array $tables
|
||||
* @param string|array $conditions
|
||||
* @param string|array $groups
|
||||
* @param string|array $orderby
|
||||
* @param int $limit
|
||||
* @param string $join_type
|
||||
* @return void
|
||||
*/
|
||||
function Subquery($alias, $columns, $tables, $conditions, $groups, $orderby, $limit, $join_type = null){
|
||||
$this->alias = $alias;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class Condition {
|
||||
/**
|
||||
* column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
var $argument;
|
||||
/**
|
||||
* operation can use 'equal', 'more', 'excess', 'less', 'below', 'like_tail', 'like_prefix', 'like', 'notlike_tail',
|
||||
* 'notlike_prefix', 'notlike', 'in', 'notin', 'not_in', 'and', 'or', 'xor', 'not', 'notequal', 'between'
|
||||
* 'null', 'notnull'
|
||||
* @var string
|
||||
*/
|
||||
var $operation;
|
||||
/**
|
||||
* pipe can use 'and', 'or'...
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
var $_value;
|
||||
|
|
@ -11,6 +29,14 @@
|
|||
var $_show;
|
||||
var $_value_to_string;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param mixed $argument
|
||||
* @param string $operation
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function Condition($column_name, $argument, $operation, $pipe){
|
||||
$this->column_name = $column_name;
|
||||
$this->argument = $argument;
|
||||
|
|
@ -23,6 +49,11 @@
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* value to string
|
||||
* @param boolean $withValue
|
||||
* @return string
|
||||
*/
|
||||
function toString($withValue = true){
|
||||
if (!isset($this->_value_to_string)) {
|
||||
if (!$this->show())
|
||||
|
|
@ -41,10 +72,18 @@
|
|||
return $this->_value_to_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* change string without value
|
||||
* @return string
|
||||
*/
|
||||
function toStringWithoutValue(){
|
||||
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* change string with value
|
||||
* @return string
|
||||
*/
|
||||
function toStringWithValue(){
|
||||
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
|
||||
}
|
||||
|
|
@ -53,6 +92,9 @@
|
|||
$this->pipe = $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
function show(){
|
||||
if(!isset($this->_show)){
|
||||
if(is_array($this->_value) && count($this->_value) === 1 && $this->_value[0] === '') {
|
||||
|
|
@ -74,6 +116,7 @@
|
|||
case 'notlike' :
|
||||
case 'in' :
|
||||
case 'notin' :
|
||||
case 'not_in' :
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'xor':
|
||||
|
|
@ -82,17 +125,32 @@
|
|||
// if variable is not set or is not string or number, return
|
||||
if(!isset($this->_value)) { $this->_show = false; break;}
|
||||
if($this->_value === '') { $this->_show = false; break; }
|
||||
if(!in_array(gettype($this->_value), array('string', 'integer'))) {$this->_show = false; break; }
|
||||
$tmpArray = array('string'=>1, 'integer'=>1);
|
||||
if(!isset($tmpArray[gettype($this->_value)]))
|
||||
{
|
||||
$this->_show = false; break;
|
||||
}
|
||||
break;
|
||||
case 'between' :
|
||||
if(!is_array($this->_value)) { $this->_show = false; break;}
|
||||
if(count($this->_value)!=2) {$this->_show = false; break;}
|
||||
case 'null':
|
||||
case 'notnull':
|
||||
break;
|
||||
default:
|
||||
// If operation is not one of the above, means the condition is invalid
|
||||
$this->_show = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return condition string
|
||||
* @param int|string|array $value
|
||||
* @return string
|
||||
*/
|
||||
function getConditionPart($value) {
|
||||
$name = $this->column_name;
|
||||
$operation = $this->operation;
|
||||
|
|
@ -131,6 +189,7 @@
|
|||
return $name.' in '.$value;
|
||||
break;
|
||||
case 'notin' :
|
||||
case 'not_in' :
|
||||
return $name.' not in '.$value;
|
||||
break;
|
||||
case 'notequal' :
|
||||
|
|
|
|||
|
|
@ -1,12 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionGroup {
|
||||
/**
|
||||
* condition list
|
||||
* @var array
|
||||
*/
|
||||
var $conditions;
|
||||
/**
|
||||
* pipe can use 'and', 'or'...
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
var $_group;
|
||||
var $_show;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array $conditions
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionGroup($conditions, $pipe = "") {
|
||||
$this->conditions = array();
|
||||
foreach($conditions as $condition){
|
||||
|
|
@ -28,6 +46,11 @@
|
|||
$this->pipe = $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* value to string
|
||||
* @param boolean $with_value
|
||||
* @return string
|
||||
*/
|
||||
function toString($with_value = true){
|
||||
if(!isset($this->_group)){
|
||||
$cond_indx = 0;
|
||||
|
|
@ -48,6 +71,10 @@
|
|||
return $this->_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* return argument list
|
||||
* @return array
|
||||
*/
|
||||
function getArguments(){
|
||||
$args = array();
|
||||
foreach($this->conditions as $condition){
|
||||
|
|
@ -57,4 +84,4 @@
|
|||
return $args;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionSubquery extends Condition {
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param mixed $argument
|
||||
* @param string $operation
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionSubquery($column_name, $argument, $operation, $pipe = ""){
|
||||
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||
$this->_value = $this->argument->toString();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionWithArgument extends Condition {
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param mixed $argument
|
||||
* @param string $operation
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionWithArgument($column_name, $argument, $operation, $pipe = ""){
|
||||
if($argument === null) { $this->_show = false; return; }
|
||||
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||
|
|
@ -13,6 +25,10 @@
|
|||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* change string without value
|
||||
* @return string
|
||||
*/
|
||||
function toStringWithoutValue(){
|
||||
$value = $this->argument->getUnescapedValue();
|
||||
|
||||
|
|
@ -37,6 +53,9 @@
|
|||
return $this->pipe . ' ' . $this->getConditionPart($q);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
function show(){
|
||||
if(!isset($this->_show)){
|
||||
if(!$this->argument->isValid()) $this->_show = false;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionWithoutArgument extends Condition {
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param mixed $argument
|
||||
* @param string $operation
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionWithoutArgument($column_name, $argument, $operation, $pipe = ""){
|
||||
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||
if(in_array($operation, array('in', 'notin'))){
|
||||
$tmpArray = array('in'=>1, 'notin'=>1, 'not_in'=>1);
|
||||
if(isset($tmpArray[$operation])){
|
||||
if(is_array($argument)) $argument = implode($argument, ',');
|
||||
$this->_value = '('. $argument .')';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class ClickCountExpression
|
||||
* ClickCountExpression
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
*
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class ClickCountExpression extends SelectExpression {
|
||||
/**
|
||||
* click count
|
||||
* @var bool
|
||||
*/
|
||||
var $click_count;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param string $alias
|
||||
* @param bool $click_count
|
||||
* @return void
|
||||
*/
|
||||
function ClickCountExpression($column_name, $alias = NULL, $click_count = false){
|
||||
parent::SelectExpression($column_name, $alias);
|
||||
|
||||
|
|
@ -25,9 +34,13 @@
|
|||
return $this->click_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column = column + 1
|
||||
* @return string
|
||||
*/
|
||||
function getExpression(){
|
||||
return "$this->column_name = $this->column_name + 1";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* @class DeleteExpression
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
* DeleteExpression
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
* @todo Fix this class
|
||||
*/
|
||||
|
||||
// TODO Fix this class
|
||||
class DeleteExpression extends Expression {
|
||||
/**
|
||||
* column value
|
||||
* @var mixed
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
function DeleteExpression($column_name, $value){
|
||||
parent::Expression($column_name);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column = value
|
||||
* @return string
|
||||
*/
|
||||
function getExpression(){
|
||||
return "$this->column_name = $this->value";
|
||||
}
|
||||
|
|
@ -32,4 +47,4 @@
|
|||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* @class Expression
|
||||
* @author Corina
|
||||
* @brief Represents an expression used in select/update/insert/delete statements
|
||||
* Expression
|
||||
* Represents an expression used in select/update/insert/delete statements
|
||||
*
|
||||
* Examples (expressions are inside double square brackets):
|
||||
* select [[columnA]], [[columnB as aliasB]] from tableA
|
||||
* update tableA set [[columnA = valueA]] where columnB = something
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class Expression {
|
||||
/**
|
||||
* column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @return void
|
||||
*/
|
||||
function Expression($column_name){
|
||||
$this->column_name = $column_name;
|
||||
}
|
||||
|
|
@ -25,6 +35,10 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column as alias
|
||||
* @return string
|
||||
*/
|
||||
function getExpression() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class InsertExpression
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
* InsertExpression
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class InsertExpression extends Expression {
|
||||
/**
|
||||
* argument
|
||||
* @var object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param object $argument
|
||||
* @return void
|
||||
*/
|
||||
function InsertExpression($column_name, $argument){
|
||||
parent::Expression($column_name);
|
||||
$this->argument = $argument;
|
||||
|
|
|
|||
|
|
@ -1,26 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class SelectExpression
|
||||
* @author Arnia Software
|
||||
* @brief Represents an expresion that appears in the select clause
|
||||
* SelectExpression
|
||||
* Represents an expresion that appears in the select clause
|
||||
*
|
||||
* @remarks
|
||||
* $column_name can be:
|
||||
* - a table column name
|
||||
* - an sql function - like count(*)
|
||||
* - an sql expression - substr(column_name, 1, 8) or score1 + score2
|
||||
* $column_name is already escaped
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class SelectExpression extends Expression {
|
||||
/**
|
||||
* column alias name
|
||||
* @var string
|
||||
*/
|
||||
var $column_alias;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param string $alias
|
||||
* @return void
|
||||
*/
|
||||
function SelectExpression($column_name, $alias = NULL){
|
||||
parent::Expression($column_name);
|
||||
$this->column_alias = $alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column as alias
|
||||
* @return string
|
||||
*/
|
||||
function getExpression() {
|
||||
return sprintf("%s%s", $this->column_name, $this->column_alias ? " as ".$this->column_alias : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class StarExpression
|
||||
* @author Corina
|
||||
* @brief Represents the * in 'select * from ...' statements
|
||||
* StarExpression
|
||||
* Represents the * in 'select * from ...' statements
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class StarExpression extends SelectExpression {
|
||||
|
||||
/**
|
||||
* constructor, set the column to asterisk
|
||||
* @return void
|
||||
*/
|
||||
function StarExpression(){
|
||||
parent::SelectExpression("*");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* @class UpdateExpression
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
* UpdateExpression
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class UpdateExpression extends Expression {
|
||||
/**
|
||||
* argument
|
||||
* @var object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param object $argument
|
||||
* @return void
|
||||
*/
|
||||
function UpdateExpression($column_name, $argument){
|
||||
parent::Expression($column_name);
|
||||
$this->argument = $argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column = value
|
||||
* @return string
|
||||
*/
|
||||
function getExpression($with_value = true){
|
||||
if($with_value)
|
||||
return $this->getExpressionWithValue();
|
||||
return $this->getExpressionWithoutValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column = value
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionWithValue(){
|
||||
$value = $this->argument->getValue();
|
||||
$operation = $this->argument->getColumnOperation();
|
||||
|
|
@ -28,6 +46,11 @@
|
|||
return "$this->column_name = $value";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column expression, ex) column = ?
|
||||
* Can use prepare statement
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionWithoutValue(){
|
||||
$operation = $this->argument->getColumnOperation();
|
||||
if(isset($operation))
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* @class UpdateExpression
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
* UpdateExpression
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/expression
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class UpdateExpressionWithoutArgument extends UpdateExpression {
|
||||
/**
|
||||
* argument
|
||||
* @var object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param object $argument
|
||||
* @return void
|
||||
*/
|
||||
function UpdateExpressionWithoutArgument($column_name, $argument){
|
||||
parent::Expression($column_name);
|
||||
$this->argument = $argument;
|
||||
|
|
@ -35,11 +45,11 @@
|
|||
function getArgument(){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function getArguments(){
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/limit
|
||||
* @version 0.1
|
||||
*/
|
||||
class Limit {
|
||||
/**
|
||||
* start number
|
||||
* @var int
|
||||
*/
|
||||
var $start;
|
||||
/**
|
||||
* list count
|
||||
* @var int
|
||||
*/
|
||||
var $list_count;
|
||||
/**
|
||||
* page count
|
||||
* @var int
|
||||
*/
|
||||
var $page_count;
|
||||
/**
|
||||
* current page
|
||||
* @var int
|
||||
*/
|
||||
var $page;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param int $list_count
|
||||
* @param int $page
|
||||
* @param int $page_count
|
||||
* @return void
|
||||
*/
|
||||
function Limit($list_count, $page= NULL, $page_count= NULL){
|
||||
$this->list_count = $list_count;
|
||||
if ($page){
|
||||
|
|
@ -16,7 +44,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
function isPageHandler(){//in case you choose to use query limit in other cases than page select
|
||||
/**
|
||||
* In case you choose to use query limit in other cases than page select
|
||||
* @return boolean
|
||||
*/
|
||||
function isPageHandler(){
|
||||
if ($this->page)return true;
|
||||
else return false;
|
||||
}
|
||||
|
|
@ -34,4 +66,4 @@
|
|||
else return $this->list_count->getValue();
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/order
|
||||
* @version 0.1
|
||||
*/
|
||||
class OrderByColumn {
|
||||
/**
|
||||
* column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
/**
|
||||
* sort order
|
||||
* @var string
|
||||
*/
|
||||
var $sort_order;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name
|
||||
* @param string $sort_order
|
||||
* @return void
|
||||
*/
|
||||
function OrderByColumn($column_name, $sort_order){
|
||||
$this->column_name = $column_name;
|
||||
$this->sort_order = $sort_order;
|
||||
|
|
@ -28,4 +47,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class CubridTableWithHint extends Table {
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* table alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
/**
|
||||
* index hint list
|
||||
* @var array
|
||||
*/
|
||||
var $index_hints_list;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param string $alias
|
||||
* @param array $index_hints_list
|
||||
* @return void
|
||||
*/
|
||||
function CubridTableWithHint($name, $alias = NULL, $index_hints_list){
|
||||
parent::Table($name, $alias);
|
||||
$this->index_hints_list = $index_hints_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return index hint string
|
||||
* @return string
|
||||
*/
|
||||
function getIndexHintString(){
|
||||
$result = '';
|
||||
|
||||
|
|
@ -32,4 +59,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class IndexHint {
|
||||
/**
|
||||
* index name
|
||||
* @var string
|
||||
*/
|
||||
var $index_name;
|
||||
/**
|
||||
* index hint type, ex) IGNORE, FORCE, USE...
|
||||
* @var string
|
||||
*/
|
||||
var $index_hint_type;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $index_name
|
||||
* @param string $index_hint_type
|
||||
* @return void
|
||||
*/
|
||||
function IndexHint($index_name, $index_hint_type){
|
||||
$this->index_name = $index_name;
|
||||
$this->index_hint_type = $index_hint_type;
|
||||
|
|
@ -18,4 +36,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class JoinTable
|
||||
* @author Arnia Software
|
||||
* @brief
|
||||
*
|
||||
* @remarks
|
||||
* class JoinTable
|
||||
* $conditions in an array of Condition objects
|
||||
*
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
class JoinTable extends Table {
|
||||
/**
|
||||
* join type
|
||||
* @var string
|
||||
*/
|
||||
var $join_type;
|
||||
/**
|
||||
* condition list
|
||||
* @var array
|
||||
*/
|
||||
var $conditions;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param string $alias
|
||||
* @param string $join_type
|
||||
* @param array $conditions
|
||||
* @return void
|
||||
*/
|
||||
function JoinTable($name, $alias, $join_type, $conditions){
|
||||
parent::Table($name, $alias);
|
||||
$this->join_type = $join_type;
|
||||
|
|
@ -43,4 +56,4 @@
|
|||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class MssqlTableWithHint extends Table {
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* table alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
/**
|
||||
* index hint type, ex) IGNORE, FORCE, USE...
|
||||
* @var array
|
||||
*/
|
||||
var $index_hints_list;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param string $alias
|
||||
* @param string $index_hints_list
|
||||
* @return void
|
||||
*/
|
||||
function MssqlTableWithHint($name, $alias = NULL, $index_hints_list){
|
||||
parent::Table($name, $alias);
|
||||
$this->index_hints_list = $index_hints_list;
|
||||
|
|
@ -14,9 +37,10 @@
|
|||
$result = parent::toString();
|
||||
|
||||
$index_hint_string = '';
|
||||
$indexTypeList = array('USE'=>1, 'FORCE'=>1);
|
||||
foreach($this->index_hints_list as $index_hint){
|
||||
$index_hint_type = $index_hint->getIndexHintType();
|
||||
if(in_array($index_hint_type, array('USE', 'FORCE')))
|
||||
if(isset($indexTypeList[$index_hint_type]))
|
||||
$index_hint_string .= 'INDEX(' . $index_hint->getIndexName() . '), ';
|
||||
}
|
||||
if($index_hint_string != ''){
|
||||
|
|
@ -26,4 +50,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class MysqlTableWithHint extends Table {
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* table alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
/**
|
||||
* index hint type, ex) IGNORE, FORCE, USE...
|
||||
* @var array
|
||||
*/
|
||||
var $index_hints_list;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param string $alias
|
||||
* @param string $index_hints_list
|
||||
* @return void
|
||||
*/
|
||||
function MysqlTableWithHint($name, $alias = NULL, $index_hints_list){
|
||||
parent::Table($name, $alias);
|
||||
$this->index_hints_list = $index_hints_list;
|
||||
|
|
@ -33,4 +56,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db/queryparts/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class Table {
|
||||
/**
|
||||
* table name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* table alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param string $alias
|
||||
* @return void
|
||||
*/
|
||||
function Table($name, $alias = NULL){
|
||||
$this->name = $name;
|
||||
$this->alias = $alias;
|
||||
|
|
@ -27,4 +45,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue