Commit a084e1fd authored by unknown's avatar unknown

bug#10979 USE does not refresh db privilege changes if the same db is used in command.

The problem happened because "mysql" didn't send mysql_select_db() if 
the current active database was specified in USE.
Now it always send mysql_select_db().
Rebuilding of completion hash is skipped in the same db is used
(for performance purposes).

parent f04b9f24
......@@ -2969,6 +2969,7 @@ static int
com_use(String *buffer __attribute__((unused)), char *line)
{
char *tmp, buff[FN_REFLEN + 1];
int select_db;
bzero(buff, sizeof(buff));
strmov(buff, line);
......@@ -2988,8 +2989,27 @@ com_use(String *buffer __attribute__((unused)), char *line)
if (!current_db || cmp_database(charset_info, current_db,tmp))
{
if (one_database)
{
skip_updates= 1;
select_db= 0; // don't do mysql_select_db()
}
else
select_db= 2; // do mysql_select_db() and build_completion_hash()
}
else
{
/*
USE to the current db specified.
We do need to send mysql_select_db() to make server
update database level privileges, which might
change since last USE (see bug#10979).
For performance purposes, we'll skip rebuilding of completion hash.
*/
skip_updates= 0;
select_db= 1; // do only mysql_select_db(), without completion
}
if (select_db)
{
/*
reconnect once if connection is down or if connection was found to
......@@ -3010,12 +3030,11 @@ com_use(String *buffer __attribute__((unused)), char *line)
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
current_db=my_strdup(tmp,MYF(MY_WME));
#ifdef HAVE_READLINE
if (select_db > 1)
build_completion_hash(rehash, 1);
#endif
}
}
else
skip_updates= 0;
put_info("Database changed",INFO_INFO);
return 0;
}
......
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