diff options
author | unknown <ram@gw.mysql.r18.ru> | 2004-09-07 17:57:46 +0500 |
---|---|---|
committer | unknown <ram@gw.mysql.r18.ru> | 2004-09-07 17:57:46 +0500 |
commit | bb88f4fbc3b1455c6bd92276a4016f6e91582227 (patch) | |
tree | 7d01c29c5d4330beb566d9aa25b10236892a9b13 | |
parent | 3a476a6e91bcd8f219393b7ec670c4833f534ea3 (diff) | |
parent | de027f10268d8f20ce9420a1f723667ce2f5f8fb (diff) | |
download | mariadb-git-bb88f4fbc3b1455c6bd92276a4016f6e91582227.tar.gz |
Merge rkalimullin@bk-internal.mysql.com:/home/bk/mysql-4.0
into gw.mysql.r18.ru:/usr/home/ram/work/4.0.b2205
-rw-r--r-- | client/mysql.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 154695aa9e5..3cc8b41af66 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2200,8 +2200,9 @@ static int com_source(String *buffer, 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; while (isspace(*line)) 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); 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) + */ + /* Let's reset current_db, assume it's gone */ + my_free(current_db, MYF(MY_ALLOW_ZERO_PTR)); + current_db= 0; + /* + 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= 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 (one_database) |