reverse merge from 1.6.0 (r10563)

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10711 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-05-17 00:57:29 +00:00
parent 09dc853b4d
commit f0aa085c94
9 changed files with 292 additions and 53 deletions

View file

@ -854,4 +854,4 @@
} }
} }
?> ?>

View file

@ -784,7 +784,7 @@
$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); $result = $this->_query($count_query, $connection);
$count_output = $this->_fetch($result); $count_output = $this->_fetch($result);
$total_count = (int)(isset($count_output->count) ? $count_output->count : NULL); $total_count = (int)(isset($count_output->output) ? $count_output->count : NULL);
$list_count = $limit->list_count->getValue(); $list_count = $limit->list_count->getValue();
if (!$list_count) $list_count = 20; if (!$list_count) $list_count = 20;
@ -834,9 +834,8 @@
return $buff; return $buff;
} }
function &getParser($force = FALSE){ function getParser($force = FALSE){
$dbParser = new DBParser('"', '"', $this->prefix); return new DBParser('"', '"', $this->prefix);
return $dbParser;
} }
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) { function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
@ -867,4 +866,4 @@
} }
return new DBCubrid; return new DBCubrid;
?> ?>

View file

@ -540,9 +540,8 @@
else return $this->queryPageLimit($queryObject, $result, $connection); else return $this->queryPageLimit($queryObject, $result, $connection);
} }
function &getParser($force = FALSE){ function getParser($force = FALSE){
$dbParser = new DBParser("[", "]", $this->prefix); return new DBParser("[", "]", $this->prefix);
return $dbParser;
} }
function queryError($queryObject){ function queryError($queryObject){
@ -615,7 +614,7 @@
$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; return $buff;
} }
$start_count = ($page - 1) * $list_count; $start_count = ($page - 1) * $list_count;
$this->param = $queryObject->getArguments(); $this->param = $queryObject->getArguments();
$virtual_no = $total_count - $start_count; $virtual_no = $total_count - $start_count;

View file

