Commit d899840a authored by Alexander Barkov's avatar Alexander Barkov

- Adding tests for DBNAME=<unknown database name>.

- Fixing a bug that DBNAME value was forgotten when followed by OPTION_LIST.

modified:
  mysql-test/suite/connect/r/mysql.result
  mysql-test/suite/connect/t/mysql.test
  storage/connect/ha_connect.cc
parent 38210b11
......@@ -12,6 +12,10 @@ NULL NULL
#
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME='t1' OPTION_LIST='host=localhost,user=root1,port=PORT';
ERROR HY000: (1045) Access denied for user 'root1'@'localhost' (using password: NO)
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='unknown' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT';
ERROR HY000: (1049) Unknown database 'unknown'
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL OPTION_LIST='host=localhost,user=root,port=PORT' DBNAME='unknown' TABNAME='t1';
ERROR HY000: (1049) Unknown database 'unknown'
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME='unknown' OPTION_LIST='host=localhost,user=root,port=PORT';
ERROR HY000: (1146) Table 'test.unknown' doesn't exist [SHOW FULL COLUMNS FROM unknown FROM test]
SHOW CREATE TABLE t2;
......
......@@ -17,7 +17,15 @@ SELECT * FROM t1;
--error ER_UNKNOWN_ERROR
--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME='t1' OPTION_LIST='host=localhost,user=root1,port=$PORT'
# TODO: bad database name
# Bad database name
--replace_result $PORT PORT "mysql_real_connect failed: " ""
--error ER_UNKNOWN_ERROR
--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='unknown' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT'
# Bad database name, with OPTION_LIST going first.
--replace_result $PORT PORT "mysql_real_connect failed: " ""
--error ER_UNKNOWN_ERROR
--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL OPTION_LIST='host=localhost,user=root,port=$PORT' DBNAME='unknown' TABNAME='t1'
# Bad table name
--replace_result $PORT PORT
......
......@@ -3375,7 +3375,14 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info,
} else if (!stricmp(pov->name.str, "option_list")) {
host= GetListOption("host", pov->value.str, "localhost");
user= GetListOption("user", pov->value.str, "root");
db= GetListOption("database", pov->value.str);
/*
Change DB only if Database=xxx is specified.
Otherwise, preserver the previous value that
has possibly come from the DBNAME=xxx option.
*/
char *db1= GetListOption("database", pov->value.str);
if (db1)
db= db1;
pwd= GetListOption("password", pov->value.str);
prt= GetListOption("port", pov->value.str);
port= (prt) ? atoi(prt) : MYSQL_PORT;
......
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