mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 12:32:14 +09:00
Issue 1669: [1.5.2] Query problem if there are columns have a same name and different types in joined tables.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10432 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
9453348cb1
commit
51220d52d0
4 changed files with 328 additions and 246 deletions
|
|
@ -1,20 +1,23 @@
|
|||
<?php
|
||||
|
||||
class QueryArgument {
|
||||
|
||||
var $argument_name;
|
||||
var $variable_name;
|
||||
var $argument_validator;
|
||||
var $column_name;
|
||||
var $table_name;
|
||||
var $operation;
|
||||
|
||||
var $ignore_value;
|
||||
|
||||
function QueryArgument($tag, $ignore_value = false) {
|
||||
static $number_of_arguments = 0;
|
||||
|
||||
$this->argument_name = $tag->attrs->var;
|
||||
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->name);
|
||||
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->column);
|
||||
if (!$this->argument_name)
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->name);
|
||||
if (!$this->argument_name)
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->column);
|
||||
|
||||
$this->variable_name = $this->argument_name;
|
||||
|
||||
|
|
@ -22,14 +25,18 @@
|
|||
$this->argument_name .= $number_of_arguments;
|
||||
|
||||
$name = $tag->attrs->name;
|
||||
if(!$name) $name = $tag->attrs->column;
|
||||
if(strpos($name, '.') === false) $this->column_name = $name;
|
||||
if (!$name)
|
||||
$name = $tag->attrs->column;
|
||||
if (strpos($name, '.') === false)
|
||||
$this->column_name = $name;
|
||||
else {
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
$this->table_name = $prefix;
|
||||
}
|
||||
|
||||
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
|
||||
if ($tag->attrs->operation)
|
||||
$this->operation = $tag->attrs->operation;
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
|
|
@ -43,12 +50,17 @@
|
|||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getTableName(){
|
||||
return $this->table_name;
|
||||
}
|
||||
|
||||
function getValidatorString() {
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument() {
|
||||
if($this->operation) return true;
|
||||
if ($this->operation)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -74,8 +86,7 @@
|
|||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class QueryTag {
|
||||
|
||||
var $action;
|
||||
var $query_id;
|
||||
var $priority;
|
||||
var $column_type;
|
||||
var $query;
|
||||
|
||||
//xml tags
|
||||
var $columns;
|
||||
var $tables;
|
||||
|
|
@ -17,7 +17,6 @@ class QueryTag {
|
|||
var $preBuff;
|
||||
var $buff;
|
||||
var $isSubQuery;
|
||||
|
||||
var $join_type;
|
||||
var $alias;
|
||||
|
||||
|
|
@ -27,7 +26,8 @@ class QueryTag {
|
|||
$this->priority = $query->attrs->priority;
|
||||
$this->query = $query;
|
||||
$this->isSubQuery = $isSubQuery;
|
||||
if($this->isSubQuery) $this->action = 'select';
|
||||
if ($this->isSubQuery)
|
||||
$this->action = 'select';
|
||||
if ($query->attrs->alias) {
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
|
|
@ -67,8 +67,9 @@ class QueryTag {
|
|||
$column_type = array();
|
||||
foreach ($table_tags as $table_tag) {
|
||||
if (is_a($table_tag, 'TableTag')) {
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_tag->getTableName());
|
||||
$column_type = array_merge($column_type, $tag_column_type);
|
||||
$table_name = $table_tag->getTableName();
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
|
||||
$column_type[$table_name] = $tag_column_type;
|
||||
}
|
||||
}
|
||||
$this->column_type[$query_id] = $column_type;
|
||||
|
|
@ -96,8 +97,26 @@ class QueryTag {
|
|||
if (isset($argument)) {
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if ($arg_name) {
|
||||
unset($column_type);
|
||||
$prebuff .= $argument->toString();
|
||||
$column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()];
|
||||
|
||||
$table_name = $argument->getTableName();
|
||||
if(isset($table_name))
|
||||
{
|
||||
$column_type = $this->column_type[$this->getQueryId()][$table_name][$argument->getColumnName()];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_tables = $this->column_type[$this->getQueryId()];
|
||||
$column_name = $argument->getColumnName();
|
||||
foreach($current_tables as $current_table)
|
||||
{
|
||||
if($current_table[$column_name])
|
||||
$column_type = $current_table[$column_name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($column_type))
|
||||
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
|
||||
, $arg_name
|
||||
|
|
@ -183,7 +202,6 @@ class QueryTag {
|
|||
return $this->buff;
|
||||
}
|
||||
|
||||
|
||||
function getArguments() {
|
||||
$arguments = array();
|
||||
if ($this->columns)
|
||||
|
|
@ -195,4 +213,5 @@ class QueryTag {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -230,7 +230,6 @@
|
|||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
|
||||
function test_distinct_outer_join() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/distinct_outer_join.xml";
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
|
|
@ -240,4 +239,25 @@
|
|||
where `sites`.`site_srl` = 0';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_getDocumentListWithinComment() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/document.getDocumentListWithinComment.xml";
|
||||
$argsString = '$args->module_srl = 19778968;
|
||||
$args->s_comment = "dfsds";
|
||||
$args->statusList = "PUBLIC, SECRET";
|
||||
';
|
||||
$expected = 'select `documents`.`document_srl`, `documents`.`list_order`
|
||||
from `xe_documents` as `documents`
|
||||
, `xe_comments` as `comments`
|
||||
where (`documents`.`module_srl` in (19778968)
|
||||
and `documents`.`document_srl` = `comments`.`document_srl`
|
||||
and `documents`.`status` in (\'public\',\'secret\')
|
||||
and `comments`.`content` like \'%dfsds%\')
|
||||
and comments.list_order <= 2100000000
|
||||
group by `documents`.`document_srl`
|
||||
order by `comments`.`list_order` asc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<query id="getDocumentListWithinComment" action="select">
|
||||
<tables>
|
||||
<table name="documents" alias="documents" />
|
||||
<table name="comments" alias="comments" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="documents.document_srl" />
|
||||
<column name="documents.list_order" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="in" column="documents.module_srl" var="module_srl" filter="number" />
|
||||
<condition operation="notin" column="documents.module_srl" var="exclude_module_srl" filter="number" pipe="and" />
|
||||
<condition operation="equal" column="documents.category_srl" var="category_srl" pipe="and" />
|
||||
<condition operation="equal" column="documents.document_srl" default="comments.document_srl" notnull="notnull" pipe="and" />
|
||||
<condition operation="equal" column="documents.member_srl" var="member_srl" filter="number" pipe="and" />
|
||||
<condition operation="in" column="documents.status" var="statusList" pipe="and" />
|
||||
<group pipe="and">
|
||||
<condition operation="more" column="documents.list_order" var="division" pipe="and" />
|
||||
<condition operation="below" column="documents.list_order" var="last_division" pipe="and" />
|
||||
</group>
|
||||
<condition operation="like" column="comments.content" var="s_comment" notnull="notnull" pipe="and" />
|
||||
</conditions>
|
||||
<navigation>
|
||||
<index var="sort_index" default="comments.list_order" order="asc" />
|
||||
<list_count var="list_count" default="20" />
|
||||
<page_count var="page_count" default="10" />
|
||||
<page var="page" default="1" />
|
||||
</navigation>
|
||||
<groups>
|
||||
<group column="documents.document_srl" />
|
||||
</groups>
|
||||
</query>
|
||||
Loading…
Add table
Add a link
Reference in a new issue