mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Issue 343 - Problem when condition have var and default attribute both.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9482 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
3815aece09
commit
36211cb65b
5 changed files with 120 additions and 28 deletions
|
|
@ -29,6 +29,24 @@
|
|||
|
||||
function toString(){
|
||||
$validator = '';
|
||||
if($this->filter){
|
||||
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length){
|
||||
$validator .= sprintf("$%s_argument->checkMinLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($this->max_length){
|
||||
$validator .= sprintf("$%s_argument->checkMaxLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->max_length
|
||||
);
|
||||
}
|
||||
if(isset($this->default_value)){
|
||||
$this->default_value = new DefaultValue($this->argument_name, $this->default_value);
|
||||
if($this->default_value->isSequence())
|
||||
|
|
@ -48,24 +66,6 @@
|
|||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
if($this->filter){
|
||||
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length){
|
||||
$validator .= sprintf("$%s_argument->checkMinLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($this->max_length){
|
||||
$validator .= sprintf("$%s_argument->checkMaxLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->max_length
|
||||
);
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,20 +23,25 @@
|
|||
$dbParser = DB::getParser();
|
||||
$this->column_name = $dbParser->parseColumnName($condition->attrs->column);
|
||||
|
||||
$isColumnName = strpos($condition->attrs->default, '.');
|
||||
$isColumnName = $isColumnName || strpos($condition->attrs->var, '.');
|
||||
// If default value is column name, it should be escaped
|
||||
if($isColumnName = strpos($condition->attrs->default, '.')){
|
||||
$condition->attrs->default = $dbParser->parseColumnName($condition->attrs->default);
|
||||
}
|
||||
|
||||
if($condition->node_name == 'query'){
|
||||
$this->query = new QueryTag($condition, true);
|
||||
$this->default_column = $this->query->toString();
|
||||
}
|
||||
else if(($condition->attrs->var && !$isColumnName) || $isColumnName === false){
|
||||
else if($condition->attrs->var && !strpos($condition->attrs->var, '.')){
|
||||
$this->argument = new QueryArgument($condition);
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
}
|
||||
else {
|
||||
if($condition->attrs->default)
|
||||
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->default) . "'" ;
|
||||
if($condition->attrs->default){
|
||||
if(!$isColumnName && !is_numeric($condition->attrs->default))
|
||||
$condition->attrs->default = "\'" . $condition->attrs->default . "\'";
|
||||
$this->default_column = "'" . $condition->attrs->default . "'" ;
|
||||
}
|
||||
else
|
||||
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'" ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
function test_module_getDefaultModules(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getDefaultModules.xml";
|
||||
$argsString = '';
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
$expected = 'SELECT "modules"."site_srl"
|
||||
, "modules"."module"
|
||||
, "modules"."mid"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
function test_module_getDefaultModules(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getDefaultModules.xml";
|
||||
$argsString = '';
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
$expected = 'SELECT [modules].[site_srl]
|
||||
, [modules].[module]
|
||||
, [modules].[mid]
|
||||
|
|
@ -127,15 +127,19 @@
|
|||
$this->_test($xml_file, $argsString, $expected, array("'10'"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query fails because XML is wrong - title column does not exist
|
||||
* in xe_modules. Maybe the developer ment "browser_title"
|
||||
*/
|
||||
function test_opage_getOpageList(){
|
||||
$xml_file = _XE_PATH_ . "modules/opage/queries/getOpageList.xml";
|
||||
$argsString = '$args->s_title = "yuhuu";
|
||||
$args->module = \'opage\';';
|
||||
$expected = 'SELECT TOP 20 *
|
||||
FROM [xe_modules] as [modules]
|
||||
WHERE [module] = ? and ([title] like ?)
|
||||
WHERE [module] = \'opage\' and ([title] like ?)
|
||||
ORDER BY [module_srl] desc';
|
||||
$this->_test($xml_file, $argsString, $expected, array("'opage'", "'%yuhuu%'"));
|
||||
$this->_test($xml_file, $argsString, $expected, array("'%yuhuu%'"));
|
||||
}
|
||||
|
||||
function test_module_getExtraVars(){
|
||||
|
|
|
|||
83
test-phpUnit/db/xml_query/mysql/MysqlSelectTest.php
Normal file
83
test-phpUnit/db/xml_query/mysql/MysqlSelectTest.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||
|
||||
class MysqlSelectTest extends MysqlTest {
|
||||
|
||||
function _test($xml_file, $argsString, $expected, $columnList = null){
|
||||
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
|
||||
}
|
||||
|
||||
function testConditionWithVarAndColumnDefaultValue_WithoutArgument(){
|
||||
$xml_file = _XE_PATH_ . "modules/resource/queries/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`
|
||||
, `package`.`package_srl` as `package_srl`
|
||||
, `package`.`path` as `path`
|
||||
, `package`.`license` as `license`
|
||||
, `package`.`title` as `title`
|
||||
, `package`.`homepage` as `homepage`
|
||||
, `package`.`description` as `package_description`
|
||||
, `package`.`voter` as `package_voter`
|
||||
, `package`.`voted` as `package_voted`
|
||||
, `package`.`downloaded` as `package_downloaded`
|
||||
, `package`.`regdate` as `package_regdate`
|
||||
, `package`.`last_update` as `package_last_update`
|
||||
, `member`.`nick_name` as `nick_name`
|
||||
, `member`.`user_id` as `user_id`
|
||||
, `item`.`item_srl` as `item_srl`
|
||||
, `item`.`document_srl` as `document_srl`
|
||||
, `item`.`file_srl` as `item_file_srl`
|
||||
, `item`.`screenshot_url` as `item_screenshot_url`
|
||||
, `item`.`version` as `item_version`
|
||||
, `item`.`voter` as `item_voter`
|
||||
, `item`.`voted` as `item_voted`
|
||||
, `item`.`downloaded` as `item_downloaded`
|
||||
, `item`.`regdate` as `item_regdate`
|
||||
from `xe_resource_packages` as `package`
|
||||
, `xe_member` as `member`
|
||||
, `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);
|
||||
}
|
||||
|
||||
function testConditionWithVarAndColumnDefaultValue_WithArgument(){
|
||||
$xml_file = _XE_PATH_ . "modules/resource/queries/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`
|
||||
, `package`.`package_srl` as `package_srl`
|
||||
, `package`.`path` as `path`
|
||||
, `package`.`license` as `license`
|
||||
, `package`.`title` as `title`
|
||||
, `package`.`homepage` as `homepage`
|
||||
, `package`.`description` as `package_description`
|
||||
, `package`.`voter` as `package_voter`
|
||||
, `package`.`voted` as `package_voted`
|
||||
, `package`.`downloaded` as `package_downloaded`
|
||||
, `package`.`regdate` as `package_regdate`
|
||||
, `package`.`last_update` as `package_last_update`
|
||||
, `member`.`nick_name` as `nick_name`
|
||||
, `member`.`user_id` as `user_id`
|
||||
, `item`.`item_srl` as `item_srl`
|
||||
, `item`.`document_srl` as `document_srl`
|
||||
, `item`.`file_srl` as `item_file_srl`
|
||||
, `item`.`screenshot_url` as `item_screenshot_url`
|
||||
, `item`.`version` as `item_version`
|
||||
, `item`.`voter` as `item_voter`
|
||||
, `item`.`voted` as `item_voted`
|
||||
, `item`.`downloaded` as `item_downloaded`
|
||||
, `item`.`regdate` as `item_regdate`
|
||||
from `xe_resource_packages` as `package`
|
||||
, `xe_member` as `member`
|
||||
, `xe_resource_items` as `item`
|
||||
where `package`.`member_srl` = `member`.`member_srl`
|
||||
and `item`.`item_srl` = 10';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue