From: Date: October 4 2007 11:40am Subject: bk commit into 5.1 tree (bar:1.2569) BUG#26051 List-Archive: http://lists.mysql.com/commits/34883 X-Bug: 26051 Message-Id: <200710040940.l949eWxE028578@bar.myoffice.izhnet.ru> Below is the list of changes that have just been committed into a local 5.1 repository of bar. When bar does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-10-04 14:40:27+05:00, bar@stripped +3 -0 Bug#26051 XML: ExtractValue() returns wrong results for boolean() XPath test Problem: boolean cast didn't work well in some cases: - node sets consisting of more than one nodes - strings Fix: making boolean cast work accoring to XPath specifications: - return true for any non-empty node sets - return true for any non-empty strings mysql-test/r/xml.result@stripped, 2007-10-04 14:40:25+05:00, bar@stripped +17 -0 Adding tests mysql-test/t/xml.test@stripped, 2007-10-04 14:40:25+05:00, bar@stripped +12 -0 Adding tests sql/item_xmlfunc.cc@stripped, 2007-10-04 14:40:25+05:00, bar@stripped +11 -1 Fixing boolean cast from strings and node sets diff -Nrup a/mysql-test/r/xml.result b/mysql-test/r/xml.result --- a/mysql-test/r/xml.result 2007-09-14 18:38:25 +05:00 +++ b/mysql-test/r/xml.result 2007-10-04 14:40:25 +05:00 @@ -1012,3 +1012,20 @@ select ExtractValue('a', '/a[@x=@ ERROR HY000: XPATH error: comparison of two nodesets is not supported: '=@y0123456789_0123456789_0123456' select ExtractValue('a', '/a[@x=$y0123456789_0123456789_0123456789_0123456789]'); ERROR HY000: Unknown XPATH variable at: '$y0123456789_0123456789_01234567' +set @xml = 'vv'; +select ExtractValue(@xml,'boolean(//n)') as NonEmptyNodeSet_to_Boolean; +NonEmptyNodeSet_to_Boolean +1 +select ExtractValue(@xml,'boolean(//n[10])') as EmptyNodeSet_to_Boolean; +EmptyNodeSet_to_Boolean +0 +select ExtractValue(@xml,'boolean("00")') as NonEmptyString_to_Boolean; +NonEmptyString_to_Boolean +1 +select ExtractValue(@xml,'boolean("11")') as NonEmptyString_to_Boolean; +NonEmptyString_to_Boolean +1 +select ExtractValue(@xml,'boolean("")') as EmptyString_to_Boolean; +EmptyString_to_Boolean +0 +End of 5.1 tests diff -Nrup a/mysql-test/t/xml.test b/mysql-test/t/xml.test --- a/mysql-test/t/xml.test 2007-05-23 12:34:44 +05:00 +++ b/mysql-test/t/xml.test 2007-10-04 14:40:25 +05:00 @@ -533,3 +533,15 @@ select UpdateXML('a',repeat('a b select ExtractValue('a', '/a[@x=@y0123456789_0123456789_0123456789_0123456789]'); --error 1105 select ExtractValue('a', '/a[@x=$y0123456789_0123456789_0123456789_0123456789]'); + +# +# Bug#26051 XML: ExtractValue() returns wrong results for boolean() XPath test +# +set @xml = 'vv'; +select ExtractValue(@xml,'boolean(//n)') as NonEmptyNodeSet_to_Boolean; +select ExtractValue(@xml,'boolean(//n[10])') as EmptyNodeSet_to_Boolean; +select ExtractValue(@xml,'boolean("00")') as NonEmptyString_to_Boolean; +select ExtractValue(@xml,'boolean("11")') as NonEmptyString_to_Boolean; +select ExtractValue(@xml,'boolean("")') as EmptyString_to_Boolean; + +--echo End of 5.1 tests diff -Nrup a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc --- a/sql/item_xmlfunc.cc 2007-08-13 18:11:11 +05:00 +++ b/sql/item_xmlfunc.cc 2007-10-04 14:40:25 +05:00 @@ -396,10 +396,20 @@ public: bool is_bool_func() { return 1; } longlong val_int() { + if (args[0]->type() == STRING_ITEM) + { + /* a string is true if and only if its length is non-zero */ + String *str= args[0]->val_str(&tmp_value); + return str->length() > 0 ? 1 : 0; + } if (args[0]->type() == XPATH_NODESET) { + /* + a node-set is true if and only if it is non-empty, + i.e. consists of one or more elements + */ String *flt= args[0]->val_nodeset(&tmp_value); - return flt->length() == sizeof(MY_XPATH_FLT) ? 1 : 0; + return flt->length() >= sizeof(MY_XPATH_FLT) ? 1 : 0; } return args[0]->val_real() ? 1 : 0; }