MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:May 19 2008 2:08pm
Subject:bk commit into 6.0 tree (anozdrin:1.2637) BUG#11638
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of anozdrin.  When anozdrin 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-05-19 18:08:10+04:00, anozdrin@quad. +5 -0
  The first part of a patch for Bug#11638: Cannot prepare and execute
  a stored procedure with OUT parameter. This is the easiest part,
  which adds support for OUT-parameters in SQL-layer.

  mysql-test/r/ps.result@stripped, 2008-05-19 18:08:09+04:00, anozdrin@quad. +29 -0
    Update result file.

  mysql-test/t/ps.test@stripped, 2008-05-19 18:08:09+04:00, anozdrin@quad. +43 -1
    Add a test case for Bug#11638 (Cannot prepare and execute
    a stored procedure with OUT parameter).

  sql/item.cc@stripped, 2008-05-19 18:08:09+04:00, anozdrin@quad. +17 -1
    1. Implement Settable_routine_parameter facet of Item_param;
    2. Remember user variable name to be used in set_value().
       user_var_entry may be NULL (if user variable does not exist).

  sql/item.h@stripped, 2008-05-19 18:08:09+04:00, anozdrin@quad. +16 -2
    1. Implement Settable_routine_parameter facet of Item_param;
    2. Remember user variable name to be used in set_value().
       user_var_entry may be NULL (if user variable does not exist).

  sql/sql_prepare.cc@stripped, 2008-05-19 18:08:09+04:00, anozdrin@quad. +2 -2
    Remember user variable name to be used in set_value().
    user_var_entry may be NULL (if user variable does not exist).

diff -Nrup a/mysql-test/r/ps.result b/mysql-test/r/ps.result
--- a/mysql-test/r/ps.result	2008-03-05 13:19:30 +03:00
+++ b/mysql-test/r/ps.result	2008-05-19 18:08:09 +04:00
@@ -2902,4 +2902,33 @@ execute stmt;
 ERROR 21000: Subquery returns more than 1 row
 deallocate prepare stmt;
 drop table t1, t2;
+
 End of 5.1 tests.
+
+#
+# Bug#11638: Cannot prepare and execute a stored procedure with
+# OUT parameter.
+#
+
+DROP PROCEDURE IF EXISTS p1;
+CREATE PROCEDURE p1(OUT v INT) SET v = 1;
+PREPARE stmt FROM 'CALL p1(?)';
+
+SET @x1 = NULL;
+EXECUTE stmt USING @x1;
+SELECT @x1;
+@x1
+1
+
+SET @x2 = 0;
+EXECUTE stmt USING @x2;
+SELECT @x2;
+@x2
+1
+
+DEALLOCATE PREPARE stmt;
+DROP PROCEDURE p1;
+
+# End of Bug#11638.
+
+End of 6.0 tests.
diff -Nrup a/mysql-test/t/ps.test b/mysql-test/t/ps.test
--- a/mysql-test/t/ps.test	2008-03-05 13:19:38 +03:00
+++ b/mysql-test/t/ps.test	2008-05-19 18:08:09 +04:00
@@ -2979,6 +2979,48 @@ execute stmt;
 deallocate prepare stmt;
 drop table t1, t2;
 
+###########################################################################
 
-
+--echo
 --echo End of 5.1 tests.
