Remove legacy DB classes and XML query parser classes

This commit is contained in:
Kijin Sung 2020-06-30 12:20:12 +09:00
parent 978d3d167a
commit ad5169bc7a
55 changed files with 7 additions and 8717 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,749 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (developers@xpressengine.com)
* @package /classes/db/queryparts
* @version 0.1
*/
class Query extends BaseObject
{
/**
* 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;
/**
* having list
* @var string|array
*/
var $having;
/**
* 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 __construct($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)
{
if (!is_array($this->columnList)) return;
$this->columnList = $columnList;
if(count($this->columnList) > 0)
{
$selectColumns = array();
$dbParser = DB::getParser();
foreach($this->columnList as $columnName)
{
$columnName = $dbParser->escapeColumnExpression($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 setSubquery($subquery)
{
$this->subquery = $subquery;
}
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 setHaving($conditions)
{
$this->having = array();
if(!isset($conditions) || count($conditions) === 0)
{
return;
}
if(!is_array($conditions))
{
$conditions = array($conditions);
}
foreach($conditions as $conditionGroup)
{
if($conditionGroup->show())
{
$this->having[] = $conditionGroup;
}
}
}
function setOrder($order)
{
if(!isset($order) || count($order) === 0)
{
return;
}
if(!is_array($order))
{
$order = array($order);
}
$this->orderby = $order;
}
function getOrder()
{
return $this->orderby;
}
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' : '';
}
/**
* Check if current query uses the click count attribute
* For CUBRID, this statement uses the click count feature.
* For the other databases, using this attribute causes a query
* to produce both a select and an update
*/
function usesClickCount()
{
return count($this->getClickCountColumns()) > 0;
}
function getClickCountColumns()
{
$click_count_columns = array();
foreach($this->columns as $column)
{
if($column->show() && is_a($column, 'ClickCountExpression'))
{
$click_count_columns[] = $column;
}
}
return $click_count_columns;
}
/**
* 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);
}
}
if(!$update) return;
return trim(implode($update, ', '));
}
/**
* Return insert sql
* @param boolean $with_values
* @return string
*/
function getInsertString($with_values = TRUE)
{
$columnsList = '';
// means we have insert-select
if($this->subquery)
{
foreach($this->columns as $column)
{
$columnsList .= $column->getColumnName() . ', ';
}
$columnsList = substr($columnsList, 0, -2);
$selectStatement = $this->subquery->toString($with_values);
$selectStatement = substr($selectStatement, 1, -1);
return "($columnsList) \n $selectStatement";
}
$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 having sql
* @param boolean $with_values
* @return string
*/
function getHavingString($with_values = TRUE)
{
if(!is_array($this->having))
{
return '';
}
$having = '';
$condition_count = 0;
foreach($this->having as $conditionGroup)
{
if($condition_count === 0)
{
$conditionGroup->setPipe("");
}
$condition_string = $conditionGroup->toString($with_values);
$having .= $condition_string;
$condition_count++;
}
return trim($having);
}
/**
* Return orderby sql
* @return string
*/
function getOrderByString()
{
if(!$this->_orderByString)
{
if(countobj($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(countobj($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(countobj($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
// The if is for delete statements, all others must have columns
if(countobj($this->columns) > 0)
{
foreach($this->columns as $column)
{
if($column->show())
{
$args = $column->getArguments();
if($args)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
}
// Condition arguments
if(countobj($this->conditions) > 0)
{
foreach($this->conditions as $conditionGroup)
{
$args = $conditionGroup->getArguments();
if(countobj($args) > 0)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
// Having arguments
if(countobj($this->having) > 0)
{
foreach($this->having as $conditionGroup)
{
$args = $conditionGroup->getArguments();
if(countobj($args) > 0)
{
$this->arguments = array_merge($this->arguments, $args);
}
}
}
// Navigation arguments
if(countobj($this->orderby) > 0)
{
foreach($this->orderby as $order)
{
$args = $order->getArguments();
if(countobj($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 */

View file

@ -1,80 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($alias, $columns, $tables, $conditions, $groups, $orderby, $limit, $join_type = null)
{
$this->alias = $alias;
$this->queryID = null;
$this->action = "select";
$this->columns = $columns;
$this->tables = $tables;
$this->conditions = $conditions;
$this->groups = $groups;
$this->orderby = $orderby;
$this->limit = $limit;
$this->join_type = $join_type;
}
function getAlias()
{
return $this->alias;
}
function isJoinTable()
{
if($this->join_type)
{
return true;
}
return false;
}
function toString($with_values = true)
{
$oDB = &DB::getInstance();
return '(' . $oDB->getSelectSql($this, $with_values) . ')';
}
function isSubquery()
{
return true;
}
}
/* End of file Subquery.class.php */
/* Location: ./classes/db/queryparts/Subquery.class.php */

View file

@ -1,277 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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;
var $_show;
var $_value_to_string;
/**
* constructor
* @param string $column_name
* @param mixed $argument
* @param string $operation
* @param string $pipe
* @return void
*/
function __construct($column_name, $argument, $operation, $pipe = 'and')
{
$this->column_name = $column_name;
$this->argument = $argument;
$this->operation = $operation;
$this->pipe = $pipe;
}
function getArgument()
{
return null;
}
/**
* value to string
* @param boolean $withValue
* @return string
*/
function toString($withValue = true)
{
if(!isset($this->_value_to_string))
{
if(!$this->show())
{
$this->_value_to_string = '';
}
else if($withValue)
{
$this->_value_to_string = $this->toStringWithValue();
}
else
{
$this->_value_to_string = $this->toStringWithoutValue();
}
}
return $this->_value_to_string;
}
/**
* change string without value
* @return string
*/
function toStringWithoutValue()
{
return strtoupper($this->pipe) . ' ' . $this->getConditionPart($this->_value);
}
/**
* change string with value
* @return string
*/
function toStringWithValue()
{
return strtoupper($this->pipe) . ' ' . $this->getConditionPart($this->_value);
}
function setPipe($pipe)
{
$this->pipe = $pipe;
}
/**
* @return boolean
*/
function show()
{
if(!isset($this->_show))
{
if(is_array($this->_value) && count($this->_value) === 1 && $this->_value[0] === '')
{
$this->_show = false;
}
else
{
$this->_show = true;
switch($this->operation)
{
case 'equal' :
case 'more' :
case 'excess' :
case 'less' :
case 'below' :
case 'gte' :
case 'gt' :
case 'lte' :
case 'lt' :
case 'like_tail' :
case 'like_prefix' :
case 'like' :
case 'notlike_tail' :
case 'notlike_prefix' :
case 'notlike' :
case 'not_like' :
case 'regexp' :
case 'notregexp' :
case 'not_regexp' :
case 'in' :
case 'notin' :
case 'not_in' :
case 'and':
case 'or':
case 'xor':
case 'not':
case 'notequal' :
case 'not_equal' :
// 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;
}
$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':
case 'not_null':
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;
switch($operation)
{
case 'equal' :
return $name . ' = ' . $value;
break;
case 'more' :
case 'gte' :
return $name . ' >= ' . $value;
break;
case 'excess' :
case 'gt' :
return $name . ' > ' . $value;
break;
case 'less' :
case 'lte' :
return $name . ' <= ' . $value;
break;
case 'below' :
case 'lt' :
return $name . ' < ' . $value;
break;
case 'like_tail' :
case 'like_prefix' :
case 'like' :
return $name . ' LIKE ' . $value;
case 'notlike_tail' :
case 'notlike_prefix' :
case 'notlike' :
case 'not_like' :
return $name . ' NOT LIKE ' . $value;
break;
case 'regexp' :
return $name . ' REGEXP ' . $value;
break;
case 'notregexp' :
case 'not_regexp' :
return $name . ' NOT REGEXP ' . $value;
break;
case 'in' :
return $name . ' IN ' . $value;
break;
case 'notin' :
case 'not_in' :
return $name . ' NOT IN ' . $value;
break;
case 'notequal' :
case 'not_equal' :
return $name . ' <> ' . $value;
break;
case 'notnull' :
case 'not_null' :
return $name . ' IS NOT NULL ';
break;
case 'null' :
return $name . ' IS NULL ';
break;
case 'and' :
return $name . ' & ' . $value;
break;
case 'or' :
return $name . ' | ' . $value;
break;
case 'xor' :
return $name . ' ^ ' . $value;
break;
case 'not' :
return $name . ' ~ ' . $value;
break;
case 'between' :
return $name . ' BETWEEN ' . $value[0] . ' AND ' . $value[1];
break;
}
}
}
/* End of file Condition.class.php */
/* Location: ./classes/db/queryparts/condition/Condition.class.php */

View file

@ -1,133 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($conditions, $pipe = 'and')
{
$this->conditions = array();
foreach($conditions as $condition)
{
if($condition->show())
{
$this->conditions[] = $condition;
}
}
if(count($this->conditions) === 0)
{
$this->_show = false;
}
else
{
$this->_show = true;
}
$this->pipe = $pipe;
}
function show()
{
return $this->_show;
}
function setPipe($pipe)
{
if($this->pipe !== $pipe)
{
$this->_group = null;
}
$this->pipe = $pipe;
}
/**
* value to string
* @param boolean $with_value
* @return string
*/
function toString($with_value = true)
{
if(!isset($this->_group))
{
$cond_indx = 0;
$group = '';
foreach($this->conditions as $condition)
{
if($cond_indx === 0)
{
$condition->setPipe("");
}
$group .= $condition->toString($with_value) . ' ';
$cond_indx++;
}
if($this->pipe !== "" && trim($group) !== '')
{
$group = strtoupper($this->pipe) . ' (' . $group . ')';
}
$this->_group = $group;
}
return $this->_group;
}
/**
* return argument list
* @return array
*/
function getArguments()
{
$args = array();
foreach($this->conditions as $condition)
{
if($condition instanceof ConditionGroup)
{
foreach($condition->getArguments() as $arg)
{
if($arg)
{
$args[] = $arg;
}
}
}
else
{
$arg = $condition->getArgument();
if($arg)
{
$args[] = $arg;
}
}
}
return $args;
}
}
/* End of file ConditionGroup.class.php */
/* Location: ./classes/db/queryparts/condition/ConditionGroup.class.php */

View file

@ -1,28 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($column_name, $argument, $operation, $pipe = "")
{
parent::__construct($column_name, $argument, $operation, $pipe);
$this->_value = $this->argument->toString();
}
}
/* End of file ConditionSubquery.class.php */
/* Location: ./classes/db/queryparts/condition/ConditionSubquery.class.php */

View file

@ -1,99 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($column_name, $argument, $operation, $pipe = "")
{
if($argument === null)
{
$this->_show = false;
return;
}
parent::__construct($column_name, $argument, $operation, $pipe);
$this->_value = $argument->getValue();
}
function getArgument()
{
if(!$this->show())
return;
return $this->argument;
}
/**
* change string without value
* @return string
*/
function toStringWithoutValue()
{
$value = $this->argument->getUnescapedValue();
if(is_array($value))
{
$q = '';
foreach($value as $v)
{
$q .= '?,';
}
if($q !== '')
{
$q = substr($q, 0, -1);
}
$q = '(' . $q . ')';
}
else
{
// Prepared statements: column names should not be sent as query arguments, but instead concatenated to query string
if($this->argument->isColumnName())
{
$q = $value;
}
else
{
$q = '?';
}
}
return strtoupper($this->pipe) . ' ' . $this->getConditionPart($q);
}
/**
* @return boolean
*/
function show()
{
if(!isset($this->_show))
{
if(!$this->argument->isValid())
{
$this->_show = false;
}
if($this->_value === '\'\'')
{
$this->_show = false;
}
if(!isset($this->_show))
{
return parent::show();
}
}
return $this->_show;
}
}
/* End of file ConditionWithArgument.class.php */
/* Location: ./classes/db/queryparts/condition/ConditionWithArgument.class.php */

View file

@ -1,40 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($column_name, $argument, $operation, $pipe = "")
{
parent::__construct($column_name, $argument, $operation, $pipe);
$tmpArray = array('in' => 1, 'notin' => 1, 'not_in' => 1);
if(isset($tmpArray[$operation]))
{
if(is_array($argument))
{
$argument = implode($argument, ',');
}
$this->_value = '(' . $argument . ')';
}
else
{
$this->_value = $argument;
}
}
}
/* End of file ConditionWithoutArgument.class.php */
/* Location: ./classes/db/queryparts/condition/ConditionWithoutArgument.class.php */

View file

@ -1,62 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* ClickCountExpression
* @author Arnia Software
* @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 __construct($column_name, $alias = NULL, $click_count = false)
{
parent::__construct($column_name, $alias);
if(!is_bool($click_count))
{
// error_log("Click_count value for $column_name was not boolean", 0);
$this->click_count = false;
}
$this->click_count = $click_count;
}
function show()
{
return $this->click_count;
}
/**
* Return column expression, ex) column = column + 1
* @return string
*/
function getExpression()
{
$db_type = Context::getDBType();
if($db_type == 'cubrid')
{
return "INCR($this->column_name)";
}
else
{
return "$this->column_name";
}
}
}
/* End of file ClickCountExpression.class.php */
/* Location: ./classes/db/queryparts/expression/ClickCountExpression.class.php */

View file

@ -1,63 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* DeleteExpression
*
* @author Arnia Software
* @package /classes/db/queryparts/expression
* @version 0.1
* @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 __construct($column_name, $value)
{
parent::__construct($column_name);
$this->value = $value;
}
/**
* Return column expression, ex) column = value
* @return string
*/
function getExpression()
{
return "$this->column_name = $this->value";
}
function getValue()
{
// TODO Escape value according to column type instead of variable type
if(!is_numeric($this->value))
{
return "'" . $this->value . "'";
}
return $this->value;
}
function show()
{
if(!$this->value)
{
return false;
}
return true;
}
}
/* End of file DeleteExpression.class.php */
/* Location: ./classes/db/queryparts/expression/DeleteExpression.class.php */

View file

@ -1,56 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct($column_name)
{
$this->column_name = $column_name;
}
function getColumnName()
{
return $this->column_name;
}
function show()
{
return false;
}
/**
* Return column expression, ex) column as alias
* @return string
*/
function getExpression()
{
}
}
/* End of file Expression.class.php */
/* Location: ./classes/db/queryparts/expression/Expression.class.php */

View file

@ -1,74 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct($column_name, $argument)
{
parent::__construct($column_name);
$this->argument = $argument;
}
function getValue($with_values = true)
{
if($with_values)
{
return $this->argument->getValue();
}
return '?';
}
function show()
{
if(!$this->argument)
{
return false;
}
$value = $this->argument->getValue();
if(!isset($value))
{
return false;
}
return true;
}
function getArgument()
{
return $this->argument;
}
function getArguments()
{
if($this->argument)
{
return array($this->argument);
}
else
{
return array();
}
}
}
/* End of file InsertExpression.class.php */
/* Location: ./classes/db/queryparts/expression/InsertExpression.class.php */

View file

@ -1,70 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* SelectExpression
* Represents an expresion that appears in the select clause
*
* $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 __construct($column_name, $alias = NULL)
{
parent::__construct($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) : "");
}
function show()
{
return true;
}
function getArgument()
{
return null;
}
function getArguments()
{
return array();
}
function isSubquery()
{
return false;
}
}
/* End of file SelectExpression.class.php */
/* Location: ./classes/db/queryparts/expression/SelectExpression.class.php */

View file

@ -1,37 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct()
{
parent::__construct("*");
}
function getArgument()
{
return null;
}
function getArguments()
{
// StarExpression has no arguments
return array();
}
}
/* End of file StarExpression.class.php */
/* Location: ./classes/db/queryparts/expression/StarExpression.class.php */

View file

@ -1,119 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct($column_name, $argument)
{
parent::__construct($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();
if(isset($operation))
{
return "$this->column_name = $this->column_name $operation $value";
}
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))
{
return "$this->column_name = $this->column_name $operation ?";
}
return "$this->column_name = ?";
}
function getValue()
{
// TODO Escape value according to column type instead of variable type
$value = $this->argument->getValue();
if(!is_numeric($value))
{
return "'" . $value . "'";
}
return $value;
}
function show()
{
if(!$this->argument)
{
return false;
}
$value = $this->argument->getValue();
if(!isset($value))
{
return false;
}
return true;
}
function getArgument()
{
return $this->argument;
}
function getArguments()
{
if($this->argument)
{
return array($this->argument);
}
else
{
return array();
}
}
}
/* End of file UpdateExpression.class.php */
/* Location: ./classes/db/queryparts/expression/UpdateExpression.class.php */

View file

@ -1,74 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct($column_name, $argument)
{
parent::__construct($column_name, $argument);
$this->argument = $argument;
}
function getExpression($with_value = true)
{
return "$this->column_name = $this->argument";
}
function getValue()
{
// TODO Escape value according to column type instead of variable type
$value = $this->argument;
if(!is_numeric($value))
{
return "'" . $value . "'";
}
return $value;
}
function show()
{
if(!$this->argument)
{
return false;
}
$value = $this->argument;
if(!isset($value))
{
return false;
}
return true;
}
function getArgument()
{
return null;
}
function getArguments()
{
return array();
}
}
/* End of file UpdateExpressionWithoutArgument.class.php */
/* Location: ./classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php */

View file

@ -1,101 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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
* @param int $offset
* @return void
*/
function __construct($list_count, $page = NULL, $page_count = NULL, $offset = NULL)
{
$this->list_count = $list_count;
if($list_count->getValue())
{
if($page && $page->getValue())
{
$this->start = ($page->getValue() - 1) * $list_count->getValue();
$this->page_count = $page_count;
$this->page = $page;
}
elseif($offset)
{
$this->start = $offset->getValue();
}
}
}
/**
* 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;
}
}
function getOffset()
{
return $this->start;
}
function getLimit()
{
return $this->list_count->getValue();
}
function toString()
{
if($this->start)
{
return $this->start . ' , ' . $this->list_count->getValue();
}
else
{
return $this->list_count->getValue() ?: '';
}
}
}
/* End of file Limit.class.php */
/* Location: ./classes/db/limit/Limit.class.php */

View file

@ -1,74 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($column_name, $sort_order)
{
$this->column_name = $column_name;
$this->sort_order = $sort_order;
}
function toString()
{
$result = $this->getColumnName();
$result .= ' ';
$result .= is_a($this->sort_order, 'Argument') ? $this->sort_order->getValue() : strtoupper($this->sort_order);
return $result;
}
function getColumnName()
{
return is_a($this->column_name, 'Argument') ? $this->column_name->getValue() : $this->column_name;
}
function getPureColumnName()
{
return is_a($this->column_name, 'Argument') ? $this->column_name->getPureValue() : $this->column_name;
}
function getPureSortOrder()
{
return is_a($this->sort_order, 'Argument') ? $this->sort_order->getPureValue() : $this->sort_order;
}
function getArguments()
{
$args = array();
if(is_a($this->column_name, 'Argument'))
{
$args[] = $this->column_name;
}
if(is_a($this->sort_order, 'Argument'))
{
$args[] = $this->sort_order;
}
}
}
/* End of file OrderByColumn.class.php */
/* Location: ./classes/db/order/OrderByColumn.class.php */

View file

@ -1,48 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($index_name, $index_hint_type)
{
$this->index_name = $index_name;
$this->index_hint_type = $index_hint_type;
}
function getIndexName()
{
return $this->index_name;
}
function getIndexHintType()
{
return $this->index_hint_type;
}
}
/* End of file IndexHint.class.php */
/* Location: ./classes/db/queryparts/table/IndexHint.class.php */

View file

@ -1,78 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* 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 __construct($name, $alias, $join_type, $conditions)
{
parent::__construct($name, $alias);
$this->join_type = $join_type;
$this->conditions = $conditions;
}
function toString($with_value = true)
{
$part = strtoupper($this->join_type) . ' ' . $this->name;
$part .= $this->alias ? (' AS ' . $this->alias) : '';
$part .= ' ON ';
$condition_count = 0;
foreach($this->conditions as $conditionGroup)
{
if($condition_count === 0)
{
$conditionGroup->setPipe("");
}
$part .= $conditionGroup->toString($with_value);
$condition_count++;
}
return $part;
}
function isJoinTable()
{
return true;
}
function getArguments()
{
$args = array();
foreach($this->conditions as $conditionGroup)
{
$args = array_merge($args, $conditionGroup->getArguments());
}
return $args;
}
}
/* End of file JoinTable.class.php */
/* Location: ./classes/db/queryparts/table/JoinTable.class.php */

View file

@ -1,83 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($name, $alias = NULL, $index_hints_list)
{
parent::__construct($name, $alias);
$this->index_hints_list = $index_hints_list;
}
function toString()
{
$result = parent::toString();
$use_index_hint = '';
$force_index_hint = '';
$ignore_index_hint = '';
foreach($this->index_hints_list as $index_hint)
{
$index_hint_type = $index_hint->getIndexHintType();
if($index_hint_type == 'USE')
{
$use_index_hint .= $index_hint->getIndexName() . ', ';
}
else if($index_hint_type == 'FORCE')
{
$force_index_hint .= $index_hint->getIndexName() . ', ';
}
else if($index_hint_type == 'IGNORE')
{
$ignore_index_hint .= $index_hint->getIndexName() . ', ';
}
}
if($use_index_hint != '')
{
$result .= ' USE INDEX (' . substr($use_index_hint, 0, -2) . ') ';
}
if($force_index_hint != '')
{
$result .= ' FORCE INDEX (' . substr($force_index_hint, 0, -2) . ') ';
}
if($ignore_index_hint != '')
{
$result .= ' IGNORE INDEX (' . substr($ignore_index_hint, 0, -2) . ') ';
}
return $result;
}
}
/* End of file MysqlTableWithHint.class.php */
/* Location: ./classes/db/queryparts/table/MysqlTableWithHint.class.php */

View file

@ -1,59 +0,0 @@
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @author NAVER (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 __construct($name, $alias = NULL)
{
$this->name = $name;
$this->alias = $alias;
}
function toString()
{
//return $this->name;
return sprintf("%s%s", $this->name, $this->alias ? (' AS ' . $this->alias) : '');
}
function getName()
{
return $this->name;
}
function getAlias()
{
return $this->alias;
}
function isJoinTable()
{
return false;
}
}
/* End of file Table.class.php */
/* Location: ./classes/db/queryparts/table/Table.class.php */