List:Commits« Previous MessageNext Message »
From:pem Date:January 26 2006 12:29pm
Subject:bk commit into 5.0 tree (pem:1.2009) BUG#16303
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of pem. When pem 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.2009 06/01/26 13:29:46 pem@stripped +6 -0
  Fixed BUG#16303: erroneus stored procedures and functions should be droppable
    Use a special lookup function for DROP, which doesn't attempt to parse the
    definition.

  sql/sql_parse.cc
    1.524 06/01/26 13:29:42 pem@stripped +7 -11
    Use the new sp_routine_exists_in_table() instead of sp_find_routine(), since we don't
    want the routine definition parsed when doing DROP PROCEDURE/FUNCTION.

  sql/sql_acl.cc
    1.187 06/01/26 13:29:42 pem@stripped +1 -1
    Call to sp_exists_routine() renamed to sp_exist_routines().

  sql/sp.h
    1.33 06/01/26 13:29:42 pem@stripped +4 -1
    New function sp_routine_exists_in_table() for DROP PROCEDURE/FUNCTION.
    
    Renamed sp_exists_routine to sp_exist_routines,
    and changed the misnamed parameter 'tables' to 'routines'.

  sql/sp.cc
    1.105 06/01/26 13:29:42 pem@stripped +47 -8
    New function sp_routine_exists_in_table() for DROP PROCEDURE/FUNCTION; which doesn't
    want to parse the definition, only know if it exists.
    
    Renamed sp_exists_routine to sp_exist_routines and added comment,
    and changed the misnamed parameter/variable 'tables'/'table' to
    'routines'/'routine'.
    

  mysql-test/t/sp-destruct.test
    1.4 06/01/26 13:29:42 pem@stripped +10 -1
    Added test case for BUG#16303.

  mysql-test/r/sp-destruct.result
    1.4 06/01/26 13:29:42 pem@stripped +7 -1
    Updated test result for BUG#16303.

# 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:	pem
# Host:	pem.mysql.com
# Root:	/extern/mysql/work/bug16303/mysql-5.0

--- 1.186/sql/sql_acl.cc	2006-01-18 17:09:18 +01:00
+++ 1.187/sql/sql_acl.cc	2006-01-26 13:29:42 +01:00
@@ -3030,7 +3030,7 @@
 
   if (!revoke_grant)
   {
-    if (sp_exists_routine(thd, table_list, is_proc, no_error)<0)
+    if (sp_exist_routines(thd, table_list, is_proc, no_error)<0)
       DBUG_RETURN(TRUE);
   }
 

--- 1.523/sql/sql_parse.cc	2006-01-23 17:03:03 +01:00
+++ 1.524/sql/sql_parse.cc	2006-01-26 13:29:42 +01:00
@@ -4445,21 +4445,17 @@
   case SQLCOM_DROP_PROCEDURE:
   case SQLCOM_DROP_FUNCTION:
     {
-      sp_head *sp;
       int result;
-      char *db, *name;
+      int type= (lex->sql_command == SQLCOM_DROP_PROCEDURE ?
+                 TYPE_ENUM_PROCEDURE : TYPE_ENUM_FUNCTION);
 
-      if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
-        sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, lex->spname,
-                            &thd->sp_proc_cache, FALSE);
-      else
-        sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, lex->spname,
-                            &thd->sp_func_cache, FALSE);
+      result= sp_routine_exists_in_table(thd, type, lex->spname);
       mysql_reset_errors(thd, 0);
