List:Commits« Previous MessageNext Message »
From:tim Date:August 7 2007 6:54am
Subject:bk commit into 5.0 tree (tsmith:1.2490) BUG#29050
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of tsmith. When tsmith 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, 2007-08-07 00:54:47-06:00, tsmith@stripped +8 -0
  Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  mysql-test/r/sp.result@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +18 -0
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  mysql-test/r/trigger.result@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +2 -2
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  mysql-test/t/sp.test@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +25 -0
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  mysql-test/t/trigger.test@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +2 -2
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  sql/sql_lex.cc@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +37 -0
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  sql/sql_lex.h@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +2 -0
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  sql/sql_parse.cc@stripped, 2007-08-07 00:54:45-06:00, tsmith@stripped +1 -1
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

  sql/sql_yacc.yy@stripped, 2007-08-07 00:54:46-06:00, tsmith@stripped +6 -9
    Backport fix for bug #29050, Creation of a legal stored procedure fails if a database is not selected prior

# 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:	tsmith
# Host:	ramayana.hindu.god
# Root:	/home/tsmith/m/bk/mysql-5.0.44-sp

--- 1.223/sql/sql_lex.cc	2007-05-25 16:17:18 -06:00
+++ 1.224/sql/sql_lex.cc	2007-08-07 00:54:45 -06:00
@@ -1974,6 +1974,43 @@
 }
 
 
