List:Commits« Previous MessageNext Message »
From:bar Date:March 3 2006 2:36pm
Subject:bk commit into 5.1 tree (bar:1.2214) BUG#16318
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.2214 06/03/03 18:36:14 bar@stripped +3 -0
    Bug#16318: XML: extractvalue() incorrectly returns last() = 1
  xml.result, xml.test:
    Adding test case.
  item_xmlfunc.cc:
    - adding "size" member into MY_XPATH_FLT struct,
    to pass parent's context size when iterating
    in a predicate. Previously, temporaty context
    size was calculated instead, which is always 1.
    As a result, things like last() and count() 
    didn't work fine.
    - adding iteration into Item_func_xpath_elementbyindex:
    similar to Item_func_xpath_predicate.
    This is to make things like last() and count()
    work inside square brackets.

  mysql-test/r/xml.result
    1.7 06/03/03 18:35:40 bar@stripped +36 -0
    Adding test case.

  mysql-test/t/xml.test
    1.7 06/03/03 18:35:34 bar@stripped +16 -0
    Adding test case.

  sql/item_xmlfunc.cc
    1.7 06/03/03 18:31:28 bar@stripped +29 -12
    Bug#16318: XML: extractvalue() incorrectly returns last() = 1
    - adding "size" member into MY_XPATH_FLT struct,
    to pass parent's context size when iterating
    in a predicate. Previously, temporaty context
    size was calculated instead, which is always 1.
    As a result, things like last() and count() 
    didn't work fine.
    - adding iteration into Item_func_xpath_elementbyindex:
    similar to Item_func_xpath_predicate.
    This is to make things like last() and count()
    work inside square brackets.

# 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.intranet.mysql.r18.ru
# Root:	/usr/home/bar/mysql-5.1-new.b16318

--- 1.6/mysql-test/r/xml.result	2006-03-02 10:42:02 +04:00
+++ 1.7/mysql-test/r/xml.result	2006-03-03 18:35:40 +04:00
@@ -561,3 +561,39 @@
 select extractvalue('<A_B>A</A_B>','/A_B');
 extractvalue('<A_B>A</A_B>','/A_B')
 A
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[position()]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[position()]')
+B1 B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=last()]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=last()]')
+B1 B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()]')
+B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()-1]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()-1]')
+B1
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=1]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=1]')
+
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=2]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=2]')
+B1 B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=position()]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=position()]')
+B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)]')
+B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)-1]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)-1]')
+B1
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=1]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=1]')
+
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=2]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=2]')
+B1 B2
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=position()]');
+extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=position()]')
+B2

--- 1.6/mysql-test/t/xml.test	2006-03-02 10:42:02 +04:00
+++ 1.7/mysql-test/t/xml.test	2006-03-03 18:35:34 +04:00
@@ -254,3 +254,19 @@
 # Bug #16320 XML: extractvalue() won't accept names containing underscores
 #
 select extractvalue('<A_B>A</A_B>','/A_B');
+
+#
+# Bug#16318: XML: extractvalue() incorrectly returns last() = 1
+#
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[position()]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=last()]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()-1]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=1]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=2]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[last()=position()]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)-1]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=1]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=2]');
+select extractvalue('<a>A<b>B1</b><b>B2</b></a>','/a/b[count(.)=position()]');

--- 1.6/sql/item_xmlfunc.cc	2006-03-02 10:37:58 +04:00
+++ 1.7/sql/item_xmlfunc.cc	2006-03-03 18:31:28 +04:00
@@ -30,7 +30,6 @@
   2. add nodeset_to_nodeset_comparator
   3. add lacking functions:
        - name()
-       - last()
        - lang()
        - string()
        - id()
@@ -75,6 +74,7 @@
 {
   uint num;     /* absolute position in MY_XML_NODE array */
   uint pos;     /* relative position in context           */
+  uint size;    /* context size                           */
 } MY_XPATH_FLT;
 
 
@@ -123,6 +123,15 @@
     MY_XPATH_FLT add;
     add.num= num;
     add.pos= pos;
+    add.size= 0;
+    return append_element(&add);
+  }
+  inline bool append_element(uint32 num, uint32 pos, uint32 size)
+  {
+    MY_XPATH_FLT add;
+    add.num= num;
+    add.pos= pos;
+    add.size= size;
     return append_element(&add);
   }
   inline MY_XPATH_FLT *element(uint i)
@@ -451,7 +460,11 @@
   void fix_length_and_dec() { max_length=10; }
   longlong val_int()
   {
+    uint predicate_supplied_context_size;
     String *res= args[0]->val_nodeset(&tmp_value);
+    if (res->length() == sizeof(MY_XPATH_FLT) &&
+        (predicate_supplied_context_size= ((MY_XPATH_FLT*)res->ptr())->size))
+      return predicate_supplied_context_size;
     return res->length() / sizeof(MY_XPATH_FLT);
   }
 };
@@ -731,13 +744,15 @@
 {
   Item_nodeset_func *nodeset_func= (Item_nodeset_func*) args[0];
   Item_func *comp_func= (Item_func*)args[1];
-  uint pos= 0;
+  uint pos= 0, size;
   prepare(str);
+  size= fltend - fltbeg;
   for (MY_XPATH_FLT *flt= fltbeg; flt < fltend; flt++)
   {
     nodeset_func->context_cache.length(0);
     ((XPathFilter*)(&nodeset_func->context_cache))->append_element(flt->num,
-                                                                   flt->pos);
+                                                                   flt->pos,
+                                                                   size);
     if (comp_func->val_int())
       ((XPathFilter*)str)->append_element(flt->num, pos++);
   }
@@ -747,17 +762,19 @@
 
 String *Item_nodeset_func_elementbyindex::val_nodeset(String *nodeset)
 {
+  Item_nodeset_func *nodeset_func= (Item_nodeset_func*) args[0];
   prepare(nodeset);
-  int index= args[1]->val_int() - 1;
-  if (index >= 0)
+  MY_XPATH_FLT *flt;
+  uint pos, size= fltend - fltbeg;
+  for (pos= 0, flt= fltbeg; flt < fltend; flt++)
   {
-    MY_XPATH_FLT *flt;
-    uint pos;
-    for (pos= 0, flt= fltbeg; flt < fltend; flt++)
-    {
-      if (flt->pos == (uint) index || args[1]->is_bool_func())
-        ((XPathFilter*)nodeset)->append_element(flt->num, pos++);
-    }
+    nodeset_func->context_cache.length(0);
+    ((XPathFilter*)(&nodeset_func->context_cache))->append_element(flt->num,
+                                                                   flt->pos,
+                                                                   size);
+    int index= args[1]->val_int() - 1;
+    if (index >= 0 && (flt->pos == (uint) index || args[1]->is_bool_func()))
+      ((XPathFilter*)nodeset)->append_element(flt->num, pos++);
   }
   return nodeset;
 }
Thread
bk commit into 5.1 tree (bar:1.2214) BUG#16318bar3 Mar