List:Commits« Previous MessageNext Message »
From:konstantin Date:December 7 2005 9:47pm
Subject:bk commit into 5.0 tree (konstantin:1.1991) BUG#5967
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kostja. When kostja 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.1991 05/12/08 00:46:45 konstantin@stripped +5 -0
  A fix and a test case for Bug#15441 "Running SP causes Server 
  to Crash": the bug was that due to non-standard name
  resolution precedence in stored procedures (See Bug#5967)
  a stored procedure variable took precedence over a table column
  when the arguments for VALUES() function were resolved.
  The implementation of VALUES() function was not designed to work
  with Item_splocal and crashed.
  VALUES() function is non-standard. It can refer to, and
  is meaningful for, table columns only. The patch disables SP 
  variables as possible arguments of VALUES() function.

  sql/sql_yacc.yy
    1.447 05/12/08 00:46:31 konstantin@stripped +1 -1
    Actual fix for Bug#15441 "Running SP causes Server to Crash":
    we should not allow VALUES() function to reference SP variables.

  sql/item.h
    1.187 05/12/08 00:46:31 konstantin@stripped +10 -0
    Add a comment for Item_insert_value.

  sql/item.cc
    1.208 05/12/08 00:46:30 konstantin@stripped +7 -0
    Cleanup Item_insert_value::fix_fields().

  mysql-test/t/sp.test
    1.167 05/12/08 00:46:30 konstantin@stripped +50 -0
    Add a test case for Bug#15441 "Running SP causes Server to Crash".

  mysql-test/r/sp.result
    1.178 05/12/08 00:46:30 konstantin@stripped +27 -0
    Test results fixed (Bug#15441).

# 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:	konstantin
# Host:	dragonfly.local
# Root:	/opt/local/work/mysql-5.0-15441

--- 1.207/sql/item.cc	2005-12-07 17:02:39 +03:00
+++ 1.208/sql/item.cc	2005-12-08 00:46:30 +03:00
@@ -5148,10 +5148,17 @@
     Item_ref *ref= (Item_ref *)arg;
     if (ref->ref[0]->type() != FIELD_ITEM)
     {
+      my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
       return TRUE;
     }
     arg= ref->ref[0];
   }
+  /*
+    According to our SQL grammar, VALUES() function can reference
+    only to a column.
+  */
+  DBUG_ASSERT(arg->type() == FIELD_ITEM);
+
   Item_field *field_arg= (Item_field *)arg;
 
   if (field_arg->field->table->insert_values)

--- 1.186/sql/item.h	2005-12-07 17:02:39 +03:00
+++ 1.187/sql/item.h	2005-12-08 00:46:31 +03:00
@@ -2056,6 +2056,16 @@
   }
 };
 
+/*
+  Item_insert_value -- an implementation of VALUES() function.
+  You can use the VALUES(col_name) function in the UPDATE clause
+  to refer to column values from the INSERT portion of the INSERT
+  ... UPDATE statement. In other words, VALUES(col_name) in the
+  UPDATE clause refers to the value of col_name that would be
+  inserted, had no duplicate-key conflict occurred.
+  In all other places this function returns NULL.
+*/
+
 class Item_insert_value : public Item_field
 {
 public:

--- 1.446/sql/sql_yacc.yy	2005-12-07 17:02:40 +03:00
+++ 1.447/sql/sql_yacc.yy	2005-12-08 00:46:31 +03:00
@@ -4438,7 +4438,7 @@
 	    }
 	    $$= new Item_default_value(Lex->current_context(), $3);
 	  }
-	| VALUES '(' simple_ident ')'
+	| VALUES '(' simple_ident_nospvar ')'
 	  { $$= new Item_insert_value(Lex->current_context(), $3); }
 	| FUNC_ARG0 '(' ')'
 	  {

--- 1.177/mysql-test/r/sp.result	2005-12-07 17:02:37 +03:00
+++ 1.178/mysql-test/r/sp.result	2005-12-08 00:46:30 +03:00
@@ -4284,4 +4284,31 @@
 drop schema if exists mysqltest2|
 drop schema if exists mysqltest3|
 use test|
+drop table if exists t3|
+drop procedure if exists p1|
+create table t3 (id int not null primary key, county varchar(25))|
+insert into t3 (id, county) values (1, 'York')|
+create procedure p1(c varchar(25))
+begin
+update t3 set id=2, county=values(c);
+end|
+call p1('county')|
+ERROR 42S22: Unknown column 'c' in 'field list'
+drop procedure p1|
+create procedure p1(county varchar(25))
+begin
+declare c varchar(25) default "hello";
+insert into t3 (id, county) values (1, county)
+on duplicate key update county= values(county);
+select * from t3;
+update t3 set id=2, county=values(id);
+select * from t3;
+end|
+call p1('Yale')|
+id	county
+1	Yale
+id	county
+2	NULL
+drop table t3|
+drop procedure p1|
 drop table t1,t2;

--- 1.166/mysql-test/t/sp.test	2005-12-07 17:02:38 +03:00
+++ 1.167/mysql-test/t/sp.test	2005-12-08 00:46:30 +03:00
@@ -5029,6 +5029,56 @@
 use test|
 
 #
+# Bug#15441 "Running SP causes Server to Crash": check that an SP variable
+# can not be used in VALUES() function.
+#
+--disable_warnings
+drop table if exists t3|
+drop procedure if exists p1|
+--enable_warnings
+create table t3 (id int not null primary key, county varchar(25))|
+insert into t3 (id, county) values (1, 'York')|
+
+# First check that a stored procedure that refers to a parameter in VALUES()
+# function won't parse.
+
+create procedure p1(c varchar(25))
+begin
+  update t3 set id=2, county=values(c);
+end|
+--error ER_BAD_FIELD_ERROR
+call p1('county')|
+drop procedure p1|
+
+# Now check the case when there is an ambiguity between column names
+# and stored procedure parameters: the parser shall resolve the argument
+# of VALUES() function to the column name.
+
+# It's hard to deduce what county refers to in every case (INSERT statement):
+# 1st county refers to the column
+# 2nd county refers to the procedure parameter
+# 3d and 4th county refers to the column, again, but
+# for 4th county it has the value of SP parameter
+
+# In UPDATE statement, just check that values() function returns NULL for
+# non- INSERT...UPDATE statements, as stated in the manual.
+
+create procedure p1(county varchar(25))
+begin
+  declare c varchar(25) default "hello";
+
+  insert into t3 (id, county) values (1, county)
+  on duplicate key update county= values(county);
+  select * from t3;
+
+  update t3 set id=2, county=values(id);
+  select * from t3;
+end|
+call p1('Yale')|
+drop table t3|
+drop procedure p1|
+
+#
 # BUG#NNNN: New bug synopsis
 #
 #--disable_warnings
Thread
bk commit into 5.0 tree (konstantin:1.1991) BUG#5967konstantin7 Dec