diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php
index e325b185d..393d34779 100644
--- a/classes/db/DB.class.php
+++ b/classes/db/DB.class.php
@@ -1,1228 +1,6 @@
*/
-/**
- * - DB parent class
- * - usage of db in XE is via xml
- * - there are 2 types of xml - query xml, schema xml
- * - in case of query xml, DB::executeQuery() method compiles xml file into php code and then execute it
- * - query xml has unique query id, and will be created in module
- * - queryid = module_name.query_name
- *
- * @author NAVER (developers@xpressengine.com)
- * @package /classes/db
- * @version 0.1
- */
-class DB
+class DB extends Rhymix\Framework\DB
{
-
- static $isSupported = FALSE;
-
- /**
- * priority of DBMS
- * @var array
- */
- protected static $priority_dbms = array(
- 'mysql' => 1,
- );
-
- /**
- * master database connection string
- * @var array
- */
- protected $master_db = NULL;
-
- /**
- * array of slave databases connection strings
- * @var array
- */
- protected $slave_db = NULL;
- protected $result = NULL;
-
- /**
- * error code (0 means no error)
- * @var int
- */
- protected $errno = 0;
-
- /**
- * error message
- * @var string
- */
- protected $errstr = '';
-
- /**
- * query string of latest executed query
- * @var string
- */
- protected $query = '';
- protected $connection = '';
-
- /**
- * elapsed time of latest executed query
- * @var int
- */
- protected $elapsed_time = 0;
-
- /**
- * elapsed time of latest executed DB class
- * @var int
- */
- protected $elapsed_dbclass_time = 0;
-
- /**
- * transaction flag
- * @var boolean
- */
- protected $transaction_started = FALSE;
- protected $is_connected = FALSE;
-
- /**
- * returns enable list in supported dbms list
- * will be written by classes/DB/DB***.class.php
- * @var array
- */
- protected static $supported_list = array();
-
- /**
- * location of query cache
- * @var string
- */
- protected $cache_file = 'files/cache/queries/';
-
- /**
- * stores database type, e.g. mysql
- * @var string
- */
- public $db_type;
- public $db_version = '';
-
- /**
- * flag to decide if class prepared statements or not (when supported); can be changed from db.config.info
- * @var string
- */
- public $use_prepared_statements;
-
- /**
- * leve of transaction
- * @var unknown
- */
- protected $transactionNestedLevel = 0;
-
- /**
- * returns instance of certain db type
- * @param string $db_type type of db
- * @return DB return DB object instance
- */
- public static function getInstance($db_type = NULL)
- {
- if(!$db_type)
- {
- $db_type = config('db.master.type');
- }
- if(!$db_type && Context::isInstalled())
- {
- Rhymix\Framework\Debug::displayError(lang('msg_db_not_setted'));
- exit;
- }
- if(!strncmp($db_type, 'mysql', 5))
- {
- $db_type = 'mysql';
- }
-
- if(!isset($GLOBALS['__DB__']))
- {
- $GLOBALS['__DB__'] = array();
- }
- if(!isset($GLOBALS['__DB__'][$db_type]))
- {
- $class_name = 'DB' . ucfirst($db_type);
- $class_file = RX_BASEDIR . "classes/db/$class_name.class.php";
- if(!file_exists($class_file))
- {
- Rhymix\Framework\Debug::displayError(sprintf('DB type "%s" is not supported.', $db_type));
- exit;
- }
-
- // get a singletone instance of the database driver class
- require_once($class_file);
- $GLOBALS['__DB__'][$db_type] = new $class_name;
- $GLOBALS['__DB__'][$db_type]->db_type = $db_type;
- }
-
- return $GLOBALS['__DB__'][$db_type];
- }
-
- /**
- * returns instance of db
- * @return DB return DB object instance
- */
- public static function create()
- {
- return new static();
- }
-
- /**
- * constructor
- * @return void
- */
- public function __construct()
- {
- $this->cache_file = _XE_PATH_ . $this->cache_file;
- }
-
- /**
- * returns list of supported dbms list
- * this list return by directory list
- * check by instance can creatable
- * @return array return supported DBMS list
- */
- public static function getSupportedList()
- {
- return self::_getSupportedList();
- }
-
- /**
- * returns enable list in supported dbms list
- * this list return by child class
- * @return array return enable DBMS list in supported dbms list
- */
- public static function getEnableList()
- {
- if(!self::$supported_list)
- {
- $oDB = new DB();
- self::$supported_list = self::_getSupportedList();
- }
-
- $enableList = array();
- if(is_array(self::$supported_list))
- {
- foreach(self::$supported_list AS $key => $value)
- {
- if($value->enable)
- {
- $enableList[] = $value;
- }
- }
- }
- return $enableList;
- }
-
- /**
- * returns list of disable in supported dbms list
- * this list return by child class
- * @return array return disable DBMS list in supported dbms list
- */
- public static function getDisableList()
- {
- if(!self::$supported_list)
- {
- $oDB = new DB();
- self::$supported_list = self::_getSupportedList();
- }
-
- $disableList = array();
- if(is_array(self::$supported_list))
- {
- foreach(self::$supported_list AS $key => $value)
- {
- if(!$value->enable)
- {
- $disableList[] = $value;
- }
- }
- }
- return $disableList;
- }
-
- /**
- * returns list of supported dbms list
- *
- * @return array return supported DBMS list
- */
- protected static function _getSupportedList()
- {
- if(self::$supported_list)
- {
- return self::$supported_list;
- }
-
- $get_supported_list = array();
- $db_classes_path = _XE_PATH_ . "classes/db/";
- $filter = "/^DB([^\.]+)\.class\.php/i";
- $supported_list = FileHandler::readDir($db_classes_path, $filter, TRUE);
-
- // after creating instance of class, check is supported
- foreach ($supported_list as $db_type)
- {
- if (strtolower($db_type) !== 'mysql')
- {
- continue;
- }
- $class_name = sprintf("DB%s%s", strtoupper(substr($db_type, 0, 1)), strtolower(substr($db_type, 1)));
- $class_file = sprintf(_XE_PATH_ . "classes/db/%s.class.php", $class_name);
- if (!file_exists($class_file))
- {
- continue;
- }
-
- require_once($class_file);
- $oDB = new $class_name();
-
- $obj = new stdClass;
- $obj->db_type = $db_type;
- $obj->enable = $oDB->isSupported() ? TRUE : FALSE;
- unset($oDB);
-
- $get_supported_list[] = $obj;
- }
-
- // sort
- usort($get_supported_list, function($a, $b) {
- $priority_a = isset(self::$priority_dbms[$a->db_type]) ? self::$priority_dbms[$a->db_type] : 0;
- $priority_b = isset(self::$priority_dbms[$b->db_type]) ? self::$priority_dbms[$b->db_type] : 0;
- return $a - $b;
- });
-
- return self::$supported_list = $get_supported_list;
- }
-
- /**
- * Return dbms supportable status
- * The value is set in the child class
- * @return boolean true: is supported, false: is not supported
- */
- public function isSupported()
- {
- return self::$isSupported;
- }
-
- /**
- * Return connected status
- * @param string $type master or slave
- * @param int $indx key of server list
- * @return boolean true: connected, false: not connected
- */
- public function isConnected($type = 'master', $indx = 0)
- {
- if($type == 'master')
- {
- return $this->master_db["is_connected"] ? TRUE : FALSE;
- }
- else
- {
- return $this->slave_db[$indx]["is_connected"] ? TRUE : FALSE;
- }
- }
-
- /**
- * start recording log
- * @param string $query query string
- * @return void
- */
- public function actStart($query)
- {
- $this->setError(0, 'success');
- $this->query = $query;
- $this->act_start = microtime(true);
- $this->elapsed_time = 0;
- }
-
- /**
- * finish recording log
- * @return void
- */
- public function actFinish()
- {
- if(!$this->query)
- {
- return;
- }
- $this->act_finish = microtime(true);
- $elapsed_time = $this->act_finish - $this->act_start;
- $this->elapsed_time = $elapsed_time;
- $GLOBALS['__db_elapsed_time__'] += $elapsed_time;
-
- $site_module_info = Context::get('site_module_info');
- $log = array();
- $log['query'] = $this->query;
- $log['elapsed_time'] = $elapsed_time;
- $log['connection'] = $this->connection;
- $log['query_id'] = $this->query_id;
- $log['module'] = $site_module_info->module;
- $log['act'] = Context::get('act');
- $log['time'] = date('Y-m-d H:i:s');
- $log['backtrace'] = array();
-
- if (config('debug.enabled') && ($this->isError() || in_array('queries', config('debug.display_content') ?: array())))
- {
- $bt = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
- foreach($bt as $no => $call)
- {
- if($call['function'] == 'executeQuery' || $call['function'] == 'executeQueryArray')
- {
- $call_no = $no;
- $call_no++;
- $log['called_file'] = $bt[$call_no]['file'];
- $log['called_line'] = $bt[$call_no]['line'];
- $call_no++;
- $log['called_method'] = $bt[$call_no]['class'].$bt[$call_no]['type'].$bt[$call_no]['function'];
- $log['backtrace'] = array_slice($bt, $call_no, 1);
- break;
- }
- }
- }
- else
- {
- $log['called_file'] = $log['called_line'] = $log['called_method'] = null;
- $log['backtrace'] = array();
- }
-
- // leave error log if an error occured
- if($this->isError())
- {
- $log['result'] = 'error';
- $log['errno'] = $this->errno;
- $log['errstr'] = $this->errstr;
- }
- else
- {
- $log['result'] = 'success';
- $log['errno'] = null;
- $log['errstr'] = null;
- }
-
- $this->setQueryLog($log);
- }
-
- /**
- * set query debug log
- * @param array $log values set query debug
- * @return void
- */
- public function setQueryLog($log)
- {
- Rhymix\Framework\Debug::addQuery($log);
- }
-
- /**
- * set error
- * @param int $errno error code
- * @param string $errstr error message
- * @return void
- */
- public function setError($errno = 0, $errstr = 'success')
- {
- $this->errno = $errno;
- $this->errstr = $errstr;
- }
-
- /**
- * Return error status
- * @return boolean true: error, false: no error
- */
- public function isError()
- {
- return ($this->errno !== 0);
- }
-
- /**
- * Returns object of error info
- * @return object object of error
- */
- public function getError()
- {
- $this->errstr = Context::convertEncodingStr($this->errstr);
- return new BaseObject($this->errno, $this->errstr);
- }
-
- /**
- * Execute Query that result of the query xml file
- * This function finds xml file or cache file of $query_id, compiles it and then execute it
- * @param string $query_id query id (module.queryname)
- * @param array|object $args arguments for query
- * @param array $arg_columns column list. if you want get specific colums from executed result, add column list to $arg_columns
- * @return object result of query
- */
- public function executeQuery($query_id, $args = NULL, $arg_columns = NULL, $type = NULL)
- {
- static $cache_file = array();
-
- if(!$query_id)
- {
- return new BaseObject(-1, 'msg_invalid_queryid');
- }
- if(!$this->db_type)
- {
- return new BaseObject(-1, 'msg_db_not_setted');
- }
-
- $this->actDBClassStart();
-
- $this->query_id = $query_id;
-
- if(!isset($cache_file[$query_id]) || !file_exists($cache_file[$query_id]))
- {
- $id_args = explode('.', $query_id);
- if(count($id_args) == 2)
- {
- $target = 'modules';
- $module = $id_args[0];
- $id = $id_args[1];
- }
- elseif(count($id_args) == 3)
- {
- $target = $id_args[0];
- $typeList = array('addons' => 1, 'widgets' => 1);
- if(!isset($typeList[$target]))
- {
- $this->actDBClassFinish();
- return new BaseObject(-1, 'msg_invalid_queryid');
- }
- $module = $id_args[1];
- $id = $id_args[2];
- }
- if(!$target || !$module || !$id)
- {
- $this->actDBClassFinish();
- return new BaseObject(-1, 'msg_invalid_queryid');
- }
-
- $xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
- if(!file_exists($xml_file))
- {
- $this->actDBClassFinish();
- return new BaseObject(-1, 'msg_invalid_queryid');
- }
-
- // look for cache file
- $cache_file[$query_id] = $this->checkQueryCacheFile($query_id, $xml_file);
- }
- $result = $this->_executeQuery($cache_file[$query_id], $args, $query_id, $arg_columns, $type);
-
- $this->actDBClassFinish();
- // execute query
- return $result;
- }
-
- /**
- * Look for query cache file
- * @param string $query_id query id for finding
- * @param string $xml_file original xml query file
- * @return string cache file
- */
- public function checkQueryCacheFile($query_id, $xml_file)
- {
- // first try finding cache file
- $cache_file = sprintf('%s%s%s.%s.%s.cache.php', _XE_PATH_, $this->cache_file, $query_id, __ZBXE_VERSION__, $this->db_type);
-
- $cache_time = -1;
- if(file_exists($cache_file))
- {
- $cache_time = filemtime($cache_file);
- }
-
- // if there is no cache file or is not new, find original xml query file and parse it
- if($cache_time < filemtime($xml_file) || $cache_time < filemtime(_XE_PATH_ . 'classes/db/DB.class.php') || $cache_time < filemtime(_XE_PATH_ . 'classes/xml/XmlQueryParser.class.php'))
- {
- $oParser = new XmlQueryParser();
- $oParser->parse($query_id, $xml_file, $cache_file);
- }
-
- return $cache_file;
- }
-
- /**
- * Execute query and return the result
- * @param string $cache_file cache file of query
- * @param array|object $source_args arguments for query
- * @param string $query_id query id
- * @param array $arg_columns column list. if you want get specific colums from executed result, add column list to $arg_columns
- * @return object result of query
- */
- public function _executeQuery($cache_file, $source_args, $query_id, $arg_columns, $type)
- {
- global $lang;
-
- if(!in_array($type, array('master','slave'))) $type = 'slave';
-
- if(!file_exists($cache_file))
- {
- return new BaseObject(-1, 'msg_invalid_queryid');
- }
-
- if (is_object($source_args))
- {
- $args = clone $source_args;
- }
- elseif (is_array($source_args))
- {
- $args = (object)$source_args;
- }
- else
- {
- $args = null;
- }
-
- $output = include($cache_file);
-
- if($output instanceof BaseObject && !$output->toBool())
- {
- return $output;
- }
- if(!is_object($output) || !method_exists($output, 'getAction'))
- {
- return new BaseObject(-1, sprintf(lang('msg_failed_to_load_query'), $query_id));
- }
-
- // execute appropriate query
- switch($output->getAction())
- {
- case 'insert' :
- case 'insert-select' :
- $this->resetCountCache($output->tables);
- $output = $this->_executeInsertAct($output);
- break;
- case 'update' :
- $this->resetCountCache($output->tables);
- $output = $this->_executeUpdateAct($output);
- break;
- case 'delete' :
- $this->resetCountCache($output->tables);
- $output = $this->_executeDeleteAct($output);
- break;
- case 'select' :
- $arg_columns = is_array($arg_columns) ? $arg_columns : array();
- $output->setColumnList($arg_columns);
- $connection = $this->_getConnection($type);
- $output = $this->_executeSelectAct($output, $connection);
- break;
- }
-
- if($this->isError())
- {
- $output = $this->getError();
- }
- elseif(!($output instanceof BaseObject))
- {
- $output = new BaseObject();
- }
- $output->add('_query', $this->query);
- $output->add('_elapsed_time', sprintf("%0.5f", $this->elapsed_time));
-
- return $output;
- }
-
- /**
- * Returns counter cache data
- * @param array|string $tables tables to get data
- * @param string $condition condition to get data
- * @return int count of cache data
- */
- public function getCountCache($tables, $condition)
- {
- return FALSE;
- }
-
- /**
- * Save counter cache data
- * @param array|string $tables tables to save data
- * @param string $condition condition to save data
- * @param int $count count of cache data to save
- * @return void
- */
- public function putCountCache($tables, $condition, $count = 0)
- {
- return FALSE;
- }
-
- /**
- * Reset counter cache data
- * @param array|string $tables tables to reset cache data
- * @return boolean true: success, false: failed
- */
- public function resetCountCache($tables)
- {
- return FALSE;
- }
-
- /**
- * Drop tables
- * @param string $table_name
- * @return void
- */
- public function dropTable($table_name)
- {
- if(!$table_name)
- {
- return;
- }
- $query = sprintf("drop table %s%s", $this->prefix, $table_name);
- $this->_query($query);
- }
-
- /**
- * Return select query string
- * @param object $query
- * @param boolean $with_values
- * @return string
- */
- public function getSelectSql($query, $with_values = TRUE)
- {
- $select = $query->getSelectString($with_values);
- if($select == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
- $select = 'SELECT ' . $select;
-
- $from = $query->getFromString($with_values);
- if($from == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
- $from = ' FROM ' . $from;
-
- $where = $query->getWhereString($with_values);
- if($where != '')
- {
- $where = ' WHERE ' . $where;
- }
-
- $tableObjects = $query->getTables();
- $index_hint_list = '';
- /*
- foreach($tableObjects as $tableObject)
- {
- if(is_a($tableObject, 'CubridTableWithHint'))
- {
- $index_hint_list .= $tableObject->getIndexHintString() . ', ';
- }
- }
- $index_hint_list = substr($index_hint_list, 0, -2);
- if($index_hint_list != '')
- {
- $index_hint_list = 'USING INDEX ' . $index_hint_list;
- }
- */
-
- $groupBy = $query->getGroupByString();
- if($groupBy != '')
- {
- $groupBy = ' GROUP BY ' . $groupBy;
- }
-
- $having = $query->getHavingString($with_values);
- if($having != '')
- {
- $having = ' HAVING ' . $having;
- }
-
- $orderBy = $query->getOrderByString();
- if($orderBy != '')
- {
- $orderBy = ' ORDER BY ' . $orderBy;
- }
-
- $limit = $query->getLimitString();
- if($limit != '')
- {
- $limit = ' LIMIT ' . $limit;
- }
-
- return "$select $from $where $index_hint_list $groupBy $having $orderBy $limit";
- }
-
- /**
- * Given a SELECT statement that uses click count
- * returns the corresponding update sql string
- * for databases that don't have click count support built in
- * (aka all besides CUBRID)
- *
- * Function does not check if click count columns exist!
- * You must call $query->usesClickCount() before using this function
- *
- * @param $queryObject
- */
- public function getClickCountQuery($queryObject)
- {
- $new_update_columns = array();
- $click_count_columns = $queryObject->getClickCountColumns();
- foreach($click_count_columns as $click_count_column)
- {
- $click_count_column_name = $click_count_column->column_name;
-
- $increase_by_1 = new Argument($click_count_column_name, null);
- $increase_by_1->setColumnOperation('+');
- $increase_by_1->ensureDefaultValue(1);
-
- $update_expression = new UpdateExpression($click_count_column_name, $increase_by_1);
- $new_update_columns[] = $update_expression;
- }
- $queryObject->columns = $new_update_columns;
- return $queryObject;
- }
-
- /**
- * Return delete query string
- * @param object $query
- * @param boolean $with_values
- * @param boolean $with_priority
- * @return string
- */
- public function getDeleteSql($query, $with_values = TRUE, $with_priority = FALSE)
- {
- $sql = 'DELETE ';
-
- $sql .= $with_priority ? $query->getPriority() : '';
- $tables = $query->getTables();
-
- $sql .= $tables[0]->getAlias();
-
- $from = $query->getFromString($with_values);
- if($from == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
- $sql .= ' FROM ' . $from;
-
- $where = $query->getWhereString($with_values);
- if($where != '')
- {
- $sql .= ' WHERE ' . $where;
- }
-
- return $sql;
- }
-
- /**
- * Return update query string
- * @param object $query
- * @param boolean $with_values
- * @param boolean $with_priority
- * @return string
- */
- public function getUpdateSql($query, $with_values = TRUE, $with_priority = FALSE)
- {
- $columnsList = $query->getUpdateString($with_values);
- if($columnsList == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
-
- $tables = $query->getFromString($with_values);
- if($tables == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
-
- $where = $query->getWhereString($with_values);
- if($where != '')
- {
- $where = ' WHERE ' . $where;
- }
-
- $priority = $with_priority ? $query->getPriority() : '';
-
- return "UPDATE $priority $tables SET $columnsList " . $where;
- }
-
- /**
- * Return insert query string
- * @param object $query
- * @param boolean $with_values
- * @param boolean $with_priority
- * @return string
- */
- public function getInsertSql($query, $with_values = TRUE, $with_priority = FALSE)
- {
- $tableName = $query->getFirstTableName();
- $values = $query->getInsertString($with_values);
- $priority = $with_priority ? $query->getPriority() : '';
-
- return "INSERT $priority INTO $tableName \n $values";
- }
-
- /**
- * Return index from slave server list
- * @return int
- */
- public function _getSlaveConnectionStringIndex()
- {
- $max = count($this->slave_db);
- $indx = rand(0, $max - 1);
- return $indx;
- }
-
- /**
- * Return connection resource
- * @param string $type use 'master' or 'slave'. default value is 'master'
- * @param int $indx if indx value is NULL, return rand number in slave server list
- * @return resource
- */
- public function _getConnection($type = 'master', $indx = NULL)
- {
- if($type == 'master' || $this->transactionNestedLevel)
- {
- if(!$this->master_db['is_connected'])
- {
- $this->_connect($type);
- }
- $this->connection = 'master (' . $this->master_db['host'] . ')';
- return $this->master_db["resource"];
- }
-
- if($indx === NULL)
- {
- $indx = $this->_getSlaveConnectionStringIndex($type);
- }
-
- if($this->slave_db[$indx]['host'] == $this->master_db['host'] && $this->slave_db[$indx]['port'] == $this->master_db['port'])
- {
- if(!$this->master_db['is_connected'])
- {
- $this->_connect($type);
- }
- $this->connection = 'master (' . $this->master_db['host'] . ')';
- return $this->master_db["resource"];
- }
-
- if(!$this->slave_db[$indx]['is_connected'])
- {
- $this->_connect($type, $indx);
- }
- $this->connection = 'slave (' . $this->slave_db[$indx]['host'] . ')';
- return $this->slave_db[$indx]["resource"];
- }
-
- /**
- * check db information exists
- * @return boolean
- */
- public function _dbInfoExists()
- {
- return $this->master_db ? true : false;
- }
-
- /**
- * DB disconnection
- *
- * @param resource $connection
- * @return void
- */
- protected function _close($connection)
- {
-
- }
-
- /**
- * DB disconnection
- * @param string $type 'master' or 'slave'
- * @param int $indx number in slave dbms server list
- * @return void
- */
- public function close($type = 'master', $indx = 0)
- {
- if(!$this->isConnected($type, $indx))
- {
- return;
- }
-
- if($type == 'master')
- {
- $connection = &$this->master_db;
- }
- else
- {
- $connection = &$this->slave_db[$indx];
- }
-
- $this->commit();
- $this->_close($connection["resource"]);
-
- $connection["is_connected"] = FALSE;
- }
-
- /**
- * DB transaction start
- * this method is protected
- * @return boolean
- */
- protected function _begin($transactionLevel = 0)
- {
- return TRUE;
- }
-
- /**
- * DB transaction start
- * @return void
- */
- public function begin()
- {
- if(!$this->isConnected())
- {
- return;
- }
-
- if($this->_begin($this->transactionNestedLevel))
- {
- $this->transaction_started = TRUE;
- $this->transactionNestedLevel++;
- }
- }
-
- /**
- * DB transaction rollback
- * this method is protected
- * @return boolean
- */
- protected function _rollback($transactionLevel = 0)
- {
- return TRUE;
- }
-
- /**
- * DB transaction rollback
- * @return void
- */
- public function rollback()
- {
- if(!$this->isConnected() || !$this->transaction_started)
- {
- return;
- }
- if($this->_rollback($this->transactionNestedLevel))
- {
- $this->transactionNestedLevel--;
-
- if(!$this->transactionNestedLevel)
- {
- $this->transaction_started = FALSE;
- }
- }
- }
-
- /**
- * DB transaction commit
- * this method is protected
- * @return boolean
- */
- protected function _commit()
- {
- return TRUE;
- }
-
- /**
- * DB transaction commit
- * @param boolean $force regardless transaction start status or connect status, forced to commit
- * @return void
- */
- public function commit($force = FALSE)
- {
- if(!$force && (!$this->isConnected() || !$this->transaction_started))
- {
- return;
- }
- if($this->transactionNestedLevel == 1 && $this->_commit())
- {
- $this->transaction_started = FALSE;
- $this->transactionNestedLevel = 0;
- }
- else
- {
- $this->transactionNestedLevel--;
- }
- }
-
- /**
- * Execute the query
- * this method is protected
- * @param string $query
- * @param resource $connection
- * @return void
- */
- protected function __query($query, $connection)
- {
-
- }
-
- /**
- * Execute the query
- *
- * @param string $query
- * @param resource $connection
- * @return resource
- */
- public function _query($query, $connection = NULL)
- {
- if($connection == NULL)
- {
- $connection = $this->_getConnection('master');
- }
- // Notify to start a query execution
- $this->actStart($query);
-
- // Run the query statement
- $result = $this->__query($query, $connection);
-
- // Notify to complete a query execution
- $this->actFinish();
- // Return result
- return $result;
- }
-
- /**
- * DB info settings
- * this method is protected
- * @return void
- */
- protected function _setDBInfo()
- {
- $db_info = config('db');
- $this->master_db = $db_info['master'];
- $this->slave_db = $db_info ? array_values($db_info) : null;
- $this->prefix = $this->master_db['prefix'];
- $this->use_prepared_statements = config('use_prepared_statements');
- }
-
- /**
- * DB Connect
- * this method is protected
- * @param array $connection
- * @return void
- */
- protected function __connect($connection)
- {
-
- }
-
- /**
- * If have a task after connection, add a taks in this method
- * this method is protected
- * @param resource $connection
- * @return void
- */
- protected function _afterConnect($connection)
- {
-
- }
-
- /**
- * DB Connect
- * this method is protected
- * @param string $type 'master' or 'slave'
- * @param int $indx number in slave dbms server list
- * @return void
- */
- protected function _connect($type = 'master', $indx = 0)
- {
- if($this->isConnected($type, $indx))
- {
- return;
- }
-
- // Ignore if no DB information exists
- if(!$this->_dbInfoExists())
- {
- return;
- }
-
- if($type == 'master')
- {
- $connection = &$this->master_db;
- }
- else
- {
- $connection = &$this->slave_db[$indx];
- }
-
- $result = $this->__connect($connection);
- if($result === NULL || $result === FALSE)
- {
- $connection["is_connected"] = FALSE;
- return;
- }
-
- // Check connections
- $connection["resource"] = $result;
- $connection["is_connected"] = TRUE;
-
- // Save connection info for db logs
- $this->connection = $type . ' (' . $connection['host'] . ')';
-
- // regist $this->close callback
- register_shutdown_function(array($this, "close"));
-
- $this->_afterConnect($result);
- }
-
- /**
- * Start recording DBClass log
- * @return void
- */
- public function actDBClassStart()
- {
- $this->setError(0, 'success');
- $this->act_dbclass_start = microtime(true);
- $this->elapsed_dbclass_time = 0;
- }
-
- /**
- * Finish recording DBClass log
- * @return void
- */
- public function actDBClassFinish()
- {
- if(!$this->query)
- {
- return;
- }
- $this->act_dbclass_finish = microtime(true);
- $elapsed_dbclass_time = $this->act_dbclass_finish - $this->act_dbclass_start;
- $this->elapsed_dbclass_time = $elapsed_dbclass_time;
- $GLOBALS['__dbclass_elapsed_time__'] += $elapsed_dbclass_time;
- }
-
- /**
- * Returns a database specific parser instance
- * used for escaping expressions and table/column identifiers
- *
- * Requires an implementation of the DB class (won't work if database is not set)
- * this method is singleton
- *
- * @param boolean $force force load DBParser instance
- * @return DBParser
- */
- public function getParser($force = FALSE)
- {
- static $dbParser = NULL;
- if(!$dbParser || $force)
- {
- $oDB = DB::getInstance();
- $dbParser = $oDB->getParser();
- }
-
- return $dbParser;
- }
-
- /**
- * Get the number of rows affected by the last query
- * @return int
- */
- public function getAffectedRows()
- {
- return -1;
- }
-
- /**
- * Get the ID generated in the last query
- * @return int
- */
- public function getInsertID()
- {
- return 0;
- }
+
}
-/* End of file DB.class.php */
-/* Location: ./classes/db/DB.class.php */
diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php
deleted file mode 100644
index 8729d1135..000000000
--- a/classes/db/DBMysql.class.php
+++ /dev/null
@@ -1,1171 +0,0 @@
- */
-
-/**
- * Merged class for MySQL and MySQLi, with or without InnoDB
- */
-class DBMySQL extends DB
-{
- /**
- * prefix of a tablename (One or more Rhymix can be installed in a single DB)
- * @var string
- */
- var $prefix = 'rx_';
- var $comment_syntax = '/* %s */';
- var $charset = 'utf8mb4';
-
- /**
- * Column type used in MySQL
- *
- * Becasue a common column type in schema/query xml is used for colum_type,
- * it should be replaced properly for each DBMS
- * @var array
- */
- var $column_type = array(
- 'bignumber' => 'bigint',
- 'number' => 'bigint',
- 'varchar' => 'varchar',
- 'char' => 'char',
- 'text' => 'text',
- 'bigtext' => 'longtext',
- 'date' => 'varchar(14)',
- 'float' => 'float',
- );
-
- /**
- * Last statement executed
- */
- var $last_stmt;
-
- /**
- * Query parameters for prepared statement
- */
- var $params = array();
-
- /**
- * Constructor
- * @return void
- */
- function __construct()
- {
- $this->_setDBInfo();
- $this->_connect();
- }
-
- /**
- * DB Connect
- * this method is private
- * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
- * @return mysqli
- */
- protected function __connect($connection)
- {
- // Attempt to connect
- if($connection['port'])
- {
- $mysqli = new mysqli($connection['host'], $connection['user'], $connection['pass'], $connection['database'], $connection['port']);
- }
- else
- {
- $mysqli = new mysqli($connection['host'], $connection['user'], $connection['pass'], $connection['database']);
- }
-
- // Check connection error
- if($mysqli->connect_errno)
- {
- Rhymix\Framework\Debug::displayError(sprintf('DB ERROR %d : %s', $mysqli->connect_errno, $mysqli->connect_error));
- exit;
- }
-
- // Set DB charset
- $this->charset = isset($connection['charset']) ? $connection['charset'] : 'utf8';
- $mysqli->set_charset($this->charset);
-
- return $mysqli;
- }
-
- /**
- * DB disconnection
- * this method is private
- * @param mysqli $connection
- * @return void
- */
- protected function _close($connection)
- {
- if ($connection instanceof mysqli)
- {
- $connection->close();
- }
- }
-
- /**
- * Handles quatation of the string variables from the query
- * @param string $string
- * @return string
- */
- function addQuotes($string)
- {
- if(!is_numeric($string))
- {
- $connection = $this->_getConnection('master');
- $string = $connection->real_escape_string($string);
- }
- return $string;
- }
-
- /**
- * DB transaction start
- * this method is private
- * @return boolean
- */
- protected function _begin($transactionLevel = 0)
- {
- $connection = $this->_getConnection('master');
-
- if(!$transactionLevel)
- {
- $connection->begin_transaction();
- $this->setQueryLog(array('query' => 'START TRANSACTION'));
- }
- else
- {
- $this->_query("SAVEPOINT SP" . $transactionLevel, $connection);
- }
- return true;
- }
-
- /**
- * DB transaction rollback
- * this method is private
- * @return boolean
- */
- protected function _rollback($transactionLevel = 0)
- {
- $connection = $this->_getConnection('master');
- $point = $transactionLevel - 1;
-
- if($point)
- {
- $this->_query("ROLLBACK TO SP" . $point, $connection);
- }
- else
- {
- $connection->rollback();
- $this->setQueryLog(array('query' => 'ROLLBACK'));
- }
- return true;
- }
-
- /**
- * DB transaction commit
- * this method is private
- * @return boolean
- */
- protected function _commit()
- {
- $connection = $this->_getConnection('master');
- $connection->commit();
- $this->setQueryLog(array('query' => 'COMMIT'));
- return true;
- }
-
- /**
- * Execute the query
- * this method is private
- * @param string $query
- * @param resource $connection
- * @return resource
- */
- function __query($query, $connection)
- {
- if (!($connection instanceof mysqli) || $connection->connection_errno)
- {
- $this->setError(-1, 'Unable to connect to DB.');
- return false;
- }
-
- if($this->use_prepared_statements == 'Y')
- {
- // 1. Prepare query
- $stmt = $connection->prepare($query);
- if(!$stmt)
- {
- $this->setError($connection->errno, $connection->error);
- return $this->last_stmt = $result;
- }
-
- // 2. Bind parameters
- if ($this->params)
- {
- $types = '';
- $params = array();
- foreach($this->params as $k => $o)
- {
- $value = $o->getUnescapedValue();
- $type = $o->getType();
-
- // Skip column names -> this should be concatenated to query string
- if($o->isColumnName())
- {
- continue;
- }
-
- switch($type)
- {
- case 'number' :
- $type = 'i';
- break;
- case 'varchar' :
- $type = 's';
- break;
- default:
- $type = 's';
- }
-
- if(is_array($value))
- {
- foreach($value as $v)
- {
- $params[] = $v;
- $types .= $type;
- }
- }
- else
- {
- $params[] = $value;
- $types .= $type;
- }
- }
-
- // 2. Bind parameters
- $args = array();
- $args[0] = $stmt;
- $args[1] = $types;
- $i = 2;
- foreach($params as $key => $param)
- {
- $copy[$key] = $param;
- $args[$i++] = &$copy[$key];
- }
-
- $status = call_user_func_array('mysqli_stmt_bind_param', $args);
- if(!$status)
- {
- $this->setError(-1, "Invalid arguments: " . $connection->error);
- return $this->last_stmt = $stmt;
- }
- }
-
- // 3. Execute query
- $status = $stmt->execute();
- if(!$status)
- {
- $this->setError(-1, "Prepared statement failed: " . $connection->error);
- return $this->last_stmt = $stmt;
- }
-
- // Return stmt for other processing
- return $this->last_stmt = $stmt;
- }
- else
- {
- $result = $connection->query($query);
- if($connection->errno)
- {
- $this->setError($connection->errno, $connection->error);
- }
-
- return $this->last_stmt = $result;
- }
- }
-
- /**
- * Fetch the result
- * @param resource $result
- * @param int|NULL $arrayIndexEndValue
- * @return array
- */
- function _fetch($result, $arrayIndexEndValue = NULL)
- {
- $output = array();
- if(!$this->isConnected() || $this->isError() || !$result)
- {
- return $output;
- }
-
- // No prepared statements
- if($this->use_prepared_statements != 'Y')
- {
- while($tmp = $this->db_fetch_object($result))
- {
- if($arrayIndexEndValue)
- {
- $output[$arrayIndexEndValue--] = $tmp;
- }
- else
- {
- $output[] = $tmp;
- }
- }
- $result->free_result();
- }
-
- // Prepared stements: bind result variable and fetch data
- else
- {
- $stmt = $result;
- $fields = $stmt->result_metadata()->fetch_fields();
- $row = array();
- $resultArray = array();
-
- /**
- * Mysqli has a bug that causes LONGTEXT columns not to get loaded
- * Unless store_result is called before
- * MYSQLI_TYPE for longtext is 252
- */
- $longtext_exists = false;
- foreach($fields as $field)
- {
- // When joined tables are used and the same column name appears twice, we should add it separately, otherwise bind_result fails
- if(isset($resultArray[$field->name]))
- {
- $field->name = 'repeat_' . $field->name;
- }
-
- // Array passed needs to contain references, not values
- $row[$field->name] = '';
- $resultArray[$field->name] = &$row[$field->name];
-
- if($field->type == 252)
- {
- $longtext_exists = true;
- }
- }
- $resultArray = array_merge(array($stmt), $resultArray);
-
- if($longtext_exists)
- {
- $stmt->store_result();
- }
-
- call_user_func_array('mysqli_stmt_bind_result', $resultArray);
- array_shift($resultArray);
-
- while($stmt->fetch())
- {
- $resultObject = new stdClass;
- foreach($resultArray as $key => $value)
- {
- if(strpos($key, 'repeat_'))
- {
- $key = substr($key, 6);
- }
- $resultObject->$key = $value;
- }
-
- if($arrayIndexEndValue)
- {
- $output[$arrayIndexEndValue--] = $resultObject;
- }
- else
- {
- $output[] = $resultObject;
- }
- }
-
- $stmt->free_result();
- $stmt->close();
- }
-
- // Return object if there is only 1 result.
- if(count($output) == 1)
- {
- if(isset($arrayIndexEndValue))
- {
- return $output;
- }
- else
- {
- return $output[0];
- }
- }
- else
- {
- return $output;
- }
- }
-
- /**
- * Return the sequence value incremented by 1
- * Auto_increment column only used in the sequence table
- * @return int
- */
- function getNextSequence()
- {
- $query = sprintf("INSERT INTO `%ssequence` (seq) VALUES ('0')", $this->prefix);
- $this->_query($query);
- $sequence = $this->getInsertID();
- if($sequence % 10000 == 0)
- {
- $query = sprintf("DELETE FROM `%ssequence` WHERE seq < %d", $this->prefix, $sequence);
- $this->_query($query);
- }
-
- return $sequence;
- }
-
- /**
- * Function to obtain mysql old password(mysql only)
- * @param string $password input password
- * @param string $saved_password saved password in DBMS
- * @return boolean
- */
- function isValidOldPassword($password, $saved_password)
- {
- $query = sprintf("SELECT PASSWORD('%s') AS password, OLD_PASSWORD('%s') AS old_password", $this->addQuotes($password), $this->addQuotes($password));
- $result = $this->_query($query);
- $tmp = $this->_fetch($result);
- if($tmp->password === $saved_password || $tmp->old_password === $saved_password)
- {
- return true;
- }
- return false;
- }
-
- /**
- * Check a table exists status
- * @param string $target_name
- * @return boolean
- */
- function isTableExists($target_name)
- {
- $query = sprintf("SHOW TABLES LIKE '%s%s'", $this->prefix, $this->addQuotes($target_name));
- $result = $this->_query($query);
- $tmp = $this->_fetch($result);
- if(!$tmp)
- {
- return false;
- }
- return true;
- }
-
- /**
- * Add a column to the table
- * @param string $table_name table name
- * @param string $column_name column name
- * @param string $type column type, default value is 'number'
- * @param int $size column size
- * @param string|int $default default value
- * @param boolean $notnull not null status, default value is false
- * @return void
- */
- function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false, $after_column = null)
- {
- $type = strtolower($type);
- $type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
- if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
- {
- $size = '';
- }
-
- $query = sprintf("ALTER TABLE `%s%s` ADD `%s` ", $this->prefix, $table_name, $column_name);
- if($size)
- {
- $query .= sprintf(" %s(%s) ", $type, $size);
- }
- else
- {
- $query .= sprintf(" %s ", $type);
- }
- if(isset($default))
- {
- $query .= sprintf(" DEFAULT '%s' ", $default);
- }
- if($notnull)
- {
- $query .= " NOT NULL ";
- }
- if($after_column)
- {
- $query .= sprintf(" AFTER `%s` ", $after_column);
- }
-
- return $this->_query($query);
- }
-
- /**
- * Drop a column from the table
- * @param string $table_name table name
- * @param string $column_name column name
- * @return void
- */
- function dropColumn($table_name, $column_name)
- {
- $query = sprintf("ALTER TABLE `%s%s` DROP `%s` ", $this->prefix, $table_name, $column_name);
- $this->_query($query);
- }
-
- /**
- * Modify a column
- * @param string $table_name table name
- * @param string $column_name column name
- * @param string $type column type, default value is 'number'
- * @param int $size column size
- * @param string|int $default default value
- * @param boolean $notnull not null status, default value is false
- * @return bool
- */
- function modifyColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false)
- {
- $type = strtolower($type);
- $type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
- if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
- {
- $size = '';
- }
-
- $query = sprintf("ALTER TABLE `%s%s` MODIFY `%s` ", $this->prefix, $table_name, $column_name);
- if($size)
- {
- $query .= sprintf(" %s(%s) ", $type, $size);
- }
- else
- {
- $query .= sprintf(" %s ", $type);
- }
- if($default)
- {
- $query .= sprintf(" DEFAULT '%s' ", $default);
- }
- if($notnull)
- {
- $query .= " NOT NULL ";
- }
-
- return $this->_query($query) ? true : false;
- }
-
- /**
- * Check column exist status of the table
- * @param string $table_name table name
- * @param string $column_name column name
- * @return boolean
- */
- function isColumnExists($table_name, $column_name)
- {
- $query = sprintf("SHOW FIELDS FROM `%s%s`", $this->prefix, $table_name);
- $result = $this->_query($query);
- if($this->isError())
- {
- return;
- }
- $output = $this->_fetch($result);
- if($output)
- {
- $column_name = strtolower($column_name);
- foreach($output as $key => $val)
- {
- $name = strtolower($val->Field);
- if($column_name == $name)
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Get information about a column
- * @param string $table_name table name
- * @param string $column_name column name
- * @return BaseObject
- */
- function getColumnInfo($table_name, $column_name)
- {
- $query = sprintf("SHOW FIELDS FROM `%s%s` WHERE `Field` = '%s'", $this->prefix, $table_name, $column_name);
- $result = $this->_query($query);
- if($this->isError())
- {
- return;
- }
- $output = $this->_fetch($result);
- if($output)
- {
- $dbtype = $output->{'Type'};
- if($xetype = array_search($dbtype, $this->column_type))
- {
- $size = null;
- }
- elseif(strpos($dbtype, '(') !== false)
- {
- list($dbtype, $size) = explode('(', $dbtype, 2);
- $size = intval(rtrim($size, ')'));
- if($xetype = array_search($dbtype, $this->column_type))
- {
- // no-op
- }
- else
- {
- $xetype = $dbtype;
- }
- }
- else
- {
- $xetype = $dbtype;
- $size = null;
- }
- return (object)array(
- 'name' => $output->{'Field'},
- 'dbtype' => $dbtype,
- 'xetype' => $xetype,
- 'size' => $size,
- 'default_value' => $output->{'Default'},
- 'notnull' => strncmp($output->{'Null'}, 'NO', 2) == 0 ? true : false,
- );
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Add an index to the table
- * $target_columns = array(col1, col2)
- * $is_unique? unique : none
- * @param string $table_name table name
- * @param string $index_name index name
- * @param string|array $target_columns target column or columns
- * @param boolean $is_unique
- * @return void
- */
- function addIndex($table_name, $index_name, $target_columns, $is_unique = false)
- {
- if(!is_array($target_columns))
- {
- $target_columns = array($target_columns);
- }
-
- $query = sprintf("ALTER TABLE `%s%s` ADD %s INDEX `%s` (%s);", $this->prefix, $table_name, $is_unique ? 'UNIQUE' : '', $index_name, implode(',', $target_columns));
- $this->_query($query);
- }
-
- /**
- * Drop an index from the table
- * @param string $table_name table name
- * @param string $index_name index name
- * @param boolean $is_unique
- * @return void
- */
- function dropIndex($table_name, $index_name, $is_unique = false)
- {
- $query = sprintf("ALTER TABLE `%s%s` DROP INDEX `%s`", $this->prefix, $table_name, $index_name);
- $this->_query($query);
- }
-
- /**
- * Check index status of the table
- * @param string $table_name table name
- * @param string $index_name index name
- * @return boolean
- */
- function isIndexExists($table_name, $index_name)
- {
- $query = sprintf("SHOW INDEXES FROM `%s%s`", $this->prefix, $table_name);
- $result = $this->_query($query);
- if($this->isError())
- {
- return;
- }
- $output = $this->_fetch($result);
- if(!$output)
- {
- return;
- }
- if(!is_array($output))
- {
- $output = array($output);
- }
-
- for($i = 0; $i < count($output); $i++)
- {
- if($output[$i]->Key_name == $index_name)
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Creates a table by using xml contents
- * @param string $xml_doc xml schema contents
- * @return void|object
- */
- function createTableByXml($xml_doc)
- {
- return $this->_createTable($xml_doc);
- }
-
- /**
- * Creates a table by using xml file path
- * @param string $file_name xml schema file path
- * @return void|object
- */
- function createTableByXmlFile($file_name)
- {
- if(!file_exists($file_name))
- {
- return;
- }
- // read xml file
- $buff = FileHandler::readFile($file_name);
- return $this->_createTable($buff);
- }
-
- /**
- * Create table by using the schema xml
- *
- * type : number, varchar, tinytext, text, bigtext, char, date, \n
- * opt : notnull, default, size\n
- * index : primary key, index, unique\n
- * @param string $xml_doc xml schema contents
- * @return void|object
- */
- function _createTable($xml_doc)
- {
- // Get table definition.
- $table = Rhymix\Framework\Parsers\DBTableParser::loadXML('', $xml_doc);
- if (!$table)
- {
- return false;
- }
-
- // Execute the CREATE TABLE query.
- $schema = $table->getCreateQuery($this->prefix, $this->charset, config('db.master.engine'));
- $output = $this->_query($schema);
- return $output ? true : false;
- }
-
- /**
- * Drop table
- *
- * @param string $name
- * @return bool
- */
- function dropTable($table_name)
- {
- // Generate the drop query
- $query = sprintf('DROP TABLE `%s`', $this->addQuotes($this->prefix . $table_name));
-
- // Execute the drop query
- $output = $this->_query($query);
- if($output)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Handles insertAct
- * @param BaseObject $queryObject
- * @param boolean $with_values
- * @return mixed
- */
- function _executeInsertAct($queryObject, $with_values = true)
- {
- if ($this->use_prepared_statements == 'Y')
- {
- $this->params = $queryObject->getArguments();
- $with_values = false;
- }
-
- $query = $this->getInsertSql($queryObject, $with_values, true);
- if ($query instanceof BaseObject)
- {
- $this->params = array();
- return $query;
- }
- else
- {
- $output = $this->_query($query);
- $this->params = array();
- return $output;
- }
- }
-
- /**
- * Handles updateAct
- * @param BaseObject $queryObject
- * @param boolean $with_values
- * @return mixed
- */
- function _executeUpdateAct($queryObject, $with_values = true)
- {
- if ($this->use_prepared_statements == 'Y')
- {
- $this->params = $queryObject->getArguments();
- $with_values = false;
- }
-
- $query = $this->getUpdateSql($queryObject, $with_values, true);
- if ($query instanceof BaseObject)
- {
- $this->params = array();
- return $query;
- }
- else
- {
- $output = $this->_query($query);
- $this->params = array();
- return $output;
- }
- }
-
- /**
- * Handles deleteAct
- * @param BaseObject $queryObject
- * @param boolean $with_values
- * @return mixed
- */
- function _executeDeleteAct($queryObject, $with_values = true)
- {
- if ($this->use_prepared_statements == 'Y')
- {
- $this->params = $queryObject->getArguments();
- $with_values = false;
- }
-
- $query = $this->getDeleteSql($queryObject, $with_values, true);
- if ($query instanceof BaseObject)
- {
- $this->params = array();
- return $query;
- }
- else
- {
- $output = $this->_query($query);
- $this->params = array();
- return $output;
- }
- }
-
- /**
- * Handle selectAct
- * In order to get a list of pages easily when selecting \n
- * it supports a method as navigation
- * @param BaseObject $queryObject
- * @param resource $connection
- * @param boolean $with_values
- * @return BaseObject
- */
- function _executeSelectAct($queryObject, $connection = null, $with_values = true)
- {
- if ($this->use_prepared_statements == 'Y')
- {
- $this->params = $queryObject->getArguments();
- $with_values = false;
- }
-
- $result = null;
- $limit = $queryObject->getLimit();
- if($limit && $limit->isPageHandler())
- {
- $output = $this->queryPageLimit($queryObject, $result, $connection, $with_values);
- $this->params = array();
- return $output;
- }
- else
- {
- $query = $this->getSelectSql($queryObject, $with_values);
- if($query instanceof BaseObject)
- {
- $this->params = array();
- return $query;
- }
-
- $result = $this->_query($query, $connection);
- if($this->isError())
- {
- $this->params = array();
- return $this->queryError($queryObject);
- }
-
- $data = $this->_fetch($result);
- $buff = new BaseObject;
- $buff->data = $data;
-
- if($queryObject->usesClickCount())
- {
- $update_query = $this->getClickCountQuery($queryObject);
- $this->_executeUpdateAct($update_query, $with_values);
- }
-
- $this->params = array();
- return $buff;
- }
- }
-
- /**
- * Get the number of rows affected by the last query
- * @return int
- */
- function getAffectedRows()
- {
- $stmt = $this->last_stmt;
- return $stmt ? $stmt->affected_rows : -1;
- }
-
- /**
- * Get the ID generated in the last query
- * @return int
- */
- function getInsertID()
- {
- $connection = $this->_getConnection('master');
- return $connection->insert_id;
- }
-
- /**
- * @deprecated
- * @return int
- */
- function db_insert_id()
- {
- return $this->getInsertID();
- }
-
- /**
- * Fetch a result row as an object
- * @param resource $result
- * @return BaseObject
- */
- function db_fetch_object($result)
- {
- return $result->fetch_object();
- }
-
- /**
- * Free result memory
- * @param resource $result
- * @return boolean Returns TRUE on success or FALSE on failure.
- */
- function db_free_result($result)
- {
- return $result->free_result();
- }
-
- /**
- * Return the DBParser
- * @param boolean $force
- * @return DBParser
- */
- function getParser($force = FALSE)
- {
- $dbParser = new DBParser('`', '`', $this->prefix);
- return $dbParser;
- }
-
- /**
- * If have a error, return error object
- * @param BaseObject $queryObject
- * @return BaseObject
- */
- function queryError($queryObject)
- {
- $limit = method_exists($queryObject, 'getLimit') ? $queryObject->getLimit() : false;
- if($limit && $limit->isPageHandler())
- {
- $buff = new BaseObject;
- $buff->total_count = 0;
- $buff->total_page = 0;
- $buff->page = 1;
- $buff->data = array();
- $buff->page_navigation = new PageHandler(/* $total_count */0, /* $total_page */1, /* $page */1, /* $page_count */10); //default page handler values
- return $buff;
- }
- else
- {
- return;
- }
- }
-
- /**
- * If select query execute, return page info
- * @param BaseObject $queryObject
- * @param resource $result
- * @param resource $connection
- * @param boolean $with_values
- * @return BaseObject Object with page info containing
- */
- function queryPageLimit($queryObject, $result, $connection, $with_values = true)
- {
- $limit = $queryObject->getLimit();
- // Total count
- $temp_where = $queryObject->getWhereString($with_values, false);
- $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString($with_values), ($temp_where === '' ? '' : ' WHERE ' . $temp_where));
-
- // Check for distinct query and if found update count query structure
- $temp_select = $queryObject->getSelectString($with_values);
- $uses_distinct = stripos($temp_select, "distinct") !== false;
- $uses_groupby = $queryObject->getGroupByString() != '';
- if($uses_distinct || $uses_groupby)
- {
- $count_query = sprintf('select %s %s %s %s'
- , $temp_select == '*' ? '1' : $temp_select
- , 'FROM ' . $queryObject->getFromString($with_values)
- , ($temp_where === '' ? '' : ' WHERE ' . $temp_where)
- , ($uses_groupby ? ' GROUP BY ' . $queryObject->getGroupByString() : '')
- );
-
- // If query uses grouping or distinct, count from original select
- $count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
- }
-
- $result_count = $this->_query($count_query, $connection);
- $count_output = $this->_fetch($result_count);
- $total_count = (int) (isset($count_output->count) ? $count_output->count : NULL);
-
- $list_count = $limit->list_count->getValue();
- if(!$list_count)
- {
- $list_count = 20;
- }
- $page_count = $limit->page_count->getValue();
- if(!$page_count)
- {
- $page_count = 10;
- }
- $page = $limit->page->getValue();
- if(!$page || $page < 1)
- {
- $page = 1;
- }
-
- // total pages
- if($total_count)
- {
- $total_page = (int) (($total_count - 1) / $list_count) + 1;
- }
- else
- {
- $total_page = 1;
- }
-
- // check the page variables
- if($page > $total_page)
- {
- // If requested page is bigger than total number of pages, return empty list
- $buff = new BaseObject;
- $buff->total_count = $total_count;
- $buff->total_page = $total_page;
- $buff->page = $page;
- $buff->data = array();
- $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
- return $buff;
- }
- $start_count = ($page - 1) * $list_count;
-
- $query = $this->getSelectPageSql($queryObject, $with_values, $start_count, $list_count);
-
- $result = $this->_query($query, $connection);
- if($this->isError())
- {
- return $this->queryError($queryObject);
- }
-
- $virtual_no = $total_count - ($page - 1) * $list_count;
- $data = $this->_fetch($result, $virtual_no);
-
- $buff = new BaseObject;
- $buff->total_count = $total_count;
- $buff->total_page = $total_page;
- $buff->page = $page;
- $buff->data = $data;
- $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
- return $buff;
- }
-
- /**
- * If select query execute, return paging sql
- * @param object $query
- * @param boolean $with_values
- * @param int $start_count
- * @param int $list_count
- * @return string select paging sql
- */
- function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0)
- {
- $select = $query->getSelectString($with_values);
- if($select == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
- $select = 'SELECT ' . $select;
-
- $from = $query->getFromString($with_values);
- if($from == '')
- {
- return new BaseObject(-1, "Invalid query");
- }
- $from = ' FROM ' . $from;
-
- $where = $query->getWhereString($with_values);
- if($where != '')
- {
- $where = ' WHERE ' . $where;
- }
-
- $groupBy = $query->getGroupByString();
- if($groupBy != '')
- {
- $groupBy = ' GROUP BY ' . $groupBy;
- }
-
- $orderBy = $query->getOrderByString();
- if($orderBy != '')
- {
- $orderBy = ' ORDER BY ' . $orderBy;
- }
-
- $limit = $query->getLimitString();
- if($limit != '')
- {
- $limit = sprintf(' LIMIT %d, %d', $start_count, $list_count);
- }
-
- return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
- }
-
- /**
- * Find out the best supported character set
- *
- * @return string
- */
- function getBestSupportedCharset()
- {
- if($output = $this->_fetch($this->_query("SHOW CHARACTER SET LIKE 'utf8%'")))
- {
- $mb4_support = false;
- foreach($output as $row)
- {
- if($row->Charset === 'utf8mb4')
- {
- $mb4_support = true;
- }
- }
- return $mb4_support ? 'utf8mb4' : 'utf8';
- }
- else
- {
- return 'utf8';
- }
- }
-}
-
-DBMysql::$isSupported = class_exists('mysqli');
diff --git a/classes/db/queryparts/Query.class.php b/classes/db/queryparts/Query.class.php
deleted file mode 100644
index 968bb2b3e..000000000
--- a/classes/db/queryparts/Query.class.php
+++ /dev/null
@@ -1,749 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/Subquery.class.php b/classes/db/queryparts/Subquery.class.php
deleted file mode 100644
index 2a1390f2f..000000000
--- a/classes/db/queryparts/Subquery.class.php
+++ /dev/null
@@ -1,80 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/condition/Condition.class.php b/classes/db/queryparts/condition/Condition.class.php
deleted file mode 100644
index 908c8fcd8..000000000
--- a/classes/db/queryparts/condition/Condition.class.php
+++ /dev/null
@@ -1,277 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/condition/ConditionGroup.class.php b/classes/db/queryparts/condition/ConditionGroup.class.php
deleted file mode 100644
index 2b6057ed8..000000000
--- a/classes/db/queryparts/condition/ConditionGroup.class.php
+++ /dev/null
@@ -1,133 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/condition/ConditionSubquery.class.php b/classes/db/queryparts/condition/ConditionSubquery.class.php
deleted file mode 100644
index 60c2808d7..000000000
--- a/classes/db/queryparts/condition/ConditionSubquery.class.php
+++ /dev/null
@@ -1,28 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/condition/ConditionWithArgument.class.php b/classes/db/queryparts/condition/ConditionWithArgument.class.php
deleted file mode 100644
index 9f42fd118..000000000
--- a/classes/db/queryparts/condition/ConditionWithArgument.class.php
+++ /dev/null
@@ -1,99 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/condition/ConditionWithoutArgument.class.php b/classes/db/queryparts/condition/ConditionWithoutArgument.class.php
deleted file mode 100644
index 7b489d4a2..000000000
--- a/classes/db/queryparts/condition/ConditionWithoutArgument.class.php
+++ /dev/null
@@ -1,40 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/expression/ClickCountExpression.class.php b/classes/db/queryparts/expression/ClickCountExpression.class.php
deleted file mode 100644
index d91d66ccd..000000000
--- a/classes/db/queryparts/expression/ClickCountExpression.class.php
+++ /dev/null
@@ -1,62 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/DeleteExpression.class.php b/classes/db/queryparts/expression/DeleteExpression.class.php
deleted file mode 100644
index 24e93cf96..000000000
--- a/classes/db/queryparts/expression/DeleteExpression.class.php
+++ /dev/null
@@ -1,63 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/Expression.class.php b/classes/db/queryparts/expression/Expression.class.php
deleted file mode 100644
index 7e29976da..000000000
--- a/classes/db/queryparts/expression/Expression.class.php
+++ /dev/null
@@ -1,56 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/InsertExpression.class.php b/classes/db/queryparts/expression/InsertExpression.class.php
deleted file mode 100644
index fa64b1af2..000000000
--- a/classes/db/queryparts/expression/InsertExpression.class.php
+++ /dev/null
@@ -1,74 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/SelectExpression.class.php b/classes/db/queryparts/expression/SelectExpression.class.php
deleted file mode 100644
index 78ea23408..000000000
--- a/classes/db/queryparts/expression/SelectExpression.class.php
+++ /dev/null
@@ -1,70 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/StarExpression.class.php b/classes/db/queryparts/expression/StarExpression.class.php
deleted file mode 100644
index 3318d9543..000000000
--- a/classes/db/queryparts/expression/StarExpression.class.php
+++ /dev/null
@@ -1,37 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/UpdateExpression.class.php b/classes/db/queryparts/expression/UpdateExpression.class.php
deleted file mode 100644
index ffe8146bf..000000000
--- a/classes/db/queryparts/expression/UpdateExpression.class.php
+++ /dev/null
@@ -1,119 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php b/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php
deleted file mode 100644
index 5c025162e..000000000
--- a/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php
+++ /dev/null
@@ -1,74 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/limit/Limit.class.php b/classes/db/queryparts/limit/Limit.class.php
deleted file mode 100644
index 6d6e851bf..000000000
--- a/classes/db/queryparts/limit/Limit.class.php
+++ /dev/null
@@ -1,101 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/order/OrderByColumn.class.php b/classes/db/queryparts/order/OrderByColumn.class.php
deleted file mode 100644
index 7a6a67e08..000000000
--- a/classes/db/queryparts/order/OrderByColumn.class.php
+++ /dev/null
@@ -1,74 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/table/IndexHint.class.php b/classes/db/queryparts/table/IndexHint.class.php
deleted file mode 100644
index 4b80ecf97..000000000
--- a/classes/db/queryparts/table/IndexHint.class.php
+++ /dev/null
@@ -1,48 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/table/JoinTable.class.php b/classes/db/queryparts/table/JoinTable.class.php
deleted file mode 100644
index 6e882cc28..000000000
--- a/classes/db/queryparts/table/JoinTable.class.php
+++ /dev/null
@@ -1,78 +0,0 @@
- */
-
-/**
- * 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 */
diff --git a/classes/db/queryparts/table/MysqlTableWithHint.class.php b/classes/db/queryparts/table/MysqlTableWithHint.class.php
deleted file mode 100644
index 1642ad7aa..000000000
--- a/classes/db/queryparts/table/MysqlTableWithHint.class.php
+++ /dev/null
@@ -1,83 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/db/queryparts/table/Table.class.php b/classes/db/queryparts/table/Table.class.php
deleted file mode 100644
index 6c0a17c69..000000000
--- a/classes/db/queryparts/table/Table.class.php
+++ /dev/null
@@ -1,59 +0,0 @@
- */
-
-/**
- * @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 */
diff --git a/classes/xml/XmlQueryParser.class.php b/classes/xml/XmlQueryParser.class.php
deleted file mode 100644
index 66284031a..000000000
--- a/classes/xml/XmlQueryParser.class.php
+++ /dev/null
@@ -1,114 +0,0 @@
- */
-
-/**
- * File containing the XE 1.5 XmlQueryParserClass
- */
-if(!defined('__XE_LOADED_XML_CLASS__'))
-{
- define('__XE_LOADED_XML_CLASS__', 1);
-}
-
-/**
- * New XmlQueryParser class
- * Parses XE XML query files
- *
- * @author Corina Udrescu (corina.udrescu@arnia.ro)
- * @package classes\xml
- * @version 0.1
- */
-class XmlQueryParser extends XmlParser
-{
-
- /**
- * constructor
- * @return void
- */
- function __construct()
- {
-
- }
-
- /**
- * Create XmlQueryParser instance for Singleton
- *
- * @return XmlQueryParser object
- */
- function &getInstance()
- {
- static $theInstance = NULL;
- if(!isset($theInstance))
- {
- $theInstance = new XmlQueryParser();
- }
- return $theInstance;
- }
-
- /**
- * Parses an XML query file
- *
- * 1. Read xml file
- * 2. Check the action
- * 3. Parse and write cache file
- *
- * @param $query_id
- * @param $xml_file
- * @param $cache_file
- *
- * @return QueryParser object
- */
- function &parse_xml_query($query_id, $xml_file, $cache_file)
- {
- // Read xml file
- $xml_obj = $this->getXmlFileContent($xml_file);
-
- // insert, update, delete, select action
- $action = strtolower($xml_obj->query->attrs->action);
- if(!$action)
- {
- return;
- }
-
- // Write query cache file
- $parser = new QueryParser($xml_obj->query);
- FileHandler::writeFile($cache_file, $parser->toString());
-
- return $parser;
- }
-
- /**
- * Override for parent "parse" method
- *
- * @param null $query_id
- * @param null $xml_file
- * @param null $cache_file
- *
- * @return void
- */
- function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
- {
- $this->parse_xml_query($query_id, $xml_file, $cache_file);
- }
-
- /**
- * Returns XML file contents as an object
- * or NULL in case of error
- *
- * @param $xml_file
- * @return array|NULL
- */
- function getXmlFileContent($xml_file)
- {
- $buff = FileHandler::readFile($xml_file);
- $xml_obj = parent::parse($buff);
- if(!$xml_obj)
- {
- return;
- }
- unset($buff);
- return $xml_obj;
- }
-
-}
-/* End of file XmlQueryParser.class.php */
-/* Location: ./classes/xml/XmlQueryParser.class.php */
diff --git a/classes/xml/xmlquery/DBParser.class.php b/classes/xml/xmlquery/DBParser.class.php
deleted file mode 100644
index 0fd4d46ee..000000000
--- a/classes/xml/xmlquery/DBParser.class.php
+++ /dev/null
@@ -1,333 +0,0 @@
- */
-
-/**
- * File containing the DBParser class
- */
-
-/**
- * Escapes query statements:
- * - column names: member.member_srl => "member"."member_srl"
- * - expressions: SUM(member.member_srl) => SUM("member"."member_srl")
- *
- * @author Corina Udrescu (corina.udrescu@arnia.ro)
- * @package classes\xml\xmlquery
- * @version 0.1
- */
-class DBParser
-{
-
- /**
- * Character for escape target value on the left
- *
- * For example, in CUBRID left and right escape
- * chars are the same, the double quote - "
- * But for SQL Server, the escape is made with
- * [double brackets], so the left and right char differ
- *
- *
- * @var string
- */
- var $escape_char_left;
-
- /**
- * Character for escape target value on the right
- *
- * For example, in CUBRID left and right escape
- * chars are the same, the double quote - "
- * But for SQL Server, the escape is made with
- * [double brackets], so the left and right char differ
- *
- * @var string
- */
- var $escape_char_right;
-
- /**
- * Table prefix string
- *
- * Default is "xe_"
- *
- * @var string
- */
- var $table_prefix;
-
- /**
- * Constructor
- *
- * @param string $escape_char_left
- * @param string $escape_char_right
- * @param string $table_prefix
- *
- * @return void
- */
- function __construct($escape_char_left, $escape_char_right = "", $table_prefix = "xe_")
- {
- $this->escape_char_left = $escape_char_left;
- if($escape_char_right !== "")
- {
- $this->escape_char_right = $escape_char_right;
- }
- else
- {
- $this->escape_char_right = $escape_char_left;
- }
- $this->table_prefix = $table_prefix;
- }
-
- /**
- * Get escape character
- *
- * @param string $leftOrRight left or right
- * @return string
- */
- function getEscapeChar($leftOrRight)
- {
- if($leftOrRight === 'left')
- {
- return $this->escape_char_left;
- }
- else
- {
- return $this->escape_char_right;
- }
- }
-
- /**
- * Escape the value
- *
- * @param mixed $name
- * @return string
- */
- function escape($name)
- {
- return $this->escape_char_left . $name . $this->escape_char_right;
- }
-
- /**
- * Escape the string value
- *
- * @param string $name
- * @return string
- */
- function escapeString($name)
- {
- return "'" . $this->escapeStringValue($name) . "'";
- }
-
- /**
- * Escape the string value
- *
- * @param string $value
- * @return string
- */
- function escapeStringValue($value)
- {
- if($value == "*")
- {
- return $value;
- }
- if(is_string($value))
- {
- return $value = str_replace("'", "''", $value);
- }
- return $value;
- }
-
- /**
- * Return table full name
- *
- * @param string $name table name without table prefix
- *
- * @return string table full name with table prefix
- */
- function parseTableName($name)
- {
- return $this->table_prefix . $name;
- }
-
- /**
- * Return column name after escape
- *
- * @param string $name column name before escape
- *
- * @return string column name after escape
- */
- function parseColumnName($name)
- {
- return $this->escapeColumn($name);
- }
-
- /**
- * Escape column name
- *
- * @param string $column_name
- * @return string column name with db name
- */
- function escapeColumn($column_name)
- {
- if($this->isUnqualifiedColumnName($column_name))
- {
- return $this->escape($column_name);
- }
- if($this->isQualifiedColumnName($column_name))
- {
- list($table, $column) = explode('.', $column_name);
- // $table can also be an alias, so the prefix should not be added
- return $this->escape($table) . '.' . $this->escape($column);
- //return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
- }
- }
-
- /**
- * Checks to see if a given column name is unqualified
- *
- * Ex: "member_srl" -> unqualified
- * "member"."member_srl" -> qualified
- *
- * @param string $column_name
- * @return bool
- */
- function isUnqualifiedColumnName($column_name)
- {
- if(strpos($column_name, '.') === FALSE && strpos($column_name, '(') === FALSE)
- {
- return TRUE;
- }
- return FALSE;
- }
-
- /**
- * Checks to see if a given column name is qualified
- *
- * Ex: "member_srl" -> unqualified
- * "member"."member_srl" -> qualified
- *
- * @param string $column_name
- * @return bool
- */
- function isQualifiedColumnName($column_name)
- {
- if(strpos($column_name, '.') !== FALSE && strpos($column_name, '(') === FALSE)
- {
- return TRUE;
- }
- return FALSE;
- }
-
- /**
- * Escapes a query expression
- *
- * An expression can be:
- *