1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Fixed Bug#2205.

This commit is contained in:
unknown
2004-01-05 21:45:14 +02:00
parent 63f15064a4
commit d4a7fa95ee

View File

@@ -2436,8 +2436,9 @@ com_delimiter(String *buffer __attribute__((unused)), char *line)
static int
com_use(String *buffer __attribute__((unused)), char *line)
{
char *tmp;
char buff[256];
char *tmp, buff[FN_REFLEN + 1];
MYSQL_RES *res;
MYSQL_ROW row;
bzero(buff, sizeof(buff));
strmov(buff, line);
@@ -2447,6 +2448,31 @@ com_use(String *buffer __attribute__((unused)), char *line)
put_info("USE must be followed by a database name", INFO_ERROR);
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(charset_info, 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(charset_info, current_db, tmp))
{
if (one_database)