+/**
+  This method should be called only during parsing.
+  It is aware of compound statements (stored routine bodies)
+  and will initialize the destination with the default
+  database of the stored routine, rather than the default
+  database of the connection it is parsed in.
+  E.g. if one has no current database selected, or current database 
+  set to 'bar' and then issues:
+
+  CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
+
+  t1 is meant to refer to foo.t1, not to bar.t1.
+
+  This method is needed to support this rule.
+
+  @return TRUE in case of error (parsing should be aborted, FALSE in
+  case of success
+*/
+
+bool
+st_lex::copy_db_to(char **p_db, uint *p_db_length) const
+{
+  if (sphead)
+  {
+    DBUG_ASSERT(sphead->m_db.str && sphead->m_db.length);
+    /*
+      It is safe to assign the string by-pointer, both sphead and
+      its statements reside in the same memory root.
+    */
+    *p_db= sphead->m_db.str;
+    if (p_db_length)
+      *p_db_length= sphead->m_db.length;
+    return FALSE;
+  }
+  return thd->copy_db_to(p_db, p_db_length);
+}
+
 /*
   initialize limit counters
 

--- 1.247/sql/sql_lex.h	2007-05-25 14:35:58 -06:00
+++ 1.248/sql/sql_lex.h	2007-08-07 00:54:45 -06:00
@@ -1237,6 +1237,8 @@
     context_stack.pop();
   }
 
+  bool copy_db_to(char **p_db, uint *p_db_length) const;
+
   Name_resolution_context *current_context()
   {
     return context_stack.head();

--- 1.626/sql/sql_parse.cc	2007-06-14 14:58:22 -06:00
+++ 1.627/sql/sql_parse.cc	2007-08-07 00:54:45 -06:00
@@ -6382,7 +6382,7 @@
     ptr->db= table->db.str;
     ptr->db_length= table->db.length;
   }
-  else if (thd->copy_db_to(&ptr->db, &ptr->db_length))
+  else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
     DBUG_RETURN(0);
 
   ptr->alias= alias_str;

--- 1.523/sql/sql_yacc.yy	2007-06-14 05:37:36 -06:00
+++ 1.524/sql/sql_yacc.yy	2007-08-07 00:54:46 -06:00
@@ -1565,14 +1565,14 @@
 	  }
 	| ident
 	  {
-            THD *thd= YYTHD;
+            LEX *lex= Lex;
             LEX_STRING db;
 	    if (check_routine_name($1))
             {
 	      my_error(ER_SP_WRONG_NAME, MYF(0), $1.str);
 	      MYSQL_YYABORT;
 	    }
-            if (thd->copy_db_to(&db.str, &db.length))
+            if (lex->copy_db_to(&db.str, &db.length))
               MYSQL_YYABORT;
 	    $$= new sp_name(db, $1, false);
             if ($$)
@@ -3624,10 +3624,9 @@
           opt_create_database_options
 	  {
 	    LEX *lex=Lex;
-            THD *thd= Lex->thd;
 	    lex->sql_command=SQLCOM_ALTER_DB;
 	    lex->name= $3;
-            if (lex->name == NULL && thd->copy_db_to(&lex->name, NULL))
+            if (lex->name == NULL && lex->copy_db_to(&lex->name, NULL))
               MYSQL_YYABORT;
 	  }
 	| ALTER PROCEDURE sp_name
@@ -3790,10 +3789,9 @@
 	| RENAME opt_to table_ident
 	  {
 	    LEX *lex=Lex;
-            THD *thd= lex->thd;
 	    lex->select_lex.db=$3->db.str;
             if (lex->select_lex.db == NULL &&
-                thd->copy_db_to(&lex->select_lex.db, NULL))
+                lex->copy_db_to(&lex->select_lex.db, NULL))
             {
               MYSQL_YYABORT;
             }
@@ -5139,7 +5137,7 @@
             {
               THD *thd= lex->thd;
               LEX_STRING db;
-              if (thd->copy_db_to(&db.str, &db.length))
+              if (lex->copy_db_to(&db.str, &db.length))
                 MYSQL_YYABORT;
               sp_name *name= new sp_name(db, $1, false);
               if (name)
@@ -9016,8 +9014,7 @@
 	'*'
 	  {
 	    LEX *lex= Lex;
-            THD *thd= lex->thd;
-            if (thd->copy_db_to(&lex->current_select->db, NULL))
+            if (lex->copy_db_to(&lex->current_select->db, NULL))
               MYSQL_YYABORT;
 	    if (lex->grant == GLOBAL_ACLS)
 	      lex->grant = DB_ACLS & ~GRANT_ACL;

--- 1.61/mysql-test/r/trigger.result	2007-06-12 05:35:35 -06:00
+++ 1.62/mysql-test/r/trigger.result	2007-08-07 00:54:45 -06:00
@@ -351,7 +351,7 @@
 ERROR HY000: Trigger in wrong schema
 use mysqltest;
 create trigger test.trg1 before insert on t1 for each row set @a:= 1;
-ERROR HY000: Trigger in wrong schema
+ERROR 42S02: Table 'test.t1' doesn't exist
 drop database mysqltest;
 use test;
 create table t1 (i int, j int default 10, k int not null, key (k));
@@ -842,7 +842,7 @@
 create trigger t1_bi before insert on test.t1 for each row set @a:=0;
 ERROR 3D000: No database selected
 create trigger test.t1_bi before insert on t1 for each row set @a:=0;
-ERROR 3D000: No database selected
+ERROR 42S02: Table 'test.t1' doesn't exist
 drop trigger t1_bi;
 ERROR 3D000: No database selected
 create table t1 (id int);

--- 1.68/mysql-test/t/trigger.test	2007-06-12 05:35:35 -06:00
+++ 1.69/mysql-test/t/trigger.test	2007-08-07 00:54:45 -06:00
@@ -406,7 +406,7 @@
 --error ER_TRG_IN_WRONG_SCHEMA
 create trigger trg1 before insert on mysqltest.t1 for each row set @a:= 1;
 use mysqltest;
---error ER_TRG_IN_WRONG_SCHEMA
+--error ER_NO_SUCH_TABLE
 create trigger test.trg1 before insert on t1 for each row set @a:= 1;
 drop database mysqltest;
 use test;
@@ -1040,7 +1040,7 @@
 connection addconwithoutdb;
 --error ER_NO_DB_ERROR
 create trigger t1_bi before insert on test.t1 for each row set @a:=0;
---error ER_NO_DB_ERROR
+--error ER_NO_SUCH_TABLE
 create trigger test.t1_bi before insert on t1 for each row set @a:=0;
 --error ER_NO_DB_ERROR
 drop trigger t1_bi;

--- 1.230/mysql-test/r/sp.result	2007-06-01 16:42:02 -06:00
+++ 1.231/mysql-test/r/sp.result	2007-08-07 00:54:45 -06:00
@@ -6173,4 +6173,22 @@
 DROP VIEW v1;
 DROP FUNCTION metered;
 DROP TABLE t1;
+drop database if exists mysqltest_db1;
+drop table if exists test.t1;
+create database mysqltest_db1;
+use mysqltest_db1;
+drop database mysqltest_db1;
+create table test.t1 (id int);
+insert into test.t1 (id) values (1);
+create procedure test.sp_bug29050() begin select * from t1; end//
+show warnings;
+Level	Code	Message
+call test.sp_bug29050();
+id
+1
+show warnings;
+Level	Code	Message
+use test;
+drop procedure sp_bug29050;
+drop table t1;
 End of 5.0 tests

--- 1.220/mysql-test/t/sp.test	2007-06-01 16:42:03 -06:00
+++ 1.221/mysql-test/t/sp.test	2007-08-07 00:54:45 -06:00
@@ -7130,5 +7130,30 @@
 DROP FUNCTION metered;
 DROP TABLE t1;
 
+#
+# Bug#29050 Creation of a legal stored procedure fails if a database is not
+# selected prior
+#
+--disable_warnings
+drop database if exists mysqltest_db1;
+drop table if exists test.t1;
+--enable_warnings
+create database mysqltest_db1;
+use mysqltest_db1;
+# For the sake of its side effect
+drop database mysqltest_db1; 
+# Now we have no current database selected.
+create table test.t1 (id int);
+insert into test.t1 (id) values (1);
+delimiter //;
+create procedure test.sp_bug29050() begin select * from t1; end//
+delimiter ;//
+show warnings;
+call test.sp_bug29050();
+show warnings;
+# Restore the old current database
+use test;
+drop procedure sp_bug29050;
+drop table t1;
 
 --echo End of 5.0 tests
Thread
bk commit into 5.0 tree (tsmith:1.2490) BUG#29050tim7 Aug