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:
- * - * - * @param $column_name - * @return string - */ - function parseExpression($column_name) - { - $functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - foreach($functions as $k => $v) - { - $function = &$functions[$k]; - if(strlen($function) == 1) - { - continue; // skip delimiters - } - $pos = strrpos("(", $function); - $matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - $total_brackets = substr_count($function, "("); - $brackets = 0; - foreach($matches as $i => $j) - { - $match = &$matches[$i]; - if($match == '(') - { - $brackets++; - continue; - } - if(strpos($match, ')') !== FALSE) - { - continue; - } - if(in_array($match, array(',', '.'))) - { - continue; - } - if($brackets == $total_brackets) - { - if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS')) && !preg_match('/^[A-Z]+$/', $match)) - { - $match = $this->escapeColumnExpression($match); - } - } - } - $function = implode('', $matches); - } - return implode('', $functions); - } - - /** - * Checks if a given argument is an asterisk - * - * @param string $column_name - * @return bool - */ - function isStar($column_name) - { - if(substr($column_name, -1) == '*') - { - return TRUE; - } - return FALSE; - } - - /** - * Checks to see if expression is an aggregate star function - * like count(*) - * - * @param string $column_name - * @return bool - */ - function isStarFunction($column_name) - { - if(strpos($column_name, "(*)") !== FALSE) - { - return TRUE; - } - return FALSE; - } - - /** - * Return column name after escape - * @param string $column_name - * @return string - */ - function escapeColumnExpression($column_name) - { - if($this->isStar($column_name)) - { - return $column_name; - } - if($this->isStarFunction($column_name)) - { - return $column_name; - } - if(stripos($column_name, 'distinct') !== FALSE) - { - return $column_name; - } - return $this->escapeColumn($column_name); - } - -} -/* End of file DBParser.class.php */ -/* Location: ./classes/xml/xmlquery/DBParser.class.php */ diff --git a/classes/xml/xmlquery/QueryParser.class.php b/classes/xml/xmlquery/QueryParser.class.php deleted file mode 100644 index 4fe996d1f..000000000 --- a/classes/xml/xmlquery/QueryParser.class.php +++ /dev/null @@ -1,127 +0,0 @@ - */ - -/** - * File containing the QueryParser class - */ - -/** - * Parses an XML Object and returns a string used for generating the PHP cache file
- * The XML Object structure must be the one defined in the XmlParser class - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery - * @version 0.1 - */ -class QueryParser -{ - - /** - * Property containing the associated QueryTag object - * - * @var QueryTag object - */ - var $queryTag; - - /** - * Constructor - * - * @param object $query XML object obtained after reading the XML Query file - * @param bool $isSubQuery - * @return void - */ - function __construct($query = NULL, $isSubQuery = FALSE) - { - if($query) - { - $this->queryTag = new QueryTag($query, $isSubQuery); - } - } - - /** - * Returns table information - * - * Used for finding column type info (string/numeric)
- * Obtains the table info from XE's XML schema files - * - * @param object $query_id - * @param bool $table_name - * @return array - */ - function getTableInfo($query_id, $table_name) - { - $column_type = array(); - $module = ''; - - $id_args = explode('.', $query_id); - if(count($id_args) == 2) - { - $target = 'modules'; - $module = $id_args[0]; - $id = $id_args[1]; - } - else if(count($id_args) == 3) - { - $target = $id_args[0]; - $targetList = array('modules' => 1, 'addons' => 1, 'widgets' => 1); - if(!isset($targetList[$target])) - { - return; - } - $module = $id_args[1]; - $id = $id_args[2]; - } - - // get column properties from the table - $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name); - if(!file_exists($table_file)) - { - $searched_list = FileHandler::readDir(_XE_PATH_ . 'modules'); - $searched_count = count($searched_list); - for($i = 0; $i < $searched_count; $i++) - { - $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name); - if(file_exists($table_file)) - { - break; - } - } - } - - if(file_exists($table_file)) - { - $table_xml = FileHandler::readFile($table_file); - $xml_parser = new XmlParser(); - $table_obj = $xml_parser->parse($table_xml); - if($table_obj->table) - { - if(isset($table_obj->table->column) && !is_array($table_obj->table->column)) - { - $table_obj->table->column = array($table_obj->table->column); - } - - foreach($table_obj->table->column as $k => $v) - { - $column_type[$v->attrs->name] = $v->attrs->type; - } - } - } - - return $column_type; - } - - /** - * Returns the contents for the query cache file - * - * @return string - */ - function toString() - { - return "queryTag->toString() - . 'return $query; ?>'; - } - -} -/* End of file QueryParser.class.php */ -/* Location: ./classes/xml/xmlquery/QueryParser.class.php */ diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php deleted file mode 100644 index b37aa91da..000000000 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ /dev/null @@ -1,396 +0,0 @@ - */ - -/** - * Argument class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/argument - * @version 0.1 - */ -class Argument -{ - - /** - * argument value - * @var mixed - */ - var $value; - - /** - * argument name - * @var string - */ - var $name; - - /** - * argument type - * @var string - */ - var $type; - - /** - * result of argument type check - * @var bool - */ - var $isValid; - - /** - * error message - * @var BaseObject - */ - var $errorMessage; - - /** - * column operation - */ - var $column_operation; - - /** - * Check if arg value is user submnitted or default - * @var mixed - */ - var $uses_default_value; - - /** - * Caches escaped and toString value so that the parsing won't happen multiple times - * @var mixed - */ - var $_value; // - - /** - * constructor - * @param string $name - * @param mixed $value - * @return void - */ - - function __construct($name, $value) - { - $this->value = $value; - $this->name = $name; - $this->isValid = TRUE; - } - - function getType() - { - if(isset($this->type)) - { - return $this->type; - } - if(is_string($this->value)) - { - return 'column_name'; - } - - return 'number'; - } - - function setColumnType($value) - { - $this->type = $value; - } - - function setColumnOperation($operation) - { - $this->column_operation = $operation; - } - - function getName() - { - return $this->name; - } - - function getValue() - { - if(!isset($this->_value)) - { - $value = $this->getEscapedValue(); - $this->_value = $this->toString($value); - } - return $this->_value; - } - - function getPureValue() - { - return $this->value; - } - - function getColumnOperation() - { - return $this->column_operation; - } - - function getEscapedValue() - { - return $this->escapeValue($this->value); - } - - function getUnescapedValue() - { - if($this->value === 'null') - { - return null; - } - return $this->value; - } - - /** - * mixed value to string - * @param mixed $value - * @return string - */ - function toString($value) - { - if(is_array($value)) - { - if(count($value) === 0) - { - return ''; - } - if(count($value) === 1 && $value[0] === '') - { - return ''; - } - return '(' . implode(',', $value) . ')'; - } - return $value; - } - - /** - * escape value - * @param mixed $value - * @return mixed - */ - function escapeValue($value) - { - $column_type = $this->getType(); - if($column_type == 'column_name') - { - $dbParser = DB::getParser(); - return $dbParser->parseExpression($value); - } - if(!isset($value)) - { - return null; - } - - $columnTypeList = array('date' => 1, 'varchar' => 1, 'char' => 1, 'text' => 1, 'bigtext' => 1); - if(isset($columnTypeList[$column_type])) - { - if(!is_array($value)) - { - $value = $this->_escapeStringValue($value); - } - else - { - foreach($value as $key=>$val) - { - $value[$key] = $this->_escapeStringValue($val); - } - } - } - if($this->uses_default_value) - { - return $value; - } - if($column_type == 'number') - { - if(is_array($value)) - { - foreach($value AS $key => $val) - { - if(isset($val) && $val !== '') - { - $value[$key] = (int) $val; - } - } - } - else - { - $value = (int) $value; - } - } - - return $value; - } - - /** - * escape string value - * @param string $value - * @return string - */ - function _escapeStringValue($value) - { - // Remove non-utf8 chars. - $regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x'; - - $value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value); - $db = DB::getInstance(); - $value = $db->addQuotes($value); - return '\'' . $value . '\''; - } - - function utf8Replacer($captures) - { - if(strlen($captures[1])) - { - // Valid byte sequence. Return unmodified. - return $captures[1]; - } - else if(strlen($captures[2])) - { - // Remove user defined area - if("\xF3\xB0\x80\x80" <= $captures[2]) - { - return; - } - - return $captures[2]; - } - else - { - return; - } - } - - function isValid() - { - return $this->isValid; - } - - function isColumnName() - { - $type = $this->getType(); - $value = $this->getUnescapedValue(); - if($type == 'column_name') - { - return TRUE; - } - if($type == 'number' && is_null($value)) - { - return FALSE; - } - if($type == 'number' && !is_numeric($value) && $this->uses_default_value) - { - return TRUE; - } - return FALSE; - } - - function getErrorMessage() - { - return $this->errorMessage; - } - - function ensureDefaultValue($default_value) - { - if($this->value === NULL || $this->value === '') - { - $this->value = $default_value; - $this->uses_default_value = TRUE; - } - } - - /** - * check filter by filter type - * @param string $filter_type - * @return void - */ - function checkFilter($filter_type) - { - if(isset($this->value) && $this->value != '') - { - global $lang; - $val = $this->value; - $key = $this->name; - switch($filter_type) - { - case 'email' : - case 'email_address' : - if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'homepage' : - if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'userid' : - case 'user_id' : - if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'number' : - case 'numbers' : - if(is_array($val)) - { - $val = join(',', $val); - } - if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'alpha' : - if(!preg_match('/^[a-z]+$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'alpha_number' : - if(!preg_match('/^[0-9a-z]+$/is', $val)) - { - $this->isValid = FALSE; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - } - } - } - - function checkMaxLength($length) - { - if($this->value && (strlen($this->value) > $length)) - { - global $lang; - $this->isValid = FALSE; - $key = $this->name; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); - } - } - - function checkMinLength($length) - { - if($this->value && (strlen($this->value) < $length)) - { - global $lang; - $this->isValid = FALSE; - $key = $this->name; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); - } - } - - function checkNotNull() - { - if(!isset($this->value)) - { - global $lang; - $this->isValid = FALSE; - $key = $this->name; - $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key)); - } - } - -} -/* End of file Argument.class.php */ -/* Location: ./classes/xml/xmlquery/argument/Argument.class.php */ diff --git a/classes/xml/xmlquery/argument/ConditionArgument.class.php b/classes/xml/xmlquery/argument/ConditionArgument.class.php deleted file mode 100644 index be97fc097..000000000 --- a/classes/xml/xmlquery/argument/ConditionArgument.class.php +++ /dev/null @@ -1,153 +0,0 @@ - */ - -/** - * ConditionArgument class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/argument - * @version 0.1 - */ -class ConditionArgument extends Argument -{ - - /** - * Operator keyword. for example 'in', 'notint', 'between' - * @var string - */ - var $operation; - - /** - * constructor - * @param string $name - * @param mixed $value - * @param string $operation - * @return void - */ - function __construct($name, $value, $operation) - { - $operationList = array('in' => 1, 'notin' => 1, 'not_in' => 1, 'between' => 1); - if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '') - { - $value = str_replace(' ', '', $value); - $value = str_replace('\'', '', $value); - $value = explode(',', $value); - } - parent::__construct($name, $value); - $this->operation = $operation; - } - - /** - * create condition value. set $this->value - * @return void - */ - function createConditionValue() - { - if(!isset($this->value)) - { - return; - } - - $operation = $this->operation; - $value = $this->value; - - switch($operation) - { - case 'like_prefix' : - if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') - { - $this->value = '^' . str_replace('%', '(.*)', preg_quote($value)); - } - else - { - $this->value = $value . '%'; - } - break; - case 'like_tail' : - if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') - { - $this->value = str_replace('%', '(.*)', preg_quote($value)) . '$'; - } - else - { - $this->value = '%' . $value; - } - break; - case 'like' : - if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') - { - $this->value = str_replace('%', '(.*)', preg_quote($value)); - } - else - { - $this->value = '%' . $value . '%'; - } - break; - case 'notlike' : - $this->value = '%' . $value . '%'; - break; - case 'notlike_prefix' : - $this->value = $value . '%'; - break; - case 'notlike_tail' : - $this->value = '%' . $value; - break; - case 'in': - if(!is_array($value)) - { - $this->value = array($value); - } - break; - case 'notin': - case 'not_in': - if(!is_array($value)) - { - $this->value = array($value); - } - break; - } - } - - /** - * Since ConditionArgument is used in WHERE clause, - * where the argument value is compared to a table column, - * it is assumed that all arguments have type. There are cases though - * where the column does not have any type - if it was removed from - * the XML schema for example - see the is_secret column in xe_documents table. - * In this case, the column type is retrieved according to argument - * value type (using the PHP function is_numeric). - * - * @return type string - */ - function getType() - { - if($this->type) - { - return $this->type; - } - else if(!is_numeric($this->value)) - { - return 'varchar'; - } - else - { - return ''; - } - } - - function setColumnType($column_type) - { - if(!isset($this->value)) - { - return; - } - if($column_type === '') - { - return; - } - - $this->type = $column_type; - } - -} -/* End of file ConditionArgument.class.php */ -/* Location: ./classes/xml/xmlquery/argument/ConditionArgument.class.php */ diff --git a/classes/xml/xmlquery/argument/SortArgument.class.php b/classes/xml/xmlquery/argument/SortArgument.class.php deleted file mode 100644 index a89c56bb5..000000000 --- a/classes/xml/xmlquery/argument/SortArgument.class.php +++ /dev/null @@ -1,20 +0,0 @@ - */ - -/** - * SortArgument class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/argument - * @version 0.1 - */ -class SortArgument extends Argument -{ - - function getValue() - { - return $this->getUnescapedValue(); - } - -} -/* End of file SortArgument.class.php */ -/* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */ diff --git a/classes/xml/xmlquery/queryargument/DefaultValue.class.php b/classes/xml/xmlquery/queryargument/DefaultValue.class.php deleted file mode 100644 index 0e0d53471..000000000 --- a/classes/xml/xmlquery/queryargument/DefaultValue.class.php +++ /dev/null @@ -1,177 +0,0 @@ - */ - -/** - * DefaultValue class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/queryargument - * @version 0.1 - */ -class DefaultValue -{ - - /** - * Column name - * @var string - */ - var $column_name; - - /** - * Value - * @var mixed - */ - var $value; - - /** - * sequnence status - * @var bool - */ - var $is_sequence = FALSE; - - /** - * operation status - * @var bool - */ - var $is_operation = FALSE; - - /** - * operation - * @var string - */ - var $operation = ''; - - /** - * Checks if value is plain string or name of XE function (ipaddress, plus, etc). - * @var bool - */ - var $_is_string = FALSE; - - /** - * Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR]) - * @var bool - */ - var $_is_string_from_function = FALSE; - - /** - * constructor - * @param string $column_name column name - * @param mixed $value value - * @return void - */ - function __construct($column_name, $value) - { - $dbParser = DB::getParser(); - $this->column_name = $dbParser->parseColumnName($column_name); - $this->value = $value; - $this->value = $this->_setValue(); - } - - function isString() - { - return $this->_is_string; - $str_pos = strpos($this->value, '('); - if($str_pos === false) - { - return TRUE; - } - return FALSE; - } - - function isStringFromFunction() - { - return $this->_is_string_from_function; - } - - function isSequence() - { - return $this->is_sequence; - } - - function isOperation() - { - return $this->is_operation; - } - - function getOperation() - { - return $this->operation; - } - - function _setValue() - { - if(!isset($this->value)) - { - return; - } - - // If value contains comma separated values and does not contain paranthesis - // -> default value is an array - if(strpos($this->value, ',') !== FALSE && strpos($this->value, '(') === FALSE) - { - return sprintf('array(%s)', $this->value); - } - - $str_pos = strpos($this->value, '('); - // // TODO Replace this with parseExpression - if($str_pos === FALSE) - { - $this->_is_string = TRUE; - return '\'' . $this->value . '\''; - } - //if($str_pos===false) return $this->value; - - $func_name = substr($this->value, 0, $str_pos); - $args = substr($this->value, $str_pos + 1, -1); - - switch($func_name) - { - case 'ipaddress' : - $val = '\\RX_CLIENT_IP'; - $this->_is_string_from_function = TRUE; - break; - case 'unixtime' : - $val = '\\RX_TIME'; - $this->_is_string_from_function = TRUE; - break; - case 'curdate' : - $val = 'getInternalDateTime()'; - $this->_is_string_from_function = TRUE; - break; - case 'sequence' : - $this->is_sequence = TRUE; - $val = '$sequence'; - break; - case 'plus' : - $args = abs($args); - $this->is_operation = TRUE; - $this->operation = '+'; - $val = sprintf('%d', $args); - break; - case 'minus' : - $args = abs($args); - $this->is_operation = TRUE; - $this->operation = '-'; - $val = sprintf('%d', $args); - break; - case 'multiply' : - $args = intval($args); - $this->is_operation = TRUE; - $this->operation = '*'; - $val = sprintf('%d', $args); - break; - default : - $val = '\'' . $this->value . '\''; - //$val = $this->value; - } - - return $val; - } - - function toString() - { - return $this->value; - } - -} -/* End of file DefaultValue.class.php */ -/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ diff --git a/classes/xml/xmlquery/queryargument/QueryArgument.class.php b/classes/xml/xmlquery/queryargument/QueryArgument.class.php deleted file mode 100644 index 7e97975b6..000000000 --- a/classes/xml/xmlquery/queryargument/QueryArgument.class.php +++ /dev/null @@ -1,191 +0,0 @@ - */ - -/** - * QueryArgument class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/queryargument - * @version 0.1 - */ -class QueryArgument -{ - - /** - * Argument name - * @var string - */ - var $argument_name; - - /** - * Variable name - * @var string - */ - var $variable_name; - - /** - * Argument validator - * @var QueryArgumentValidator - */ - var $argument_validator; - - /** - * Column name - * @var string - */ - var $column_name; - - /** - * Table name - * @var string - */ - var $table_name; - - /** - * Operation - * @var string - */ - var $operation; - - /** - * Ignore value - * @var bool - */ - var $ignore_value; - - /** - * constructor - * @param object $tag tag object - * @param bool $ignore_value - * @return void - */ - function __construct($tag, $ignore_value = FALSE) - { - static $number_of_arguments = 0; - - $this->argument_name = $tag->attrs->var; - if(!$this->argument_name) - { - $this->argument_name = str_replace('.', '_', $tag->attrs->name); - } - if(!$this->argument_name) - { - $this->argument_name = str_replace('.', '_', $tag->attrs->column); - } - - $this->variable_name = $this->argument_name; - - $number_of_arguments++; - $this->argument_name .= $number_of_arguments; - - $name = $tag->attrs->name; - if(!$name) - { - $name = $tag->attrs->column; - } - if(strpos($name, '.') === FALSE) - { - $this->column_name = $name; - } - else - { - list($prefix, $name) = explode('.', $name); - $this->column_name = $name; - $this->table_name = $prefix; - } - - if($tag->attrs->operation) - { - $this->operation = $tag->attrs->operation; - } - - $this->argument_validator = new QueryArgumentValidator($tag, $this); - $this->ignore_value = $ignore_value; - } - - function getArgumentName() - { - return $this->argument_name; - } - - function getColumnName() - { - return $this->column_name; - } - - function getTableName() - { - return $this->table_name; - } - - function getValidatorString() - { - return $this->argument_validator->toString(); - } - - function isConditionArgument() - { - if($this->operation) - { - return TRUE; - } - return FALSE; - } - - /** - * Change QueryArgument object to string - * @return string - */ - function toString() - { - if($this->isConditionArgument()) - { - // Instantiation - $arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n" - , $this->argument_name - , $this->variable_name - , '$args->' . $this->variable_name - , $this->operation - ); - // Call methods to validate argument and ensure default value - $arg .= $this->argument_validator->toString(); - - // Prepare condition string - $arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n" - , $this->argument_name - ); - - // Check that argument passed validation, else return - $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" - , $this->argument_name - , $this->argument_name - ); - } - else - { - $arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n" - , $this->argument_name - , $this->variable_name - , $this->ignore_value ? 'NULL' : '$args->{\'' . $this->variable_name . '\'}'); - - $arg .= $this->argument_validator->toString(); - - $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" - , $this->argument_name - , $this->argument_name - ); - } - - // If the argument is null, skip it - if($this->argument_validator->isIgnorable()) - { - $arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name) - . $arg - . sprintf("} else\n" . '${\'%s_argument\'} = NULL;', $this->argument_name); - } - - return $arg; - } - -} -/* End of file QueryArgument.class.php */ -/* Location: ./classes/xml/xmlquery/queryargument/QueryArgument.class.php */ diff --git a/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php b/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php deleted file mode 100644 index f757c3b9c..000000000 --- a/classes/xml/xmlquery/queryargument/SortQueryArgument.class.php +++ /dev/null @@ -1,34 +0,0 @@ - */ - -/** - * SortQueryArgument class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/queryargument - * @version 0.1 - */ -class SortQueryArgument extends QueryArgument -{ - - /** - * Change SortQueryArgument object to string - * @return string - */ - function toString() - { - $arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n" - , $this->argument_name - , $this->argument_name - , '$args->' . $this->variable_name); - $arg .= $this->argument_validator->toString(); - - $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" - , $this->argument_name - , $this->argument_name - ); - return $arg; - } - -} -/* End of file DefaultValue.class.php */ -/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ diff --git a/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php b/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php deleted file mode 100644 index 2bcfbe1b9..000000000 --- a/classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php +++ /dev/null @@ -1,135 +0,0 @@ - */ - -/** - * QueryArgumentValidator class - * @author NAVER (developers@xpressengine.com) - * @package /classes/xml/xmlquery/queryargument/validator - * @version 0.1 - */ -class QueryArgumentValidator -{ - - /** - * Argument name - * @var string - */ - var $argument_name; - - /** - * Default value - * @var string - */ - var $default_value; - - /** - * Notnull status setting, if value should be not null, this value is 'notnull' - * @var string - */ - var $notnull; - - /** - * Filter for value type, for example number - * @var string - */ - var $filter; - - /** - * Minimum length for value - * @var int - */ - var $min_length; - - /** - * Maximum length for value - * @var int - */ - var $max_length; - var $validator_string; - - /** - * Query argument for validate - * @var QueryArgument object - */ - var $argument; - - /** - * constructor - * @param Xml_Node_ $tag tag object by Query xml file parse - * @param QueryArgument $argument - * @return void - */ - function __construct($tag, $argument) - { - $this->argument = $argument; - $this->argument_name = $this->argument->getArgumentName(); - - $this->default_value = $tag->attrs->default; - $this->notnull = $tag->attrs->notnull; - $this->filter = $tag->attrs->filter; - $this->min_length = $tag->attrs->min_length; - $this->max_length = $tag->attrs->max_length; - } - - function isIgnorable() - { - if(isset($this->default_value) || isset($this->notnull)) - { - return FALSE; - } - return TRUE; - } - - function toString() - { - $validator = ''; - if($this->filter) - { - $validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n" - , $this->argument_name - , $this->filter - ); - } - if($this->min_length) - { - $validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n" - , $this->argument_name - , $this->min_length - ); - } - if($this->max_length) - { - $validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);' . "\n" - , $this->argument_name - , $this->max_length - ); - } - if(isset($this->default_value)) - { - $this->default_value = new DefaultValue($this->argument_name, $this->default_value); - if($this->default_value->isSequence()) - $validator .= '$db = DB::getInstance(); $sequence = $db->getNextSequence(); '; - if($this->default_value->isOperation()) - { - $validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n" - , $this->argument_name - , $this->default_value->getOperation() - ); - } - $validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n" - , $this->argument_name - , $this->default_value->toString() - ); - } - if($this->notnull) - { - $validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n" - , $this->argument_name - ); - } - return $validator; - } - -} -/* End of file QueryArgumentValidator.class.php */ -/* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */ diff --git a/classes/xml/xmlquery/tags/column/ColumnTag.class.php b/classes/xml/xmlquery/tags/column/ColumnTag.class.php deleted file mode 100644 index 4ed4ae34d..000000000 --- a/classes/xml/xmlquery/tags/column/ColumnTag.class.php +++ /dev/null @@ -1,35 +0,0 @@ - */ - -/** - * Models the <column> tag inside an XML Query file
- * Since the <column> tag supports different attributes depending on - * the type of query (select, update, insert, delete) this is only - * the base class for the classes that will model each type tag. - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class ColumnTag -{ - - /** - * Column name - * @var string - */ - var $name; - - /** - * Constructor - * @param string $name - * @return void - */ - function __construct($name) - { - $this->name = $name; - } - -} -/* End of file ColumnTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php b/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php deleted file mode 100644 index d8c412b8d..000000000 --- a/classes/xml/xmlquery/tags/column/InsertColumnTag.class.php +++ /dev/null @@ -1,62 +0,0 @@ - */ - -/** - * Models the <column> tag inside an XML Query file whose action is 'insert' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class InsertColumnTag extends ColumnTag -{ - - /** - * Argument - * - * @var QueryArgument object - */ - var $argument; - - /** - * Constructor - * - * @param object $column - * - * @return void - */ - function __construct($column) - { - parent::__construct($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - $this->argument = new QueryArgument($column); - } - - /** - * Returns the string to be output in the cache file - * used for instantiating an InsertExpression when a - * query is executed - * - * @return string - */ - function getExpressionString() - { - return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})' - , $this->name - , $this->argument->argument_name); - } - - /** - * Returns the QueryArgument object associated with this INSERT statement - * - * @return QueryArgument - */ - function getArgument() - { - return $this->argument; - } - -} -/* End of file InsertColumnTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php b/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php deleted file mode 100644 index f5cf226d4..000000000 --- a/classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php +++ /dev/null @@ -1,49 +0,0 @@ - */ - -/** - * Models the <column> tag inside an XML Query file whose action is 'insert-select' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class InsertColumnTagWithoutArgument extends ColumnTag -{ - - /** - * Constructor - * - * @param object $column - * @return void - */ - function __construct($column) - { - parent::__construct($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - } - - /** - * Returns the string to be output in the cache file - * - * @return string - */ - function getExpressionString() - { - return sprintf('new Expression(\'%s\')', $this->name); - } - - /** - * Returns the QueryArgument object associated with this INSERT statement - * - * @return null - */ - function getArgument() - { - return NULL; - } - -} -/* End of file InsertColumnTagWithoutArgument.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php */ diff --git a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php b/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php deleted file mode 100644 index 91c2f997e..000000000 --- a/classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php +++ /dev/null @@ -1,92 +0,0 @@ - */ - -/** - * Models the <columns> tag inside an XML Query file whose action is 'insert' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class InsertColumnsTag -{ - - /** - * Column list - * - * @var array value is InsertColumnTag object - */ - var $columns; - - /** - * Constructor - * - * @param array|string $xml_columns - * @return void - */ - function __construct($xml_columns) - { - $this->columns = array(); - - if(!$xml_columns) - { - return; - } - - if(!is_array($xml_columns)) - { - $xml_columns = array($xml_columns); - } - - foreach($xml_columns as $column) - { - if($column->name === 'query') - { - $this->columns[] = new QueryTag($column, TRUE); - } - else if(!isset($column->attrs->var) && !isset($column->attrs->default)) - { - $this->columns[] = new InsertColumnTagWithoutArgument($column); - } - else - { - $this->columns[] = new InsertColumnTag($column); - } - } - } - - /** - * InsertColumnTag object to string - * - * @return string - */ - function toString() - { - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column) - { - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; - } - - /** - * Return argument list - * - * @return array - */ - function getArguments() - { - $arguments = array(); - foreach($this->columns as $column) - { - $arguments[] = $column->getArgument(); - } - return $arguments; - } - -} -/* End of file InsertColumnsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php b/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php deleted file mode 100644 index a955d0045..000000000 --- a/classes/xml/xmlquery/tags/column/SelectColumnTag.class.php +++ /dev/null @@ -1,84 +0,0 @@ - */ - -/** - * Models the <column> tag inside an XML Query file whose action is 'select' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class SelectColumnTag extends ColumnTag -{ - - /** - * Column alias - * - * @var string - */ - var $alias; - - /** - * Click count status - * - * @var bool - */ - var $click_count; - - /** - * Constructor - * - * @param string|object $column - * @return void - */ - function __construct($column) - { - if($column == "*" || $column->attrs->name == '*') - { - parent::__construct(NULL); - $this->name = "*"; - } - else - { - parent::__construct($column->attrs->name); - $dbParser = DB::getParser(); - $this->name = $dbParser->parseExpression($this->name); - - $this->alias = $column->attrs->alias; - $this->click_count = $column->attrs->click_count; - } - } - - /** - * Returns the string to be output in the cache file - * - * A select column tag in an XML query can be used for: - * - * - * @return string - */ - function getExpressionString() - { - if($this->name == '*') - { - return "new StarExpression()"; - } - if($this->click_count) - { - return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''", $this->click_count); - } - if(strpos($this->name, '$') === 0) - { - return sprintf('new SelectExpression($args->%s)', substr($this->name, 1)); - } - $dbParser = DB::getParser(); - return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ''); - } - -} -/* End of file SelectColumnTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php b/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php deleted file mode 100644 index 96975041c..000000000 --- a/classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php +++ /dev/null @@ -1,117 +0,0 @@ - */ - -/** - * Models the <columns> tag inside an XML Query file whose action is 'select' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class SelectColumnsTag -{ - - /** - * Column list - * - * @var array value is SelectColumnTag object - */ - var $columns; - - /** - * Constructor - * - * @param $xml_columns_tag - * @internal param \Xml_Node_ $xml_columns - * @return void - */ - function __construct($xml_columns_tag) - { - if(!$xml_columns_tag) - { - $xml_columns_tag = new Xml_Node_(); - } - - $xml_columns = $xml_columns_tag->column; - $xml_queries = $xml_columns_tag->query; - - $this->columns = array(); - - if(!$xml_columns) - { - $this->columns[] = new SelectColumnTag("*"); - return; - } - - if(!is_array($xml_columns)) - { - $xml_columns = array($xml_columns); - } - - foreach($xml_columns as $column) - { - $this->columns[] = new SelectColumnTag($column); - } - - - if(!$xml_queries) - { - return; - } - - if(!is_array($xml_queries)) - { - $xml_queries = array($xml_queries); - } - - foreach($xml_queries as $column) - { - $this->columns[] = new QueryTag($column, TRUE); - } - } - - /** - * Returns the string to be output in the cache file - * - * @return string - */ - function toString() - { - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column) - { - if(is_a($column, 'QueryTag')) - { - $output_columns .= $column->toString() . PHP_EOL . ','; - } - else - { - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; - } - - /** - * Return argument list - * - * @return array - */ - function getArguments() - { - $arguments = array(); - foreach($this->columns as $column) - { - if(is_a($column, 'QueryTag')) - { - $arguments = array_merge($arguments, $column->getArguments()); - } - } - return $arguments; - } - -} -/* End of file SelectColumnsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php b/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php deleted file mode 100644 index 55c390e75..000000000 --- a/classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php +++ /dev/null @@ -1,108 +0,0 @@ - */ - -/** - * Models the <column> tag inside an XML Query file whose action is 'update' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class UpdateColumnTag extends ColumnTag -{ - - /** - * Argument - * - * @var QueryArgument object - */ - var $argument; - - /** - * Default value - * - * @var string - */ - var $default_value; - - /** - * Constructor - * - * @param object $column - * @return void - */ - function __construct($column) - { - parent::__construct($column->attrs->name); - - $dbParser = DB::getParser(); - $this->name = $dbParser->parseColumnName($this->name); - - if($column->attrs->var) - { - $this->argument = new QueryArgument($column); - } - else - { - if(strpos($column->attrs->default, '.') !== FALSE) - { - $this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'"; - } - else - { - $default_value = new DefaultValue($this->name, $column->attrs->default); - if($default_value->isOperation()) - { - $this->argument = new QueryArgument($column, TRUE); - } - //else $this->default_value = $dbParser->parseColumnName($column->attrs->default); - else - { - $this->default_value = $default_value->toString(); - if($default_value->isStringFromFunction()) - { - $this->default_value = '"\'".' . $this->default_value . '."\'"'; - } - if($default_value->isString()) - { - $this->default_value = '"' . $this->default_value . '"'; - } - } - } - } - } - - /** - * Returns the string to be output in the cache file - * - * @return string - */ - function getExpressionString() - { - if($this->argument) - { - return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})' - , $this->name - , $this->argument->argument_name); - } - else - { - return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)' - , $this->name - , $this->default_value); - } - } - - /** - * Returns the Argument associated with this update statement - * - * @return QueryArgument - */ - function getArgument() - { - return $this->argument; - } - -} -/* End of file UpdateColumnTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php */ diff --git a/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php b/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php deleted file mode 100644 index be0fea125..000000000 --- a/classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php +++ /dev/null @@ -1,83 +0,0 @@ - */ - -/** - * Models the <columns> tag inside an XML Query file whose action is 'update' - * - * @author Corina Udrescu (corina.udrescu@arnia.ro) - * @package classes\xml\xmlquery\tags\column - * @version 0.1 - */ -class UpdateColumnsTag -{ - - /** - * Column list - * - * @var array value is UpdateColumnTag object - */ - var $columns; - - /** - * Constructor - * - * @param array|object $xml_columns - * @return void - */ - function __construct($xml_columns) - { - $this->columns = array(); - - if(!is_array($xml_columns)) - { - $xml_columns = array($xml_columns); - } - - foreach($xml_columns as $column) - { - if($column->name === 'query') - { - $this->columns[] = new QueryTag($column, true); - } - else - { - $this->columns[] = new UpdateColumnTag($column); - } - } - } - - /** - * Returns the string to be output in the cache file - * - * @return string - */ - function toString() - { - $output_columns = 'array(' . PHP_EOL; - foreach($this->columns as $column) - { - $output_columns .= $column->getExpressionString() . PHP_EOL . ','; - } - $output_columns = substr($output_columns, 0, -1); - $output_columns .= ')'; - return $output_columns; - } - - /** - * Return argument list - * - * @return array - */ - function getArguments() - { - $arguments = array(); - foreach($this->columns as $column) - { - $arguments[] = $column->getArgument(); - } - return $arguments; - } - -} -/* End of file UpdateColumnsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php deleted file mode 100644 index 8c27d66e3..000000000 --- a/classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php +++ /dev/null @@ -1,99 +0,0 @@ - */ - -/** - * ConditionGroupTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/condition - * @version 0.1 - */ -class ConditionGroupTag -{ - - /** - * condition list - * @var string|array value is ConditionTag object - */ - var $conditions; - - /** - * pipe - * @var string - */ - var $pipe; - - /** - * constructor - * @param string|array $conditions - * @param string $pipe - * @return void - */ - function __construct($conditions, $pipe = 'and') - { - $this->pipe = $pipe; - - if(!is_array($conditions)) - { - $conditions = array($conditions); - } - - foreach($conditions as $condition) - { - if($condition->node_name === 'group') - { - $subconditions = $condition->condition; - $subgroups = $condition->group; - $subconditions = $subconditions ? (is_array($subconditions) ? $subconditions : [$subconditions]) : []; - $subgroups = $subgroups ? (is_array($subgroups) ? $subgroups : [$subgroups]) : []; - $this->conditions[] = new ConditionGroupTag(array_merge($subconditions, $subgroups), $condition->attrs->pipe); - } - else - { - $this->conditions[] = new ConditionTag($condition); - } - } - } - - function getConditions() - { - return $this->conditions; - } - - /** - * ConditionTag object to string - * @return string - */ - function getConditionGroupString() - { - $conditions_string = 'array(' . PHP_EOL; - foreach($this->conditions as $condition) - { - if($condition instanceof ConditionGroupTag) - { - $conditions_string .= $condition->getConditionGroupString() . PHP_EOL . ','; - } - else - { - $conditions_string .= $condition->getConditionString() . PHP_EOL . ','; - } - } - $conditions_string = substr($conditions_string, 0, -2); //remove ',' - $conditions_string .= ')'; - - return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\'' . $this->pipe . '\'' : ''); - } - - function getArguments() - { - $arguments = array(); - foreach($this->conditions as $condition) - { - $arguments = array_merge($arguments, $condition->getArguments()); - } - return $arguments; - } - -} -/* End of file ConditionGroupTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionTag.class.php deleted file mode 100644 index fe4ce7ee1..000000000 --- a/classes/xml/xmlquery/tags/condition/ConditionTag.class.php +++ /dev/null @@ -1,187 +0,0 @@ - */ - -/** - * ConditionTag - * Models the tag inside an XML Query file. Base class. - * - * @author Corina - * @package /classes/xml/xmlquery/tags/condition - * @version 0.1 - */ -class ConditionTag -{ - - /** - * operation for example 'in', 'between', 'not in'... - * @var string - */ - var $operation; - - /** - * Column name - * @var string - */ - var $column_name; - - /** - * Pipe - * @var string - */ - var $pipe; - - /** - * Argument name - * @var string - */ - var $argument_name; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $argument; - - /** - * Default column - * @var string - */ - var $default_column; - - /** - * QueryTag object - * @var QueryTag - */ - var $query; - - /** - * constructor - * @param object $condition - * @return void - */ - function __construct($condition) - { - $this->operation = $condition->attrs->operation; - $this->pipe = $condition->attrs->pipe ?: 'and'; - $dbParser = DB::getParser(); - $this->column_name = $dbParser->parseExpression($condition->attrs->column); - - // If default value is column name, it should be escaped - if($isColumnName = (strpos($condition->attrs->default, '.') !== FALSE - && strpos($condition->attrs->default, '.') !== 0 - && strpos($condition->attrs->default, '%') === FALSE )) - { - $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default); - } - - if($condition->node_name == 'query') - { - $this->query = new QueryTag($condition, TRUE); - $this->default_column = $this->query->toString(); - } - else if($condition->attrs->var && !strpos($condition->attrs->var, '.')) - { - $this->argument = new QueryArgument($condition); - $this->argument_name = $this->argument->getArgumentName(); - } - else - { - if(isset($condition->attrs->default)) - { - $operationList = array('in' => 1, 'between' => 1, 'notin' => 1, 'not_in' => 1); - if(isset($operationList[$this->operation])) - { - $default_value = $condition->attrs->default; - if(strpos($default_value, "'") !== FALSE) - { - $default_value = "\"" . $default_value . "\""; - } - else - { - $default_value = "'" . $default_value . "'"; - } - } - else - { - $default_value_object = new DefaultValue($this->column_name, $condition->attrs->default); - $default_value = $default_value_object->toString(); - - if($default_value_object->isStringFromFunction()) - { - $default_value = '"\'".' . $default_value . '."\'"'; - } - - if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default)) - { - if(strpos($default_value, "'") !== FALSE) - { - $default_value = "\"" . $default_value . "\""; - } - else - { - $default_value = "'" . $default_value . "'"; - } - } - } - $this->default_column = $default_value; - } - else - { - $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'"; - } - } - } - - function setPipe($pipe) - { - $this->pipe = $pipe; - } - - function getArguments() - { - $arguments = array(); - if($this->query) - { - $arguments = array_merge($arguments, $this->query->getArguments()); - } - if($this->argument) - { - $arguments[] = $this->argument; - } - return $arguments; - } - - function getConditionString() - { - if($this->query) - { - return sprintf("new ConditionSubquery('%s',%s,%s%s)" - , $this->column_name - , $this->default_column - , '"' . $this->operation . '"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } - else if(isset($this->default_column)) - { - return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)" - , $this->column_name - , $this->default_column - , '"' . $this->operation . '"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } - else - { - return sprintf("new ConditionWithArgument('%s',%s,%s%s)" - , $this->column_name - , '$' . $this->argument_name . '_argument' - , '"' . $this->operation . '"' - , $this->pipe ? ", '" . $this->pipe . "'" : '' - ); - } - } - -} -/* End of file ConditionTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php b/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php deleted file mode 100644 index 66a172297..000000000 --- a/classes/xml/xmlquery/tags/condition/ConditionsTag.class.php +++ /dev/null @@ -1,102 +0,0 @@ - */ - -/** - * ConditionsTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/condition - * @version 0.1 - */ -class ConditionsTag -{ - - /** - * ConditionGroupTag list - * @var array value is ConditionGroupTag object - */ - var $condition_groups; - - /** - * constructor - * @param object $xml_conditions - * @return void - */ - function __construct($xml_conditions) - { - $this->condition_groups = array(); - if(!$xml_conditions) - { - return; - } - - $xml_condition_list = array(); - if($xml_conditions->condition) - { - $xml_condition_list = $xml_conditions->condition; - } - - if($xml_conditions->query) - { - if(!is_array($xml_condition_list)) - { - $xml_condition_list = array($xml_condition_list); - } - if(!is_array($xml_conditions->query)) - { - $xml_conditions->query = array($xml_conditions->query); - } - $xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query); - } - if($xml_condition_list) - { - $this->condition_groups[] = new ConditionGroupTag($xml_condition_list); - } - - $xml_groups = $xml_conditions->group; - if($xml_groups) - { - if(!is_array($xml_groups)) - { - $xml_groups = array($xml_groups); - } - foreach($xml_groups as $group) - { - $subconditions = $group->condition; - $subgroups = $group->group; - $subconditions = $subconditions ? (is_array($subconditions) ? $subconditions : [$subconditions]) : []; - $subgroups = $subgroups ? (is_array($subgroups) ? $subgroups : [$subgroups]) : []; - $this->condition_groups[] = new ConditionGroupTag(array_merge($subconditions, $subgroups), $group->attrs->pipe); - } - } - } - - /** - * ConditionGroupTag object to string - * @return string - */ - function toString() - { - $output_conditions = 'array(' . PHP_EOL; - foreach($this->condition_groups as $condition) - { - $output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ','; - } - $output_conditions = substr($output_conditions, 0, -1); - $output_conditions .= ')'; - return $output_conditions; - } - - function getArguments() - { - $arguments = array(); - foreach($this->condition_groups as $condition) - { - $arguments = array_merge($arguments, $condition->getArguments()); - } - return $arguments; - } - -} -/* End of file ConditionsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php b/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php deleted file mode 100644 index db6c0c353..000000000 --- a/classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php +++ /dev/null @@ -1,27 +0,0 @@ - */ - -/** - * JoinConditionsTag class - * - * @author Corina - * @package /classes/xml/xmlquery/tags/condition - * @version 0.1 - */ -class JoinConditionsTag extends ConditionsTag -{ - - /** - * constructor - * @param object $xml_conditions - * @return void - */ - function __construct($xml_conditions) - { - parent::__construct($xml_conditions); - $this->condition_groups[0]->conditions[0]->setPipe(""); - } - -} -/* End of file JoinConditionsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/group/GroupsTag.class.php b/classes/xml/xmlquery/tags/group/GroupsTag.class.php deleted file mode 100644 index ab5e70111..000000000 --- a/classes/xml/xmlquery/tags/group/GroupsTag.class.php +++ /dev/null @@ -1,66 +0,0 @@ - */ - -/** - * GroupsTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/group - * @version 0.1 - */ -class GroupsTag -{ - - /** - * column list - * @var array - */ - var $groups; - - /** - * constructor - * @param array|string $xml_groups - * @return void - */ - function __construct($xml_groups) - { - $this->groups = array(); - - if($xml_groups) - { - if(!is_array($xml_groups)) - { - $xml_groups = array($xml_groups); - } - - $dbParser = &DB::getParser(); - for($i = 0; $i < count($xml_groups); $i++) - { - $group = $xml_groups[$i]; - $column = trim($group->attrs->column); - if(!$column) - { - continue; - } - - $column = $dbParser->parseExpression($column); - $this->groups[] = $column; - } - } - } - - function toString() - { - $output = 'array(' . PHP_EOL; - foreach($this->groups as $group) - { - $output .= "'" . $group . "' ,"; - } - $output = substr($output, 0, -1); - $output .= ')'; - return $output; - } - -} -/* End of file GroupsTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/IndexTag.class.php b/classes/xml/xmlquery/tags/navigation/IndexTag.class.php deleted file mode 100644 index fdd0bb39f..000000000 --- a/classes/xml/xmlquery/tags/navigation/IndexTag.class.php +++ /dev/null @@ -1,95 +0,0 @@ - */ - -/** - * IndexTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/navigation - * @version 0.1 - */ -class IndexTag -{ - - /** - * argument name - * @var string - */ - var $argument_name; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $argument; - - /** - * Default value - * @var string - */ - var $default; - - /** - * Sort order - * @var string - */ - var $sort_order; - - /** - * Sort order argument - * @var SortQueryArgument object - */ - var $sort_order_argument; - - /** - * constructor - * @param object $index - * @return void - */ - function __construct($index) - { - $this->argument_name = $index->attrs->var; - - // Sort index - column by which to sort - //$dbParser = new DB(); $dbParser = &$dbParser->getParser(); - //$index->attrs->default = $dbParser->parseExpression($index->attrs->default); - $this->default = $index->attrs->default; - $this->argument = new QueryArgument($index); - - // Sort order - asc / desc - $this->sort_order = $index->attrs->order; - $sortList = array('asc' => 1, 'desc' => 1); - if(!isset($sortList[$this->sort_order])) - { - $arg = new Xml_Node_(); - $arg->attrs = new Xml_Node_(); - $arg->attrs->var = $this->sort_order; - $arg->attrs->default = 'asc'; - $this->sort_order_argument = new SortQueryArgument($arg); - $this->sort_order = '$' . $this->sort_order_argument->getArgumentName() . '_argument'; - } - else - { - $this->sort_order = '"' . $this->sort_order . '"'; - } - } - - function toString() - { - return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order); - } - - function getArguments() - { - $arguments = array(); - $arguments[] = $this->argument; - if($this->sort_order_argument) - { - $arguments[] = $this->sort_order_argument; - } - return $arguments; - } - -} -/* End of file IndexTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/navigation/IndexTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php b/classes/xml/xmlquery/tags/navigation/LimitTag.class.php deleted file mode 100644 index 6bef36a33..000000000 --- a/classes/xml/xmlquery/tags/navigation/LimitTag.class.php +++ /dev/null @@ -1,98 +0,0 @@ - */ - -/** - * LimitTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/navigation - * @version 0.1 - */ -class LimitTag -{ - - /** - * Value is relate to limit query - * @var array - */ - var $arguments; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $page; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $page_count; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $list_count; - - /** - * QueryArgument object - * @var QueryArgument - */ - var $offset; - - /** - * constructor - * @param object $index - * @return void - */ - function __construct($index) - { - if($index->page && $index->page->attrs && $index->page_count && $index->page_count->attrs) - { - if(!isset($index->page->attrs->default)) - $index->page->attrs->default = 1; - if(!isset($index->page_count->attrs->default)) - $index->page_count->attrs->default = 10; - $this->page = new QueryArgument($index->page); - $this->page_count = new QueryArgument($index->page_count); - $this->arguments[] = $this->page; - $this->arguments[] = $this->page_count; - } - - if(!isset($index->list_count->attrs->default)) - $index->list_count->attrs->default = 0; - $this->list_count = new QueryArgument($index->list_count); - $this->arguments[] = $this->list_count; - - if(isset($index->offset) && isset($index->offset->attrs)) - { - $this->offset = new QueryArgument($index->offset); - $this->arguments[] = $this->offset; - } - } - - function toString() - { - if($this->page) - { - return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName()); - } - elseif($this->offset) - { - return sprintf('new Limit(${\'%s_argument\'}, NULL, NULL, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->offset->getArgumentName()); - } - else - { - return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName()); - } - } - - function getArguments() - { - return $this->arguments; - } - -} -/* End of file LimitTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */ diff --git a/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php b/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php deleted file mode 100644 index 50034c984..000000000 --- a/classes/xml/xmlquery/tags/navigation/NavigationTag.class.php +++ /dev/null @@ -1,137 +0,0 @@ - */ - -/** - * NavigationTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/navigation - * @version 0.1 - */ -class NavigationTag -{ - - /** - * Order - * @var array - */ - var $order; - - /** - * List count - * @var int - */ - var $list_count; - - /** - * Page count - * @var int - */ - var $page_count; - - /** - * Page - * @var int - */ - var $page; - - /** - * Limit - * @var LimitTag object - */ - var $limit; - - /** - * constructor - * @param object $xml_navigation - * @return void - */ - function __construct($xml_navigation) - { - $this->order = array(); - if($xml_navigation) - { - $order = $xml_navigation->index; - if($order) - { - if(!is_array($order)) - { - $order = array($order); - } - foreach($order as $order_info) - { - $this->order[] = new IndexTag($order_info); - } - - if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs) - { - $this->limit = new LimitTag($xml_navigation); - } - - if($xml_navigation->list_count) - { - $this->list_count = $xml_navigation->list_count->attrs; - } - - if($xml_navigation->page_count) - { - $this->page_count = $xml_navigation->page_count->attrs; - } - - if($xml_navigation->page) - { - $this->page = $xml_navigation->page->attrs; - } - } - } - } - - /** - * NavigationTag object to string - * @return string - */ - function getOrderByString() - { - $output = 'array(' . PHP_EOL; - foreach($this->order as $order) - { - $output .= $order->toString() . PHP_EOL . ','; - } - $output = substr($output, 0, -1); - $output .= ')'; - return $output; - } - - /** - * LimitTag object to string - * @return string - */ - function getLimitString() - { - if($this->limit) - { - return $this->limit->toString(); - } - else - { - return ""; - } - } - - function getArguments() - { - $arguments = array(); - foreach($this->order as $order) - { - $arguments = array_merge($order->getArguments(), $arguments); - } - if($this->limit) - { - $arguments = array_merge($this->limit->getArguments(), $arguments); - } - return $arguments; - } - -} -/* End of file NavigationTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/navigation/NavigationTag.class.php */ diff --git a/classes/xml/xmlquery/tags/query/QueryTag.class.php b/classes/xml/xmlquery/tags/query/QueryTag.class.php deleted file mode 100644 index 5171a8734..000000000 --- a/classes/xml/xmlquery/tags/query/QueryTag.class.php +++ /dev/null @@ -1,407 +0,0 @@ - */ - -/** - * QueryTag class - * - * @author Arnia Software - * @package /classes/xml/xmlquery/tags/query - * @version 0.1 - */ -class QueryTag -{ - - /** - * Action for example, 'select', 'insert', 'delete'... - * @var string - */ - var $action; - - /** - * Query id - * @var string - */ - var $query_id; - - /** - * Priority - * @var string - */ - var $priority; - - /** - * column type list - * @var array - */ - var $column_type; - - /** - * Query stdClass object - * @var object - */ - var $query; - - /** - * Columns in xml tags - * @var object - */ - var $columns; - - /** - * Tables in xml tags - * @var object - */ - var $tables; - - /** - * Subquery in xml tags - * @var object - */ - var $subquery; - - /** - * Conditions in xml tags - * @var object - */ - var $conditions; - - /** - * Groups in xml tags - * @var object - */ - var $groups; - - /** - * Having in xml tags - * @var object - */ - var $having; - - /** - * Navigation in xml tags - * @var object - */ - var $navigation; - - /** - * Arguments in xml tags - * @var object - */ - var $arguments; - - /** - * PreBuff - * @var string - */ - var $preBuff; - - /** - * Buff - * @var string - */ - var $buff; - - /** - * Subquery status - * @var bool - */ - var $isSubQuery; - - /** - * Join type - * @var string - */ - var $join_type; - - /** - * alias - * @var string - */ - var $alias; - - /** - * constructor - * @param object $query - * @param bool $isSubQuery - * @return void - */ - function __construct($query, $isSubQuery = FALSE) - { - $this->action = $query->attrs->action; - $this->query_id = $query->attrs->id; - $this->priority = $query->attrs->priority; - $this->query = $query; - $this->isSubQuery = $isSubQuery; - if($this->isSubQuery) - { - $this->action = 'select'; - } - if($query->attrs->alias) - { - $dbParser = DB::getParser(); - $this->alias = $dbParser->escape($query->attrs->alias); - } - $this->join_type = $query->attrs->join_type; - - $this->getColumns(); - $tables = $this->getTables(); - $this->setTableColumnTypes($tables); - $this->getSubquery(); // Used for insert-select - $this->getConditions(); - $this->getGroups(); - $this->getNavigation(); - - $this->getPrebuff(); - $this->getBuff(); - } - - function show() - { - return TRUE; - } - - function getQueryId() - { - return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id; - } - - function getPriority() - { - return $this->query->attrs->priority; - } - - function getAction() - { - return $this->query->attrs->action; - } - - function setTableColumnTypes($tables) - { - $query_id = $this->getQueryId(); - if(!isset($this->column_type[$query_id])) - { - $table_tags = $tables->getTables(); - $column_type = array(); - foreach($table_tags as $table_tag) - { - if(is_a($table_tag, 'TableTag')) - { - $table_name = $table_tag->getTableName(); - $table_alias = $table_tag->getTableAlias(); - $tag_column_type = QueryParser::getTableInfo($query_id, $table_name); - $column_type[$table_alias] = $tag_column_type; - } - } - $this->column_type[$query_id] = $column_type; - } - } - - function getColumns() - { - if($this->action == 'select') - { - return $this->columns = new SelectColumnsTag($this->query->columns); - } - else if($this->action == 'insert' || $this->action == 'insert-select') - { - return $this->columns = new InsertColumnsTag($this->query->columns->column); - } - else if($this->action == 'update') - { - return $this->columns = new UpdateColumnsTag($this->query->columns->column); - } - else if($this->action == 'delete') - { - return $this->columns = null; - } - } - - function getPrebuff() - { - if($this->isSubQuery) - { - return; - } - // TODO Check if this work with arguments in join clause - $arguments = $this->getArguments(); - - $prebuff = ''; - foreach($arguments as $argument) - { - if(isset($argument)) - { - $arg_name = $argument->getArgumentName(); - if($arg_name) - { - unset($column_type); - $prebuff .= $argument->toString(); - - $table_alias = $argument->getTableName(); - if(isset($table_alias)) - { - if(isset($this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()])) - { - $column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]; - } - } - else - { - $current_tables = $this->column_type[$this->getQueryId()]; - $column_name = $argument->getColumnName(); - foreach($current_tables as $current_table) - { - if(isset($current_table[$column_name])) - { - $column_type = $current_table[$column_name]; - } - } - } - - if(isset($column_type)) - { - $prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n" - , $arg_name - , $arg_name - , $column_type); - } - } - } - } - $prebuff .= "\n"; - - return $this->preBuff = $prebuff; - } - - function getBuff() - { - $buff = ''; - if($this->isSubQuery) - { - $buff = 'new Subquery('; - $buff .= "'" . $this->alias . '\', '; - $buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL; - $buff .= $this->tables->toString() . ',' . PHP_EOL; - $buff .= $this->conditions->toString() . ',' . PHP_EOL; - $buff .= $this->groups->toString() . ',' . PHP_EOL; - $buff .= $this->navigation->getOrderByString() . ',' . PHP_EOL; - $limit = $this->navigation->getLimitString(); - $buff .= $limit ? $limit : 'null' . PHP_EOL; - $buff .= $this->join_type ? "'" . $this->join_type . "'" : ''; - $buff .= ')'; - - $this->buff = $buff; - return $this->buff; - } - - $buff .= '$query = new Query();' . PHP_EOL; - $buff .= sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n"); - $buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n"); - $buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n"); - $buff .= $this->preBuff; - if($this->columns) - { - $buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL; - } - - $buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL; - if($this->action == 'insert-select') - { - $buff .= '$query->setSubquery(' . $this->subquery->toString() . ');' . PHP_EOL; - } - $buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL; - $buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL; - $buff .= '$query->setHaving(' . $this->having->toString() . ');' . PHP_EOL; - $buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL; - $buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL; - - $this->buff = $buff; - return $this->buff; - } - - function getTables() - { - if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))) - { - return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint); - } - else - { - return $this->tables = new TablesTag($this->query->tables); - } - } - - function getSubquery() - { - if($this->query->query) - { - $this->subquery = new QueryTag($this->query->query, true); - } - } - - function getConditions() - { - return $this->conditions = new ConditionsTag($this->query->conditions); - } - - function getGroups() - { - if($this->query->groups) - { - $this->groups = new GroupsTag($this->query->groups->group); - $this->having = new ConditionsTag($this->query->groups->having); - } - else - { - $this->groups = new GroupsTag(NULL); - $this->having = new ConditionsTag(array()); - } - - return $this->groups; - } - - function getNavigation() - { - return $this->navigation = new NavigationTag($this->query->navigation); - } - - function toString() - { - return $this->buff; - } - - function getTableString() - { - return $this->buff; - } - - function getConditionString() - { - return $this->buff; - } - - function getExpressionString() - { - return $this->buff; - } - - function getArguments() - { - $arguments = array(); - if($this->columns) - { - $arguments = array_merge($arguments, $this->columns->getArguments()); - } - if($this->action == 'insert-select') - { - $arguments = array_merge($arguments, $this->subquery->getArguments()); - } - $arguments = array_merge($arguments, $this->tables->getArguments()); - $arguments = array_merge($arguments, $this->conditions->getArguments()); - $arguments = array_merge($arguments, $this->having->getArguments()); - $arguments = array_merge($arguments, $this->navigation->getArguments()); - return $arguments; - } - -} -/* End of file QueryTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/navigation/QueryTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/HintTableTag.class.php b/classes/xml/xmlquery/tags/table/HintTableTag.class.php deleted file mode 100644 index ac9aea17f..000000000 --- a/classes/xml/xmlquery/tags/table/HintTableTag.class.php +++ /dev/null @@ -1,66 +0,0 @@ - */ - -/** - * HintTableTag - * Models the tag inside an XML Query file and the corresponding tag - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 - */ -class HintTableTag extends TableTag -{ - - /** - * Action for example, 'select', 'insert', 'delete'... - * @var array - */ - var $index; - - /** - * constructor - * Initialises Table Tag properties - * @param object $table XML
tag - * @param array $index - * @return void - */ - function __construct($table, $index) - { - parent::__construct($table); - $this->index = $index; - } - - function getTableString() - { - $dbParser = DB::getParser(); - $dbType = ucfirst(Context::getDBType()); - - $result = sprintf('new %sTableWithHint(\'%s\'%s, array(' - , starts_with('mysql', $dbType, false) ? 'Mysql' : $dbType - , $dbParser->escape($this->name) - , $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ', null' - //, ', \'' . $dbParser->escape($this->index->name) .'\', \'' . $this->index->type .'\'' - ); - foreach($this->index as $indx) - { - $result .= "new IndexHint("; - $result .= '\'' . $dbParser->escape($indx->name) . '\', \'' . $indx->type . '\'' . ') , '; - } - $result = substr($result, 0, -2); - $result .= '))'; - return $result; - } - - function getArguments() - { - if(!isset($this->conditionsTag)) - { - return array(); - } - return $this->conditionsTag->getArguments(); - } - -} -/* End of file HintTableTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/table/HintTableTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/TableTag.class.php b/classes/xml/xmlquery/tags/table/TableTag.class.php deleted file mode 100644 index c171ccc48..000000000 --- a/classes/xml/xmlquery/tags/table/TableTag.class.php +++ /dev/null @@ -1,145 +0,0 @@ - */ - -/** - * TableTag - * Models the
tag inside an XML Query file - * @abstract - * Example - *
- *
- * Attributes - * name - name of the table - table prefix will be automatically added - * alias - table alias. If no value is specified, the table name will be set as default alias - * join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc. - * - permitted values: 'left join','left outer join','right join','right outer join' - * Children - * Can have children of type - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 - */ -class TableTag -{ - - /** - * Unescaped name - * @var string - */ - var $unescaped_name; - - /** - * name - * @var string - */ - var $name; - - /** - * alias - * @var string - */ - var $alias; - - /** - * Join type - * @example 'left join', 'left outer join', 'right join', 'right outer join' - * @var string - */ - var $join_type; - - /** - * Condition object - * @var object - */ - var $conditions; - - /** - * JoinConditionsTag - * @var JoinConditionsTag object - */ - var $conditionsTag; - - /** - * constructor - * Initialises Table Tag properties - * @param object $table XML
tag - * @return void - */ - function __construct($table) - { - $dbParser = DB::getParser(); - - $this->unescaped_name = $table->attrs->name; - $this->name = $dbParser->parseTableName($table->attrs->name); - - $this->alias = $table->attrs->alias; - if(!$this->alias) - { - $this->alias = $table->attrs->name; - } - - $this->join_type = $table->attrs->type; - - $this->conditions = $table->conditions; - - if($this->isJoinTable()) - { - $this->conditionsTag = new JoinConditionsTag($this->conditions); - } - } - - function isJoinTable() - { - $joinList = array('left join' => 1, 'left outer join' => 1, 'right join' => 1, 'right outer join' => 1); - if(isset($joinList[$this->join_type]) && countobj($this->conditions)) - { - return true; - } - return false; - } - - function getTableAlias() - { - return $this->alias; - } - - function getTableName() - { - return $this->unescaped_name; - } - - /** - * Returns string for printing in PHP query cache file - * The string contains code for instantiation of either - * a Table or a JoinTable object - * @return string - */ - function getTableString() - { - $dbParser = DB::getParser(); - - if($this->isJoinTable()) - { - return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)' - , $dbParser->escape($this->name) - , $dbParser->escape($this->alias) - , $this->join_type, $this->conditionsTag->toString()); - } - return sprintf('new Table(\'%s\'%s)' - , $dbParser->escape($this->name) - , $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ''); - } - - function getArguments() - { - if(!isset($this->conditionsTag)) - { - return array(); - } - return $this->conditionsTag->getArguments(); - } - -} -/* End of file TableTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/table/TableTag.class.php */ diff --git a/classes/xml/xmlquery/tags/table/TablesTag.class.php b/classes/xml/xmlquery/tags/table/TablesTag.class.php deleted file mode 100644 index 86e94ea4f..000000000 --- a/classes/xml/xmlquery/tags/table/TablesTag.class.php +++ /dev/null @@ -1,122 +0,0 @@ - */ - -/** - * TablesTag class - * Models the tag inside an XML Query file - * @abstract - * Example - * - *
- * - * Attributes - * None. - * Children - * Can have children of type
or - * - * @author Arnia Sowftare - * @package /classes/xml/xmlquery/tags/table - * @version 0.1 - */ -class TablesTag -{ - - /** - * Table list - * @var array - */ - var $tables; - - /** - * constructor - * @param object $xml_tables_tag - * @param object $xml_index_hints_tag - * @return void - */ - function __construct($xml_tables_tag, $xml_index_hints_tag = NULL) - { - $this->tables = array(); - - $xml_tables = $xml_tables_tag->table; - if(!is_array($xml_tables)) - { - $xml_tables = array($xml_tables); - } - - if($xml_index_hints_tag) - { - $index_nodes = $xml_index_hints_tag->index; - if(!is_array($index_nodes)) - { - $index_nodes = array($index_nodes); - } - foreach($index_nodes as $index_node) - { - if(!isset($indexes[$index_node->attrs->table])) - { - $indexes[$index_node->attrs->table] = array(); - } - $count = count($indexes[$index_node->attrs->table]); - $indexes[$index_node->attrs->table][$count] = (object) NULL; - $indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name; - $indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type; - } - } - - foreach($xml_tables as $tag) - { - if($tag->attrs->query == 'true') - { - $this->tables[] = new QueryTag($tag, true); - } - else - { - if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name]) - { - $this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]); - } - else - { - $this->tables[] = new TableTag($tag); - } - } - } - } - - function getTables() - { - return $this->tables; - } - - function toString() - { - $output_tables = 'array(' . PHP_EOL; - foreach($this->tables as $table) - { - if(is_a($table, 'QueryTag')) - { - $output_tables .= $table->toString() . PHP_EOL . ','; - } - else - { - $output_tables .= $table->getTableString() . PHP_EOL . ','; - } - } - $output_tables = substr($output_tables, 0, -1); - $output_tables .= ')'; - return $output_tables; - } - - function getArguments() - { - $arguments = array(); - foreach($this->tables as $table) - { - $arguments = array_merge($arguments, $table->getArguments()); - } - return $arguments; - } - -} -/* End of file TablesTag.class.php */ -/* Location: ./classes/xml/xmlquery/tags/table/TablesTag.class.php */ diff --git a/common/autoload.php b/common/autoload.php index cbcd870ba..9ab819280 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -49,27 +49,6 @@ $GLOBALS['RX_AUTOLOAD_FILE_MAP'] = array_change_key_case(array( 'CacheHandler' => 'classes/cache/CacheHandler.class.php', 'Context' => 'classes/context/Context.class.php', 'DB' => 'classes/db/DB.class.php', - 'Query' => 'classes/db/queryparts/Query.class.php', - 'Subquery' => 'classes/db/queryparts/Subquery.class.php', - 'Condition' => 'classes/db/queryparts/condition/Condition.class.php', - 'ConditionGroup' => 'classes/db/queryparts/condition/ConditionGroup.class.php', - 'ConditionSubquery' => 'classes/db/queryparts/condition/ConditionSubquery.class.php', - 'ConditionWithArgument' => 'classes/db/queryparts/condition/ConditionWithArgument.class.php', - 'ConditionWithoutArgument' => 'classes/db/queryparts/condition/ConditionWithoutArgument.class.php', - 'ClickCountExpression' => 'classes/db/queryparts/expression/ClickCountExpression.class.php', - 'DeleteExpression' => 'classes/db/queryparts/expression/DeleteExpression.class.php', - 'Expression' => 'classes/db/queryparts/expression/Expression.class.php', - 'InsertExpression' => 'classes/db/queryparts/expression/InsertExpression.class.php', - 'SelectExpression' => 'classes/db/queryparts/expression/SelectExpression.class.php', - 'StarExpression' => 'classes/db/queryparts/expression/StarExpression.class.php', - 'UpdateExpression' => 'classes/db/queryparts/expression/UpdateExpression.class.php', - 'UpdateExpressionWithoutArgument' => 'classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php', - 'Limit' => 'classes/db/queryparts/limit/Limit.class.php', - 'OrderByColumn' => 'classes/db/queryparts/order/OrderByColumn.class.php', - 'IndexHint' => 'classes/db/queryparts/table/IndexHint.class.php', - 'JoinTable' => 'classes/db/queryparts/table/JoinTable.class.php', - 'MysqlTableWithHint' => 'classes/db/queryparts/table/MysqlTableWithHint.class.php', - 'Table' => 'classes/db/queryparts/table/Table.class.php', 'DisplayHandler' => 'classes/display/DisplayHandler.class.php', 'HTMLDisplayHandler' => 'classes/display/HTMLDisplayHandler.php', 'JSCallbackDisplayHandler' => 'classes/display/JSCallbackDisplayHandler.php', @@ -104,36 +83,6 @@ $GLOBALS['RX_AUTOLOAD_FILE_MAP'] = array_change_key_case(array( 'XmlJsFilter' => 'classes/xml/XmlJsFilter.class.php', 'XmlLangParser' => 'classes/xml/XmlLangParser.class.php', 'XmlParser' => 'classes/xml/XmlParser.class.php', - 'XmlQueryParser' => 'classes/xml/XmlQueryParser.class.php', - 'DBParser' => 'classes/xml/xmlquery/DBParser.class.php', - 'QueryParser' => 'classes/xml/xmlquery/QueryParser.class.php', - 'Argument' => 'classes/xml/xmlquery/argument/Argument.class.php', - 'ConditionArgument' => 'classes/xml/xmlquery/argument/ConditionArgument.class.php', - 'SortArgument' => 'classes/xml/xmlquery/argument/SortArgument.class.php', - 'DefaultValue' => 'classes/xml/xmlquery/queryargument/DefaultValue.class.php', - 'QueryArgument' => 'classes/xml/xmlquery/queryargument/QueryArgument.class.php', - 'SortQueryArgument' => 'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php', - 'QueryArgumentValidator' => 'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php', - 'ColumnTag' => 'classes/xml/xmlquery/tags/column/ColumnTag.class.php', - 'InsertColumnTag' => 'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php', - 'InsertColumnTagWithoutArgument' => 'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php', - 'InsertColumnsTag' => 'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php', - 'SelectColumnTag' => 'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php', - 'SelectColumnsTag' => 'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php', - 'UpdateColumnTag' => 'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php', - 'UpdateColumnsTag' => 'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php', - 'ConditionGroupTag' => 'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php', - 'ConditionTag' => 'classes/xml/xmlquery/tags/condition/ConditionTag.class.php', - 'ConditionsTag' => 'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php', - 'JoinConditionsTag' => 'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php', - 'GroupsTag' => 'classes/xml/xmlquery/tags/group/GroupsTag.class.php', - 'IndexTag' => 'classes/xml/xmlquery/tags/navigation/IndexTag.class.php', - 'LimitTag' => 'classes/xml/xmlquery/tags/navigation/LimitTag.class.php', - 'NavigationTag' => 'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php', - 'QueryTag' => 'classes/xml/xmlquery/tags/query/QueryTag.class.php', - 'HintTableTag' => 'classes/xml/xmlquery/tags/table/HintTableTag.class.php', - 'TableTag' => 'classes/xml/xmlquery/tags/table/TableTag.class.php', - 'TablesTag' => 'classes/xml/xmlquery/tags/table/TablesTag.class.php', 'Bmp' => 'common/libraries/bmp.php', 'Ftp' => 'common/libraries/ftp.php', 'Tar' => 'common/libraries/tar.php', diff --git a/common/legacy.php b/common/legacy.php index 2bb87f44b..a3363364e 100644 --- a/common/legacy.php +++ b/common/legacy.php @@ -138,9 +138,9 @@ function getClass($module_name) * @param string[] $arg_columns Column list * @return object Query result data */ -function executeQuery($query_id, $args = NULL, $arg_columns = NULL) +function executeQuery($query_id, $args = [], $arg_columns = NULL) { - $oDB = DB::getInstance(); + $oDB = Rhymix\Framework\DB::getInstance(); return $oDB->executeQuery($query_id, $args, $arg_columns); } @@ -154,9 +154,9 @@ function executeQuery($query_id, $args = NULL, $arg_columns = NULL) * @param string[] $arg_columns Column list * @return object Query result data */ -function executeQueryArray($query_id, $args = NULL, $arg_columns = NULL) +function executeQueryArray($query_id, $args = [], $arg_columns = NULL) { - $oDB = DB::getInstance(); + $oDB = Rhymix\Framework\DB::getInstance(); $output = $oDB->executeQuery($query_id, $args, $arg_columns); if(isset($output->data) && is_object($output->data)) { @@ -173,8 +173,7 @@ function executeQueryArray($query_id, $args = NULL, $arg_columns = NULL) */ function getNextSequence() { - $oDB = DB::getInstance(); - $seq = $oDB->getNextSequence(); + $seq = Rhymix\Framework\DB::getInstance()->getNextSequence(); setUserSequence($seq); return $seq; }