From 8ce067caead824123c16f190d606f8e0b061a6c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 May 2007 13:32:29 +0500 Subject: Bug#26518 XPath and variables problem Problem: XPath variables didn't work. Fix: adding variables support, both user-defined and sp local variables are now supported by XPath. mysql-test/r/xml.result: Adding test case mysql-test/t/xml.test: Adding test case sql/item_xmlfunc.cc: Adding variables support: - SP variables with standard XPath syntax: $i - User variables with non-standard syntax: $@i --- mysql-test/t/xml.test | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'mysql-test/t/xml.test') diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test index 8517dce111f..94b45fa249f 100644 --- a/mysql-test/t/xml.test +++ b/mysql-test/t/xml.test @@ -444,3 +444,75 @@ select ExtractValue('test', '/a/parent'); select ExtractValue('test', '/a/preceding'); select ExtractValue('test', '/a/preceding-sibling'); select ExtractValue('test', '/a/self'); + +# +# Bug#26518 XPath and variables problem +# Check with user defined variables +# +set @i=1; +select ExtractValue('b1b2','/a/b[$@i]'); +set @i=2; +select ExtractValue('b1b2','/a/b[$@i]'); +set @i=NULL; +select ExtractValue('b1b2','/a/b[$@i]'); + +# +# Check variables in a stored procedure - both local and user variables +# Make sure that SP and local variables with the same name work together. +# +DELIMITER |; +CREATE PROCEDURE spxml(xml VARCHAR(128)) +BEGIN + DECLARE c INT; + DECLARE i INT DEFAULT 1; + SET c= ExtractValue(xml,'count(/a/b)'); + SET @i= c; + WHILE i <= c DO + BEGIN + SELECT i, @i, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$@i]'); + SET i= i + 1; + SET @i= @i - 1; + END; + END WHILE; +END| +DELIMITER ;| + +call spxml('b1b2b3'); +drop procedure spxml; + +# +# Additional tests for bug#26518 +--echo Multiple matches, but no index specification +SELECT ExtractValue('b1b2','/a/b'); +--echo No matches +SELECT ExtractValue('b1b2','/a/c'); +--echo Index out of range +SELECT ExtractValue('b1b2','/a/b[-1]'); +SELECT ExtractValue('b1b2','/a/b[10]'); +--echo With string-to-number conversion +SELECT ExtractValue('b1b2','/a/b["1"]'); +SELECT ExtractValue('b1b2','/a/b["1 and string"]'); +SELECT ExtractValue('b1b2','/a/b["string and 1"]'); +SELECT ExtractValue('b1b2','/a/b["string"]'); +--echo String-to-number conversion from a user variable +SET @i='1'; +SELECT ExtractValue('b1b2','/a/b[$@i]'); +SET @i='1 and string'; +SELECT ExtractValue('b1b2','/a/b[$@i]'); +SET @i='string and 1'; +SELECT ExtractValue('b1b2','/a/b[$@i]'); +SET @i='string'; +SELECT ExtractValue('b1b2','/a/b[$@i]'); + +--echo String-to-number conversion with a CHAR SP variable +DELIMITER |; +CREATE PROCEDURE spxml(xml VARCHAR(128), i CHAR(16)) +BEGIN + SELECT ExtractValue(xml,'/a/b[$i]'); +END| +DELIMITER ;| +CALL spxml('b1b2', '1'); +CALL spxml('b1b2', '1 and string'); +CALL spxml('b1b2', 'string and 1'); +CALL spxml('b1b2', 'string'); +DROP PROCEDURE spxml; -- cgit v1.2.1