51 'notnull' =>
'is not null',
135 private $transactionNestedLevel = 0;
150 return new BaseObject(-1,
'msg_db_not_setted');
159 $class_name =
'DB' . ucfirst($db_type);
160 $class_file =
_XE_PATH_ .
"classes/db/$class_name.class.php";
161 if(!file_exists($class_file))
163 return new BaseObject(-1,
'msg_db_not_setted');
167 require_once($class_file);
168 $GLOBALS[
'__DB__'][
$db_type] = call_user_func(array($class_name,
'create'));
203 return $oDB->_getSupportedList();
213 if(!self::$supported_list)
216 self::$supported_list = $oDB->_getSupportedList();
219 $enableList = array();
220 if(is_array(self::$supported_list))
222 foreach(self::$supported_list AS $key => $value)
226 $enableList[] = $value;
240 if(!self::$supported_list)
243 self::$supported_list = $oDB->_getSupportedList();
246 $disableList = array();
247 if(is_array(self::$supported_list))
249 foreach(self::$supported_list AS $key => $value)
253 $disableList[] = $value;
267 static $get_supported_list =
'';
268 if(is_array($get_supported_list))
270 self::$supported_list = $get_supported_list;
271 return self::$supported_list;
273 $get_supported_list = array();
274 $db_classes_path =
_XE_PATH_ .
"classes/db/";
275 $filter =
"/^DB([^\.]+)\.class\.php/i";
283 $class_name = sprintf(
"DB%s%s", strtoupper(substr(
$db_type, 0, 1)), strtolower(substr(
$db_type, 1)));
284 $class_file = sprintf(
_XE_PATH_ .
"classes/db/%s.class.php", $class_name);
285 if(!file_exists($class_file))
291 require_once($class_file);
292 $oDB =
new $class_name(FALSE);
301 $obj->enable = $oDB->isSupported() ? TRUE : FALSE;
303 $get_supported_list[] =
$obj;
307 @usort($get_supported_list, array($this,
'_sortDBMS'));
309 self::$supported_list = $get_supported_list;
310 return self::$supported_list;
318 if(!isset($this->priority_dbms[$a->db_type]))
324 $priority_a = $this->priority_dbms[$a->db_type];
327 if(!isset($this->priority_dbms[$b->db_type]))
333 $priority_b = $this->priority_dbms[$b->db_type];
336 if($priority_a == $priority_b)
341 return ($priority_a > $priority_b) ? -1 : 1;
351 return self::$isSupported;
362 if($type ==
'master')
364 return $this->master_db[
"is_connected"] ? TRUE : FALSE;
368 return $this->slave_db[$indx][
"is_connected"] ? TRUE : FALSE;
382 $this->elapsed_time = 0;
405 $log[
'query_id'] = $this->query_id;
406 $log[
'module'] = $site_module_info->module;
408 $log[
'time'] = date(
'Y-m-d H:i:s');
410 $bt = version_compare(PHP_VERSION,
'5.3.6',
'>=') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace();
412 foreach($bt as $no => $call)
414 if($call[
'function'] ==
'executeQuery' || $call[
'function'] ==
'executeQueryArray')
418 $log[
'called_file'] = $bt[$call_no][
'file'].
':'.$bt[$call_no][
'line'];
419 $log[
'called_file'] = str_replace(
_XE_PATH_ ,
'', $log[
'called_file']);
421 $log[
'called_method'] = $bt[$call_no][
'class'].$bt[$call_no][
'type'].$bt[$call_no][
'function'];
429 $log[
'result'] =
'Failed';
433 if(__DEBUG_DB_OUTPUT__ == 1)
435 $debug_file =
_XE_PATH_ .
"files/_debug_db_query.php";
437 if(!file_exists($debug_file))
439 $buff[] =
'<?php exit(); ?' .
'>';
441 $buff[] = print_r($log, TRUE);
442 @file_put_contents($debug_file, implode(
"\n", $buff) .
"\n\n", FILE_APPEND|LOCK_EX);
447 $log[
'result'] =
'Success';
452 $log_args =
new stdClass;
454 $log_args->query_id = $this->query_id;
455 $log_args->caller = $log[
'called_method'] .
'() in ' . $log[
'called_file'];
456 $log_args->connection = $log[
'connection'];
467 $GLOBALS[
'__db_queries__'][] = $log;
488 return ($this->errno !== 0);
498 return new BaseObject($this->errno, $this->errstr);
515 return new BaseObject(-1,
'msg_invalid_queryid');
524 $this->query_id = $query_id;
528 $id_args = explode(
'.', $query_id);
529 if(count($id_args) == 2)
532 $module = $id_args[0];
535 elseif(count($id_args) == 3)
537 $target = $id_args[0];
538 $typeList = array(
'addons' => 1,
'widgets' => 1);
539 if(!isset($typeList[$target]))
544 $module = $id_args[1];
547 if(!$target || !$module || !$id)
550 return new BaseObject(-1,
'msg_invalid_queryid');
553 $xml_file = sprintf(
'%s%s/%s/queries/%s.xml',
_XE_PATH_, $target, $module, $id);
554 if(!file_exists($xml_file))
557 return new BaseObject(-1,
'msg_invalid_queryid');
588 if($cache_time < filemtime($xml_file) || $cache_time < filemtime(
_XE_PATH_ .
'classes/db/DB.class.php') || $cache_time < filemtime(
_XE_PATH_ .
'classes/xml/XmlQueryParser.class.php'))
591 $oParser->parse($query_id, $xml_file,
$cache_file);
609 if(!in_array($type, array(
'master',
'slave'))) $type =
'slave';
613 return new BaseObject(-1,
'msg_invalid_queryid');
618 $args = clone $source_args;
632 case 'insert-select' :
645 $arg_columns = is_array($arg_columns) ? $arg_columns : array();
646 $output->setColumnList($arg_columns);
656 else if(!is_a(
$output,
'BaseObject') && !is_subclass_of(
$output,
'BaseObject'))
660 $output->add(
'_query', $this->query);
661 $output->add(
'_elapsed_time', sprintf(
"%0.5f", $this->elapsed_time));
806 $query = sprintf(
"drop table %s%s", $this->prefix, $table_name);
818 $select =
$query->getSelectString($with_values);
823 $select =
'SELECT ' . $select;
825 $from =
$query->getFromString($with_values);
830 $from =
' FROM ' . $from;
832 $where =
$query->getWhereString($with_values);
835 $where =
' WHERE ' . $where;
838 $tableObjects =
$query->getTables();
839 $index_hint_list =
'';
840 foreach($tableObjects as $tableObject)
842 if(is_a($tableObject,
'CubridTableWithHint'))
844 $index_hint_list .= $tableObject->getIndexHintString() .
', ';
847 $index_hint_list = substr($index_hint_list, 0, -2);
848 if($index_hint_list !=
'')
850 $index_hint_list =
'USING INDEX ' . $index_hint_list;
853 $groupBy =
$query->getGroupByString();
856 $groupBy =
' GROUP BY ' . $groupBy;
859 $orderBy =
$query->getOrderByString();
862 $orderBy =
' ORDER BY ' . $orderBy;
865 $limit =
$query->getLimitString();
868 $limit =
' LIMIT ' . $limit;
871 return $select .
' ' . $from .
' ' . $where .
' ' . $index_hint_list .
' ' . $groupBy .
' ' . $orderBy .
' ' . $limit;
887 $new_update_columns = array();
888 $click_count_columns = $queryObject->getClickCountColumns();
889 foreach($click_count_columns as $click_count_column)
891 $click_count_column_name = $click_count_column->column_name;
893 $increase_by_1 =
new Argument($click_count_column_name, null);
894 $increase_by_1->setColumnOperation(
'+');
895 $increase_by_1->ensureDefaultValue(1);
897 $update_expression =
new UpdateExpression($click_count_column_name, $increase_by_1);
898 $new_update_columns[] = $update_expression;
900 $queryObject->columns = $new_update_columns;
915 $sql .= $with_priority ?
$query->getPriority() :
'';
916 $tables =
$query->getTables();
918 $sql .= $tables[0]->getAlias();
920 $from =
$query->getFromString($with_values);
925 $sql .=
' FROM ' . $from;
927 $where =
$query->getWhereString($with_values);
930 $sql .=
' WHERE ' . $where;
945 $columnsList =
$query->getUpdateString($with_values);
946 if($columnsList ==
'')
951 $tables =
$query->getFromString($with_values);
957 $where =
$query->getWhereString($with_values);
960 $where =
' WHERE ' . $where;
963 $priority = $with_priority ?
$query->getPriority() :
'';
965 return "UPDATE $priority $tables SET $columnsList " . $where;
977 $tableName =
$query->getFirstTableName();
978 $values =
$query->getInsertString($with_values);
979 $priority = $with_priority ?
$query->getPriority() :
'';
981 return "INSERT $priority INTO $tableName \n $values";
990 $max = count($this->slave_db);
991 $indx = rand(0, $max - 1);
1003 if($type ==
'master')
1005 if(!$this->master_db[
'is_connected'])
1009 $this->connection =
'Master ' . $this->master_db[
'db_hostname'];
1010 return $this->master_db[
"resource"];
1018 if(!$this->slave_db[$indx][
'is_connected'])
1023 $this->connection =
'Slave ' . $this->slave_db[$indx][
'db_hostname'];
1024 return $this->slave_db[$indx][
"resource"];
1033 if(!$this->master_db)
1037 if(count($this->slave_db) === 0)
1061 function close($type =
'master', $indx = 0)
1068 if($type ==
'master')
1104 if($this->
_begin($this->transactionNestedLevel))
1106 $this->transaction_started = TRUE;
1107 $this->transactionNestedLevel++;
1127 if(!$this->
isConnected() || !$this->transaction_started)
1131 if($this->
_rollback($this->transactionNestedLevel))
1133 $this->transactionNestedLevel--;
1135 if(!$this->transactionNestedLevel)
1137 $this->transaction_started = FALSE;
1159 if(!$force && (!$this->
isConnected() || !$this->transaction_started))
1163 if($this->transactionNestedLevel == 1 && $this->
_commit())
1165 $this->transaction_started = FALSE;
1166 $this->transactionNestedLevel = 0;
1170 $this->transactionNestedLevel--;
1219 $this->master_db = $db_info->master_db;
1220 if($db_info->master_db[
"db_hostname"] == $db_info->slave_db[0][
"db_hostname"]
1221 && $db_info->master_db[
"db_port"] == $db_info->slave_db[0][
"db_port"]
1222 && $db_info->master_db[
"db_userid"] == $db_info->slave_db[0][
"db_userid"]
1223 && $db_info->master_db[
"db_password"] == $db_info->slave_db[0][
"db_password"]
1224 && $db_info->master_db[
"db_database"] == $db_info->slave_db[0][
"db_database"]
1231 $this->slave_db = $db_info->slave_db;
1233 $this->prefix = $db_info->master_db[
"db_table_prefix"];
1234 $this->use_prepared_statements = $db_info->use_prepared_statements;
1279 if($type ==
'master')
1300 $this->connection = ucfirst($type) .
' ' .
$connection[
"db_hostname"];
1303 register_shutdown_function(array($this,
"close"));
1316 $this->elapsed_dbclass_time = 0;
1347 static $dbParser = NULL;
1348 if(!$dbParser || $force)
1351 $dbParser = $oDB->getParser();
setError($errno=0, $errstr= 'success')
_getSlaveConnectionStringIndex()
_executeQuery($cache_file, $source_args, $query_id, $arg_columns, $type)
getUpdateSql($query, $with_values=TRUE, $with_priority=FALSE)
putCountCache($tables, $condition, $count=0)
getClickCountQuery($queryObject)
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
getInsertSql($query, $with_values=TRUE, $with_priority=FALSE)
close($type= 'master', $indx=0)
isConnected($type= 'master', $indx=0)
checkQueryCacheFile($query_id, $xml_file)
getDeleteSql($query, $with_values=TRUE, $with_priority=FALSE)
executeQuery($query_id, $args=NULL, $arg_columns=NULL, $type=NULL)
_afterConnect($connection)
getInstance($db_type=NULL)
__query($query, $connection)
_connect($type= 'master', $indx=0)
_getConnection($type= 'master', $indx=NULL)
getSelectSql($query, $with_values=TRUE)
_query($query, $connection=NULL)
getCountCache($tables, $condition)
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
writeSlowlog($type, $elapsed_time, $obj)
_rollback($transactionLevel=0)
if(isset($_REQUEST['encode'])) if(isset($_REQUEST['decode'])) $lang
_begin($transactionLevel=0)