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.2136 06/04/13 15:58:10 pem@stripped +4 -0
Fixed BUG#18444: Fully qualified stored function names don't work
correctly in SELECT statements
Always strdup the thd->db pointer when assigning it to tables, or it might
get invalidated by a free in mysql_change_db().
sql/sql_parse.cc
1.538 06/04/13 15:58:01 pem@stripped +27 -9
Always strdup string when setting db pointers in tables to thd->db,
since the latter can get invalidated by mysql_change_db(), which
can happens during stored function execution for instance.
Also fixed db pointer comparison which may not be relevant; must
compare the strings instead.
sql/sql_db.cc
1.128 06/04/13 15:58:01 pem@stripped +6 -2
Moved variable initialization in mysql_change_db() to fix
the debug output (the malloc output appeared before the
"enter").
Added debug info for setting thd->db.
mysql-test/t/sp.test
1.182 06/04/13 15:58:01 pem@stripped +21 -0
Added new testcase for BUG#18444.
mysql-test/r/sp.result
1.194 06/04/13 15:58:01 pem@stripped +15 -0
Updated result for new test case (BUG#18444).
# 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/5.0/bug18444/mysql-5.0-runtime
--- 1.127/sql/sql_db.cc 2006-03-01 15:43:51 +01:00
+++ 1.128/sql/sql_db.cc 2006-04-13 15:58:01 +02:00
@@ -1098,8 +1098,7 @@
bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
{
int length, db_length;
- char *dbname= thd->slave_thread ? (char *) name :
- my_strdup((char *) name, MYF(MY_WME));
+ char *dbname;
char path[FN_REFLEN];
HA_CREATE_INFO create;
bool system_db= 0;
@@ -1112,6 +1111,9 @@
DBUG_PRINT("enter",("name: '%s'",name));
LINT_INIT(db_length);
+ dbname= thd->slave_thread ?
+ (char *) name :
+ my_strdup((char *) name, MYF(MY_WME));
/* dbname can only be NULL if malloc failed */
if (!dbname || !(db_length= strlen(dbname)))
@@ -1188,11 +1190,13 @@
my_free(dbname, MYF(0));
thd->db= NULL;
thd->db_length= 0;
+ DBUG_PRINT("info",("thd->db= 0x0"));
}
else
{
thd->db= dbname; // THD::~THD will free this
thd->db_length= db_length;
+ DBUG_PRINT("info",("thd->db= 0x%lx '%s'/%d", dbname, dbname, db_length));
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!no_access_check)
--- 1.537/sql/sql_parse.cc 2006-04-07 13:30:34 +02:00
+++ 1.538/sql/sql_parse.cc 2006-04-13 15:58:01 +02:00
@@ -4691,7 +4691,8 @@
view_store_options(thd, first_table, &buff);
buff.append(STRING_WITH_LEN("VIEW "));
/* Test if user supplied a db (ie: we did not use thd->db) */
- if (first_table->db != thd->db && first_table->db[0])
+ if (thd->db && first_table->db &&
+ my_strcasecmp(system_charset_info, thd->db, first_table->db))
{
append_identifier(thd, &buff, first_table->db,
first_table->db_length);
@@ -5339,16 +5340,25 @@
static bool check_db_used(THD *thd,TABLE_LIST *tables)
{
+ char *thddb= NULL;
+
for (; tables; tables= tables->next_global)
{
if (!tables->db)
{
- if (!(tables->db=thd->db))
+ /*
+ We must copy thd->db since it might be invalidated by mysql_change_db()
+ */
+ if (!thddb)
{
- my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR),
- MYF(0)); /* purecov: tested */
- return TRUE; /* purecov: tested */
+ if (thd->db == 0 || !(thddb= thd->strdup(thd->db)))
+ {
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR),
+ MYF(0));
+ return TRUE;
+ }
}
+ tables->db= thddb;
}
}
return FALSE;
@@ -6006,8 +6016,18 @@
}
else if (thd->db)
{
- ptr->db= thd->db;
- ptr->db_length= thd->db_length;
+ /*
+ We must copy thd->db since it might be invalidated by mysql_change_db()
+ */
+ if ((ptr->db= thd->strdup(thd->db)))
+ ptr->db_length= thd->db_length;
+ else
+ {
+ /* The following can't be "" as we may do 'casedn_str()' on it */
+ ptr->db= empty_c_string;
+ ptr->db_length= 0;
+ DBUG_RETURN(0);
+ }
}
else
{
@@ -6015,8 +6035,6 @@
ptr->db= empty_c_string;
ptr->db_length= 0;
}
- if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
- ptr->db= thd->strdup(ptr->db);
ptr->alias= alias_str;
if (lower_case_table_names && table->table.length)
--- 1.193/mysql-test/r/sp.result 2006-03-28 14:18:44 +02:00
+++ 1.194/mysql-test/r/sp.result 2006-04-13 15:58:01 +02:00
@@ -4837,4 +4837,19 @@
b 3
a 1
delete from t1|
+create table t3 (i int)|
+insert into t3 values (1), (2)|
+create database sp_db1|
+use sp_db1|
+create function bug18444(i int) returns int
+no sql
+deterministic
+return i + 1|
+use test|
+select sp_db1.bug18444(i) from t3|
+sp_db1.bug18444(i)
+2
+3
+drop database sp_db1|
+drop table t3|
drop table t1,t2;
--- 1.181/mysql-test/t/sp.test 2006-03-28 14:17:15 +02:00
+++ 1.182/mysql-test/t/sp.test 2006-04-13 15:58:01 +02:00
@@ -5684,6 +5684,27 @@
#
+# BUG#18444: Fully qualified stored function names don't work correctly
+# in SELECT statements
+#
+create table t3 (i int)|
+insert into t3 values (1), (2)|
+
+create database sp_db1|
+use sp_db1|
+create function bug18444(i int) returns int
+ no sql
+ deterministic
+ return i + 1|
+
+use test|
+select sp_db1.bug18444(i) from t3|
+
+drop database sp_db1|
+drop table t3|
+
+
+#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
| Thread |
|---|
| • bk commit into 5.0 tree (pem:1.2136) BUG#18444 | pem | 13 Apr |