From 7de48344cc1240a05258306be9cf22f90269fb6e Mon Sep 17 00:00:00 2001 From: ucorina Date: Fri, 22 Jul 2011 11:50:08 +0000 Subject: [PATCH] Fixed select bug - unless default value is explicitly set as empty string, ignore arguments whose value is empty string. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8624 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- .../queryparts/condition/Condition.class.php | 1 + .../xml/xmlquery/argument/Argument.class.php | 2 +- .../queryargument/QueryArgument.class.php | 18 ++++-------------- .../argument/ConditionArgumentTest.php | 13 +++++++++++++ .../cubrid/CubridInsertOnlineTest.php | 2 -- .../cubrid/CubridSelectOnlineTest.php | 14 +++++++++++++- .../db/xml_query/cubrid/CubridSelectTest.php | 18 +++++++++++++++--- 7 files changed, 47 insertions(+), 21 deletions(-) diff --git a/classes/db/queryparts/condition/Condition.class.php b/classes/db/queryparts/condition/Condition.class.php index b81802f67..35ccfc453 100644 --- a/classes/db/queryparts/condition/Condition.class.php +++ b/classes/db/queryparts/condition/Condition.class.php @@ -53,6 +53,7 @@ function show(){ if($this->hasArgument() && !$this->argument->isValid()) return false; + if($this->hasArgument() && ($this->_value === '\'\'')) return false; switch($this->operation) { case 'equal' : case 'more' : diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 7a528f50c..b9c869946 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -7,7 +7,7 @@ var $isValid; var $errorMessage; - + function Argument($name, $value){ $this->value = $value; $this->name = $name; diff --git a/classes/xml/xmlquery/queryargument/QueryArgument.class.php b/classes/xml/xmlquery/queryargument/QueryArgument.class.php index 3257ce17f..92f9bdfd5 100644 --- a/classes/xml/xmlquery/queryargument/QueryArgument.class.php +++ b/classes/xml/xmlquery/queryargument/QueryArgument.class.php @@ -5,17 +5,9 @@ var $argument_validator; var $column_name; var $operation; - var $ignoreValue; function QueryArgument($tag){ - // HACK (this is for backwords compatibility - there are many xml files that have variable names (var) given with .) - // eg. var = point.memeber_srl (getMemberList query from point module) - $this->argument_name = str_replace('.', '_',$tag->attrs->var); - if(!$this->argument_name) $this->ignoreValue = true; - else $this->ignoreValue = false; - - - + $this->argument_name = $tag->attrs->var; if(!$this->argument_name) $this->argument_name = $tag->attrs->name; if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->column); @@ -28,10 +20,7 @@ } if($tag->attrs->operation) $this->operation = $tag->attrs->operation; - - // If we work with ConditionArgument, check if default value exists, and if yes, create argument - if($this->operation && $tag->attrs->default) $this->ignoreValue = false; - + require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php'); $this->argument_validator = new QueryArgumentValidator($tag, $this); @@ -59,7 +48,7 @@ $arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n" , $this->argument_name , $this->argument_name - , $this->ignoreValue ? 'null' : '$args->'.$this->argument_name + , '$args->'.$this->argument_name , $this->operation ); @@ -67,6 +56,7 @@ $arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n" , $this->argument_name , $this->argument_name + , '$args->'.$this->argument_name , $this->ignoreValue ? 'null' : '$args->'.$this->argument_name); diff --git a/test-phpUnit/classes/xml/xmlquery/argument/ConditionArgumentTest.php b/test-phpUnit/classes/xml/xmlquery/argument/ConditionArgumentTest.php index 116cf232a..633e00cfb 100644 --- a/test-phpUnit/classes/xml/xmlquery/argument/ConditionArgumentTest.php +++ b/test-phpUnit/classes/xml/xmlquery/argument/ConditionArgumentTest.php @@ -16,6 +16,19 @@ class ConditionArgumentTest extends CubridTest { $condition = new Condition('"extra_vars"."document_srl"',$document_srl_argument,"in", 'and'); $this->assertEquals('and "extra_vars"."document_srl" in (1234)', $condition->toString()); } + + function testZeroValue(){ + $args->site_srl = 0; + $site_srl_argument = new ConditionArgument('site_srl', $args->site_srl, 'equal'); + $site_srl_argument->checkNotNull(); + $site_srl_argument->createConditionValue(); + if(!$site_srl_argument->isValid()) return $site_srl_argument->getErrorMessage(); + $site_srl_argument->setColumnType('number'); + + $condition = new Condition('"sites"."site_srl"',$site_srl_argument,"equal"); + $this->assertEquals(' "sites"."site_srl" = 0', $condition->toString()); + } + /** * @todo Implement testCreateConditionValue(). */ diff --git a/test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php b/test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php index e1568307a..f55bd3720 100644 --- a/test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php +++ b/test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php @@ -50,8 +50,6 @@ $this->assertNotEquals(-225, $output->error); $this->assertNotEquals('Missing value for attribute "homepage" with the NOT NULL constraint.', $output->message); - - } function test_communication_addFriendGroup(){ diff --git a/test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php b/test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php index 3965b2488..fcc7eecb6 100644 --- a/test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php +++ b/test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php @@ -11,7 +11,7 @@ $this->assertEquals($output->data->module_srl, 111); } - function test_module_getInfo(){ + function test_module_getInfo(){ $args->site_srl = 0; $output = executeQuery('module.getSiteInfo', $args); $this->assertTrue(is_a($output, 'Object')); @@ -46,5 +46,17 @@ $this->assertTrue(is_int($output->page), $output->message); } + + function test_member_getMemberList(){ + $args->is_admin = ''; + $args->is_denied = ''; + $args->sort_index = "list_order"; + $args->sort_order = 'asc'; + $args->list_count = 40; + $args->page_count = 10; + + $output = executeQuery('member.getMemberList', $args); + $this->assertEquals(0, $output->error, $output->message); + } } ?> diff --git a/test-phpUnit/db/xml_query/cubrid/CubridSelectTest.php b/test-phpUnit/db/xml_query/cubrid/CubridSelectTest.php index daf89436d..edaa484a2 100644 --- a/test-phpUnit/db/xml_query/cubrid/CubridSelectTest.php +++ b/test-phpUnit/db/xml_query/cubrid/CubridSelectTest.php @@ -194,9 +194,21 @@ , "xe_documents" as "documents" WHERE "documents"."document_srl" = 10 and "modules"."module_srl" = "documents"."module_srl"'; - $this->_test($xml_file, $argsString, $expected); - - + $this->_test($xml_file, $argsString, $expected); } + + function test_member_getMemberList(){ + $xml_file = _XE_PATH_ . "modules/member/queries/getMemberList.xml"; + $argsString = '$args->is_admin = \'\'; + $args->is_denied = \'\'; + $args->sort_index = "list_order"; + $args->sort_order = \'asc\'; + $args->list_count = 40; + $args->page_count = 10;'; + $expected = 'select * from "xe_member" as "member" + order by "list_order" asc + limit 0, 40'; + $this->_test($xml_file, $argsString, $expected); + } } \ No newline at end of file