-      if (sp)
+      if (result == SP_OK)
       {
-        db= thd->strdup(sp->m_db.str);
-	name= thd->strdup(sp->m_name.str);
+        char *db= lex->spname->m_db.str;
+	char *name= lex->spname->m_name.str;
+
 	if (check_routine_access(thd, ALTER_PROC_ACL, db, name,
                                  lex->sql_command == SQLCOM_DROP_PROCEDURE, 0))
           goto error;

--- 1.3/mysql-test/r/sp-destruct.result	2005-11-25 17:09:18 +01:00
+++ 1.4/mysql-test/r/sp-destruct.result	2006-01-26 13:29:42 +01:00
@@ -72,6 +72,12 @@
 create trigger t1_ai after insert on t1 for each row call bug14233_3();
 insert into t1 values (0);
 ERROR HY000: Failed to load routine test.bug14233_3. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
-delete from mysql.proc where name like 'bug14233%';
 drop trigger t1_ai;
 drop table t1;
+drop function bug14233_1;
+drop function bug14233_2;
+drop procedure bug14233_3;
+show procedure status;
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment
+show function status;
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment

--- 1.3/mysql-test/t/sp-destruct.test	2005-11-25 17:09:18 +01:00
+++ 1.4/mysql-test/t/sp-destruct.test	2006-01-26 13:29:42 +01:00
@@ -119,6 +119,15 @@
 insert into t1 values (0);
 
 # Clean-up
-delete from mysql.proc where name like 'bug14233%';
 drop trigger t1_ai;
 drop table t1;
+
+#
+# BUG#16303: erroneus stored procedures and functions should be droppable
+#
+drop function bug14233_1;
+drop function bug14233_2;
+drop procedure bug14233_3;
+# Assert: These should show nothing.
+show procedure status;
+show function status;

--- 1.104/sql/sp.cc	2006-01-11 00:07:34 +01:00
+++ 1.105/sql/sp.cc	2006-01-26 13:29:42 +01:00
@@ -1002,22 +1002,26 @@
 }
 
 
+/*
+  This is used by sql_acl.cc:mysql_routine_grant() and is used to find
+  the routines in 'routines'.
+*/
 
 int
-sp_exists_routine(THD *thd, TABLE_LIST *tables, bool any, bool no_error)
+sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
 {
-  TABLE_LIST *table;
+  TABLE_LIST *routine;
   bool result= 0;
   DBUG_ENTER("sp_exists_routine");
-  for (table= tables; table; table= table->next_global)
+  for (routine= routines; routine; routine= routine->next_global)
   {
     sp_name *name;
     LEX_STRING lex_db;
     LEX_STRING lex_name;
-    lex_db.length= strlen(table->db);
-    lex_name.length= strlen(table->table_name);
-    lex_db.str= thd->strmake(table->db, lex_db.length);
-    lex_name.str= thd->strmake(table->table_name, lex_name.length);
+    lex_db.length= strlen(routine->db);
+    lex_name.length= strlen(routine->table_name);
+    lex_db.str= thd->strmake(routine->db, lex_db.length);
+    lex_name.str= thd->strmake(routine->table_name, lex_name.length);
     name= new sp_name(lex_db, lex_name);
     name->init_qname(thd);
     if (sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
@@ -1034,13 +1038,48 @@
       if (!no_error)
       {
 	my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", 
-		 table->table_name);
+		 routine->table_name);
 	DBUG_RETURN(-1);
       }
       DBUG_RETURN(0);
     }
   }
   DBUG_RETURN(result);
+}
+
+
+/*
+  Check if a routine exists in the mysql.proc table, without actually
+  parsing the definition. (Used for dropping)
+
+  SYNOPSIS
+    sp_routine_exists_in_table()
+      thd        - thread context
+      name       - name of procedure
+
+  RETURN VALUE
+    0     - Success
+    non-0 - Error;  SP_OPEN_TABLE_FAILED or SP_KEY_NOT_FOUND
+*/
+
+int
+sp_routine_exists_in_table(THD *thd, int type, sp_name *name)
+{
+  TABLE *table;
+  int ret;
+  Open_tables_state open_tables_state_backup;
+
+  if (!(table= open_proc_table_for_read(thd, &open_tables_state_backup)))
+    ret= SP_OPEN_TABLE_FAILED;
+  else
+  {
+    if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
+      ret= SP_OK;
+    else
+      ret= SP_KEY_NOT_FOUND;
+    close_proc_table(thd, &open_tables_state_backup);
+  }
+  return ret;
 }
 
 

--- 1.32/sql/sp.h	2005-12-07 10:47:20 +01:00
+++ 1.33/sql/sp.h	2006-01-26 13:29:42 +01:00
@@ -40,7 +40,10 @@
                 sp_cache **cp, bool cache_only);
 
 int
-sp_exists_routine(THD *thd, TABLE_LIST *procs, bool any, bool no_error);
+sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any, bool no_error);
+
+int
+sp_routine_exists_in_table(THD *thd, int type, sp_name *name);
 
 int
 sp_create_procedure(THD *thd, sp_head *sp);
Thread
bk commit into 5.0 tree (pem:1.2009) BUG#16303pem26 Jan