@ -317,9 +317,20 @@ class DBMysql extends DB {
if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column; if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column;
else $columns = $xml_obj->table->column; else $columns = $xml_obj->table->column;
$primary_list = array(); $primary_list = array();
$unique_list = array(); $unique_list = array();
$index_list = array(); $index_list = array();
foreach($columns as $column) {
$name = $column->attrs->name;
$type = $column->attrs->type;
$size = $column->attrs->size;
$notnull = $column->attrs->notnull;
$primary_key = $column->attrs->primary_key;
$index = $column->attrs->index;
$unique = $column->attrs->unique;
$default = $column->attrs->default;
$auto_increment = $column->attrs->auto_increment;
foreach($columns as $column) { foreach($columns as $column) {
$name = $column->attrs->name; $name = $column->attrs->name;
@ -368,14 +379,22 @@ class DBMysql extends DB {
if(!$output) return false; if(!$output) return false;
} }
/** /**
* @brief Handle the insertAct * @brief Handle selectAct
**/ *
function _executeInsertAct($queryObject, $with_values = true) { * In order to get a list of pages easily when selecting \n
$query = $this->getInsertSql($queryObject, $with_values, true); * it supports a method as navigation
if(is_a($query, 'Object')) return; **/
return $this->_query($query); function _executeSelectAct($queryObject, $connection = null, $with_values = true) {
} $limit = $queryObject->getLimit();
$result = NULL;
if ($limit && $limit->isPageHandler())
return $this->queryPageLimit($queryObject, $result, $connection, $with_values);
else {
$query = $this->getSelectSql($queryObject, $with_values);
if (is_a($query, 'Object'))
return;
$query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : '';
/** /**
* @brief Handle updateAct * @brief Handle updateAct
@ -429,33 +448,41 @@ class DBMysql extends DB {
return mysql_insert_id($connection); return mysql_insert_id($connection);
} }
function db_fetch_object(&$result) function getParser($force = FALSE){
{ return new DBParser('`', '`', $this->prefix);
return mysql_fetch_object($result); }
} function db_fetch_object(&$result)
{
return mysql_fetch_object($result);
}
function db_free_result(&$result){ function db_free_result(&$result){
return mysql_free_result($result); return mysql_free_result($result);
} }
function &getParser($force = FALSE){ function queryPageLimit($queryObject, $result, $connection, $with_values = true){
$dbParser = new DBParser('`', '`', $this->prefix); $limit = $queryObject->getLimit();
return $dbParser; // Total count
} $temp_where = $queryObject->getWhereString($with_values, false);
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString($with_values), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
// Check for distinct query and if found update count query structure
$temp_select = $queryObject->getSelectString($with_values);
$uses_distinct = false;
if(strpos(strtolower($temp_select), "distinct") !== false) {
$count_query = sprintf('select %s %s %s', 'FROM ' . $queryObject->getFromString($with_values), $temp_select, ($temp_where === '' ? '' : ' WHERE '. $temp_where));
$uses_distinct = true;
}
// If query uses grouping or distinct, count from original select
if ($queryObject->getGroupByString() != '' || $uses_distinct) {
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
}
function queryError($queryObject){ $count_query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
$limit = $queryObject->getLimit(); $result_count = $this->_query($count_query, $connection);
if ($limit && $limit->isPageHandler()){ $count_output = $this->_fetch($result_count);
$buff = new Object (); $total_count = (int)(isset($count_output->count) ? $count_output->count : NULL);
$buff->total_count = 0;
$buff->total_page = 0;
$buff->page = 1;
$buff->data = array ();
$buff->page_navigation = new PageHandler (/*$total_count*/0, /*$total_page*/1, /*$page*/1, /*$page_count*/10);//default page handler values
return $buff;
}else
return;
}
function queryPageLimit($queryObject, $result, $connection, $with_values = true){ function queryPageLimit($queryObject, $result, $connection, $with_values = true){
$limit = $queryObject->getLimit(); $limit = $queryObject->getLimit();

View file

@ -1,3 +1,4 @@
<<<<<<< .working
<?php <?php
class Query extends Object { class Query extends Object {
@ -93,6 +94,61 @@
$this->tables = $tables; $this->tables = $tables;
} }
=======
<?php
class Query extends Object {
var $queryID;
var $action;
var $priority;
var $columns;
var $tables;
var $conditions;
var $groups;
var $orderby;
var $limit;
var $arguments = null;
var $columnList = null;
var $_orderByString;
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;
$this->priority = $priority;
if(!isset($tables)) return;
$this->columns = $this->setColumns($columns);
$this->tables = $this->setTables($tables);
$this->conditions = $this->setConditions($conditions);
$this->groups = $this->setGroups($groups);
$this->orderby = $this->setOrder($orderby);
$this->limit = $this->setLimit($limit);
}
function show(){
return true;
}
function setQueryId($queryID){
$this->queryID = $queryID;
}
function setAction($action){
$this->action = $action;
}
>>>>>>> .merge-right.r10563
function setSubquery($subquery){ function setSubquery($subquery){
$this->subquery = $subquery; $this->subquery = $subquery;
@ -204,6 +260,7 @@
} }
<<<<<<< .working
$valuesList = ''; $valuesList = '';
foreach($this->columns as $column){ foreach($this->columns as $column){
if($column->show()){ if($column->show()){
@ -359,3 +416,159 @@
?> ?>
=======
$valuesList = '';
foreach($this->columns as $column){
if($column->show()){
$columnsList .= $column->getColumnName() . ', ';
$valuesList .= $column->getValue($with_values) . ', ';
}
}
$columnsList = substr($columnsList, 0, -2);
$valuesList = substr($valuesList, 0, -2);
return "($columnsList) \n VALUES ($valuesList)";
}
function getTables(){
return $this->tables;
}
// from table_a
// from table_a inner join table_b on x=y
// from (select * from table a) as x
// from (select * from table t) as x inner join table y on y.x
function getFromString($with_values = true){
$from = '';
$simple_table_count = 0;
foreach($this->tables as $table){
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
else $from .= ', '.$table->toString($with_values) . ' ';
if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
$simple_table_count++;
}
if(trim($from) == '') return '';
return $from;
}
function getWhereString($with_values = true, $with_optimization = true){
$where = '';
$condition_count = 0;
foreach ($this->conditions as $conditionGroup) {
if ($condition_count === 0) {
$conditionGroup->setPipe("");
}
$condition_string = $conditionGroup->toString($with_values);
$where .= $condition_string;
$condition_count++;
}
if ($with_optimization &&
(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
if ($condition_count !== 0)
$where = '(' . $where . ') ';
foreach ($this->orderby as $order) {
$colName = $order->getColumnName();
if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
if ($condition_count === 0)
$opt_condition->setPipe("");
$where .= $opt_condition->toString($with_values) . ' ';
$condition_count++;
}
}
}
return trim($where);
}
function getGroupByString(){
$groupBy = '';
if($this->groups) if($this->groups[0] !== "")
$groupBy = implode(', ', $this->groups);
return $groupBy;
}
function getOrderByString(){
if(!$this->_orderByString){
if(count($this->orderby) === 0) return '';
$orderBy = '';
foreach($this->orderby as $order){
$orderBy .= $order->toString() .', ';
}
$orderBy = substr($orderBy, 0, -2);
$this->_orderByString = $orderBy;
}
return $this->_orderByString;
}
function getLimit(){
return $this->limit;
}
function getLimitString(){
$limit = '';
if(count($this->limit) > 0){
$limit = '';
$limit .= $this->limit->toString();
}
return $limit;
}
function getFirstTableName(){
return $this->tables[0]->getName();
}
function getArguments(){
if(!isset($this->arguments)){
$this->arguments = array();
// Join table arguments
if(count($this->tables) > 0)
{
foreach($this->tables as $table)
{
if($table->isJoinTable())
{
$args = $table->getArguments();
if($args) $this->arguments = array_merge($this->arguments, $args);
}
}
}
// Column arguments
if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
foreach($this->columns as $column){
if($column->show()){
$args = $column->getArguments();
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);
}
// 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);
}
}
return $this->arguments;
}
}
?>>>>>>>> .merge-right.r10563

View file

@ -69,14 +69,14 @@
// Write query cache file // Write query cache file
$parser = new QueryParser($xml_obj->query); $parser = new QueryParser($xml_obj->query);
FileHandler::writeFile($cache_file, $parser->toString()); FileHandler::writeFile($cache_file, $parser->toString());
return $parser; return $parser;
} }
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL) function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
{ {
$query_parser = &$this->parse_xml_query($query_id, $xml_file, $cache_file); $this->parse_xml_query($query_id, $xml_file, $cache_file);
} }
function getXmlFileContent($xml_file){ function getXmlFileContent($xml_file){

View file

@ -12,20 +12,21 @@
var $click_count; var $click_count;
function SelectColumnTag($column){ function SelectColumnTag($column){
parent::ColumnTag($column->attrs->name); if ($column == "*" || $column->attrs->name == '*')
if(!$this->name) { {
if($column->attrs->var) parent::ColumnTag(NULL);
$this->name = '$' . $column->attrs->var; $this->name = "*";
else
$this->name = "*";
} }
if($this->name != "*" && substr($this->name, 0, 1) != '$') { else
{
parent::ColumnTag($column->attrs->name);
$dbParser = DB::getParser(); $dbParser = DB::getParser();
$this->name = $dbParser->parseExpression($this->name); $this->name = $dbParser->parseExpression($this->name);
$this->alias = $column->attrs->alias; $this->alias = $column->attrs->alias;
$this->click_count = $column->attrs->click_count; $this->click_count = $column->attrs->click_count;
} }
}
} }
function getExpressionString(){ function getExpressionString(){

View file

@ -176,7 +176,7 @@ class QueryTag {
return $this->buff; return $this->buff;
} }
function getTables() { function getTables(){
if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))) if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for)))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint); return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else else

View file

@ -42,7 +42,7 @@
$this->tables[] = new QueryTag($tag, true); $this->tables[] = new QueryTag($tag, true);
} }
else { else {
if(isset($indexes) && $indexes && isset($indexes[$tag->attrs->name])) if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name])
$this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]); $this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]);
else else
$this->tables[] = new TableTag($tag); $this->tables[] = new TableTag($tag);