mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +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,104 +1,115 @@
|
|||
<?php
|
||||
|
||||
class QueryArgument {
|
||||
var $argument_name;
|
||||
var $variable_name;
|
||||
var $argument_validator;
|
||||
var $column_name;
|
||||
var $operation;
|
||||
class QueryArgument {
|
||||
|
||||
var $ignore_value;
|
||||
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;
|
||||
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);
|
||||
$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);
|
||||
|
||||
$this->variable_name = $this->argument_name;
|
||||
$this->variable_name = $this->argument_name;
|
||||
|
||||
$number_of_arguments++;
|
||||
$this->argument_name .= $number_of_arguments;
|
||||
$number_of_arguments++;
|
||||
$this->argument_name .= $number_of_arguments;
|
||||
|
||||
$name = $tag->attrs->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;
|
||||
}
|
||||
|
||||
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
$name = $tag->attrs->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;
|
||||
}
|
||||
|
||||
function getArgumentName(){
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName(){
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getValidatorString(){
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument(){
|
||||
if($this->operation) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
if($this->isConditionArgument()){
|
||||
// Instantiation
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, '$args->'.$this->variable_name
|
||||
, $this->operation
|
||||
);
|
||||
// Call methods to validate argument and ensure default value
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
// Prepare condition string
|
||||
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
|
||||
// Check that argument passed validation, else return
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
else {
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, $this->ignore_value ? 'null' : '$args->'.$this->variable_name);
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if($this->argument_validator->isIgnorable()){
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->'.$this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
if ($tag->attrs->operation)
|
||||
$this->operation = $tag->attrs->operation;
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
}
|
||||
|
||||
function getArgumentName() {
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName() {
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getTableName(){
|
||||
return $this->table_name;
|
||||
}
|
||||
|
||||
function getValidatorString() {
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument() {
|
||||
if ($this->operation)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function toString() {
|
||||
if ($this->isConditionArgument()) {
|
||||
// Instantiation
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, '$args->' . $this->variable_name
|
||||
, $this->operation
|
||||
);
|
||||
// Call methods to validate argument and ensure default value
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
// Prepare condition string
|
||||
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
|
||||
// Check that argument passed validation, else return
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
} else {
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, $this->ignore_value ? 'null' : '$args->' . $this->variable_name);
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if ($this->argument_validator->isIgnorable()) {
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -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,22 +17,22 @@ class QueryTag {
|
|||
var $preBuff;
|
||||
var $buff;
|
||||
var $isSubQuery;
|
||||
|
||||
var $join_type;
|
||||
var $join_type;
|
||||
var $alias;
|
||||
|
||||
function QueryTag($query, $isSubQuery = false){
|
||||
function QueryTag($query, $isSubQuery = false) {
|
||||
$this->action = $query->attrs->action;
|
||||
$this->query_id = $query->attrs->id;
|
||||
$this->priority = $query->attrs->priority;
|
||||
$this->query = $query;
|
||||
$this->isSubQuery = $isSubQuery;
|
||||
if($this->isSubQuery) $this->action = 'select';
|
||||
if($query->attrs->alias){
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
$this->join_type = $query->attrs->join_type;
|
||||
if ($this->isSubQuery)
|
||||
$this->action = 'select';
|
||||
if ($query->attrs->alias) {
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
$this->join_type = $query->attrs->join_type;
|
||||
|
||||
$this->getColumns();
|
||||
$tables = $this->getTables();
|
||||
|
|
@ -44,155 +44,174 @@ class QueryTag {
|
|||
$this->getBuff();
|
||||
}
|
||||
|
||||
function show(){
|
||||
function show() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getQueryId(){
|
||||
function getQueryId() {
|
||||
return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id;
|
||||
}
|
||||
|
||||
function getPriority(){
|
||||
function getPriority() {
|
||||
return $this->query->attrs->priority;
|
||||
}
|
||||
|
||||
function getAction(){
|
||||
function getAction() {
|
||||
return $this->query->attrs->action;
|
||||
}
|
||||
|
||||
function setTableColumnTypes($tables){
|
||||
function setTableColumnTypes($tables) {
|
||||
$query_id = $this->getQueryId();
|
||||
if(!isset($this->column_type[$query_id])){
|
||||
if (!isset($this->column_type[$query_id])) {
|
||||
$table_tags = $tables->getTables();
|
||||
$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);
|
||||
}
|
||||
foreach ($table_tags as $table_tag) {
|
||||
if (is_a($table_tag, 'TableTag')) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
function getColumns(){
|
||||
if($this->action == 'select'){
|
||||
return $this->columns = new SelectColumnsTag($this->query->columns);
|
||||
}else if($this->action == 'insert'){
|
||||
return $this->columns = new InsertColumnsTag($this->query->columns->column);
|
||||
}else if($this->action == 'update') {
|
||||
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
|
||||
}else if($this->action == 'delete') {
|
||||
return $this->columns = null;
|
||||
function getColumns() {
|
||||
if ($this->action == 'select') {
|
||||
return $this->columns = new SelectColumnsTag($this->query->columns);
|
||||
} else if ($this->action == 'insert') {
|
||||
return $this->columns = new InsertColumnsTag($this->query->columns->column);
|
||||
} else if ($this->action == 'update') {
|
||||
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
|
||||
} else if ($this->action == 'delete') {
|
||||
return $this->columns = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getPrebuff(){
|
||||
function getPrebuff() {
|
||||
// TODO Check if this work with arguments in join clause
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$prebuff = '';
|
||||
foreach($arguments as $argument){
|
||||
if(isset($argument)){
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if($arg_name){
|
||||
$prebuff .= $argument->toString();
|
||||
$column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()];
|
||||
if(isset($column_type))
|
||||
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
|
||||
, $arg_name
|
||||
, $arg_name
|
||||
, $column_type );
|
||||
}
|
||||
}
|
||||
foreach ($arguments as $argument) {
|
||||
if (isset($argument)) {
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if ($arg_name) {
|
||||
unset($column_type);
|
||||
$prebuff .= $argument->toString();
|
||||
|
||||
$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
|
||||
, $arg_name
|
||||
, $column_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
$prebuff .= "\n";
|
||||
|
||||
return $this->preBuff = $prebuff;
|
||||
}
|
||||
|
||||
function getBuff(){
|
||||
function getBuff() {
|
||||
$buff = '';
|
||||
if($this->isSubQuery){
|
||||
if ($this->isSubQuery) {
|
||||
$buff = 'new Subquery(';
|
||||
$buff .= "'" . $this->alias . '\', ';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ). ', '.PHP_EOL;
|
||||
$buff .= $this->tables->toString() .','.PHP_EOL;
|
||||
$buff .= $this->conditions->toString() .',' .PHP_EOL;
|
||||
$buff .= $this->groups->toString() . ',' .PHP_EOL;
|
||||
$buff .= $this->navigation->getOrderByString() .','.PHP_EOL;
|
||||
$limit = $this->navigation->getLimitString() ;
|
||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL;
|
||||
$buff .= $this->tables->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->conditions->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->groups->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->navigation->getOrderByString() . ',' . PHP_EOL;
|
||||
$limit = $this->navigation->getLimitString();
|
||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||
$buff .= ')';
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
$buff .= '$query = new Query();'.PHP_EOL;
|
||||
$buff .= '$query = new Query();' . PHP_EOL;
|
||||
$buff .= sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n");
|
||||
$buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n");
|
||||
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
|
||||
$buff .= $this->preBuff;
|
||||
if($this->columns)
|
||||
$buff .= '$query->setColumns(' . $this->columns->toString() . ');'.PHP_EOL;
|
||||
if ($this->columns)
|
||||
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
|
||||
|
||||
$buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL;
|
||||
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL;
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
if($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);
|
||||
else
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
function getTables() {
|
||||
if ($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);
|
||||
else
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
}
|
||||
|
||||
function getConditions(){
|
||||
function getConditions() {
|
||||
return $this->conditions = new ConditionsTag($this->query->conditions);
|
||||
}
|
||||
|
||||
function getGroups(){
|
||||
function getGroups() {
|
||||
return $this->groups = new GroupsTag($this->query->groups->group);
|
||||
}
|
||||
|
||||
function getNavigation(){
|
||||
function getNavigation() {
|
||||
return $this->navigation = new NavigationTag($this->query->navigation);
|
||||
}
|
||||
|
||||
function toString(){
|
||||
function toString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTableString(){
|
||||
function getTableString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getConditionString(){
|
||||
function getConditionString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
function getExpressionString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
|
||||
function getArguments(){
|
||||
function getArguments() {
|
||||
$arguments = array();
|
||||
if($this->columns)
|
||||
if ($this->columns)
|
||||
$arguments = array_merge($arguments, $this->columns->getArguments());
|
||||
$arguments = array_merge($arguments, $this->tables->getArguments());
|
||||
$arguments = array_merge($arguments, $this->tables->getArguments());
|
||||
$arguments = array_merge($arguments, $this->conditions->getArguments());
|
||||
$arguments = array_merge($arguments, $this->navigation->getArguments());
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
class MysqlSelectTest extends MysqlTest {
|
||||
class MysqlSelectTest extends MysqlTest {
|
||||
|
||||
function _test($xml_file, $argsString, $expected, $columnList = null){
|
||||
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
|
||||
}
|
||||
function _test($xml_file, $argsString, $expected, $columnList = null) {
|
||||
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
|
||||
}
|
||||
|
||||
function testConditionWithVarAndColumnDefaultValue_WithoutArgument(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
|
||||
$argsString = '$args->item_srl = "";';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
function testConditionWithVarAndColumnDefaultValue_WithoutArgument() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
|
||||
$argsString = '$args->item_srl = "";';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
, `package`.`status` as `status`
|
||||
, `package`.`category_srl` as `category_srl`
|
||||
, `package`.`member_srl` as `member_srl`
|
||||
|
|
@ -40,13 +40,13 @@
|
|||
, `xe_resource_items` as `item`
|
||||
where `package`.`member_srl` = `member`.`member_srl`
|
||||
and `item`.`item_srl` = `package`.`latest_item_srl`';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function testConditionWithVarAndColumnDefaultValue_WithArgument(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
|
||||
$argsString = '$args->item_srl = "10";';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
function testConditionWithVarAndColumnDefaultValue_WithArgument() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
|
||||
$argsString = '$args->item_srl = "10";';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
, `package`.`status` as `status`
|
||||
, `package`.`category_srl` as `category_srl`
|
||||
, `package`.`member_srl` as `member_srl`
|
||||
|
|
@ -77,20 +77,20 @@
|
|||
, `xe_resource_items` as `item`
|
||||
where `package`.`member_srl` = `member`.`member_srl`
|
||||
and `item`.`item_srl` = 10';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function testSubstring(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/substring.xml";
|
||||
$argsString = '$args->var_start_mmdd = "1102"; ';
|
||||
$expected = 'select * from `xe_member` as `member` where substr(`extra_vars_t1`.`value`,5,4) >= 1102';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
function testSubstring() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/substring.xml";
|
||||
$argsString = '$args->var_start_mmdd = "1102"; ';
|
||||
$expected = 'select * from `xe_member` as `member` where substr(`extra_vars_t1`.`value`,5,4) >= 1102';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function testResource_getLatestItemList(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItemList.xml";
|
||||
$argsString = '';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
function testResource_getLatestItemList() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItemList.xml";
|
||||
$argsString = '';
|
||||
$expected = 'select `package`.`module_srl` as `module_srl`
|
||||
, `package`.`status` as `status`
|
||||
, `package`.`category_srl` as `category_srl`
|
||||
, `package`.`member_srl` as `member_srl`
|
||||
|
|
@ -130,71 +130,71 @@
|
|||
and `package`.`update_order` <= 2100000000
|
||||
order by `package`.`update_order` asc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_Syndication_getGrantedModules(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/syndication.getGrantedModules.xml";
|
||||
$argsString = '';
|
||||
$expected = 'select `module_srl`
|
||||
function test_Syndication_getGrantedModules() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/syndication.getGrantedModules.xml";
|
||||
$argsString = '';
|
||||
$expected = 'select `module_srl`
|
||||
from `xe_module_grants` as `module_grants`
|
||||
where `name` in (\'access\',\'view\',\'list\')
|
||||
and (`group_srl` >= 1 or `group_srl` = -1 or `group_srl` = -2) group by `module_srl`';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_Like_Clause(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.like.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
function test_Like_Clause() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.like.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
from `xe_modules` as `modules`
|
||||
where `module` = \'opage\'
|
||||
and (`mid` like \'%test%\')
|
||||
order by `module_srl` desc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_NotLike_Clause(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlike.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
function test_NotLike_Clause() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlike.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
from `xe_modules` as `modules`
|
||||
where `module` = \'opage\'
|
||||
and (`mid` not like \'%test%\')
|
||||
order by `module_srl` desc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_NotLikeTail_Clause(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notliketail.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
function test_NotLikeTail_Clause() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notliketail.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
from `xe_modules` as `modules`
|
||||
where `module` = \'opage\'
|
||||
and (`mid` not like \'%test\')
|
||||
order by `module_srl` desc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_NotLikePrefix_Clause(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlikeprefix.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
function test_NotLikePrefix_Clause() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlikeprefix.xml";
|
||||
$argsString = '$args->s_mid = "test";';
|
||||
$expected = 'select *
|
||||
from `xe_modules` as `modules`
|
||||
where `module` = \'opage\'
|
||||
and (`mid` not like \'test%\')
|
||||
order by `module_srl` desc
|
||||
limit 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_WidgetsNewestDocument_getNewestDocuments(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/widgets.newest_document.getNewestDocuments.xml";
|
||||
$argsString = '$args->module_srl = "566036,3777868";';
|
||||
$expected = 'select `modules`.`site_srl` as `site_srl`
|
||||
function test_WidgetsNewestDocument_getNewestDocuments() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/widgets.newest_document.getNewestDocuments.xml";
|
||||
$argsString = '$args->module_srl = "566036,3777868";';
|
||||
$expected = 'select `modules`.`site_srl` as `site_srl`
|
||||
, `modules`.`mid` as `mid`
|
||||
, `documents`.*
|
||||
from `xe_modules` as `modules`
|
||||
|
|
@ -205,13 +205,13 @@
|
|||
and `documents`.`list_order` <= 2100000000
|
||||
order by `documents`.`list_order` asc
|
||||
limit 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_homepage_getNewestComments(){
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/homepage.getNewestComments.xml";
|
||||
$argsString = ';';
|
||||
$expected = 'select `sites`.`domain` as `domain`
|
||||
function test_homepage_getNewestComments() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/homepage.getNewestComments.xml";
|
||||
$argsString = ';';
|
||||
$expected = 'select `sites`.`domain` as `domain`
|
||||
, `comments`.*
|
||||
from `xe_homepages` as `homepages`
|
||||
, `xe_sites` as `sites`
|
||||
|
|
@ -227,17 +227,37 @@
|
|||
and `module_grants`.`group_srl` is null)
|
||||
and `comments`.`list_order` <= 2100000000
|
||||
order by `comments`.`list_order` asc limit 0, 5';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
$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;';
|
||||
$expected = 'select distinct `modules`.`module_srl` as `module_site_srl`
|
||||
function test_distinct_outer_join() {
|
||||
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/distinct_outer_join.xml";
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
$expected = 'select distinct `modules`.`module_srl` as `module_site_srl`
|
||||
from `xe_sites` as `sites`
|
||||
left join `xe_modules` as `modules` on `modules`.`module_srl` = `sites`.`index_module_srl`
|
||||
where `sites`.`site_srl` = 0';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
$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