From: Date: March 27 2008 11:57am Subject: bk commit into 5.1 tree (bar:1.2574) BUG#26051 List-Archive: http://lists.mysql.com/commits/44505 X-Bug: 26051 Message-Id: <200803271057.m2RAvBGe017340@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, 2008-03-27 14:57:06+04: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 - return 0 for NULL strings mysql-test/r/xml.result@stripped, 2008-03-27 14:57:04+04:00, bar@stripped +19 -0 Adding tests mysql-test/t/xml.test@stripped, 2008-03-27 14:57:04+04:00, bar@stripped +12 -0 Adding tests sql/item_xmlfunc.cc@stripped, 2008-03-27 14:57:04+04: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-11-21 16:00:05 +04:00 +++ b/mysql-test/r/xml.result 2008-03-27 14:57:04 +04:00 @@ -1029,4 +1029,23 @@ SELECT 1 FROM t1 ORDER BY(UPDATEXML(a, ' 1 1 DROP TABLE t1; +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 +select ExtractValue(@xml,'boolean($@empty)') as NULLString_to_Boolean; +NULLString_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-11-21 16:00:06 +04:00 +++ b/mysql-test/t/xml.test 2008-03-27 14:57:04 +04:00 @@ -551,4 +551,16 @@ INSERT INTO t1 VALUES (0), (0); SELECT 1 FROM t1 ORDER BY(UPDATEXML(a, '1', '1')); DROP TABLE t1; +# +# 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; +select ExtractValue(@xml,'boolean($@empty)') as NULLString_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-10-30 11:19:23 +04:00 +++ b/sql/item_xmlfunc.cc 2008-03-27 14:57:04 +04:00 @@ -398,8 +398,18 @@ public: { 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; + } + if (args[0]->result_type() == STRING_RESULT) + { + /* a string is true if and only if its length is non-zero */ + String *str= args[0]->val_str(&tmp_value); + return str && str->length() > 0 ? 1 : 0; } return args[0]->val_real() ? 1 : 0; }