+
+###########################################################################
+
+--echo
+--echo #
+--echo # Bug#11638: Cannot prepare and execute a stored procedure with
+--echo # OUT parameter.
+--echo #
+--echo
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+CREATE PROCEDURE p1(OUT v INT) SET v = 1;
+
+PREPARE stmt FROM 'CALL p1(?)';
+
+--echo
+SET @x1 = NULL;
+EXECUTE stmt USING @x1;
+SELECT @x1;
+
+--echo
+SET @x2 = 0;
+EXECUTE stmt USING @x2;
+SELECT @x2;
+
+--echo
+DEALLOCATE PREPARE stmt;
+DROP PROCEDURE p1;
+
+--echo
+--echo # End of Bug#11638.
+
+###########################################################################
+
+--echo
+--echo End of 6.0 tests.
+
+###########################################################################
diff -Nrup a/sql/item.cc b/sql/item.cc
--- a/sql/item.cc	2008-04-14 14:09:58 +04:00
+++ b/sql/item.cc	2008-05-19 18:08:09 +04:00
@@ -2693,9 +2693,12 @@ bool Item_param::set_longdata(const char
     1 Out of memory
 */
 
-bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
+bool Item_param::set_from_user_var(THD *thd,
+                                   const LEX_STRING *user_var_name,
+                                   const user_var_entry *entry)
 {
   DBUG_ENTER("Item_param::set_from_user_var");
+
   if (entry && entry->value)
   {
     item_result_type= entry->type;
@@ -2761,6 +2764,8 @@ bool Item_param::set_from_user_var(THD *
   else
     set_null();
 
+  m_user_var_name= user_var_name;
+
   DBUG_RETURN(0);
 }
 
@@ -3154,6 +3159,17 @@ Item_param::eq(const Item *arg, bool bin
     break;
   }
   return FALSE;
+}
+
+bool Item_param::set_value(THD *thd, sp_rcontext *ctx, Item **it)
+{
+  Item_func_set_user_var *suv=
+    new Item_func_set_user_var(*m_user_var_name, *it);
+  /*
+    Item_func_set_user_var is not fixed after construction, call
+    fix_fields().
+  */
+  return (!suv || suv->fix_fields(thd, it) || suv->check(0) || suv->update());
 }
 
 /* End of Item_param related */
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2008-03-15 01:19:52 +03:00
+++ b/sql/item.h	2008-05-19 18:08:09 +04:00
@@ -1603,7 +1603,8 @@ public:
 
 /* Item represents one placeholder ('?') of prepared statement */
 
-class Item_param :public Item
+class Item_param :public Item,
+                  private Settable_routine_parameter
 {
   char cnvbuf[MAX_FIELD_WIDTH];
   String cnvstr;
@@ -1694,7 +1695,9 @@ public:
   bool set_str(const char *str, ulong length);
   bool set_longdata(const char *str, ulong length);
   void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
-  bool set_from_user_var(THD *thd, const user_var_entry *entry);
+  bool set_from_user_var(THD *thd,
+                         const LEX_STRING *user_var_name,
+                         const user_var_entry *entry);
   void reset();
   /*
     Assign placeholder value from bind data.
@@ -1739,6 +1742,17 @@ public:
   bool eq(const Item *item, bool binary_cmp) const;
   /** Item is a argument to a limit clause. */
   bool limit_clause_param;
+
+  virtual inline Settable_routine_parameter *
+    get_settable_routine_parameter()
+  {
+    return this;
+  }
+
+  virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
+
+private:
+  const LEX_STRING *m_user_var_name;
 };
 
 
diff -Nrup a/sql/sql_prepare.cc b/sql/sql_prepare.cc
--- a/sql/sql_prepare.cc	2008-04-16 00:29:39 +04:00
+++ b/sql/sql_prepare.cc	2008-05-19 18:08:09 +04:00
@@ -970,7 +970,7 @@ static bool insert_params_from_vars(Prep
     entry= (user_var_entry*)hash_search(&stmt->thd->user_vars,
                                         (uchar*) varname->str,
                                          varname->length);
-    if (param->set_from_user_var(stmt->thd, entry) ||
+    if (param->set_from_user_var(stmt->thd, varname, entry) ||
         param->convert_str_value(stmt->thd))
       DBUG_RETURN(1);
   }
@@ -1022,7 +1022,7 @@ static bool insert_params_from_vars_with
       (e.g. value.cs_info.character_set_client is used in the query_val_str()).
     */
     setup_one_conversion_function(thd, param, param->param_type);
-    if (param->set_from_user_var(thd, entry))
+    if (param->set_from_user_var(thd, varname, entry))
       DBUG_RETURN(1);
     val= param->query_val_str(&buf);
 
Thread
bk commit into 6.0 tree (anozdrin:1.2637) BUG#11638Alexander Nozdrin19 May