diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index 2c329134b..e905a41ee 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -1,36 +1,37 @@ 5, - 'mysql' => 4, - 'mysql_innodb' => 3, - 'cubrid' => 2, - 'mssql' => 1 - ); + 'mysqli' => 5, + 'mysql' => 4, + 'mysql_innodb' => 3, + 'cubrid' => 2, + 'mssql' => 1 + ); /** * count cache path @@ -70,27 +72,27 @@ class DB * @var array */ var $cond_operation = array( - 'equal' => '=', - 'more' => '>=', - 'excess' => '>', - 'less' => '<=', - 'below' => '<', - 'notequal' => '<>', - 'notnull' => 'is not null', - 'null' => 'is null', - ); + 'equal' => '=', + 'more' => '>=', + 'excess' => '>', + 'less' => '<=', + 'below' => '<', + 'notequal' => '<>', + 'notnull' => 'is not null', + 'null' => 'is null', + ); /** * master database connection string * @var array */ var $master_db = NULL; + /** * array of slave databases connection strings * @var array */ var $slave_db = NULL; - var $result = NULL; /** @@ -98,22 +100,26 @@ class DB * @var int */ var $errno = 0; + /** * error message * @var string */ var $errstr = ''; + /** * query string of latest executed query * @var string */ var $query = ''; var $connection = ''; + /** * elapsed time of latest executed query * @var int */ var $elapsed_time = 0; + /** * elapsed time of latest executed DB class * @var int @@ -125,7 +131,6 @@ class DB * @var boolean */ var $transaction_started = FALSE; - var $is_connected = FALSE; /** @@ -160,15 +165,27 @@ class DB */ function &getInstance($db_type = NULL) { - if(!$db_type) $db_type = Context::getDBType(); - if(!$db_type && Context::isInstalled()) return new Object(-1, 'msg_db_not_setted'); + if(!$db_type) + { + $db_type = Context::getDBType(); + } + if(!$db_type && Context::isInstalled()) + { + return new Object(-1, 'msg_db_not_setted'); + } - if(!isset($GLOBALS['__DB__'])) $GLOBALS['__DB__'] = array(); + if(!isset($GLOBALS['__DB__'])) + { + $GLOBALS['__DB__'] = array(); + } if(!isset($GLOBALS['__DB__'][$db_type])) { - $class_name = 'DB'.ucfirst($db_type); - $class_file = _XE_PATH_."classes/db/$class_name.class.php"; - if(!file_exists($class_file)) return new Object(-1, 'msg_db_not_setted'); + $class_name = 'DB' . ucfirst($db_type); + $class_file = _XE_PATH_ . "classes/db/$class_name.class.php"; + if(!file_exists($class_file)) + { + return new Object(-1, 'msg_db_not_setted'); + } // get a singletone instance of the database driver class require_once($class_file); @@ -194,8 +211,8 @@ class DB */ function DB() { - $this->count_cache_path = _XE_PATH_.$this->count_cache_path; - $this->cache_file = _XE_PATH_.$this->cache_file; + $this->count_cache_path = _XE_PATH_ . $this->count_cache_path; + $this->cache_file = _XE_PATH_ . $this->cache_file; } /** @@ -226,8 +243,13 @@ class DB $enableList = array(); if(is_array($this->supported_list)) { - foreach($this->supported_list AS $key=>$value) - if($value->enable) array_push($enableList, $value); + foreach($this->supported_list AS $key => $value) + { + if($value->enable) + { + array_push($enableList, $value); + } + } } return $enableList; } @@ -248,8 +270,13 @@ class DB $disableList = array(); if(is_array($this->supported_list)) { - foreach($this->supported_list AS $key=>$value) - if(!$value->enable) array_push($disableList, $value); + foreach($this->supported_list AS $key => $value) + { + if(!$value->enable) + { + array_push($disableList, $value); + } + } } return $disableList; } @@ -268,7 +295,7 @@ class DB return $this->supported_list; } $get_supported_list = array(); - $db_classes_path = _XE_PATH_."classes/db/"; + $db_classes_path = _XE_PATH_ . "classes/db/"; $filter = "/^DB([^\.]+)\.class\.php/i"; $supported_list = FileHandler::readDir($db_classes_path, $filter, TRUE); @@ -277,18 +304,27 @@ class DB { $db_type = $supported_list[$i]; - if(version_compare(phpversion(), '5.0') < 0 && preg_match('/pdo/i',$db_type)) continue; + if(version_compare(phpversion(), '5.0') < 0 && preg_match('/pdo/i', $db_type)) + { + 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; + $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; + } unset($oDB); require_once($class_file); $tmp_fn = create_function('', "return new {$class_name}();"); - $oDB = $tmp_fn(); + $oDB = $tmp_fn(); - if(!$oDB) continue; + if(!$oDB) + { + continue; + } $obj = NULL; $obj->db_type = $db_type; @@ -353,8 +389,14 @@ class DB */ 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; + if($type == 'master') + { + return $this->master_db["is_connected"] ? TRUE : FALSE; + } + else + { + return $this->slave_db[$indx]["is_connected"] ? TRUE : FALSE; + } } /** @@ -376,7 +418,10 @@ class DB */ function actFinish() { - if(!$this->query) return; + if(!$this->query) + { + return; + } $this->act_finish = getMicroTime(); $elapsed_time = $this->act_finish - $this->act_start; $this->elapsed_time = $elapsed_time; @@ -400,13 +445,19 @@ class DB if(__DEBUG_DB_OUTPUT__ == 1) { - $debug_file = _XE_PATH_."files/_debug_db_query.php"; + $debug_file = _XE_PATH_ . "files/_debug_db_query.php"; $buff = array(); - if(!file_exists($debug_file)) $buff[] = ''; + if(!file_exists($debug_file)) + { + $buff[] = ''; + } $buff[] = print_r($log, TRUE); - if(@!$fp = fopen($debug_file, "a")) return; - fwrite($fp, implode("\n", $buff)."\n\n"); + if(@!$fp = fopen($debug_file, "a")) + { + return; + } + fwrite($fp, implode("\n", $buff) . "\n\n"); fclose($fp); } } @@ -420,10 +471,10 @@ class DB if(__LOG_SLOW_QUERY__ > 0 && $elapsed_time > __LOG_SLOW_QUERY__) { $buff = ''; - $log_file = _XE_PATH_.'files/_db_slow_query.php'; + $log_file = _XE_PATH_ . 'files/_db_slow_query.php'; if(!file_exists($log_file)) { - $buff = ''."\n"; + $buff = '' . "\n"; } $buff .= sprintf("%s\t%s\n\t%0.6f sec\tquery_id:%s\n\n", date("Y-m-d H:i"), $this->query, $elapsed_time, $this->query_id); @@ -479,8 +530,14 @@ class DB { static $cache_file = array(); - if(!$query_id) return new Object(-1, 'msg_invalid_queryid'); - if(!$this->db_type) return; + if(!$query_id) + { + return new Object(-1, 'msg_invalid_queryid'); + } + if(!$this->db_type) + { + return; + } $this->actDBClassStart(); @@ -498,7 +555,7 @@ class DB elseif(count($id_args) == 3) { $target = $id_args[0]; - $typeList = array('addons'=>1, 'widgets'=>1); + $typeList = array('addons' => 1, 'widgets' => 1); if(!isset($typeList[$target])) { $this->actDBClassFinish(); @@ -530,25 +587,30 @@ class DB 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 */ - function checkQueryCacheFile($query_id,$xml_file) + 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); - if(file_exists($cache_file)) $cache_time = filemtime($cache_file); - else $cache_time = -1; + if(file_exists($cache_file)) + { + $cache_time = filemtime($cache_file); + } + else + { + $cache_time = -1; + } // 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.150.class.php')) + if($cache_time < filemtime($xml_file) || $cache_time < filemtime(_XE_PATH_ . 'classes/db/DB.class.php') || $cache_time < filemtime(_XE_PATH_ . 'classes/xml/XmlQueryParser.150.class.php')) { - require_once(_XE_PATH_.'classes/xml/XmlQueryParser.150.class.php'); + require_once(_XE_PATH_ . 'classes/xml/XmlQueryParser.150.class.php'); $oParser = new XmlQueryParser(); $oParser->parse($query_id, $xml_file, $cache_file); } @@ -556,7 +618,6 @@ class DB return $cache_file; } - /** * Execute query and return the result * @param string $cache_file cache file of query @@ -569,13 +630,22 @@ class DB { global $lang; - if(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid'); + if(!file_exists($cache_file)) + { + return new Object(-1, 'msg_invalid_queryid'); + } - if($source_args) $args = @clone($source_args); + if($source_args) + { + $args = clone $source_args; + } $output = include($cache_file); - if( (is_a($output, 'Object') || is_subclass_of($output, 'Object')) && !$output->toBool()) return $output; + if((is_a($output, 'Object') || is_subclass_of($output, 'Object')) && !$output->toBool()) + { + return $output; + } // execute appropriate query switch($output->getAction()) @@ -594,22 +664,27 @@ class DB $output = $this->_executeDeleteAct($output); break; case 'select' : - $arg_columns = is_array($arg_columns)?$arg_columns:array(); + $arg_columns = is_array($arg_columns) ? $arg_columns : array(); $output->setColumnList($arg_columns); $connection = $this->_getConnection('slave'); $output = $this->_executeSelectAct($output, $connection); break; } - if($this->isError()) $output = $this->getError(); - else if(!is_a($output, 'Object') && !is_subclass_of($output, 'Object')) $output = new Object(); + if($this->isError()) + { + $output = $this->getError(); + } + else if(!is_a($output, 'Object') && !is_subclass_of($output, 'Object')) + { + $output = new Object(); + } $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 @@ -619,30 +694,54 @@ class DB function getCountCache($tables, $condition) { return FALSE; - if(!$tables) return FALSE; - if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path); + if(!$tables) + { + return FALSE; + } + if(!is_dir($this->count_cache_path)) + { + return FileHandler::makeDir($this->count_cache_path); + } $condition = md5($condition); - if(!is_array($tables)) $tables_str = $tables; - else $tables_str = implode('.',$tables); + if(!is_array($tables)) + { + $tables_str = $tables; + } + else + { + $tables_str = implode('.', $tables); + } $cache_path = sprintf('%s/%s%s', $this->count_cache_path, $this->prefix, $tables_str); - if(!is_dir($cache_path)) FileHandler::makeDir($cache_path); + if(!is_dir($cache_path)) + { + FileHandler::makeDir($cache_path); + } $cache_filename = sprintf('%s/%s.%s', $cache_path, $tables_str, $condition); - if(!file_exists($cache_filename)) return FALSE; + if(!file_exists($cache_filename)) + { + return FALSE; + } $cache_mtime = filemtime($cache_filename); - if(!is_array($tables)) $tables = array($tables); + if(!is_array($tables)) + { + $tables = array($tables); + } foreach($tables as $alias => $table) { - $table_filename = sprintf('%s/cache.%s%s', $this->count_cache_path, $this->prefix, $table) ; - if(!file_exists($table_filename) || filemtime($table_filename) > $cache_mtime) return FALSE; + $table_filename = sprintf('%s/cache.%s%s', $this->count_cache_path, $this->prefix, $table); + if(!file_exists($table_filename) || filemtime($table_filename) > $cache_mtime) + { + return FALSE; + } } - $count = (int)FileHandler::readFile($cache_filename); + $count = (int) FileHandler::readFile($cache_filename); return $count; } @@ -656,16 +755,31 @@ class DB function putCountCache($tables, $condition, $count = 0) { return FALSE; - if(!$tables) return FALSE; - if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path); + if(!$tables) + { + return FALSE; + } + if(!is_dir($this->count_cache_path)) + { + return FileHandler::makeDir($this->count_cache_path); + } $condition = md5($condition); - if(!is_array($tables)) $tables_str = $tables; - else $tables_str = implode('.',$tables); + if(!is_array($tables)) + { + $tables_str = $tables; + } + else + { + $tables_str = implode('.', $tables); + } $cache_path = sprintf('%s/%s%s', $this->count_cache_path, $this->prefix, $tables_str); - if(!is_dir($cache_path)) FileHandler::makeDir($cache_path); + if(!is_dir($cache_path)) + { + FileHandler::makeDir($cache_path); + } $cache_filename = sprintf('%s/%s.%s', $cache_path, $tables_str, $condition); @@ -680,10 +794,19 @@ class DB function resetCountCache($tables) { return FALSE; - if(!$tables) return FALSE; - if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path); + if(!$tables) + { + return FALSE; + } + if(!is_dir($this->count_cache_path)) + { + return FileHandler::makeDir($this->count_cache_path); + } - if(!is_array($tables)) $tables = array($tables); + if(!is_array($tables)) + { + $tables = array($tables); + } foreach($tables as $alias => $table) { $filename = sprintf('%s/cache.%s%s', $this->count_cache_path, $this->prefix, $table); @@ -702,13 +825,34 @@ class DB { $result = array(); - if(function_exists('mysql_connect')) $result[] = 'MySQL'; - if(function_exists('cubrid_connect')) $result[] = 'Cubrid'; - if(function_exists('ibase_connect')) $result[] = 'FireBird'; - if(function_exists('pg_connect')) $result[] = 'Postgre'; - if(function_exists('sqlite_open')) $result[] = 'sqlite2'; - if(function_exists('mssql_connect')) $result[] = 'MSSQL'; - if(function_exists('PDO')) $result[] = 'sqlite3(PDO)'; + if(function_exists('mysql_connect')) + { + $result[] = 'MySQL'; + } + if(function_exists('cubrid_connect')) + { + $result[] = 'Cubrid'; + } + if(function_exists('ibase_connect')) + { + $result[] = 'FireBird'; + } + if(function_exists('pg_connect')) + { + $result[] = 'Postgre'; + } + if(function_exists('sqlite_open')) + { + $result[] = 'sqlite2'; + } + if(function_exists('mssql_connect')) + { + $result[] = 'MSSQL'; + } + if(function_exists('PDO')) + { + $result[] = 'sqlite3(PDO)'; + } return $result; } @@ -720,7 +864,10 @@ class DB */ function dropTable($table_name) { - if(!$table_name) return; + if(!$table_name) + { + return; + } $query = sprintf("drop table %s%s", $this->prefix, $table_name); $this->_query($query); } @@ -734,35 +881,57 @@ class DB function getSelectSql($query, $with_values = TRUE) { $select = $query->getSelectString($with_values); - if($select == '') return new Object(-1, "Invalid query"); - $select = 'SELECT ' .$select; + if($select == '') + { + return new Object(-1, "Invalid query"); + } + $select = 'SELECT ' . $select; $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); - $from = ' FROM '.$from; + if($from == '') + { + return new Object(-1, "Invalid query"); + } + $from = ' FROM ' . $from; $where = $query->getWhereString($with_values); - if($where != '') $where = ' WHERE ' . $where; + 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; + if($groupBy != '') + { + $groupBy = ' GROUP BY ' . $groupBy; + } $orderBy = $query->getOrderByString(); - if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy; + if($orderBy != '') + { + $orderBy = ' ORDER BY ' . $orderBy; + } $limit = $query->getLimitString(); - if($limit != '') $limit = ' LIMIT ' . $limit; + if($limit != '') + { + $limit = ' LIMIT ' . $limit; + } return $select . ' ' . $from . ' ' . $where . ' ' . $index_hint_list . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit; } @@ -808,17 +977,23 @@ class DB { $sql = 'DELETE '; - $sql .= $with_priority?$query->getPriority():''; + $sql .= $with_priority ? $query->getPriority() : ''; $tables = $query->getTables(); $sql .= $tables[0]->getAlias(); $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); - $sql .= ' FROM '.$from; + if($from == '') + { + return new Object(-1, "Invalid query"); + } + $sql .= ' FROM ' . $from; $where = $query->getWhereString($with_values); - if($where != '') $sql .= ' WHERE ' . $where; + if($where != '') + { + $sql .= ' WHERE ' . $where; + } return $sql; } @@ -833,17 +1008,26 @@ class DB function getUpdateSql($query, $with_values = TRUE, $with_priority = FALSE) { $columnsList = $query->getUpdateString($with_values); - if($columnsList == '') return new Object(-1, "Invalid query"); + if($columnsList == '') + { + return new Object(-1, "Invalid query"); + } $tables = $query->getFromString($with_values); - if($tables == '') return new Object(-1, "Invalid query"); + if($tables == '') + { + return new Object(-1, "Invalid query"); + } $where = $query->getWhereString($with_values); - if($where != '') $where = ' WHERE ' . $where; + if($where != '') + { + $where = ' WHERE ' . $where; + } - $priority = $with_priority?$query->getPriority():''; + $priority = $with_priority ? $query->getPriority() : ''; - return "UPDATE $priority $tables SET $columnsList ".$where; + return "UPDATE $priority $tables SET $columnsList " . $where; } /** @@ -857,7 +1041,7 @@ class DB { $tableName = $query->getFirstTableName(); $values = $query->getInsertString($with_values); - $priority = $with_priority?$query->getPriority():''; + $priority = $with_priority ? $query->getPriority() : ''; return "INSERT $priority INTO $tableName \n $values"; } @@ -884,16 +1068,22 @@ class DB if($type == 'master') { if(!$this->master_db['is_connected']) + { $this->_connect($type); + } $this->connection = 'Master ' . $this->master_db['db_hostname']; return $this->master_db["resource"]; } if($indx === NULL) + { $indx = $this->_getSlaveConnectionStringIndex($type); + } if(!$this->slave_db[$indx]['is_connected']) + { $this->_connect($type, $indx); + } $this->connection = 'Slave ' . $this->slave_db[$indx]['db_hostname']; return $this->slave_db[$indx]["resource"]; @@ -905,10 +1095,14 @@ class DB */ function _dbInfoExists() { - if (!$this->master_db) + if(!$this->master_db) + { return FALSE; - if (count($this->slave_db) === 0) + } + if(count($this->slave_db) === 0) + { return FALSE; + } return TRUE; } @@ -931,13 +1125,19 @@ class DB */ function close($type = 'master', $indx = 0) { - if (!$this->isConnected($type, $indx)) + if(!$this->isConnected($type, $indx)) + { return; + } - if ($type == 'master') + if($type == 'master') + { $connection = &$this->master_db; + } else + { $connection = &$this->slave_db[$indx]; + } $this->_close($connection["resource"]); @@ -960,11 +1160,15 @@ class DB */ function begin() { - if (!$this->isConnected() || $this->transaction_started) + if(!$this->isConnected() || $this->transaction_started) + { return; + } if($this->_begin()) + { $this->transaction_started = TRUE; + } } /** @@ -983,10 +1187,14 @@ class DB */ function rollback() { - if (!$this->isConnected() || !$this->transaction_started) + if(!$this->isConnected() || !$this->transaction_started) + { return; + } if($this->_rollback()) + { $this->transaction_started = FALSE; + } } /** @@ -1006,10 +1214,14 @@ class DB */ function commit($force = FALSE) { - if (!$force && (!$this->isConnected() || !$this->transaction_started)) + if(!$force && (!$this->isConnected() || !$this->transaction_started)) + { return; + } if($this->_commit()) + { $this->transaction_started = FALSE; + } } /** @@ -1034,7 +1246,9 @@ class DB function _query($query, $connection = NULL) { if($connection == NULL) + { $connection = $this->_getConnection('master'); + } // Notify to start a query execution $this->actStart($query); @@ -1061,10 +1275,14 @@ class DB && $db_info->master_db["db_userid"] == $db_info->slave_db[0]["db_userid"] && $db_info->master_db["db_password"] == $db_info->slave_db[0]["db_password"] && $db_info->master_db["db_database"] == $db_info->slave_db[0]["db_database"] - ) + ) + { $this->slave_db[0] = &$this->master_db; + } else + { $this->slave_db = $db_info->slave_db; + } $this->prefix = $db_info->master_db["db_table_prefix"]; $this->use_prepared_statements = $db_info->use_prepared_statements; } @@ -1100,17 +1318,25 @@ class DB */ function _connect($type = 'master', $indx = 0) { - if ($this->isConnected($type, $indx)) + if($this->isConnected($type, $indx)) + { return; + } // Ignore if no DB information exists - if (!$this->_dbInfoExists()) + if(!$this->_dbInfoExists()) + { return; + } - if ($type == 'master') + if($type == 'master') + { $connection = &$this->master_db; + } else + { $connection = &$this->slave_db[$indx]; + } $result = $this->__connect($connection); if($result === NULL || $result === FALSE) @@ -1146,7 +1372,10 @@ class DB */ function actDBClassFinish() { - if(!$this->query) return; + if(!$this->query) + { + return; + } $this->act_dbclass_finish = getMicroTime(); $elapsed_dbclass_time = $this->act_dbclass_finish - $this->act_dbclass_start; $this->elapsed_dbclass_time = $elapsed_dbclass_time; @@ -1176,6 +1405,5 @@ class DB } } - /* End of file DB.class.php */ /* Location: ./classes/db/DB.class.php */ diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php index 430f62343..48e4ef429 100644 --- a/classes/db/DBCubrid.class.php +++ b/classes/db/DBCubrid.class.php @@ -1,4 +1,5 @@ 'numeric(20)', - 'number' => 'integer', - 'varchar' => 'character varying', - 'char' => 'character', - 'tinytext' => 'character varying(256)', - 'text' => 'character varying(1073741823)', - 'bigtext' => 'character varying(1073741823)', - 'date' => 'character varying(14)', - 'float' => 'float', - ); + 'bignumber' => 'numeric(20)', + 'number' => 'integer', + 'varchar' => 'character varying', + 'char' => 'character', + 'tinytext' => 'character varying(256)', + 'text' => 'character varying(1073741823)', + 'bigtext' => 'character varying(1073741823)', + 'date' => 'character varying(14)', + 'float' => 'float', + ); /** * constructor @@ -67,7 +70,10 @@ class DBCubrid extends DB */ function isSupported() { - if (!function_exists('cubrid_connect')) return FALSE; + if(!function_exists('cubrid_connect')) + { + return FALSE; + } return TRUE; } @@ -83,9 +89,9 @@ class DBCubrid extends DB $result = @cubrid_connect($connection["db_hostname"], $connection["db_port"], $connection["db_database"], $connection["db_userid"], $connection["db_password"]); // check connections - if (!$result) + if(!$result) { - $this->setError (-1, 'database connect fail'); + $this->setError(-1, 'database connect fail'); return; } @@ -98,7 +104,7 @@ class DBCubrid extends DB } if(__CUBRID_VERSION__ >= '8.4.0') - cubrid_set_autocommit($result, CUBRID_AUTOCOMMIT_TRUE); + cubrid_set_autocommit($result, CUBRID_AUTOCOMMIT_TRUE); return $result; } @@ -111,8 +117,8 @@ class DBCubrid extends DB */ function _close($connection) { - @cubrid_commit ($connection); - @cubrid_disconnect ($connection); + @cubrid_commit($connection); + @cubrid_disconnect($connection); $this->transaction_started = FALSE; } @@ -123,24 +129,24 @@ class DBCubrid extends DB */ function addQuotes($string) { - if (version_compare (PHP_VERSION, "5.9.0", "<") && - get_magic_quotes_gpc ()) + if(version_compare(PHP_VERSION, "5.9.0", "<") && + get_magic_quotes_gpc()) { - $string = stripslashes (str_replace ("\\","\\\\", $string)); + $string = stripslashes(str_replace("\\", "\\\\", $string)); } - if (!is_numeric ($string)) + if(!is_numeric($string)) { /* - if ($this->isConnected()) { - $string = cubrid_real_escape_string($string); - } - else { - $string = str_replace("'","\'",$string); - } + if ($this->isConnected()) { + $string = cubrid_real_escape_string($string); + } + else { + $string = str_replace("'","\'",$string); + } */ - $string = str_replace("'","''",$string); + $string = str_replace("'", "''", $string); } return $string; @@ -156,7 +162,7 @@ class DBCubrid extends DB if(__CUBRID_VERSION__ >= '8.4.0') { $connection = $this->_getConnection('master'); - cubrid_set_autocommit($connection, CUBRID_AUTOCOMMIT_FALSE); + cubrid_set_autocommit($connection, CUBRID_AUTOCOMMIT_FALSE); } return TRUE; } @@ -169,7 +175,7 @@ class DBCubrid extends DB function _rollback() { $connection = $this->_getConnection('master'); - @cubrid_rollback ($connection); + @cubrid_rollback($connection); return TRUE; } @@ -211,21 +217,25 @@ class DBCubrid extends DB $value = $param->getUnescapedValue(); $type = $param->getType(); - if($param->isColumnName()) continue; + if($param->isColumnName()) + { + continue; + } switch($type) { - case 'number' : - $bind_type = 'numeric'; + case 'number' : + $bind_type = 'numeric'; break; - case 'varchar' : - $bind_type = 'string'; - break; - default: + case 'varchar' : $bind_type = 'string'; - } + break; + default: + $bind_type = 'string'; + } - if(is_array($value)){ + if(is_array($value)) + { foreach($value as $v) { $bound = @cubrid_bind($req, ++$position, $v, $bind_type); @@ -255,12 +265,12 @@ class DBCubrid extends DB return false; } return $req; - } // Execute the query - $result = @cubrid_execute ($connection, $query); + $result = @cubrid_execute($connection, $query); // error check - if (!$result) { + if(!$result) + { $this->_setError(); return false; } @@ -275,10 +285,10 @@ class DBCubrid extends DB */ function _setError() { - $code = cubrid_error_code (); - $msg = cubrid_error_msg (); + $code = cubrid_error_code(); + $msg = cubrid_error_msg(); - $this->setError ($code, $msg); + $this->setError($code, $msg); } /** @@ -290,7 +300,10 @@ class DBCubrid extends DB function _fetch($result, $arrayIndexEndValue = NULL) { $output = array(); - if (!$this->isConnected() || $this->isError() || !$result) return array(); + if(!$this->isConnected() || $this->isError() || !$result) + { + return array(); + } if($this->use_prepared_statements == 'Y') { @@ -299,36 +312,57 @@ class DBCubrid extends DB // TODO Improve this piece of code // This code trims values from char type columns - $col_types = cubrid_column_types ($result); - $col_names = cubrid_column_names ($result); - $max = count ($col_types); + $col_types = cubrid_column_types($result); + $col_names = cubrid_column_names($result); + $max = count($col_types); - for ($count = 0; $count < $max; $count++) { - if (preg_match ("/^char/", $col_types[$count]) > 0) { + for($count = 0; $count < $max; $count++) + { + if(preg_match("/^char/", $col_types[$count]) > 0) + { $char_type_fields[] = $col_names[$count]; } } - while ($tmp = cubrid_fetch ($result, CUBRID_OBJECT)) { - if (is_array ($char_type_fields)) { - foreach ($char_type_fields as $val) { - $tmp->{$val} = rtrim ($tmp->{$val}); + while($tmp = cubrid_fetch($result, CUBRID_OBJECT)) + { + if(is_array($char_type_fields)) + { + foreach($char_type_fields as $val) + { + $tmp->{$val} = rtrim($tmp->{$val}); } } - if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $tmp; - else $output[] = $tmp; + if($arrayIndexEndValue) + { + $output[$arrayIndexEndValue--] = $tmp; + } + else + { + $output[] = $tmp; + } } - unset ($char_type_fields); + unset($char_type_fields); - if ($result) cubrid_close_request($result); + if($result) + { + cubrid_close_request($result); + } - if(count($output)==1){ + if(count($output) == 1) + { // If call is made for pagination, always return array - if(isset($arrayIndexEndValue)) return $output; + if(isset($arrayIndexEndValue)) + { + return $output; + } // Else return object instead of array - else return $output[0]; + else + { + return $output[0]; + } } return $output; } @@ -342,7 +376,7 @@ class DBCubrid extends DB { $this->_makeSequence(); - $query = sprintf ("select \"%ssequence\".\"nextval\" as \"seq\" from db_root", $this->prefix); + $query = sprintf("select \"%ssequence\".\"nextval\" as \"seq\" from db_root", $this->prefix); $result = $this->_query($query); $output = $this->_fetch($result); @@ -355,7 +389,8 @@ class DBCubrid extends DB */ function _makeSequence() { - if($_GLOBALS['XE_EXISTS_SEQUENCE']) return; + if($_GLOBALS['XE_EXISTS_SEQUENCE']) + return; // check cubrid serial $query = sprintf('select count(*) as "count" from "db_serial" where name=\'%ssequence\'', $this->prefix); @@ -363,23 +398,26 @@ class DBCubrid extends DB $output = $this->_fetch($result); // if do not create serial - if ($output->count == 0) { - $query = sprintf('select max("a"."srl") as "srl" from '. - '( select max("document_srl") as "srl" from '. - '"%sdocuments" UNION '. - 'select max("comment_srl") as "srl" from '. - '"%scomments" UNION '. - 'select max("member_srl") as "srl" from '. - '"%smember"'. - ') as "a"', $this->prefix, $this->prefix, $this->prefix); + if($output->count == 0) + { + $query = sprintf('select max("a"."srl") as "srl" from ' . + '( select max("document_srl") as "srl" from ' . + '"%sdocuments" UNION ' . + 'select max("comment_srl") as "srl" from ' . + '"%scomments" UNION ' . + 'select max("member_srl") as "srl" from ' . + '"%smember"' . + ') as "a"', $this->prefix, $this->prefix, $this->prefix); $result = $this->_query($query); $output = $this->_fetch($result); $srl = $output->srl; - if ($srl < 1) { + if($srl < 1) + { $start = 1; } - else { + else + { $start = $srl + 1000000; } @@ -391,30 +429,36 @@ class DBCubrid extends DB $_GLOBALS['XE_EXISTS_SEQUENCE'] = TRUE; } - /** * Check a table exists status * @param string $target_name * @return boolean */ - function isTableExists ($target_name) + function isTableExists($target_name) { - if($target_name == 'sequence') { - $query = sprintf ("select \"name\" from \"db_serial\" where \"name\" = '%s%s'", $this->prefix, $target_name); + if($target_name == 'sequence') + { + $query = sprintf("select \"name\" from \"db_serial\" where \"name\" = '%s%s'", $this->prefix, $target_name); } - else { - $query = sprintf ("select \"class_name\" from \"db_class\" where \"class_name\" = '%s%s'", $this->prefix, $target_name); + else + { + $query = sprintf("select \"class_name\" from \"db_class\" where \"class_name\" = '%s%s'", $this->prefix, $target_name); } - $result = $this->_query ($query); - if (cubrid_num_rows($result) > 0) { + $result = $this->_query($query); + if(cubrid_num_rows($result) > 0) + { $output = TRUE; } - else { + else + { $output = FALSE; } - if ($result) cubrid_close_request ($result); + if($result) + { + cubrid_close_request($result); + } return $output; } @@ -432,33 +476,48 @@ class DBCubrid extends DB function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = FALSE) { $type = strtoupper($this->column_type[$type]); - if ($type == 'INTEGER') $size = ''; - - $query = sprintf ("alter class \"%s%s\" add \"%s\" ", $this->prefix, $table_name, $column_name); - - if ($type == 'char' || $type == 'varchar') { - if ($size) $size = $size * 3; + if($type == 'INTEGER') + { + $size = ''; } - if ($size) { - $query .= sprintf ("%s(%s) ", $type, $size); - } - else { - $query .= sprintf ("%s ", $type); - } + $query = sprintf("alter class \"%s%s\" add \"%s\" ", $this->prefix, $table_name, $column_name); - if ($default) { - if ($type == 'INTEGER' || $type == 'BIGINT' || $type=='INT') { - $query .= sprintf ("default %d ", $default); - } - else { - $query .= sprintf ("default '%s' ", $default); + if($type == 'char' || $type == 'varchar') + { + if($size) + { + $size = $size * 3; } } - if ($notnull) $query .= "not null "; + if($size) + { + $query .= sprintf("%s(%s) ", $type, $size); + } + else + { + $query .= sprintf("%s ", $type); + } - return $this->_query ($query); + if($default) + { + if($type == 'INTEGER' || $type == 'BIGINT' || $type == 'INT') + { + $query .= sprintf("default %d ", $default); + } + else + { + $query .= sprintf("default '%s' ", $default); + } + } + + if($notnull) + { + $query .= "not null "; + } + + return $this->_query($query); } /** @@ -467,11 +526,11 @@ class DBCubrid extends DB * @param string $column_name column name * @return void */ - function dropColumn ($table_name, $column_name) + function dropColumn($table_name, $column_name) { - $query = sprintf ("alter class \"%s%s\" drop \"%s\" ", $this->prefix, $table_name, $column_name); + $query = sprintf("alter class \"%s%s\" drop \"%s\" ", $this->prefix, $table_name, $column_name); - $this->_query ($query); + $this->_query($query); } /** @@ -480,15 +539,24 @@ class DBCubrid extends DB * @param string $column_name column name * @return boolean */ - function isColumnExists ($table_name, $column_name) + function isColumnExists($table_name, $column_name) { - $query = sprintf ("select \"attr_name\" from \"db_attribute\" where ". "\"attr_name\" ='%s' and \"class_name\" = '%s%s'", $column_name, $this->prefix, $table_name); - $result = $this->_query ($query); + $query = sprintf("select \"attr_name\" from \"db_attribute\" where " . "\"attr_name\" ='%s' and \"class_name\" = '%s%s'", $column_name, $this->prefix, $table_name); + $result = $this->_query($query); - if (cubrid_num_rows ($result) > 0) $output = TRUE; - else $output = FALSE; + if(cubrid_num_rows($result) > 0) + { + $output = TRUE; + } + else + { + $output = FALSE; + } - if ($result) cubrid_close_request ($result); + if($result) + { + cubrid_close_request($result); + } return $output; } @@ -503,15 +571,16 @@ class DBCubrid extends DB * @param boolean $is_unique * @return void */ - function addIndex ($table_name, $index_name, $target_columns, $is_unique = FALSE) + function addIndex($table_name, $index_name, $target_columns, $is_unique = FALSE) { - if (!is_array ($target_columns)) { - $target_columns = array ($target_columns); + if(!is_array($target_columns)) + { + $target_columns = array($target_columns); } - $query = sprintf ("create %s index \"%s\" on \"%s%s\" (%s);", $is_unique?'unique':'', $index_name, $this->prefix, $table_name, '"'.implode('","',$target_columns).'"'); + $query = sprintf("create %s index \"%s\" on \"%s%s\" (%s);", $is_unique ? 'unique' : '', $index_name, $this->prefix, $table_name, '"' . implode('","', $target_columns) . '"'); - $this->_query ($query); + $this->_query($query); } /** @@ -521,9 +590,9 @@ class DBCubrid extends DB * @param boolean $is_unique * @return void */ - function dropIndex ($table_name, $index_name, $is_unique = FALSE) + function dropIndex($table_name, $index_name, $is_unique = FALSE) { - $query = sprintf ("drop %s index \"%s\" on \"%s%s\"", $is_unique?'unique':'', $index_name, $this->prefix, $table_name); + $query = sprintf("drop %s index \"%s\" on \"%s%s\"", $is_unique ? 'unique' : '', $index_name, $this->prefix, $table_name); $this->_query($query); } @@ -534,16 +603,22 @@ class DBCubrid extends DB * @param string $index_name index name * @return boolean */ - function isIndexExists ($table_name, $index_name) + function isIndexExists($table_name, $index_name) { - $query = sprintf ("select \"index_name\" from \"db_index\" where ". "\"class_name\" = '%s%s' and (\"index_name\" = '%s' or \"index_name\" = '%s') ", $this->prefix, $table_name, $this->prefix .$index_name, $index_name); - $result = $this->_query ($query); + $query = sprintf("select \"index_name\" from \"db_index\" where " . "\"class_name\" = '%s%s' and (\"index_name\" = '%s' or \"index_name\" = '%s') ", $this->prefix, $table_name, $this->prefix . $index_name, $index_name); + $result = $this->_query($query); - if ($this->isError ()) return FALSE; + if($this->isError()) + { + return FALSE; + } - $output = $this->_fetch ($result); + $output = $this->_fetch($result); - if (!$output) return FALSE; + if(!$output) + { + return FALSE; + } return TRUE; } @@ -576,18 +651,26 @@ class DBCubrid extends DB , strlen($this->prefix) , $this->prefix , strlen($this->prefix) + 1 - ); - $result = $this->_query ($query); + ); + $result = $this->_query($query); - if ($this->isError ()) return FALSE; + if($this->isError()) + { + return FALSE; + } - $output = $this->_fetch ($result); - if (!$output) return FALSE; + $output = $this->_fetch($result); + if(!$output) + { + return FALSE; + } - if(!is_array($output)) { + if(!is_array($output)) + { $indexes_to_be_deleted = array($output); } - else { + else + { $indexes_to_be_deleted = $output; } @@ -606,9 +689,9 @@ class DBCubrid extends DB * @param string $xml_doc xml schema contents * @return void|object */ - function createTableByXml ($xml_doc) + function createTableByXml($xml_doc) { - return $this->_createTable ($xml_doc); + return $this->_createTable($xml_doc); } /** @@ -616,12 +699,15 @@ class DBCubrid extends DB * @param string $file_name xml schema file path * @return void|object */ - function createTableByXmlFile ($file_name) + function createTableByXmlFile($file_name) { - if (!file_exists ($file_name)) return; + if(!file_exists($file_name)) + { + return; + } // read xml file - $buff = FileHandler::readFile ($file_name); - return $this->_createTable ($buff); + $buff = FileHandler::readFile($file_name); + return $this->_createTable($buff); } /** @@ -633,7 +719,7 @@ class DBCubrid extends DB * @param string $xml_doc xml schema contents * @return void|object */ - function _createTable ($xml_doc) + function _createTable($xml_doc) { // xml parsing $oXml = new XmlParser(); @@ -642,37 +728,44 @@ class DBCubrid extends DB $table_name = $xml_obj->table->attrs->name; // if the table already exists exit function - if ($this->isTableExists($table_name)) return; + if($this->isTableExists($table_name)) + { + return; + } // If the table name is sequence, it creates a serial - if ($table_name == 'sequence') { - $query = sprintf ('create serial "%s" start with 1 increment by 1'. - ' minvalue 1 '. - 'maxvalue 10000000000000000000000000000000000000'. ' nocycle;', $this->prefix.$table_name); + if($table_name == 'sequence') + { + $query = sprintf('create serial "%s" start with 1 increment by 1' . + ' minvalue 1 ' . + 'maxvalue 10000000000000000000000000000000000000' . ' nocycle;', $this->prefix . $table_name); return $this->_query($query); } - $table_name = $this->prefix.$table_name; + $table_name = $this->prefix . $table_name; - $query = sprintf ('create class "%s";', $table_name); - $this->_query ($query); + $query = sprintf('create class "%s";', $table_name); + $this->_query($query); - if (!is_array ($xml_obj->table->column)) { + if(!is_array($xml_obj->table->column)) + { $columns[] = $xml_obj->table->column; } - else { + else + { $columns = $xml_obj->table->column; } - $query = sprintf ("alter class \"%s\" add attribute ", $table_name); + $query = sprintf("alter class \"%s\" add attribute ", $table_name); $primary_list = array(); $unique_list = array(); $index_list = array(); - foreach ($columns as $column) { + foreach($columns as $column) + { $name = $column->attrs->name; $type = $column->attrs->type; $size = $column->attrs->size; @@ -682,7 +775,8 @@ class DBCubrid extends DB $unique = $column->attrs->unique; $default = $column->attrs->default; - switch ($this->column_type[$type]) { + switch($this->column_type[$type]) + { case 'integer' : $size = NULL; break; @@ -691,60 +785,63 @@ class DBCubrid extends DB break; } - if (isset ($default) && ($type == 'varchar' || $type == 'char' || - $type == 'text' || $type == 'tinytext' || $type == 'bigtext')) { - $default = sprintf ("'%s'", $default); + if(isset($default) && ($type == 'varchar' || $type == 'char' || + $type == 'text' || $type == 'tinytext' || $type == 'bigtext')) + { + $default = sprintf("'%s'", $default); } - if ($type == 'varchar' || $type == 'char') { - if($size) $size = $size * 3; + if($type == 'varchar' || $type == 'char') + { + if($size) + $size = $size * 3; } - $column_schema[] = sprintf ('"%s" %s%s %s %s', - $name, - $this->column_type[$type], - $size?'('.$size.')':'', - isset($default)?"default ".$default:'', - $notnull?'not null':''); + $column_schema[] = sprintf('"%s" %s%s %s %s', $name, $this->column_type[$type], $size ? '(' . $size . ')' : '', isset($default) ? "default " . $default : '', $notnull ? 'not null' : ''); - if ($primary_key) { + if($primary_key) + { $primary_list[] = $name; } - else if ($unique) { + else if($unique) + { $unique_list[$unique][] = $name; } - else if ($index) { + else if($index) + { $index_list[$index][] = $name; } } - $query .= implode (',', $column_schema).';'; - $this->_query ($query); + $query .= implode(',', $column_schema) . ';'; + $this->_query($query); - if (count ($primary_list)) { - $query = sprintf ("alter class \"%s\" add attribute constraint ". "\"pkey_%s\" PRIMARY KEY(%s);", $table_name, $table_name, '"'.implode('","',$primary_list).'"'); - $this->_query ($query); + if(count($primary_list)) + { + $query = sprintf("alter class \"%s\" add attribute constraint " . "\"pkey_%s\" PRIMARY KEY(%s);", $table_name, $table_name, '"' . implode('","', $primary_list) . '"'); + $this->_query($query); } - if (count ($unique_list)) { - foreach ($unique_list as $key => $val) { - $query = sprintf ("create unique index \"%s\" on \"%s\" ". "(%s);", $key, $table_name, '"'.implode('","', $val).'"'); - $this->_query ($query); + if(count($unique_list)) + { + foreach($unique_list as $key => $val) + { + $query = sprintf("create unique index \"%s\" on \"%s\" " . "(%s);", $key, $table_name, '"' . implode('","', $val) . '"'); + $this->_query($query); } } - if (count ($index_list)) { - foreach ($index_list as $key => $val) { - $query = sprintf ("create index \"%s\" on \"%s\" (%s);", $key, $table_name, '"'.implode('","',$val).'"'); - $this->_query ($query); + if(count($index_list)) + { + foreach($index_list as $key => $val) + { + $query = sprintf("create index \"%s\" on \"%s\" (%s);", $key, $table_name, '"' . implode('","', $val) . '"'); + $this->_query($query); } } } - - - /** * Handles insertAct * @param Object $queryObject @@ -759,12 +856,16 @@ class DBCubrid extends DB $with_values = FALSE; } $query = $this->getInsertSql($queryObject, $with_values); - if(is_a($query, 'Object')) return; + if(is_a($query, 'Object')) + { + return; + } - $query .= (__DEBUG_QUERY__&1 && $this->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; + $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; - $result = $this->_query ($query); - if ($result && !$this->transaction_started) { + $result = $this->_query($query); + if($result && !$this->transaction_started) + { $this->_commit(); } unset($this->param); @@ -785,18 +886,23 @@ class DBCubrid extends DB $with_values = FALSE; } $query = $this->getUpdateSql($queryObject, $with_values); - if(is_a($query, 'Object')) return; + if(is_a($query, 'Object')) + { + return; + } - $query .= (__DEBUG_QUERY__&1 && $this->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; + $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; $result = $this->_query($query); - if ($result && !$this->transaction_started) $this->_commit(); + if($result && !$this->transaction_started) + { + $this->_commit(); + } unset($this->param); return $result; } - /** * Handles deleteAct * @param Object $queryObject @@ -809,15 +915,21 @@ class DBCubrid extends DB { $this->param = $queryObject->getArguments(); $with_values = FALSE; - } - $query = $this->getDeleteSql($queryObject, $with_values); - if(is_a($query, 'Object')) return; + } + $query = $this->getDeleteSql($queryObject, $with_values); + if(is_a($query, 'Object')) + { + return; + } - $query .= (__DEBUG_QUERY__&1 && $this->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; + $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; - $result = $this->_query ($query); + $result = $this->_query($query); - if ($result && !$this->transaction_started) $this->_commit(); + if($result && !$this->transaction_started) + { + $this->_commit(); + } unset($this->param); return $result; @@ -832,26 +944,33 @@ class DBCubrid extends DB * @param boolean $with_values * @return Object */ - function _executeSelectAct($queryObject, $connection = NULL, $with_values = TRUE) { - if ($this->use_prepared_statements == 'Y') { + function _executeSelectAct($queryObject, $connection = NULL, $with_values = TRUE) + { + if($this->use_prepared_statements == 'Y') + { $this->param = $queryObject->getArguments(); $with_values = FALSE; } $limit = $queryObject->getLimit(); - if ($limit && $limit->isPageHandler()) + if($limit && $limit->isPageHandler()) { return $this->queryPageLimit($queryObject, $connection, $with_values); } - else { + else + { $query = $this->getSelectSql($queryObject, $with_values); - if (is_a($query, 'Object')) + if(is_a($query, 'Object')) + { return; + } $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; $result = $this->_query($query, $connection); - if ($this->isError()) + if($this->isError()) + { return $this->queryError($queryObject); + } $data = $this->_fetch($result); $buff = new Object (); @@ -867,15 +986,17 @@ class DBCubrid extends DB * @param Object $queryObject * @return Object */ - function queryError($queryObject){ + function queryError($queryObject) + { $limit = $queryObject->getLimit(); - if ($limit && $limit->isPageHandler()){ + if($limit && $limit->isPageHandler()) + { $buff = new Object (); $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 + $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; @@ -888,67 +1009,83 @@ class DBCubrid extends DB * @param boolean $with_values * @return Object Object with page info containing */ - function queryPageLimit($queryObject, $connection, $with_values){ + function queryPageLimit($queryObject, $connection, $with_values) + { $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)); + $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 = strpos(strtolower($temp_select), "distinct") !== FALSE; $uses_groupby = $queryObject->getGroupByString() != ''; - if($uses_distinct || $uses_groupby) { + if($uses_distinct || $uses_groupby) + { $count_query = sprintf('select %s %s %s %s' , $temp_select , 'FROM ' . $queryObject->getFromString($with_values) - , ($temp_where === '' ? '' : ' WHERE '. $temp_where) + , ($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); } - $count_query .= (__DEBUG_QUERY__&1 && $queryObject->queryID)?sprintf (' '.$this->comment_syntax, $queryObject->queryID):''; + $count_query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(' ' . $this->comment_syntax, $queryObject->queryID) : ''; $result = $this->_query($count_query, $connection); $count_output = $this->_fetch($result); - $total_count = (int)(isset($count_output->count) ? $count_output->count : NULL); + $total_count = (int) (isset($count_output->count) ? $count_output->count : NULL); $list_count = $limit->list_count->getValue(); - if (!$list_count) $list_count = 20; + if(!$list_count) + { + $list_count = 20; + } $page_count = $limit->page_count->getValue(); - if (!$page_count) $page_count = 10; + if(!$page_count) + { + $page_count = 10; + } $page = $limit->page->getValue(); - if (!$page) $page = 1; + if(!$page) + { + $page = 1; + } // total pages - if ($total_count) { + if($total_count) + { $total_page = (int) (($total_count - 1) / $list_count) + 1; } - else { + else + { $total_page = 1; } // check the page variables - if ($page > $total_page) { + if($page > $total_page) + { // If requested page is bigger than total number of pages, return empty list - $buff = new Object (); + $buff = new Object (); $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); + $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); - $query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; - $result = $this->_query ($query, $connection); - if ($this->isError ()) + $query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; + $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); @@ -968,7 +1105,8 @@ class DBCubrid extends DB * @param boolean $force * @return DBParser */ - function getParser($force = FALSE){ + function getParser($force = FALSE) + { return new DBParser('"', '"', $this->prefix); } @@ -980,32 +1118,50 @@ class DBCubrid extends DB * @param int $list_count * @return string select paging sql */ - function getSelectPageSql($query, $with_values = TRUE, $start_count = 0, $list_count = 0) { + function getSelectPageSql($query, $with_values = TRUE, $start_count = 0, $list_count = 0) + { $select = $query->getSelectString($with_values); - if($select == '') return new Object(-1, "Invalid query"); - $select = 'SELECT ' .$select; + if($select == '') + { + return new Object(-1, "Invalid query"); + } + $select = 'SELECT ' . $select; $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); - $from = ' FROM '.$from; + if($from == '') + { + return new Object(-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; + if($groupBy != '') + { + $groupBy = ' GROUP BY ' . $groupBy; + } $orderBy = $query->getOrderByString(); - if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy; + if($orderBy != '') + { + $orderBy = ' ORDER BY ' . $orderBy; + } $limit = $query->getLimitString(); - if ($limit != '') $limit = sprintf (' LIMIT %d, %d', $start_count, $list_count); + if($limit != '') + { + $limit = sprintf(' LIMIT %d, %d', $start_count, $list_count); + } return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit; } -} +} /* End of file DBCubrid.class.php */ /* Location: ./classes/db/DBCubrid.class.php */ diff --git a/classes/db/DBMssql.class.php b/classes/db/DBMssql.class.php index dd0765191..8a7bcd284 100644 --- a/classes/db/DBMssql.class.php +++ b/classes/db/DBMssql.class.php @@ -1,4 +1,5 @@ 'bigint', - 'number' => 'int', - 'varchar' => 'varchar', - 'char' => 'char', - 'text' => 'text', - 'bigtext' => 'text', - 'date' => 'varchar(14)', - 'float' => 'float', - ); + 'bignumber' => 'bigint', + 'number' => 'int', + 'varchar' => 'varchar', + 'char' => 'char', + 'text' => 'text', + 'bigtext' => 'text', + 'date' => 'varchar(14)', + 'float' => 'float', + ); /** * Constructor @@ -61,7 +63,10 @@ class DBMssql extends DB */ function isSupported() { - if (!extension_loaded("sqlsrv")) return false; + if(!extension_loaded("sqlsrv")) + { + return false; + } return true; } @@ -81,7 +86,7 @@ class DBMssql extends DB if(!$result) { $errors = print_r(sqlsrv_errors(), true); - $this->setError (-1, 'database connect fail' . PHP_EOL . $errors); + $this->setError(-1, 'database connect fail' . PHP_EOL . $errors); return; } return $result; @@ -107,7 +112,10 @@ class DBMssql extends DB */ function addQuotes($string) { - if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string)); + if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) + { + $string = stripslashes(str_replace("\\", "\\\\", $string)); + } //if(!is_numeric($string)) $string = str_replace("'","''",$string); return $string; @@ -121,7 +129,10 @@ class DBMssql extends DB function _begin() { $connection = $this->_getConnection('master'); - if(sqlsrv_begin_transaction($connection) === false) return; + if(sqlsrv_begin_transaction($connection) === false) + { + return; + } return true; } @@ -164,12 +175,21 @@ class DBMssql extends DB { foreach($this->param as $k => $o) { - if($o->isColumnName()) continue; + if($o->isColumnName()) + { + continue; + } if($o->getType() == 'number') { $value = $o->getUnescapedValue(); - if(is_array($value)) $_param = array_merge($_param, $value); - else $_param[] = $o->getUnescapedValue(); + if(is_array($value)) + { + $_param = array_merge($_param, $value); + } + else + { + $_param[] = $o->getUnescapedValue(); + } } else { @@ -177,9 +197,14 @@ class DBMssql extends DB if(is_array($value)) { foreach($value as $v) + { $_param[] = array($v, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); + } + } + else + { + $_param[] = array($value, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); } - else $_param[] = array($value, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); } } } @@ -196,18 +221,20 @@ class DBMssql extends DB $stmt = sqlsrv_prepare($connection, $query); } - if(!$stmt) + if(!$stmt) { $result = false; } - else + else { $result = sqlsrv_execute($stmt); } // Error Check - if(!$result) - $this->setError(print_r(sqlsrv_errors(),true)); + if(!$result) + { + $this->setError(print_r(sqlsrv_errors(), true)); + } $this->param = array(); @@ -217,14 +244,16 @@ class DBMssql extends DB /** * Parameters to sqlsrv_prepare need to be references, and not literals * Parameters are sent as an array, where each parameter can be: - * - a PHP variable (by reference) - * - a PHP array (containng param value, type and direction) -> also needs to be sent by reference + * - a PHP variable (by reference) + * - a PHP array (containng param value, type and direction) -> also needs to be sent by reference * @param array $_param * @return array */ - function _getParametersByReference($_param) + function _getParametersByReference($_param) { - $copy = array(); $args = array(); $i = 0; + $copy = array(); + $args = array(); + $i = 0; foreach($_param as $key => $value) { if(is_array($value)) @@ -235,7 +264,7 @@ class DBMssql extends DB $value_arg[] = $value_copy[1]; $value_arg[] = $value_copy[2]; } - else + else { $value_arg = $value; } @@ -254,30 +283,47 @@ class DBMssql extends DB function _fetch($result, $arrayIndexEndValue = NULL) { $output = array(); - if(!$this->isConnected() || $this->isError() || !$result) return $output; + if(!$this->isConnected() || $this->isError() || !$result) + { + return $output; + } $c = sqlsrv_num_fields($result); $m = null; while(sqlsrv_fetch($result)) { - if(!$m) $m = sqlsrv_field_metadata($result); - unset($row); - for($i=0;$i<$c;$i++) + if(!$m) { - $row->{$m[$i]['Name']} = sqlsrv_get_field( $result, $i, SQLSRV_PHPTYPE_STRING( 'utf-8' )); + $m = sqlsrv_field_metadata($result); + } + unset($row); + for($i = 0; $i < $c; $i++) + { + $row->{$m[$i]['Name']} = sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING('utf-8')); + } + if($arrayIndexEndValue) + { + $output[$arrayIndexEndValue--] = $row; + } + else + { + $output[] = $row; } - if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $row; - else $output[] = $row; } - if(count($output)==1) + if(count($output) == 1) { - if(isset($arrayIndexEndValue)) return $output; - else return $output[0]; + if(isset($arrayIndexEndValue)) + { + return $output; + } + else + { + return $output[0]; + } } return $output; - } /** @@ -309,7 +355,10 @@ class DBMssql extends DB $result = $this->_query($query); $tmp = $this->_fetch($result); - if(!$tmp) return false; + if(!$tmp) + { + return false; + } return true; } @@ -323,17 +372,36 @@ class DBMssql extends DB * @param boolean $notnull not null status, default value is false * @return void */ - function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) + function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false) { - if($this->isColumnExists($table_name, $column_name)) return; + if($this->isColumnExists($table_name, $column_name)) + { + return; + } $type = $this->column_type[$type]; - if(strtoupper($type)=='INTEGER') $size = ''; + if(strtoupper($type) == 'INTEGER') + { + $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($default) $query .= sprintf(" default '%s' ", $default); - if($notnull) $query .= " not null "; + 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); } @@ -346,7 +414,10 @@ class DBMssql extends DB */ function dropColumn($table_name, $column_name) { - if(!$this->isColumnExists($table_name, $column_name)) return; + if(!$this->isColumnExists($table_name, $column_name)) + { + return; + } $query = sprintf("alter table %s%s drop %s ", $this->prefix, $table_name, $column_name); $this->_query($query); } @@ -361,9 +432,15 @@ class DBMssql extends DB { $query = sprintf("select syscolumns.name as name from syscolumns, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = syscolumns.id and syscolumns.name = '%s'", $this->prefix, $table_name, $column_name); $result = $this->_query($query); - if($this->isError()) return; + if($this->isError()) + { + return; + } $tmp = $this->_fetch($result); - if(!$tmp->name) return false; + if(!$tmp->name) + { + return false; + } return true; } @@ -379,10 +456,16 @@ class DBMssql extends DB */ function addIndex($table_name, $index_name, $target_columns, $is_unique = false) { - if($this->isIndexExists($table_name, $index_name)) return; - if(!is_array($target_columns)) $target_columns = array($target_columns); + if($this->isIndexExists($table_name, $index_name)) + { + return; + } + if(!is_array($target_columns)) + { + $target_columns = array($target_columns); + } - $query = sprintf("create %s index %s on %s%s (%s)", $is_unique?'unique':'', $index_name, $this->prefix, $table_name, implode(',',$target_columns)); + $query = sprintf("create %s index %s on %s%s (%s)", $is_unique ? 'unique' : '', $index_name, $this->prefix, $table_name, implode(',', $target_columns)); $this->_query($query); } @@ -395,7 +478,10 @@ class DBMssql extends DB */ function dropIndex($table_name, $index_name, $is_unique = false) { - if(!$this->isIndexExists($table_name, $index_name)) return; + if(!$this->isIndexExists($table_name, $index_name)) + { + return; + } $query = sprintf("drop index %s%s.%s", $this->prefix, $table_name, $index_name); $this->_query($query); } @@ -411,10 +497,16 @@ class DBMssql extends DB $query = sprintf("select sysindexes.name as name from sysindexes, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = sysindexes.id and sysindexes.name = '%s'", $this->prefix, $table_name, $index_name); $result = $this->_query($query); - if($this->isError()) return; + if($this->isError()) + { + return; + } $tmp = $this->_fetch($result); - if(!$tmp->name) return false; + if(!$tmp->name) + { + return false; + } return true; } @@ -435,7 +527,10 @@ class DBMssql extends DB */ function createTableByXmlFile($file_name) { - if(!file_exists($file_name)) return; + if(!file_exists($file_name)) + { + return; + } // read xml file $buff = FileHandler::readFile($file_name); return $this->_createTable($buff); @@ -457,26 +552,35 @@ class DBMssql extends DB $xml_obj = $oXml->parse($xml_doc); // Create a table schema $table_name = $xml_obj->table->attrs->name; - if($this->isTableExists($table_name)) return; + if($this->isTableExists($table_name)) + { + return; + } if($table_name == 'sequence') { - $table_name = $this->prefix.$table_name; + $table_name = $this->prefix . $table_name; $query = sprintf('create table %s ( sequence int identity(1,1), seq int )', $table_name); return $this->_query($query); } else { - $table_name = $this->prefix.$table_name; + $table_name = $this->prefix . $table_name; - if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column; - else $columns = $xml_obj->table->column; + if(!is_array($xml_obj->table->column)) + { + $columns[] = $xml_obj->table->column; + } + else + { + $columns = $xml_obj->table->column; + } $primary_list = array(); $unique_list = array(); $index_list = array(); - $typeList = array('number'=>1, 'text'=>1); + $typeList = array('number' => 1, 'text' => 1); foreach($columns as $column) { $name = $column->attrs->name; @@ -489,34 +593,39 @@ class DBMssql extends DB $default = $column->attrs->default; $auto_increment = $column->attrs->auto_increment; - $column_schema[] = sprintf('[%s] %s%s %s %s %s', - $name, - $this->column_type[$type], - !isset($typeList[$type])&&$size?'('.$size.')':'', - isset($default)?"default '".$default."'":'', - $notnull?'not null':'null', - $auto_increment?'identity(1,1)':'' - ); + $column_schema[] = sprintf('[%s] %s%s %s %s %s', $name, $this->column_type[$type], !isset($typeList[$type]) && $size ? '(' . $size . ')' : '', isset($default) ? "default '" . $default . "'" : '', $notnull ? 'not null' : 'null', $auto_increment ? 'identity(1,1)' : ''); - if($primary_key) $primary_list[] = $name; - else if($unique) $unique_list[$unique][] = $name; - else if($index) $index_list[$index][] = $name; + if($primary_key) + { + $primary_list[] = $name; + } + else if($unique) + { + $unique_list[$unique][] = $name; + } + else if($index) + { + $index_list[$index][] = $name; + } } - if(count($primary_list)) + if(count($primary_list)) { - $column_schema[] = sprintf("primary key (%s)", '"'.implode($primary_list,'","').'"'); - } + $column_schema[] = sprintf("primary key (%s)", '"' . implode($primary_list, '","') . '"'); + } - $schema = sprintf('create table [%s] (%s%s)', $this->addQuotes($table_name), "\n", implode($column_schema,",\n")); + $schema = sprintf('create table [%s] (%s%s)', $this->addQuotes($table_name), "\n", implode($column_schema, ",\n")); $output = $this->_query($schema); - if(!$output) return false; + if(!$output) + { + return false; + } if(count($unique_list)) { foreach($unique_list as $key => $val) { - $query = sprintf("create unique index %s on %s (%s);", $key, $table_name, '['.implode('],[',$val).']'); + $query = sprintf("create unique index %s on %s (%s);", $key, $table_name, '[' . implode('],[', $val) . ']'); $this->_query($query); } } @@ -525,7 +634,7 @@ class DBMssql extends DB { foreach($index_list as $key => $val) { - $query = sprintf("create index %s on %s (%s);", $key, $table_name, '['.implode('],[',$val).']'); + $query = sprintf("create index %s on %s (%s);", $key, $table_name, '[' . implode('],[', $val) . ']'); $this->_query($query); } } @@ -533,8 +642,6 @@ class DBMssql extends DB } } - - /** * Handles insertAct * @todo Lookup _filterNumber against sql injection - see if it is still needed and how to integrate @@ -570,24 +677,35 @@ class DBMssql extends DB function getUpdateSql($query, $with_values = true, $with_priority = false) { $columnsList = $query->getUpdateString($with_values); - if($columnsList == '') return new Object(-1, "Invalid query"); + if($columnsList == '') + { + return new Object(-1, "Invalid query"); + } $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); + if($from == '') + { + return new Object(-1, "Invalid query"); + } $tables = $query->getTables(); $alias_list = ''; foreach($tables as $table) + { $alias_list .= $table->getAlias(); + } implode(',', explode(' ', $alias_list)); $where = $query->getWhereString($with_values); - if($where != '') $where = ' WHERE ' . $where; + if($where != '') + { + $where = ' WHERE ' . $where; + } - $priority = $with_priority?$query->getPriority():''; + $priority = $with_priority ? $query->getPriority() : ''; - return "UPDATE $priority $alias_list SET $columnsList FROM ".$from.$where; - } + return "UPDATE $priority $alias_list SET $columnsList FROM " . $from . $where; + } /** * Handles deleteAct @@ -614,31 +732,56 @@ class DBMssql extends DB //$limitOffset = $query->getLimit()->getOffset(); //if($limitOffset) // TODO Implement Limit with offset with subquery - $limit = '';$limitCount = ''; + $limit = ''; + $limitCount = ''; $limitQueryPart = $query->getLimit(); if($limitQueryPart) + { $limitCount = $limitQueryPart->getLimit(); - if($limitCount != '') $limit = 'SELECT TOP ' . $limitCount; + } + if($limitCount != '') + { + $limit = 'SELECT TOP ' . $limitCount; + } $select = $query->getSelectString($with_values); - if($select == '') return new Object(-1, "Invalid query"); + if($select == '') + { + return new Object(-1, "Invalid query"); + } if($limit != '') - $select = $limit.' '.$select; + { + $select = $limit . ' ' . $select; + } else - $select = 'SELECT ' .$select; + { + $select = 'SELECT ' . $select; + } $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); - $from = ' FROM '.$from; + if($from == '') + { + return new Object(-1, "Invalid query"); + } + $from = ' FROM ' . $from; $where = $query->getWhereString($with_values); - if($where != '') $where = ' WHERE ' . $where; + if($where != '') + { + $where = ' WHERE ' . $where; + } $groupBy = $query->getGroupByString(); - if($groupBy != '') $groupBy = ' GROUP BY ' . $groupBy; + if($groupBy != '') + { + $groupBy = ' GROUP BY ' . $groupBy; + } $orderBy = $query->getOrderByString(); - if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy; + if($orderBy != '') + { + $orderBy = ' ORDER BY ' . $orderBy; + } return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy; } @@ -655,16 +798,25 @@ class DBMssql extends DB { $query = $this->getSelectSql($queryObject); - if(strpos($query, "substr")) $query = str_replace ("substr", "substring", $query); + if(strpos($query, "substr")) + { + $query = str_replace("substr", "substring", $query); + } // TODO Decide if we continue to pass parameters like this $this->param = $queryObject->getArguments(); - $query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):''; + $query .= (__DEBUG_QUERY__ & 1 && $output->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; $result = $this->_query($query, $connection); - if ($this->isError ()) return $this->queryError($queryObject); - else return $this->queryPageLimit($queryObject, $result, $connection); + if($this->isError()) + { + return $this->queryError($queryObject); + } + else + { + return $this->queryPageLimit($queryObject, $result, $connection); + } } /** @@ -685,18 +837,20 @@ class DBMssql extends DB function queryError($queryObject) { $limit = $queryObject->getLimit(); - if ($limit && $limit->isPageHandler()) + if($limit && $limit->isPageHandler()) { $buff = new Object (); $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 + $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; + } } /** @@ -709,7 +863,7 @@ class DBMssql extends DB function queryPageLimit($queryObject, $result, $connection) { $limit = $queryObject->getLimit(); - if ($limit && $limit->isPageHandler()) + if($limit && $limit->isPageHandler()) { // Total count $temp_where = $queryObject->getWhereString(true, false); @@ -724,9 +878,9 @@ class DBMssql extends DB $count_query = sprintf('select %s %s %s %s' , $temp_select , 'FROM ' . $queryObject->getFromString(true) - , ($temp_where === '' ? '' : ' WHERE '. $temp_where) + , ($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); @@ -739,24 +893,32 @@ class DBMssql extends DB $total_count = (int) $count_output->count; $list_count = $limit->list_count->getValue(); - if (!$list_count) + if(!$list_count) + { $list_count = 20; + } $page_count = $limit->page_count->getValue(); - if (!$page_count) + if(!$page_count) + { $page_count = 10; + } $page = $limit->page->getValue(); - if (!$page) + if(!$page) + { $page = 1; + } // Total pages - if ($total_count) + 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($page > $total_page) { // If requested page is bigger than total number of pages, return empty list diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index ab431ef8b..67a05d784 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -1,4 +1,5 @@ 'bigint', - 'number' => 'bigint', - 'varchar' => 'varchar', - 'char' => 'char', - 'text' => 'text', - 'bigtext' => 'longtext', - 'date' => 'varchar(14)', - 'float' => 'float', - ); + 'bignumber' => 'bigint', + 'number' => 'bigint', + 'varchar' => 'varchar', + 'char' => 'char', + 'text' => 'text', + 'bigtext' => 'longtext', + 'date' => 'varchar(14)', + 'float' => 'float', + ); /** * Constructor @@ -62,7 +64,10 @@ class DBMysql extends DB */ function isSupported() { - if(!function_exists('mysql_connect')) return false; + if(!function_exists('mysql_connect')) + { + return false; + } return true; } @@ -75,8 +80,10 @@ class DBMysql extends DB function __connect($connection) { // Ignore if no DB information exists - if (strpos($connection["db_hostname"], ':') === false && $connection["db_port"]) + if(strpos($connection["db_hostname"], ':') === false && $connection["db_port"]) + { $connection["db_hostname"] .= ':' . $connection["db_port"]; + } // Attempt to connect $result = @mysql_connect($connection["db_hostname"], $connection["db_userid"], $connection["db_password"]); @@ -87,9 +94,9 @@ class DBMysql extends DB return; } // Error appears if the version is lower than 4.1 - if(mysql_get_server_info($result)<"4.1") + if(mysql_get_server_info($result) < "4.1") { - $this->setError(-1, "XE cannot be installed under the version of mysql 4.1. Current mysql version is ".mysql_get_server_info()); + $this->setError(-1, "XE cannot be installed under the version of mysql 4.1. Current mysql version is " . mysql_get_server_info()); return; } // select db @@ -133,8 +140,14 @@ class DBMysql extends DB */ function addQuotes($string) { - if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string)); - if(!is_numeric($string)) $string = @mysql_real_escape_string($string); + if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) + { + $string = stripslashes(str_replace("\\", "\\\\", $string)); + } + if(!is_numeric($string)) + { + $string = @mysql_real_escape_string($string); + } return $string; } @@ -180,7 +193,10 @@ class DBMysql extends DB // Run the query statement $result = mysql_query($query, $connection); // Error Check - if(mysql_error($connection)) $this->setError(mysql_errno($connection), mysql_error($connection)); + if(mysql_error($connection)) + { + $this->setError(mysql_errno($connection), mysql_error($connection)); + } // Return result return $result; } @@ -194,16 +210,31 @@ class DBMysql extends DB function _fetch($result, $arrayIndexEndValue = NULL) { $output = array(); - if(!$this->isConnected() || $this->isError() || !$result) return $output; + if(!$this->isConnected() || $this->isError() || !$result) + { + return $output; + } while($tmp = $this->db_fetch_object($result)) { - if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $tmp; - else $output[] = $tmp; + if($arrayIndexEndValue) + { + $output[$arrayIndexEndValue--] = $tmp; + } + else + { + $output[] = $tmp; + } } - if(count($output)==1) + if(count($output) == 1) { - if(isset($arrayIndexEndValue)) return $output; - else return $output[0]; + if(isset($arrayIndexEndValue)) + { + return $output; + } + else + { + return $output[0]; + } } $this->db_free_result($result); return $output; @@ -239,7 +270,10 @@ class DBMysql extends DB $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; + if($tmp->password == $saved_password || $tmp->old_password == $saved_password) + { + return true; + } return false; } @@ -253,7 +287,10 @@ class DBMysql extends DB $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; + if(!$tmp) + { + return false; + } return true; } @@ -267,16 +304,31 @@ class DBMysql extends DB * @param boolean $notnull not null status, default value is false * @return void */ - function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) + function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false) { $type = $this->column_type[$type]; - if(strtoupper($type)=='INTEGER') $size = ''; + if(strtoupper($type) == 'INTEGER') + { + $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($default) $query .= sprintf(" default '%s' ", $default); - if($notnull) $query .= " not null "; + 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); } @@ -303,7 +355,10 @@ class DBMysql extends DB { $query = sprintf("show fields from `%s%s`", $this->prefix, $table_name); $result = $this->_query($query); - if($this->isError()) return; + if($this->isError()) + { + return; + } $output = $this->_fetch($result); if($output) { @@ -311,7 +366,10 @@ class DBMysql extends DB foreach($output as $key => $val) { $name = strtolower($val->Field); - if($column_name == $name) return true; + if($column_name == $name) + { + return true; + } } } return false; @@ -329,9 +387,12 @@ class DBMysql extends DB */ function addIndex($table_name, $index_name, $target_columns, $is_unique = false) { - if(!is_array($target_columns)) $target_columns = array($target_columns); + 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)); + $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); } @@ -348,7 +409,6 @@ class DBMysql extends DB $this->_query($query); } - /** * Check index status of the table * @param string $table_name table name @@ -360,14 +420,26 @@ class DBMysql extends DB //$query = sprintf("show indexes from %s%s where key_name = '%s' ", $this->prefix, $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;$iisError()) { - if($output[$i]->Key_name == $index_name) return true; + 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; } @@ -389,7 +461,10 @@ class DBMysql extends DB */ function createTableByXmlFile($file_name) { - if(!file_exists($file_name)) return; + if(!file_exists($file_name)) + { + return; + } // read xml file $buff = FileHandler::readFile($file_name); return $this->_createTable($buff); @@ -411,11 +486,20 @@ class DBMysql extends DB $xml_obj = $oXml->parse($xml_doc); // Create a table schema $table_name = $xml_obj->table->attrs->name; - if($this->isTableExists($table_name)) return; - $table_name = $this->prefix.$table_name; + if($this->isTableExists($table_name)) + { + return; + } + $table_name = $this->prefix . $table_name; - if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column; - else $columns = $xml_obj->table->column; + if(!is_array($xml_obj->table->column)) + { + $columns[] = $xml_obj->table->column; + } + else + { + $columns = $xml_obj->table->column; + } $primary_list = array(); $unique_list = array(); @@ -433,30 +517,32 @@ class DBMysql extends DB $default = $column->attrs->default; $auto_increment = $column->attrs->auto_increment; - $column_schema[] = sprintf('`%s` %s%s %s %s %s', - $name, - $this->column_type[$type], - $size?'('.$size.')':'', - isset($default)?"default '".$default."'":'', - $notnull?'not null':'', - $auto_increment?'auto_increment':'' - ); + $column_schema[] = sprintf('`%s` %s%s %s %s %s', $name, $this->column_type[$type], $size ? '(' . $size . ')' : '', isset($default) ? "default '" . $default . "'" : '', $notnull ? 'not null' : '', $auto_increment ? 'auto_increment' : ''); - if($primary_key) $primary_list[] = $name; - else if($unique) $unique_list[$unique][] = $name; - else if($index) $index_list[$index][] = $name; + if($primary_key) + { + $primary_list[] = $name; + } + else if($unique) + { + $unique_list[$unique][] = $name; + } + else if($index) + { + $index_list[$index][] = $name; + } } if(count($primary_list)) { - $column_schema[] = sprintf("primary key (%s)", '`'.implode($primary_list,'`,`').'`'); + $column_schema[] = sprintf("primary key (%s)", '`' . implode($primary_list, '`,`') . '`'); } if(count($unique_list)) { foreach($unique_list as $key => $val) { - $column_schema[] = sprintf("unique %s (%s)", $key, '`'.implode($val,'`,`').'`'); + $column_schema[] = sprintf("unique %s (%s)", $key, '`' . implode($val, '`,`') . '`'); } } @@ -464,14 +550,15 @@ class DBMysql extends DB { foreach($index_list as $key => $val) { - $column_schema[] = sprintf("index %s (%s)", $key, '`'.implode($val,'`,`').'`'); + $column_schema[] = sprintf("index %s (%s)", $key, '`' . implode($val, '`,`') . '`'); } } - $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"), "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci"); + $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema, ",\n"), "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci"); $output = $this->_query($schema); - if(!$output) return false; + if(!$output) + return false; } /** @@ -484,7 +571,10 @@ class DBMysql extends DB { $query = $this->getInsertSql($queryObject, $with_values, true); $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; - if(is_a($query, 'Object')) return; + if(is_a($query, 'Object')) + { + return; + } return $this->_query($query); } @@ -498,7 +588,10 @@ class DBMysql extends DB { $query = $this->getUpdateSql($queryObject, $with_values, true); $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; - if(is_a($query, 'Object')) return; + if(is_a($query, 'Object')) + { + return; + } return $this->_query($query); } @@ -512,7 +605,10 @@ class DBMysql extends DB { $query = $this->getDeleteSql($queryObject, $with_values, true); $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; - if(is_a($query, 'Object')) return; + if(is_a($query, 'Object')) + { + return; + } return $this->_query($query); } @@ -529,18 +625,24 @@ class DBMysql extends DB { $limit = $queryObject->getLimit(); $result = NULL; - if ($limit && $limit->isPageHandler()) + if($limit && $limit->isPageHandler()) + { return $this->queryPageLimit($queryObject, $result, $connection, $with_values); + } else { $query = $this->getSelectSql($queryObject, $with_values); - if (is_a($query, 'Object')) + if(is_a($query, 'Object')) + { return; + } $query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(' ' . $this->comment_syntax, $queryObject->queryID) : ''; $result = $this->_query($query, $connection); - if ($this->isError()) + if($this->isError()) + { return $this->queryError($queryObject); + } $data = $this->_fetch($result); $buff = new Object (); @@ -607,18 +709,20 @@ class DBMysql extends DB function queryError($queryObject) { $limit = $queryObject->getLimit(); - if ($limit && $limit->isPageHandler()) + if($limit && $limit->isPageHandler()) { $buff = new Object (); $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 + $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; + } } /** @@ -634,7 +738,7 @@ class DBMysql extends DB $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)); + $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); @@ -645,34 +749,47 @@ class DBMysql extends DB $count_query = sprintf('select %s %s %s %s' , $temp_select == '*' ? '1' : $temp_select , 'FROM ' . $queryObject->getFromString($with_values) - , ($temp_where === '' ? '' : ' WHERE '. $temp_where) + , ($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); } - $count_query .= (__DEBUG_QUERY__&1 && $queryObject->queryID)?sprintf (' '.$this->comment_syntax, $queryObject->queryID):''; + $count_query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(' ' . $this->comment_syntax, $queryObject->queryID) : ''; $result_count = $this->_query($count_query, $connection); $count_output = $this->_fetch($result_count); - $total_count = (int)(isset($count_output->count) ? $count_output->count : NULL); + $total_count = (int) (isset($count_output->count) ? $count_output->count : NULL); $list_count = $limit->list_count->getValue(); - if (!$list_count) $list_count = 20; + if(!$list_count) + { + $list_count = 20; + } $page_count = $limit->page_count->getValue(); - if (!$page_count) $page_count = 10; + if(!$page_count) + { + $page_count = 10; + } $page = $limit->page->getValue(); - if (!$page) $page = 1; + if(!$page) + { + $page = 1; + } // total pages - if ($total_count) + 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($page > $total_page) { // If requested page is bigger than total number of pages, return empty list $buff = new Object (); @@ -687,10 +804,12 @@ class DBMysql extends DB $query = $this->getSelectPageSql($queryObject, $with_values, $start_count, $list_count); - $query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):''; - $result = $this->_query ($query, $connection); - if ($this->isError ()) + $query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; + $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); @@ -715,27 +834,46 @@ class DBMysql extends DB function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) { $select = $query->getSelectString($with_values); - if($select == '') return new Object(-1, "Invalid query"); - $select = 'SELECT ' .$select; + if($select == '') + { + return new Object(-1, "Invalid query"); + } + $select = 'SELECT ' . $select; $from = $query->getFromString($with_values); - if($from == '') return new Object(-1, "Invalid query"); - $from = ' FROM '.$from; + if($from == '') + { + return new Object(-1, "Invalid query"); + } + $from = ' FROM ' . $from; $where = $query->getWhereString($with_values); - if($where != '') $where = ' WHERE ' . $where; + if($where != '') + { + $where = ' WHERE ' . $where; + } $groupBy = $query->getGroupByString(); - if($groupBy != '') $groupBy = ' GROUP BY ' . $groupBy; + if($groupBy != '') + { + $groupBy = ' GROUP BY ' . $groupBy; + } $orderBy = $query->getOrderByString(); - if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy; + if($orderBy != '') + { + $orderBy = ' ORDER BY ' . $orderBy; + } $limit = $query->getLimitString(); - if ($limit != '') $limit = sprintf (' LIMIT %d, %d', $start_count, $list_count); + if($limit != '') + { + $limit = sprintf(' LIMIT %d, %d', $start_count, $list_count); + } return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit; } + } /* End of file DBMysql.class.php */ /* Location: ./classes/db/DBMysql.class.php */ diff --git a/classes/db/DBMysql_innodb.class.php b/classes/db/DBMysql_innodb.class.php index c62ad709a..857bbb16c 100644 --- a/classes/db/DBMysql_innodb.class.php +++ b/classes/db/DBMysql_innodb.class.php @@ -1,5 +1,7 @@ setError(mysql_errno($connection), mysql_error($connection)); + if(mysql_error($connection)) + { + $this->setError(mysql_errno($connection), mysql_error($connection)); + } // Return result return $result; } @@ -113,11 +118,20 @@ class DBMysql_innodb extends DBMysql $xml_obj = $oXml->parse($xml_doc); // Create a table schema $table_name = $xml_obj->table->attrs->name; - if($this->isTableExists($table_name)) return; - $table_name = $this->prefix.$table_name; + if($this->isTableExists($table_name)) + { + return; + } + $table_name = $this->prefix . $table_name; - if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column; - else $columns = $xml_obj->table->column; + if(!is_array($xml_obj->table->column)) + { + $columns[] = $xml_obj->table->column; + } + else + { + $columns = $xml_obj->table->column; + } foreach($columns as $column) { @@ -131,30 +145,32 @@ class DBMysql_innodb extends DBMysql $default = $column->attrs->default; $auto_increment = $column->attrs->auto_increment; - $column_schema[] = sprintf('`%s` %s%s %s %s %s', - $name, - $this->column_type[$type], - $size?'('.$size.')':'', - isset($default)?"default '".$default."'":'', - $notnull?'not null':'', - $auto_increment?'auto_increment':'' - ); + $column_schema[] = sprintf('`%s` %s%s %s %s %s', $name, $this->column_type[$type], $size ? '(' . $size . ')' : '', isset($default) ? "default '" . $default . "'" : '', $notnull ? 'not null' : '', $auto_increment ? 'auto_increment' : ''); - if($primary_key) $primary_list[] = $name; - else if($unique) $unique_list[$unique][] = $name; - else if($index) $index_list[$index][] = $name; + if($primary_key) + { + $primary_list[] = $name; + } + else if($unique) + { + $unique_list[$unique][] = $name; + } + else if($index) + { + $index_list[$index][] = $name; + } } if(count($primary_list)) { - $column_schema[] = sprintf("primary key (%s)", '`'.implode($primary_list,'`,`').'`'); + $column_schema[] = sprintf("primary key (%s)", '`' . implode($primary_list, '`,`') . '`'); } if(count($unique_list)) { foreach($unique_list as $key => $val) { - $column_schema[] = sprintf("unique %s (%s)", $key, '`'.implode($val,'`,`').'`'); + $column_schema[] = sprintf("unique %s (%s)", $key, '`' . implode($val, '`,`') . '`'); } } @@ -162,15 +178,19 @@ class DBMysql_innodb extends DBMysql { foreach($index_list as $key => $val) { - $column_schema[] = sprintf("index %s (%s)", $key, '`'.implode($val,'`,`').'`'); + $column_schema[] = sprintf("index %s (%s)", $key, '`' . implode($val, '`,`') . '`'); } } - $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"), "ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci"); + $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema, ",\n"), "ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci"); $output = $this->_query($schema); - if(!$output) return false; + if(!$output) + { + return false; + } } + } /* End of file DBMysql_innodb.class.php */ /* Location: ./classes/db/DBMysql_innodb.class.php */ diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index af3b944e8..2f4f4f723 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -1,4 +1,5 @@ setError($error,mysqli_connect_error()); + $this->setError($error, mysqli_connect_error()); return; } - mysqli_set_charset($result,'utf8'); + mysqli_set_charset($result, 'utf8'); return $result; } @@ -95,11 +100,14 @@ class DBMysqli extends DBMysql { */ function addQuotes($string) { - if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string)); + if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) + { + $string = stripslashes(str_replace("\\", "\\\\", $string)); + } if(!is_numeric($string)) { $connection = $this->_getConnection('master'); - $string = mysqli_escape_string($connection,$string); + $string = mysqli_escape_string($connection, $string); } return $string; } @@ -114,7 +122,7 @@ class DBMysqli extends DBMysql { function __query($query, $connection) { if($this->use_prepared_statements == 'Y') - { + { // 1. Prepare query $stmt = mysqli_prepare($connection, $query); if($stmt) @@ -126,7 +134,7 @@ class DBMysqli extends DBMysql { if(!empty($params)) { $args[0] = $stmt; - $args[1] = $types; + $args[1] = $types; $i = 2; foreach($params as $key => $param) @@ -136,25 +144,28 @@ class DBMysqli extends DBMysql { } // 2. Bind parameters - $status = call_user_func_array('mysqli_stmt_bind_param',$args); + $status = call_user_func_array('mysqli_stmt_bind_param', $args); if(!$status) - $this->setError(-1, "Invalid arguments: $query" . mysqli_error($connection) . PHP_EOL . print_r($args, true)); + { + $this->setError(-1, "Invalid arguments: $query" . mysqli_error($connection) . PHP_EOL . print_r($args, true)); + } } // 3. Execute query $status = mysqli_stmt_execute($stmt); if(!$status) + { $this->setError(-1, "Prepared statement failed: $query" . mysqli_error($connection) . PHP_EOL . print_r($args, true)); + } // Return stmt for other processing - like retrieving resultset (_fetch) return $stmt; // mysqli_stmt_close($stmt); } - } // Run the query statement - $result = mysqli_query($connection,$query); + $result = mysqli_query($connection, $query); // Error Check $error = mysqli_error($connection); if($error) @@ -176,7 +187,10 @@ class DBMysqli extends DBMysql { { $types = ''; $params = array(); - if(!$this->param) return; + if(!$this->param) + { + return; + } foreach($this->param as $k => $o) { @@ -184,21 +198,24 @@ class DBMysqli extends DBMysql { $type = $o->getType(); // Skip column names -> this should be concatenated to query string - if($o->isColumnName()) continue; + if($o->isColumnName()) + { + continue; + } switch($type) { - case 'number' : - $type = 'i'; + case 'number' : + $type = 'i'; break; - case 'varchar' : - $type = 's'; - break; - default: + case 'varchar' : $type = 's'; - } + break; + default: + $type = 's'; + } - if(is_array($value)) + if(is_array($value)) { foreach($value as $v) { @@ -211,10 +228,7 @@ class DBMysqli extends DBMysql { $params[] = $value; $types .= $type; } - - - - } + } } /** @@ -230,7 +244,10 @@ class DBMysqli extends DBMysql { return parent::_fetch($result, $arrayIndexEndValue); } $output = array(); - if(!$this->isConnected() || $this->isError() || !$result) return $output; + if(!$this->isConnected() || $this->isError() || !$result) + { + return $output; + } // Prepared stements: bind result variable and fetch data $stmt = $result; @@ -246,13 +263,18 @@ class DBMysqli extends DBMysql { foreach($fields as $field) { if(isset($resultArray[$field->name])) // When joined tables are used and the same column name appears twice, we should add it separately, otherwise bind_result fails - $field->name = 'repeat_' . $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; + if($field->type == 252) + { + $longtext_exists = true; + } } $resultArray = array_merge(array($stmt), $resultArray); @@ -270,15 +292,21 @@ class DBMysqli extends DBMysql { foreach($resultArray as $key => $value) { - if($key === 0) continue; // Skip stmt object - if(strpos($key, 'repeat_')) $key = substr($key, 6); + if($key === 0) + { + continue; // Skip stmt object + } + if(strpos($key, 'repeat_')) + { + $key = substr($key, 6); + } $resultObject->$key = $value; } $rows[] = $resultObject; } - mysqli_stmt_close($stmt); + mysqli_stmt_close($stmt); if($arrayIndexEndValue) { @@ -287,19 +315,25 @@ class DBMysqli extends DBMysql { $output[$arrayIndexEndValue--] = $row; } } - else + else { $output = $rows; } - if(count($output)==1) + if(count($output) == 1) { - if(isset($arrayIndexEndValue)) return $output; - else return $output[0]; + if(isset($arrayIndexEndValue)) + { + return $output; + } + else + { + return $output[0]; + } } return $output; - } + } /** * Handles insertAct @@ -307,7 +341,8 @@ class DBMysqli extends DBMysql { * @param boolean $with_values * @return resource */ - function _executeInsertAct($queryObject, $with_values = false){ + function _executeInsertAct($queryObject, $with_values = false) + { if($this->use_prepared_statements != 'Y') { return parent::_executeInsertAct($queryObject); @@ -324,11 +359,12 @@ class DBMysqli extends DBMysql { * @param boolean $with_values * @return resource */ - function _executeUpdateAct($queryObject, $with_values = false) { + function _executeUpdateAct($queryObject, $with_values = false) + { if($this->use_prepared_statements != 'Y') { return parent::_executeUpdateAct($queryObject); - } + } $this->param = $queryObject->getArguments(); $result = parent::_executeUpdateAct($queryObject, $with_values); unset($this->param); @@ -341,16 +377,17 @@ class DBMysqli extends DBMysql { * @param boolean $with_values * @return resource */ - function _executeDeleteAct($queryObject, $with_values = false) { + function _executeDeleteAct($queryObject, $with_values = false) + { if($this->use_prepared_statements != 'Y') { return parent::_executeDeleteAct($queryObject); - } + } $this->param = $queryObject->getArguments(); $result = parent::_executeDeleteAct($queryObject, $with_values); unset($this->param); return $result; - } + } /** * Handle selectAct @@ -366,9 +403,9 @@ class DBMysqli extends DBMysql { if($this->use_prepared_statements != 'Y') { return parent::_executeSelectAct($queryObject, $connection); - } + } $this->param = $queryObject->getArguments(); - $result = parent::_executeSelectAct($queryObject, $connection, $with_values); + $result = parent::_executeSelectAct($queryObject, $connection, $with_values); unset($this->param); return $result; } @@ -382,7 +419,7 @@ class DBMysqli extends DBMysql { function db_insert_id() { $connection = $this->_getConnection('master'); - return mysqli_insert_id($connection); + return mysqli_insert_id($connection); } /** @@ -402,8 +439,9 @@ class DBMysqli extends DBMysql { */ function db_free_result(&$result) { - return mysqli_free_result($result); - } + return mysqli_free_result($result); + } + } /* End of file DBMysqli.class.php */ /* Location: ./classes/db/DBMysqli.class.php */ diff --git a/classes/db/queryparts/Query.class.php b/classes/db/queryparts/Query.class.php index 5a75ce3f2..6c6b266e9 100644 --- a/classes/db/queryparts/Query.class.php +++ b/classes/db/queryparts/Query.class.php @@ -1,4 +1,5 @@ queryID = $queryID; $this->action = $action; $this->priority = $priority; - if(!isset($tables)) return; + if(!isset($tables)) + { + return; + } + $this->columns = $this->setColumns($columns); $this->tables = $this->setTables($tables); $this->conditions = $this->setConditions($conditions); @@ -153,7 +166,10 @@ class Query extends Object return; } - if(!is_array($columns)) $columns = array($columns); + if(!is_array($columns)) + { + $columns = array($columns); + } $this->columns = $columns; } @@ -167,7 +183,10 @@ class Query extends Object return; } - if(!is_array($tables)) $tables = array($tables); + if(!is_array($tables)) + { + $tables = array($tables); + } $this->tables = $tables; } @@ -180,34 +199,58 @@ class Query extends Object function setConditions($conditions) { $this->conditions = array(); - if(!isset($conditions) || count($conditions) === 0) return; - if(!is_array($conditions)) $conditions = array($conditions); + if(!isset($conditions) || count($conditions) === 0) + { + return; + } + if(!is_array($conditions)) + { + $conditions = array($conditions); + } foreach($conditions as $conditionGroup) { - if($conditionGroup->show()) $this->conditions[] = $conditionGroup; + if($conditionGroup->show()) + { + $this->conditions[] = $conditionGroup; + } } } function setGroups($groups) { - if(!isset($groups) || count($groups) === 0) return; - if(!is_array($groups)) $groups = array($groups); + if(!isset($groups) || count($groups) === 0) + { + return; + } + if(!is_array($groups)) + { + $groups = array($groups); + } $this->groups = $groups; } function setOrder($order) { - if(!isset($order) || count($order) === 0) return; - if(!is_array($order)) $order = array($order); + if(!isset($order) || count($order) === 0) + { + return; + } + if(!is_array($order)) + { + $order = array($order); + } $this->orderby = $order; } function setLimit($limit = NULL) { - if(!isset($limit)) return; + if(!isset($limit)) + { + return; + } $this->limit = $limit; } @@ -217,7 +260,7 @@ class Query extends Object * @param string|array $columns * @return Query return Query instance */ - function select($columns= NULL) + function select($columns = NULL) { $this->action = 'select'; $this->setColumns($columns); @@ -278,6 +321,7 @@ class Query extends Object $this->setLimit($limit); return $this; } + // END Fluent interface function getAction() @@ -287,7 +331,7 @@ class Query extends Object function getPriority() { - return $this->priority?'LOW_PRIORITY':''; + return $this->priority ? 'LOW_PRIORITY' : ''; } /** @@ -304,9 +348,12 @@ class Query extends Object function getClickCountColumns() { $click_count_columns = array(); - foreach($this->columns as $column){ + foreach($this->columns as $column) + { if($column->show() && is_a($column, 'ClickCountExpression')) + { $click_count_columns[] = $column; + } } return $click_count_columns; } @@ -321,12 +368,16 @@ class Query extends Object foreach($this->columns as $column) { if($column->show()) + { if($column->isSubquery()) { - $select[] = $column->toString($with_values) . ' as '. $column->getAlias(); + $select[] = $column->toString($with_values) . ' as ' . $column->getAlias(); } else + { $select[] = $column->getExpression($with_values); + } + } } return trim(implode($select, ', ')); } @@ -341,7 +392,9 @@ class Query extends Object foreach($this->columns as $column) { if($column->show()) + { $update[] = $column->getExpression($with_values); + } } return trim(implode($update, ', ')); } @@ -401,14 +454,26 @@ class Query extends Object $simple_table_count = 0; foreach($this->tables as $table) { - if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' '; - else $from .= ', '.$table->toString($with_values) . ' '; + if($table->isJoinTable() || !$simple_table_count) + { + $from .= $table->toString($with_values) . ' '; + } + else + { + $from .= ', ' . $table->toString($with_values) . ' '; + } - if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' '; + if(is_a($table, 'Subquery')) + { + $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' '; + } $simple_table_count++; } - if(trim($from) == '') return ''; + if(trim($from) == '') + { + return ''; + } return $from; } @@ -435,11 +500,13 @@ class Query extends Object } if($with_optimization && - (strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) + (strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) { if($condition_count !== 0) + { $where = '(' . $where . ') '; + } foreach($this->orderby as $order) { @@ -448,7 +515,9 @@ class Query extends Object { $opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and'); if($condition_count === 0) + { $opt_condition->setPipe(""); + } $where .= $opt_condition->toString($with_values) . ' '; $condition_count++; } @@ -465,8 +534,13 @@ class Query extends Object function getGroupByString() { $groupBy = ''; - if($this->groups) if($this->groups[0] !== "") - $groupBy = implode(', ', $this->groups); + if($this->groups) + { + if($this->groups[0] !== "") + { + $groupBy = implode(', ', $this->groups); + } + } return $groupBy; } @@ -478,11 +552,14 @@ class Query extends Object { if(!$this->_orderByString) { - if(count($this->orderby) === 0) return ''; + if(count($this->orderby) === 0) + { + return ''; + } $orderBy = ''; foreach($this->orderby as $order) { - $orderBy .= $order->toString() .', '; + $orderBy .= $order->toString() . ', '; } $orderBy = substr($orderBy, 0, -2); $this->_orderByString = $orderBy; @@ -533,7 +610,10 @@ class Query extends Object if($table->isJoinTable() || is_a($table, 'Subquery')) { $args = $table->getArguments(); - if($args) $this->arguments = array_merge($this->arguments, $args); + if($args) + { + $this->arguments = array_merge($this->arguments, $args); + } } } } @@ -547,30 +627,43 @@ class Query extends Object if($column->show()) { $args = $column->getArguments(); - if($args) $this->arguments = array_merge($this->arguments, $args); + if($args) + { + $this->arguments = array_merge($this->arguments, $args); + } } } } // Condition arguments if(count($this->conditions) > 0) + { foreach($this->conditions as $conditionGroup) { $args = $conditionGroup->getArguments(); - if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args); + if(count($args) > 0) + { + $this->arguments = array_merge($this->arguments, $args); + } } + } // Navigation arguments if(count($this->orderby) > 0) + { foreach($this->orderby as $order) { $args = $order->getArguments(); - if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args); + if(count($args) > 0) + { + $this->arguments = array_merge($this->arguments, $args); + } } + } } return $this->arguments; } -} +} /* End of file Query.class.php */ /* Location: ./classes/db/queryparts/Query.class.php */ diff --git a/classes/db/queryparts/Subquery.class.php b/classes/db/queryparts/Subquery.class.php index 29445e911..53c3b7bb0 100644 --- a/classes/db/queryparts/Subquery.class.php +++ b/classes/db/queryparts/Subquery.class.php @@ -1,4 +1,5 @@ join_type) return true; + if($this->join_type) + { + return true; + } return false; } @@ -60,14 +66,14 @@ class Subquery extends Query { $oDB = &DB::getInstance(); - return '(' .$oDB->getSelectSql($this, $with_values) . ')'; - + 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 index c12422acc..211f8d59d 100644 --- a/classes/db/queryparts/condition/Condition.class.php +++ b/classes/db/queryparts/condition/Condition.class.php @@ -1,4 +1,5 @@ _value_to_string)) + if(!isset($this->_value_to_string)) { - if (!$this->show()) + if(!$this->show()) { $this->_value_to_string = ''; } - else if ($withValue) + else if($withValue) { $this->_value_to_string = $this->toStringWithValue(); } @@ -135,17 +137,34 @@ class Condition case 'not': case 'notequal' : // 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($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; + $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;} + if(!is_array($this->_value)) + { + $this->_show = false; + break; + } + if(count($this->_value) != 2) + { + $this->_show = false; + break; + } case 'null': case 'notnull': break; @@ -171,67 +190,68 @@ class Condition switch($operation) { case 'equal' : - return $name.' = '.$value; + return $name . ' = ' . $value; break; case 'more' : - return $name.' >= '.$value; + return $name . ' >= ' . $value; break; case 'excess' : - return $name.' > '.$value; + return $name . ' > ' . $value; break; case 'less' : - return $name.' <= '.$value; + return $name . ' <= ' . $value; break; case 'below' : - return $name.' < '.$value; + return $name . ' < ' . $value; break; case 'like_tail' : case 'like_prefix' : case 'like' : - if(defined('__CUBRID_VERSION__') - && __CUBRID_VERSION__ >= '8.4.1') - return $name.' rlike '.$value; + if(defined('__CUBRID_VERSION__') + && __CUBRID_VERSION__ >= '8.4.1') + return $name . ' rlike ' . $value; else - return $name.' like '.$value; + return $name . ' like ' . $value; break; case 'notlike_tail' : case 'notlike_prefix' : case 'notlike' : - return $name.' not like '.$value; + return $name . ' not like ' . $value; break; case 'in' : - return $name.' in '.$value; + return $name . ' in ' . $value; break; case 'notin' : case 'not_in' : - return $name.' not in '.$value; + return $name . ' not in ' . $value; break; case 'notequal' : - return $name.' <> '.$value; + return $name . ' <> ' . $value; break; case 'notnull' : - return $name.' is not null'; + return $name . ' is not null'; break; case 'null' : - return $name.' is null'; + return $name . ' is null'; break; case 'and' : - return $name.' & '.$value; + return $name . ' & ' . $value; break; case 'or' : - return $name.' | '.$value; + return $name . ' | ' . $value; break; case 'xor' : - return $name.' ^ '.$value; + return $name . ' ^ ' . $value; break; case 'not' : - return $name.' ~ '.$value; + return $name . ' ~ ' . $value; break; case 'between' : - return $name.' between ' . $value[0] . ' and ' . $value[1]; + 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 index 8ddd45746..1a0962dde 100644 --- a/classes/db/queryparts/condition/ConditionGroup.class.php +++ b/classes/db/queryparts/condition/ConditionGroup.class.php @@ -1,4 +1,5 @@ show()) + { $this->conditions[] = $condition; + } + } + if(count($this->conditions) === 0) + { + $this->_show = false; + } + else + { + $this->_show = true; } - if(count($this->conditions) === 0) $this->_show = false; - else $this->_show = true; $this->pipe = $pipe; } @@ -47,7 +57,10 @@ class ConditionGroup function setPipe($pipe) { - if($this->pipe !== $pipe) $this->_group = null; + if($this->pipe !== $pipe) + { + $this->_group = null; + } $this->pipe = $pipe; } @@ -65,7 +78,10 @@ class ConditionGroup foreach($this->conditions as $condition) { - if($cond_indx === 0) $condition->setPipe(""); + if($cond_indx === 0) + { + $condition->setPipe(""); + } $group .= $condition->toString($with_value) . ' '; $cond_indx++; } @@ -90,10 +106,14 @@ class ConditionGroup foreach($this->conditions as $condition) { $arg = $condition->getArgument(); - if($arg) $args[] = $arg; + 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 index 602d541b6..b286db23b 100644 --- a/classes/db/queryparts/condition/ConditionSubquery.class.php +++ b/classes/db/queryparts/condition/ConditionSubquery.class.php @@ -1,4 +1,5 @@ _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 index 5ca585bd2..08366d64e 100644 --- a/classes/db/queryparts/condition/ConditionWithArgument.class.php +++ b/classes/db/queryparts/condition/ConditionWithArgument.class.php @@ -1,4 +1,5 @@ _show = false; return; } + if($argument === null) + { + $this->_show = false; + return; + } parent::Condition($column_name, $argument, $operation, $pipe); $this->_value = $argument->getValue(); } function getArgument() { - if(!$this->show()) return; + if(!$this->show()) + return; return $this->argument; } @@ -38,11 +45,17 @@ class ConditionWithArgument extends Condition if(is_array($value)) { $q = ''; - foreach ($value as $v) $q .= '?,'; - if($q !== '') $q = substr($q, 0, -1); + foreach($value as $v) + { + $q .= '?,'; + } + if($q !== '') + { + $q = substr($q, 0, -1); + } $q = '(' . $q . ')'; } - else + else { // Prepared statements: column names should not be sent as query arguments, but instead concatenated to query string if($this->argument->isColumnName()) @@ -64,8 +77,14 @@ class ConditionWithArgument extends Condition { if(!isset($this->_show)) { - if(!$this->argument->isValid()) $this->_show = false; - if($this->_value === '\'\'') $this->_show = false; + if(!$this->argument->isValid()) + { + $this->_show = false; + } + if($this->_value === '\'\'') + { + $this->_show = false; + } if(!isset($this->_show)) { return parent::show(); @@ -73,6 +92,7 @@ class ConditionWithArgument extends Condition } 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 index bfd229d6a..a028f5b67 100644 --- a/classes/db/queryparts/condition/ConditionWithoutArgument.class.php +++ b/classes/db/queryparts/condition/ConditionWithoutArgument.class.php @@ -1,4 +1,5 @@ 1, 'notin'=>1, 'not_in'=>1); + $tmpArray = array('in' => 1, 'notin' => 1, 'not_in' => 1); if(isset($tmpArray[$operation])) { - if(is_array($argument)) $argument = implode($argument, ','); - $this->_value = '('. $argument .')'; + 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 index e7be5eb9c..50f48da5f 100644 --- a/classes/db/queryparts/expression/ClickCountExpression.class.php +++ b/classes/db/queryparts/expression/ClickCountExpression.class.php @@ -1,4 +1,5 @@ -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 index b8db1198d..c86a4d4fb 100644 --- a/classes/db/queryparts/expression/DeleteExpression.class.php +++ b/classes/db/queryparts/expression/DeleteExpression.class.php @@ -1,4 +1,5 @@ -value)) return "'".$this->value."'"; + if(!is_numeric($this->value)) + { + return "'" . $this->value . "'"; + } return $this->value; } function show() { - if(!$this->value) return false; + 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 index d398a742b..463f107ed 100644 --- a/classes/db/queryparts/expression/Expression.class.php +++ b/classes/db/queryparts/expression/Expression.class.php @@ -1,4 +1,5 @@ argument->getValue(); + } return '?'; } function show() { - if(!$this->argument) return false; + if(!$this->argument) + { + return false; + } $value = $this->argument->getValue(); - if(!isset($value)) return false; + if(!isset($value)) + { + return false; + } return true; } @@ -48,11 +58,16 @@ class InsertExpression extends Expression function getArguments() { - if ($this->argument) + 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 index 1bfe661be..6ae36d52b 100644 --- a/classes/db/queryparts/expression/SelectExpression.class.php +++ b/classes/db/queryparts/expression/SelectExpression.class.php @@ -1,4 +1,5 @@ column_name, $this->column_alias ? " as ".$this->column_alias : ""); + return sprintf("%s%s", $this->column_name, $this->column_alias ? " as " . $this->column_alias : ""); } function show() @@ -61,6 +63,7 @@ class SelectExpression extends Expression { 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 index be0d9d6ce..f010c8593 100644 --- a/classes/db/queryparts/expression/StarExpression.class.php +++ b/classes/db/queryparts/expression/StarExpression.class.php @@ -1,4 +1,5 @@ -getExpressionWithValue(); + } return $this->getExpressionWithoutValue(); } @@ -46,7 +50,9 @@ class UpdateExpression extends Expression $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"; } @@ -59,7 +65,9 @@ class UpdateExpression extends Expression { $operation = $this->argument->getColumnOperation(); if(isset($operation)) + { return "$this->column_name = $this->column_name $operation ?"; + } return "$this->column_name = ?"; } @@ -67,15 +75,24 @@ class UpdateExpression extends Expression { // TODO Escape value according to column type instead of variable type $value = $this->argument->getValue(); - if(!is_numeric($value)) return "'".$value."'"; + if(!is_numeric($value)) + { + return "'" . $value . "'"; + } return $value; } function show() { - if(!$this->argument) return false; + if(!$this->argument) + { + return false; + } $value = $this->argument->getValue(); - if(!isset($value)) return false; + if(!isset($value)) + { + return false; + } return true; } @@ -86,12 +103,16 @@ class UpdateExpression extends Expression function getArguments() { - if ($this->argument) + 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 index 6388f6350..38123f221 100644 --- a/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php +++ b/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php @@ -1,4 +1,5 @@ argument; - if(!is_numeric($value)) return "'".$value."'"; + if(!is_numeric($value)) + { + return "'" . $value . "'"; + } return $value; } function show() { - if(!$this->argument) return false; + if(!$this->argument) + { + return false; + } $value = $this->argument; - if(!isset($value)) return false; + if(!isset($value)) + { + return false; + } return true; } @@ -56,6 +67,7 @@ class UpdateExpressionWithoutArgument extends UpdateExpression { 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 index be2cddf7f..bce192d08 100644 --- a/classes/db/queryparts/limit/Limit.class.php +++ b/classes/db/queryparts/limit/Limit.class.php @@ -1,4 +1,5 @@ -list_count = $list_count; - if ($page) + if($page) { $list_count_value = $list_count->getValue(); $page_value = $page->getValue(); @@ -53,8 +58,14 @@ class Limit */ function isPageHandler() { - if ($this->page)return true; - else return false; + if($this->page) + { + return true; + } + else + { + return false; + } } function getOffset() @@ -69,9 +80,16 @@ class Limit function toString() { - if ($this->page) return $this->start . ' , ' . $this->list_count->getValue(); - else return $this->list_count->getValue(); + if($this->page) + { + 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 index 20e736eda..54bdd5dfb 100644 --- a/classes/db/queryparts/order/OrderByColumn.class.php +++ b/classes/db/queryparts/order/OrderByColumn.class.php @@ -1,4 +1,5 @@ -column_name, 'Argument')) - $args[]= $this->column_name; + { + $args[] = $this->column_name; + } if(is_a($this->sort_order, 'Argument')) - $args[] = $this->sort_order; + { + $args[] = $this->sort_order; + } } + } /* End of file OrderByColumn.class.php */ /* Location: ./classes/db/order/OrderByColumn.class.php */ diff --git a/classes/db/queryparts/table/CubridTableWithHint.class.php b/classes/db/queryparts/table/CubridTableWithHint.class.php index 843ebeb72..d807891a5 100644 --- a/classes/db/queryparts/table/CubridTableWithHint.class.php +++ b/classes/db/queryparts/table/CubridTableWithHint.class.php @@ -1,4 +1,5 @@ alias . '.' - . '"' . $prefix . substr($index_hint->getIndexName(), 1) - . ($index_hint_type == 'FORCE' ? '(+)' : '') - . ', '; + . '"' . $prefix . substr($index_hint->getIndexName(), 1) + . ($index_hint_type == 'FORCE' ? '(+)' : '') + . ', '; } } $result = substr($result, 0, -2); return $result; } + } /* End of file CubridTableWithHint.class.php */ /* Location: ./classes/db/queryparts/table/CubridTableWithHint.class.php */ diff --git a/classes/db/queryparts/table/IndexHint.class.php b/classes/db/queryparts/table/IndexHint.class.php index 301248c2b..1772c7cda 100644 --- a/classes/db/queryparts/table/IndexHint.class.php +++ b/classes/db/queryparts/table/IndexHint.class.php @@ -1,4 +1,5 @@ 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 index cda1100a8..da5f951ca 100644 --- a/classes/db/queryparts/table/JoinTable.class.php +++ b/classes/db/queryparts/table/JoinTable.class.php @@ -1,4 +1,5 @@ -join_type . ' ' . $this->name ; + $part = $this->join_type . ' ' . $this->name; $part .= $this->alias ? ' as ' . $this->alias : ''; $part .= ' on '; foreach($this->conditions as $conditionGroup) + { $part .= $conditionGroup->toString($with_value); + } return $part; } @@ -54,9 +59,12 @@ class JoinTable extends Table { $args = array(); foreach($this->conditions as $conditionGroup) - $args = array_merge($args, $conditionGroup->getArguments()); + { + $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/MssqlTableWithHint.class.php b/classes/db/queryparts/table/MssqlTableWithHint.class.php index a3e70d4ff..f33ba136f 100644 --- a/classes/db/queryparts/table/MssqlTableWithHint.class.php +++ b/classes/db/queryparts/table/MssqlTableWithHint.class.php @@ -1,4 +1,5 @@ 1, 'FORCE'=>1); + $indexTypeList = array('USE' => 1, 'FORCE' => 1); foreach($this->index_hints_list as $index_hint) { $index_hint_type = $index_hint->getIndexHintType(); if(isset($indexTypeList[$index_hint_type])) + { $index_hint_string .= 'INDEX(' . $index_hint->getIndexName() . '), '; + } } if($index_hint_string != '') { @@ -53,6 +59,7 @@ class MssqlTableWithHint extends Table } return $result; } + } /* End of file MssqlTableWithHint.class.php */ /* Location: ./classes/db/queryparts/table/MssqlTableWithHint.class.php */ diff --git a/classes/db/queryparts/table/MysqlTableWithHint.class.php b/classes/db/queryparts/table/MysqlTableWithHint.class.php index 210fbdbf2..24ff7c51a 100644 --- a/classes/db/queryparts/table/MysqlTableWithHint.class.php +++ b/classes/db/queryparts/table/MysqlTableWithHint.class.php @@ -1,4 +1,5 @@ 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($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 != '') { @@ -61,6 +76,7 @@ class MysqlTableWithHint extends Table } 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 index 527d4b32d..05a3e084f 100644 --- a/classes/db/queryparts/table/Table.class.php +++ b/classes/db/queryparts/table/Table.class.php @@ -1,4 +1,5 @@ -