From 620b18e532ffd3cb175c56f6953d012072623758 Mon Sep 17 00:00:00 2001 From: ucorina Date: Mon, 25 Jul 2011 17:33:27 +0000 Subject: [PATCH] Update to string array arguments - added format with SQLSRV_PHPTYPE_STRING. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8635 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/db/DBMssql.class.php | 7 +++- .../xml/xmlquery/argument/Argument.class.php | 6 ++- test-phpUnit/db/DBTest.php | 3 +- .../xml_query/mssql/MssqlSelectOnlineTest.php | 11 ++++++ .../db/xml_query/mssql/MssqlSelectTest.php | 38 +++++++++---------- 5 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 test-phpUnit/db/xml_query/mssql/MssqlSelectOnlineTest.php diff --git a/classes/db/DBMssql.class.php b/classes/db/DBMssql.class.php index cdf1cf995..1810247f3 100644 --- a/classes/db/DBMssql.class.php +++ b/classes/db/DBMssql.class.php @@ -180,9 +180,12 @@ if(is_array($value)) $_param = array_merge($_param, $value); else $_param[] = $o->getUnescapedValue(); }else{ - // TODO treat arrays here too $value = $o->getUnescapedValue(); - $_param[] = array($value, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); + if(is_array($value)) { + foreach($value as $v) + $_param[] = array($v, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); + } + else $_param[] = array($value, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); } } } diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 14bc73a74..086e53ef2 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -35,7 +35,7 @@ } function getValue(){ - $value = $this->escapeValue($this->value); + $value = $this->getEscapedValue(); return $this->toString($value); } @@ -43,6 +43,10 @@ return $this->column_operation; } + function getEscapedValue(){ + return $this->escapeValue($this->value); + } + function getUnescapedValue(){ return $this->value; } diff --git a/test-phpUnit/db/DBTest.php b/test-phpUnit/db/DBTest.php index 17b80ab90..8fa514b39 100644 --- a/test-phpUnit/db/DBTest.php +++ b/test-phpUnit/db/DBTest.php @@ -48,8 +48,7 @@ // Test query arguments $argCount = count($expectedArgs); for($i = 0; $i < $argCount; $i++){ - //echo "$i: $expectedArgs[$i] vs $queryArguments[$i]->getValue()"; - $this->assertEquals($expectedArgs[$i], $queryArguments[$i]->getValue()); + $this->assertEquals($expectedArgs[$i], $queryArguments[$i]->getEscapedValue()); } } diff --git a/test-phpUnit/db/xml_query/mssql/MssqlSelectOnlineTest.php b/test-phpUnit/db/xml_query/mssql/MssqlSelectOnlineTest.php new file mode 100644 index 000000000..44867e38f --- /dev/null +++ b/test-phpUnit/db/xml_query/mssql/MssqlSelectOnlineTest.php @@ -0,0 +1,11 @@ +module_srl = 67; + $output = executeQuery("syndication.getGrantedModule", $args); + $this->assertEquals(0, $output->error, $output->error + ' ' + $output->message); + } + } + +?> \ No newline at end of file diff --git a/test-phpUnit/db/xml_query/mssql/MssqlSelectTest.php b/test-phpUnit/db/xml_query/mssql/MssqlSelectTest.php index 4bf2cba5e..8d8e0f7d2 100644 --- a/test-phpUnit/db/xml_query/mssql/MssqlSelectTest.php +++ b/test-phpUnit/db/xml_query/mssql/MssqlSelectTest.php @@ -4,7 +4,7 @@ class MssqlSelectTest extends MssqlTest { function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){ - $this->_testPreparedQuery($xml_file, $argsString, $expected, 'getSelectSql', $expectedArgs = NULL); + $this->_testPreparedQuery($xml_file, $argsString, $expected, 'getSelectSql', $expectedArgs); } function testSelectStar(){ @@ -142,7 +142,7 @@ $xml_file = _XE_PATH_ . "modules/module/queries/getModuleExtraVars.xml"; $argsString = '$args->module_srl = 25;'; $expected = 'SELECT * FROM [xe_module_extra_vars] as [module_extra_vars] WHERE [module_srl] in (?)'; - $this->_test($xml_file, $argsString, $expected, array("25")); + $this->_test($xml_file, $argsString, $expected, array(array(25))); } function test_module_getModuleSites(){ @@ -150,25 +150,21 @@ //$argsString = '$args->module_srls = array(67, 65);'; $argsString = '$args->module_srls = "67, 65";'; $expected = 'SELECT [modules].[module_srl] as [module_srl], [sites].[domain] as [domain] FROM [xe_modules] as [modules] , [xe_sites] as [sites] WHERE [modules].[module_srl] in (?,?) and [sites].[site_srl] = [modules].[site_srl]'; - $this->_test($xml_file, $argsString, $expected, array("67", "65")); + $this->_test($xml_file, $argsString, $expected, array(array(67, 65))); } - - - // TODO Something fishy about this query - to be investigated - /* - function test_syndication_getGrantedModules(){ - $xml_file = _XE_PATH_ . "modules/syndication/queries/getGrantedModules.xml"; - $argsString = '$args->module_srl = 12; - $args->name = array(\'access\',\'view\',\'list\');'; - $expected = 'select "module_srl" - from "xe_module_grants" as "module_grants" - where "name" in (?) - and ("group_srl" >= -2 - or "group_srl" = -2 - or "group_srl" = -2) - group by "module_srl"'; - $this->_test($xml_file, $argsString, $expected); - } - */ + function test_syndication_getGrantedModule(){ + $xml_file = _XE_PATH_ . "modules/syndication/queries/getGrantedModule.xml"; + $argsString = '$args->module_srl = 67;'; + $expected = 'select count(*) as [count] + from [xe_module_grants] as [module_grants] + where [module_srl] = ? + and [name] in (?,?,?) + and ( + [group_srl] >= ? + or [group_srl] = ? + or [group_srl] = ? + )'; + $this->_test($xml_file, $argsString, $expected, array(67, array('\'access\'', '\'view\'', '\'list\''), 1, -1, -2)); + } } \ No newline at end of file