List:Commits« Previous MessageNext Message »
From:bar Date:March 27 2007 11:12am
Subject:bk commit into 5.1 tree (bar:1.2481) BUG#26518
View as plain text  
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
  1.2481 07/03/27 16:12:26 bar@stripped +3 -0
  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.

  sql/item_xmlfunc.cc
    1.27 07/03/27 16:12:22 bar@stripped +40 -3
    Adding variables support.

  mysql-test/t/xml.test
    1.20 07/03/27 16:12:22 bar@stripped +38 -0
    Adding test case

  mysql-test/r/xml.result
    1.22 07/03/27 16:12:22 bar@stripped +34 -0
    Adding test case

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	bar
# Host:	bar.myoffice.izhnet.ru
# Root:	/home/bar/mysql-5.1.b26518

--- 1.21/mysql-test/r/xml.result	2007-01-22 13:28:51 +04:00
+++ 1.22/mysql-test/r/xml.result	2007-03-27 16:12:22 +05:00
@@ -884,3 +884,37 @@
 select ExtractValue('<a><self>test</self></a>', '/a/self');
 ExtractValue('<a><self>test</self></a>', '/a/self')
 test
+set @i=1;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]')
+b1
+set @i=2;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]')
+b2
+set @i=NULL;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]')
+
+CREATE PROCEDURE spxml(xml VARCHAR(128))
+BEGIN
+DECLARE c INT;
+DECLARE i INT DEFAULT 1;
+SET @i= 3;
+SET @j= 3;
+SET c= ExtractValue(xml,'count(/a/b)');
+WHILE i <= c DO
+BEGIN
+SELECT @i, i, @j, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$j]');
+SET i= i + 1;
+END;
+END WHILE;
+END|
+call spxml('<a><b>b1</b><b>b2</b><b>b3</b></a>');
+@i	i	@j	ExtractValue(xml,'/a/b[$i]')	ExtractValue(xml,'/a/b[$j]')
+3	1	3	b1	b3
+@i	i	@j	ExtractValue(xml,'/a/b[$i]')	ExtractValue(xml,'/a/b[$j]')
+3	2	3	b2	b3
+@i	i	@j	ExtractValue(xml,'/a/b[$i]')	ExtractValue(xml,'/a/b[$j]')
+3	3	3	b3	b3
+drop procedure spxml;

--- 1.19/mysql-test/t/xml.test	2006-12-27 18:14:24 +04:00
+++ 1.20/mysql-test/t/xml.test	2007-03-27 16:12:22 +05:00
@@ -444,3 +444,41 @@
 select ExtractValue('<a><preceding>test</preceding></a>', '/a/preceding');
 select ExtractValue('<a><preceding-sibling>test</preceding-sibling></a>', '/a/preceding-sibling');
 select ExtractValue('<a><self>test</self></a>', '/a/self');
+
+#
+# Bug#26518 XPath and variables problem
+# Check without a procedure context - with user defined variables
+#
+set @i=1;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+set @i=2;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+set @i=NULL;
+select ExtractValue('<a><b>b1</b><b>b2</b></a>','/a/b[$i]');
+
+#
+# Check variables in a stored procedure - with local variables
+# Make sure local variables have precedence
+# over user defined variables with the same names:
+# - both user and local variables with name "i" exist.
+# - only user variable with name "j" exists.
+#
+DELIMITER |;
+CREATE PROCEDURE spxml(xml VARCHAR(128))
+BEGIN
+  DECLARE c INT;
+  DECLARE i INT DEFAULT 1;
+  SET @i= 3;
+  SET @j= 3;
+  SET c= ExtractValue(xml,'count(/a/b)');
+  WHILE i <= c DO
+    BEGIN
+      SELECT @i, i, @j, ExtractValue(xml,'/a/b[$i]'), ExtractValue(xml,'/a/b[$j]');
+      SET i= i + 1;
+    END;
+  END WHILE;
+END|
+DELIMITER ;|
+
+call spxml('<a><b>b1</b><b>b2</b><b>b3</b></a>');
+drop procedure spxml;

--- 1.26/sql/item_xmlfunc.cc	2007-02-24 14:43:10 +04:00
+++ 1.27/sql/item_xmlfunc.cc	2007-03-27 16:12:22 +05:00
@@ -19,7 +19,7 @@
 
 #include "mysql_priv.h"
 #include "my_xml.h"
-
+#include "sp_pcontext.h"
 
 /*
   TODO: future development directions:
@@ -2418,6 +2418,16 @@
   SYNOPSYS
 
     [36] VariableReference ::= '$' QName
+    
+    Find variable by name and return its Item.
+    
+    Outside a stored procedure:
+    return a user variable with the given name.
+    
+    Inside a stored prodecure:
+    - return a local sp variable with the given name if it exists,
+    - otherwise, return a user variable with the same name.
+    
   RETURN
     1 - success
     0 - failure
@@ -2425,8 +2435,35 @@
 static int
 my_xpath_parse_VariableReference(MY_XPATH *xpath)
 {
-  return my_xpath_parse_term(xpath, MY_XPATH_LEX_DOLLAR) &&
-         my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT);
+  if (my_xpath_parse_term(xpath, MY_XPATH_LEX_DOLLAR) &&
+      my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT))
+  {
+    LEX_STRING name;
+    sp_variable_t *spv;
+    sp_pcontext *spc;
+    LEX *lex;
+    name.length= xpath->prevtok.end - xpath->prevtok.beg;
+    name.str= (char*) xpath->prevtok.beg;
+
+    if ((lex= current_thd->lex) &&
+        (spc= lex->spcont) &&
+        (spv= spc->find_variable(&name)))
+    {
+      Item_splocal *splocal;
+      splocal= new Item_splocal(name, spv->offset, spv->type, 0);
+#ifndef DBUG_OFF
+      if (splocal)
+        splocal->m_sp= lex->sphead;
+#endif
+      xpath->item= (Item*) splocal;
+    }
+    else
+    {
+      xpath->item= new Item_func_get_user_var(name);
+    }
+    return xpath->item ? 1 : 0;
+  }
+  return 0;
 }
 
 
Thread
bk commit into 5.1 tree (bar:1.2481) BUG#26518bar27 Mar