Commit 71ba3e55 authored by unknown's avatar unknown

A fix (bug #2205 USE database doesn't work after DROP database + CREATE database)

(Jani's CS 1.1675 04/01/05 21:45:14 was adapted an aplied).


client/mysql.cc:
  A fix (bug #2205 USE database doesn't work after DROP database + CREATE database).
parent 0d34c635
...@@ -2200,8 +2200,9 @@ static int com_source(String *buffer, char *line) ...@@ -2200,8 +2200,9 @@ static int com_source(String *buffer, char *line)
static int static int
com_use(String *buffer __attribute__((unused)), char *line) com_use(String *buffer __attribute__((unused)), char *line)
{ {
char *tmp; char *tmp, buff[FN_REFLEN + 1];
char buff[256]; MYSQL_RES *res;
MYSQL_ROW row;
while (isspace(*line)) while (isspace(*line))
line++; line++;
...@@ -2214,6 +2215,30 @@ com_use(String *buffer __attribute__((unused)), char *line) ...@@ -2214,6 +2215,30 @@ com_use(String *buffer __attribute__((unused)), char *line)
put_info("USE must be followed by a database name",INFO_ERROR); put_info("USE must be followed by a database name",INFO_ERROR);
return 0; return 0;
} }
/*
We need to recheck the current database, because it may change
under our feet, for example if DROP DATABASE or RENAME DATABASE
(latter one not yet available by the time the comment was written)
*/
current_db= 0; // Let's reset current_db, assume it's gone
/*
We don't care about in case of an error below because current_db
was just set to 0.
*/
if (!mysql_query(&mysql, "SELECT DATABASE()") &&
(res= mysql_use_result(&mysql)))
{
row= mysql_fetch_row(res);
if (row[0] &&
(!current_db || cmp_database(current_db, row[0])))
{
my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db= my_strdup(row[0], MYF(MY_WME));
}
(void) mysql_fetch_row(res); // Read eof
mysql_free_result(res);
}
if (!current_db || cmp_database(current_db,tmp)) if (!current_db || cmp_database(current_db,tmp))
{ {
if (one_database) if (one_database)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment