diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 8d886e1f7..ea1158c39 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -1,209 +1,209 @@ value = $value; + $this->name = $name; + $this->isValid = true; + } - var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times; + function getType() { + if (isset($this->type)) + return $this->type; + if (is_string($this->value)) + return 'column_name'; + return 'number'; + } - function Argument($name, $value){ - $this->value = $value; - $this->name = $name; - $this->isValid = true; - } + function setColumnType($value) { + $this->type = $value; + } - function getType(){ - if(isset($this->type)) return $this->type; - if(is_string($this->value)) return 'column_name'; - return 'number'; - } + function setColumnOperation($operation) { + $this->column_operation = $operation; + } - function setColumnType($value){ - $this->type = $value; - } + function getName() { + return $this->name; + } - function setColumnOperation($operation){ - $this->column_operation = $operation; - } - - function getName(){ - return $this->name; - } - - function getValue(){ - if(!isset($this->_value)){ + function getValue() { + if (!isset($this->_value)) { $value = $this->getEscapedValue(); $this->_value = $this->toString($value); - } - return $this->_value; } + return $this->_value; + } - function getColumnOperation(){ - return $this->column_operation; - } + function getColumnOperation() { + return $this->column_operation; + } - function getEscapedValue(){ - return $this->escapeValue($this->value); - } + function getEscapedValue() { + return $this->escapeValue($this->value); + } - function getUnescapedValue(){ - return $this->value; + function getUnescapedValue() { + return $this->value; + } + + function toString($value) { + if (is_array($value)) { + if (count($value) === 0) + return ''; + if (count($value) === 1 && $value[0] === '') + return ''; + return '(' . implode(',', $value) . ')'; } + return $value; + } - function toString($value){ - if(is_array($value)){ - if(count($value) === 0) return ''; - if(count($value) === 1 && $value[0] === '') return ''; - return '('.implode(',', $value).')'; - } - return $value; + function escapeValue($value) { + $column_type = $this->getType(); + if ($column_type == 'column_name') { + $dbParser = DB::getParser(); + return $dbParser->parseExpression($value); } + if (!isset($value)) + return null; - function escapeValue($value){ - $column_type = $this->getType(); - if($column_type == 'column_name'){ - $dbParser = DB::getParser(); - return $dbParser->parseExpression($value); + if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) { + if (!is_array($value)) + $value = $this->_escapeStringValue($value); + else { + $total = count($value); + for ($i = 0; $i < $total; $i++) + $value[$i] = $this->_escapeStringValue($value[$i]); + //$value[$i] = '\''.$value[$i].'\''; } - if(!isset($value)) return null; - - if(in_array($column_type, array('date', 'varchar', 'char','text', 'bigtext'))){ - if(!is_array($value)) - $value = $this->_escapeStringValue ($value); - else { - $total = count($value); - for($i = 0; $i < $total; $i++) - $value[$i] = $this->_escapeStringValue($value[$i]); - //$value[$i] = '\''.$value[$i].'\''; - } - } - if($column_type == 'number') - { - if(is_array($value)) - { - foreach($value AS $key=>$val) - { - if(isset($val)) - { - $value[$key] = (int)$val; - } + } + if($this->uses_default_value) return $value; + if ($column_type == 'number') { + if (is_array($value)) { + foreach ($value AS $key => $val) { + if (isset($val)) { + $value[$key] = (int) $val; } } - else - { - if(isset($val)) - { - $value = (int)$value; + } else { + $value = (int) $value; + } + } + + return $value; + } + + function _escapeStringValue($value) { + $db = &DB::getInstance(); + $value = $db->addQuotes($value); + return '\'' . $value . '\''; + } + + function isValid() { + return $this->isValid; + } + + function getErrorMessage() { + return $this->errorMessage; + } + + function ensureDefaultValue($default_value) { + if (!isset($this->value) || $this->value == '') + { + $this->value = $default_value; + $this->uses_default_value = true; + } + } + + function checkFilter($filter_type) { + if (isset($this->value) && $this->value != '') { + global $lang; + $val = $this->value; + $key = $this->name; + switch ($filter_type) { + case 'email' : + case 'email_address' : + if (!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key)); } - } - } - - return $value; - } - - function _escapeStringValue($value){ - $db = &DB::getInstance(); - $value = $db->addQuotes($value); - return '\''.$value.'\''; - - } - - function isValid(){ - return $this->isValid; - } - - function getErrorMessage(){ - return $this->errorMessage; - } - - function ensureDefaultValue($default_value){ - if(!isset($this->value) || $this->value == '') - $this->value = $default_value; - } - - function checkFilter($filter_type){ - if(isset($this->value) && $this->value != ''){ - global $lang; - $val = $this->value; - $key = $this->name; - switch($filter_type) { - case 'email' : - case 'email_address' : - if(!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) { - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'homepage' : - if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) { - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'userid' : - case 'user_id' : - if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) { - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'number' : - case 'numbers' : - if(is_array($val)) $val = join(',', $val); - if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)){ - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'alpha' : - if(!preg_match('/^[a-z]+$/is', $val)) { - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - case 'alpha_number' : - if(!preg_match('/^[0-9a-z]+$/is', $val)) { - $this->isValid = false; - $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key)); - } - break; - } - } - } - - function checkMaxLength($length){ - if($this->value && (strlen($this->value) > $length)){ - global $lang; - $this->isValid = false; - $key = $this->name; - $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); - } - } - - function checkMinLength($length){ - if($this->value && (strlen($this->value) < $length)){ - global $lang; - $this->isValid = false; - $key = $this->name; - $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); - } - } - - function checkNotNull(){ - if(!isset($this->value)){ - global $lang; - $this->isValid = false; - $key = $this->name; - $this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key)); + break; + case 'homepage' : + if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key)); + } + break; + case 'userid' : + case 'user_id' : + if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key)); + } + break; + case 'number' : + case 'numbers' : + if (is_array($val)) + $val = join(',', $val); + if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); + } + break; + case 'alpha' : + if (!preg_match('/^[a-z]+$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key)); + } + break; + case 'alpha_number' : + if (!preg_match('/^[0-9a-z]+$/is', $val)) { + $this->isValid = false; + $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key)); + } + break; } } } + function checkMaxLength($length) { + if ($this->value && (strlen($this->value) > $length)) { + global $lang; + $this->isValid = false; + $key = $this->name; + $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); + } + } + + function checkMinLength($length) { + if ($this->value && (strlen($this->value) < $length)) { + global $lang; + $this->isValid = false; + $key = $this->name; + $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); + } + } + + function checkNotNull() { + if (!isset($this->value)) { + global $lang; + $this->isValid = false; + $key = $this->name; + $this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key)); + } + } + +} ?> diff --git a/classes/xml/xmlquery/tags/query/QueryTag.class.php b/classes/xml/xmlquery/tags/query/QueryTag.class.php index 35d2011c8..1fd737915 100644 --- a/classes/xml/xmlquery/tags/query/QueryTag.class.php +++ b/classes/xml/xmlquery/tags/query/QueryTag.class.php @@ -68,8 +68,9 @@ class QueryTag { foreach ($table_tags as $table_tag) { if (is_a($table_tag, 'TableTag')) { $table_name = $table_tag->getTableName(); + $table_alias = $table_tag->getTableAlias(); $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; @@ -100,10 +101,10 @@ class QueryTag { unset($column_type); $prebuff .= $argument->toString(); - $table_name = $argument->getTableName(); - if(isset($table_name)) + $table_alias = $argument->getTableName(); + 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 { diff --git a/tests/classes/db/db/xml_query/mysql/MysqlSelectTest.php b/tests/classes/db/db/xml_query/mysql/MysqlSelectTest.php index 0e60e7b5c..576587822 100644 --- a/tests/classes/db/db/xml_query/mysql/MysqlSelectTest.php +++ b/tests/classes/db/db/xml_query/mysql/MysqlSelectTest.php @@ -200,11 +200,13 @@ class MysqlSelectTest extends MysqlTest { from `xe_modules` as `modules` , `xe_documents` as `documents` 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 `documents`.`list_order` <= 2100000000 order by `documents`.`list_order` asc limit 20'; + $this->_test($xml_file, $argsString, $expected); } @@ -253,7 +255,7 @@ class MysqlSelectTest extends MysqlTest { and `documents`.`document_srl` = `comments`.`document_srl` and `documents`.`status` in (\'public\',\'secret\') and `comments`.`content` like \'%dfsds%\') - and comments.list_order <= 2100000000 + and `comments`.`list_order` <= 2100000000 group by `documents`.`document_srl` order by `comments`.`list_order` asc limit 0, 20';