Issue 1677: XML Query - If default value is column name, value should not be wrapped in quotes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10439 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2012-03-15 12:41:20 +00:00
parent ae99536662
commit d116d633c8
3 changed files with 189 additions and 186 deletions

View file

@ -1,15 +1,15 @@
<?php <?php
class Argument { class Argument {
var $value; var $value;
var $name; var $name;
var $type; var $type;
var $isValid; var $isValid;
var $errorMessage; var $errorMessage;
var $column_operation; var $column_operation;
var $uses_default_value; // Check if arg value is user submnitted or default
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times; var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
function Argument($name, $value) { function Argument($name, $value) {
@ -19,8 +19,10 @@
} }
function getType() { function getType() {
if(isset($this->type)) return $this->type; if (isset($this->type))
if(is_string($this->value)) return 'column_name'; return $this->type;
if (is_string($this->value))
return 'column_name';
return 'number'; return 'number';
} }
@ -58,8 +60,10 @@
function toString($value) { function toString($value) {
if (is_array($value)) { if (is_array($value)) {
if(count($value) === 0) return ''; if (count($value) === 0)
if(count($value) === 1 && $value[0] === '') return ''; return '';
if (count($value) === 1 && $value[0] === '')
return '';
return '(' . implode(',', $value) . ')'; return '(' . implode(',', $value) . ')';
} }
return $value; return $value;
@ -71,7 +75,8 @@
$dbParser = DB::getParser(); $dbParser = DB::getParser();
return $dbParser->parseExpression($value); return $dbParser->parseExpression($value);
} }
if(!isset($value)) return null; if (!isset($value))
return null;
if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) { if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) {
if (!is_array($value)) if (!is_array($value))
@ -83,26 +88,18 @@
//$value[$i] = '\''.$value[$i].'\''; //$value[$i] = '\''.$value[$i].'\'';
} }
} }
if($column_type == 'number') if($this->uses_default_value) return $value;
{ if ($column_type == 'number') {
if(is_array($value)) if (is_array($value)) {
{ foreach ($value AS $key => $val) {
foreach($value AS $key=>$val) if (isset($val)) {
{
if(isset($val))
{
$value[$key] = (int) $val; $value[$key] = (int) $val;
} }
} }
} } else {
else
{
if(isset($val))
{
$value = (int) $value; $value = (int) $value;
} }
} }
}
return $value; return $value;
} }
@ -111,7 +108,6 @@
$db = &DB::getInstance(); $db = &DB::getInstance();
$value = $db->addQuotes($value); $value = $db->addQuotes($value);
return '\'' . $value . '\''; return '\'' . $value . '\'';
} }
function isValid() { function isValid() {
@ -124,7 +120,10 @@
function ensureDefaultValue($default_value) { function ensureDefaultValue($default_value) {
if (!isset($this->value) || $this->value == '') if (!isset($this->value) || $this->value == '')
{
$this->value = $default_value; $this->value = $default_value;
$this->uses_default_value = true;
}
} }
function checkFilter($filter_type) { function checkFilter($filter_type) {
@ -155,7 +154,8 @@
break; break;
case 'number' : case 'number' :
case 'numbers' : case 'numbers' :
if(is_array($val)) $val = join(',', $val); if (is_array($val))
$val = join(',', $val);
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) { if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
$this->isValid = false; $this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
@ -203,7 +203,7 @@
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
} }
} }
} }
?> ?>

View file

@ -68,8 +68,9 @@ class QueryTag {
foreach ($table_tags as $table_tag) { foreach ($table_tags as $table_tag) {
if (is_a($table_tag, 'TableTag')) { if (is_a($table_tag, 'TableTag')) {
$table_name = $table_tag->getTableName(); $table_name = $table_tag->getTableName();
$table_alias = $table_tag->getTableAlias();
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name); $tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
$column_type[$table_name] = $tag_column_type; $column_type[$table_alias] = $tag_column_type;
} }
} }
$this->column_type[$query_id] = $column_type; $this->column_type[$query_id] = $column_type;
@ -100,10 +101,10 @@ class QueryTag {
unset($column_type); unset($column_type);
$prebuff .= $argument->toString(); $prebuff .= $argument->toString();
$table_name = $argument->getTableName(); $table_alias = $argument->getTableName();
if(isset($table_name)) if(isset($table_alias))
{ {
$column_type = $this->column_type[$this->getQueryId()][$table_name][$argument->getColumnName()]; $column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()];
} }
else else
{ {

View file

@ -200,11 +200,13 @@ class MysqlSelectTest extends MysqlTest {
from `xe_modules` as `modules` from `xe_modules` as `modules`
, `xe_documents` as `documents` , `xe_documents` as `documents`
where ( where (
`documents`.`module_srl` in (566036,3777868) `documents`.`module_srl` not in (0)
and `documents`.`module_srl` in (566036,3777868)
and `modules`.`module_srl` = `documents`.`module_srl`) and `modules`.`module_srl` = `documents`.`module_srl`)
and `documents`.`list_order` <= 2100000000 and `documents`.`list_order` <= 2100000000
order by `documents`.`list_order` asc order by `documents`.`list_order` asc
limit 20'; limit 20';
$this->_test($xml_file, $argsString, $expected); $this->_test($xml_file, $argsString, $expected);
} }
@ -253,7 +255,7 @@ class MysqlSelectTest extends MysqlTest {
and `documents`.`document_srl` = `comments`.`document_srl` and `documents`.`document_srl` = `comments`.`document_srl`
and `documents`.`status` in (\'public\',\'secret\') and `documents`.`status` in (\'public\',\'secret\')
and `comments`.`content` like \'%dfsds%\') and `comments`.`content` like \'%dfsds%\')
and comments.list_order <= 2100000000 and `comments`.`list_order` <= 2100000000
group by `documents`.`document_srl` group by `documents`.`document_srl`
order by `comments`.`list_order` asc order by `comments`.`list_order` asc
limit 0, 20'; limit 0, 20';