merge changes of luminous to maserati (~r12676)

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12680 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-04 08:09:07 +00:00
commit 0f04bd3f92
50 changed files with 784 additions and 265 deletions

View file

@ -14,6 +14,7 @@ if(!defined('__XE_LOADED_DB_CLASS__'))
require(_XE_PATH_.'classes/db/queryparts/expression/InsertExpression.class.php');
require(_XE_PATH_.'classes/db/queryparts/expression/UpdateExpression.class.php');
require(_XE_PATH_.'classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php');
require(_XE_PATH_.'classes/db/queryparts/expression/ClickCountExpression.class.php');
require(_XE_PATH_.'classes/db/queryparts/table/Table.class.php');
require(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
require(_XE_PATH_.'classes/db/queryparts/table/CubridTableWithHint.class.php');
@ -123,9 +124,9 @@ class DB
* transaction flag
* @var boolean
*/
var $transaction_started = false;
var $transaction_started = FALSE;
var $is_connected = false;
var $is_connected = FALSE;
/**
* returns enable list in supported dbms list
@ -269,7 +270,7 @@ class DB
$get_supported_list = array();
$db_classes_path = _XE_PATH_."classes/db/";
$filter = "/^DB([^\.]+)\.class\.php/i";
$supported_list = FileHandler::readDir($db_classes_path, $filter, true);
$supported_list = FileHandler::readDir($db_classes_path, $filter, TRUE);
// after creating instance of class, check is supported
for($i = 0; $i < count($supported_list); $i++)
@ -289,9 +290,9 @@ class DB
if(!$oDB) continue;
$obj = null;
$obj = NULL;
$obj->db_type = $db_type;
$obj->enable = $oDB->isSupported() ? true : false;
$obj->enable = $oDB->isSupported() ? TRUE : FALSE;
$get_supported_list[] = $obj;
}
@ -352,8 +353,8 @@ 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;
}
/**
@ -402,7 +403,7 @@ class DB
$debug_file = _XE_PATH_."files/_debug_db_query.php";
$buff = array();
if(!file_exists($debug_file)) $buff[] = '<?php exit(); ?>';
$buff[] = print_r($log, true);
$buff[] = print_r($log, TRUE);
if(@!$fp = fopen($debug_file, "a")) return;
fwrite($fp, implode("\n", $buff)."\n\n");
@ -453,7 +454,7 @@ class DB
*/
function isError()
{
return $this->errno === 0 ? false : true;
return $this->errno === 0 ? FALSE : TRUE;
}
/**
@ -617,8 +618,8 @@ class DB
*/
function getCountCache($tables, $condition)
{
return false;
if(!$tables) return false;
return FALSE;
if(!$tables) return FALSE;
if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path);
$condition = md5($condition);
@ -630,7 +631,7 @@ class DB
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);
@ -638,7 +639,7 @@ class DB
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;
if(!file_exists($table_filename) || filemtime($table_filename) > $cache_mtime) return FALSE;
}
$count = (int)FileHandler::readFile($cache_filename);
@ -654,8 +655,8 @@ class DB
*/
function putCountCache($tables, $condition, $count = 0)
{
return false;
if(!$tables) return false;
return FALSE;
if(!$tables) return FALSE;
if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path);
$condition = md5($condition);
@ -678,8 +679,8 @@ class DB
*/
function resetCountCache($tables)
{
return false;
if(!$tables) return false;
return FALSE;
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);
@ -690,7 +691,7 @@ class DB
FileHandler::writeFile($filename, '');
}
return true;
return TRUE;
}
/**
@ -730,7 +731,7 @@ class DB
* @param boolean $with_values
* @return string
*/
function getSelectSql($query, $with_values = true)
function getSelectSql($query, $with_values = TRUE)
{
$select = $query->getSelectString($with_values);
if($select == '') return new Object(-1, "Invalid query");
@ -766,6 +767,36 @@ class DB
return $select . ' ' . $from . ' ' . $where . ' ' . $index_hint_list . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
}
/**
* Given a SELECT statement that uses click count
* returns the corresponding update sql string
* for databases that don't have click count support built in
* (aka all besides CUBRID)
*
* Function does not check if click count columns exist!
* You must call $query->usesClickCount() before using this function
*
* @param $queryObject
*/
function getClickCountQuery($queryObject)
{
$new_update_columns = array();
$click_count_columns = $queryObject->getClickCountColumns();
foreach($click_count_columns as $click_count_column)
{
$click_count_column_name = $click_count_column->column_name;
$increase_by_1 = new Argument($click_count_column_name, null);
$increase_by_1->setColumnOperation('+');
$increase_by_1->ensureDefaultValue(1);
$update_expression = new UpdateExpression($click_count_column_name, $increase_by_1);
$new_update_columns[] = $update_expression;
}
$queryObject->columns = $new_update_columns;
return $queryObject;
}
/**
* Return delete query string
* @param object $query
@ -773,7 +804,7 @@ class DB
* @param boolean $with_priority
* @return string
*/
function getDeleteSql($query, $with_values = true, $with_priority = false)
function getDeleteSql($query, $with_values = TRUE, $with_priority = FALSE)
{
$sql = 'DELETE ';
@ -799,7 +830,7 @@ class DB
* @param boolean $with_priority
* @return string
*/
function getUpdateSql($query, $with_values = true, $with_priority = false)
function getUpdateSql($query, $with_values = TRUE, $with_priority = FALSE)
{
$columnsList = $query->getUpdateString($with_values);
if($columnsList == '') return new Object(-1, "Invalid query");
@ -822,7 +853,7 @@ class DB
* @param boolean $with_priority
* @return string
*/
function getInsertSql($query, $with_values = true, $with_priority = false)
function getInsertSql($query, $with_values = TRUE, $with_priority = FALSE)
{
$tableName = $query->getFirstTableName();
$values = $query->getInsertString($with_values);
@ -875,10 +906,10 @@ class DB
function _dbInfoExists()
{
if (!$this->master_db)
return false;
return FALSE;
if (count($this->slave_db) === 0)
return false;
return true;
return FALSE;
return TRUE;
}
/**
@ -910,7 +941,7 @@ class DB
$this->_close($connection["resource"]);
$connection["is_connected"] = false;
$connection["is_connected"] = FALSE;
}
/**
@ -920,7 +951,7 @@ class DB
*/
function _begin()
{
return true;
return TRUE;
}
/**
@ -933,7 +964,7 @@ class DB
return;
if($this->_begin())
$this->transaction_started = true;
$this->transaction_started = TRUE;
}
/**
@ -943,7 +974,7 @@ class DB
*/
function _rollback()
{
return true;
return TRUE;
}
/**
@ -955,7 +986,7 @@ class DB
if (!$this->isConnected() || !$this->transaction_started)
return;
if($this->_rollback())
$this->transaction_started = false;
$this->transaction_started = FALSE;
}
/**
@ -965,7 +996,7 @@ class DB
*/
function _commit()
{
return true;
return TRUE;
}
/**
@ -973,12 +1004,12 @@ class DB
* @param boolean $force regardless transaction start status or connect status, forced to commit
* @return void
*/
function commit($force = false)
function commit($force = FALSE)
{
if (!$force && (!$this->isConnected() || !$this->transaction_started))
return;
if($this->_commit())
$this->transaction_started = false;
$this->transaction_started = FALSE;
}
/**
@ -1000,9 +1031,9 @@ class DB
* @param resource $connection
* @return resource
*/
function _query($query, $connection = null)
function _query($query, $connection = NULL)
{
if($connection == null)
if($connection == NULL)
$connection = $this->_getConnection('master');
// Notify to start a query execution
$this->actStart($query);
@ -1082,15 +1113,15 @@ class DB
$connection = &$this->slave_db[$indx];
$result = $this->__connect($connection);
if($result === NULL || $result === false)
if($result === NULL || $result === FALSE)
{
$connection["is_connected"] = false;
$connection["is_connected"] = FALSE;
return;
}
// Check connections
$connection["resource"] = $result;
$connection["is_connected"] = true;
$connection["is_connected"] = TRUE;
// Save connection info for db logs
$this->connection = ucfirst($type) . ' ' . $connection["db_hostname"];
@ -1132,9 +1163,9 @@ class DB
* @param boolean $force force load DBParser instance
* @return DBParser
*/
function &getParser($force = false)
function &getParser($force = FALSE)
{
static $dbParser = null;
static $dbParser = NULL;
if(!$dbParser || $force)
{
$oDB = &DB::getInstance();

View file

@ -767,6 +767,12 @@ class DBMssql extends DB
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
if($queryObject->usesClickCount())
{
$update_query = $this->getClickCountQuery($queryObject);
$this->_executeUpdateAct($update_query);
}
}
$start_count = ($page - 1) * $list_count;

View file

@ -545,6 +545,13 @@ class DBMysql extends DB
$data = $this->_fetch($result);
$buff = new Object ();
$buff->data = $data;
if($queryObject->usesClickCount())
{
$update_query = $this->getClickCountQuery($queryObject);
$this->_executeUpdateAct($update_query, $with_values);
}
return $buff;
}
}

View file

@ -57,13 +57,13 @@ class Query extends Object
* argument list
* @var array
*/
var $arguments = null;
var $arguments = NULL;
/**
* column list
* @var array
*/
var $columnList = null;
var $columnList = NULL;
/**
* order by text
@ -84,15 +84,15 @@ class Query extends Object
* @param string $priority
* @return void
*/
function Query($queryID = null
, $action = null
, $columns = null
, $tables = null
, $conditions = null
, $groups = null
, $orderby = null
, $limit = null
, $priority = null)
function Query($queryID = NULL
, $action = NULL
, $columns = NULL
, $tables = NULL
, $conditions = NULL
, $groups = NULL
, $orderby = NULL
, $limit = NULL
, $priority = NULL)
{
$this->queryID = $queryID;
$this->action = $action;
@ -109,7 +109,7 @@ class Query extends Object
function show()
{
return true;
return TRUE;
}
function setQueryId($queryID)
@ -162,7 +162,7 @@ class Query extends Object
{
if(!isset($tables) || count($tables) === 0)
{
$this->setError(true);
$this->setError(TRUE);
$this->setMessage("You must provide at least one table for the query.");
return;
}
@ -217,7 +217,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);
@ -290,12 +290,33 @@ class Query extends Object
return $this->priority?'LOW_PRIORITY':'';
}
/**
* Check if current query uses the click count attribute
* For CUBRID, this statement uses the click count feature.
* For the other databases, using this attribute causes a query
* to produce both a select and an update
*/
function usesClickCount()
{
return count($this->getClickCountColumns()) > 0;
}
function getClickCountColumns()
{
$click_count_columns = array();
foreach($this->columns as $column){
if($column->show() && is_a($column, 'ClickCountExpression'))
$click_count_columns[] = $column;
}
return $click_count_columns;
}
/**
* Return select sql
* @param boolean $with_values
* @return string
*/
function getSelectString($with_values = true)
function getSelectString($with_values = TRUE)
{
foreach($this->columns as $column)
{
@ -315,7 +336,7 @@ class Query extends Object
* @param boolean $with_values
* @return string
*/
function getUpdateString($with_values = true)
function getUpdateString($with_values = TRUE)
{
foreach($this->columns as $column)
{
@ -330,7 +351,7 @@ class Query extends Object
* @param boolean $with_values
* @return string
*/
function getInsertString($with_values = true)
function getInsertString($with_values = TRUE)
{
$columnsList = '';
// means we have insert-select
@ -374,7 +395,7 @@ class Query extends Object
* @param boolean $with_values
* @return string
*/
function getFromString($with_values = true)
function getFromString($with_values = TRUE)
{
$from = '';
$simple_table_count = 0;
@ -397,7 +418,7 @@ class Query extends Object
* @param boolean $with_optimization
* @return string
*/
function getWhereString($with_values = true, $with_optimization = true)
function getWhereString($with_values = TRUE, $with_optimization = TRUE)
{
$where = '';
$condition_count = 0;

View file

@ -26,9 +26,8 @@ class ClickCountExpression extends SelectExpression
if(!is_bool($click_count))
{
error_log("Click_count value for $column_name was not boolean", 0);
// error_log("Click_count value for $column_name was not boolean", 0);
$this->click_count = false;
return;
}
$this->click_count = $click_count;
}
@ -44,7 +43,15 @@ class ClickCountExpression extends SelectExpression
*/
function getExpression()
{
return "$this->column_name = $this->column_name + 1";
$db_type = Context::getDBType();
if($db_type == 'cubrid')
{
return "INCR($this->column_name)";
}
else
{
return "$this->column_name";
}
}
}