diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 1fe6a7409..d5046763b 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -67,7 +67,7 @@ return $dbParser->parseExpression($value); } if(!isset($value)) return null; - if(in_array($this->type, array('date', 'varchar', 'char','text', 'bigtext'))){ + if(in_array($this->getType(), array('date', 'varchar', 'char','text', 'bigtext'))){ if(!is_array($value)) $value = $this->_escapeStringValue ($value); else { diff --git a/classes/xml/xmlquery/argument/ConditionArgument.class.php b/classes/xml/xmlquery/argument/ConditionArgument.class.php index 2094d9eeb..e11350aa1 100644 --- a/classes/xml/xmlquery/argument/ConditionArgument.class.php +++ b/classes/xml/xmlquery/argument/ConditionArgument.class.php @@ -40,8 +40,19 @@ } } + /** + * Since ConditionArgument is used in WHERE clause, + * where the argument value is compared to a table column, + * it is assumed that all arguments have type. There are cases though + * where the column does not have any type - if it was removed from + * the XML schema for example - see the is_secret column in xe_documents table. + * In this case, the column type is retrieved according to argument + * value type (using the PHP function is_numeric). + * + * @return type string + */ function getType(){ - return $this->type; + return $this->type ? $this->type : (!is_numeric($this->value) ? "varchar" : ""); } function setColumnType($column_type){ diff --git a/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php b/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php new file mode 100644 index 000000000..e4264945d --- /dev/null +++ b/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php @@ -0,0 +1,20 @@ +_testQuery($xml_file, $argsString, $expected, 'getUpdateSql', $columnList); + } + + function test_document_updateDocumentStatus(){ + $xml_file = _XE_PATH_ . "modules/document/queries/updateDocumentStatus.xml"; + $argsString = '$args->is_secret = \'Y\'; + $args->status = \'SECRET\'; + '; + $expected = 'update `xe_documents` set `status` = \'secret\' where `is_secret` = \'y\''; + $this->_test($xml_file, $argsString, $expected); + } + + + } \ No newline at end of file