Skip to content

Commit 29277bf

Browse files
committed
MDEV-36701 command line client doesn't check session_track information
subscribe for SESSION_TRACK_SCHEMA messages and change the db accordingly
1 parent e925ddd commit 29277bf

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

client/mysql.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,26 @@ static int reconnect(void)
32003200
return 0;
32013201
}
32023202

3203+
#ifndef EMBEDDED_LIBRARY
3204+
static void status_info_cb(void *data, enum enum_mariadb_status_info type, ...)
3205+
{
3206+
va_list ap;
3207+
va_start(ap, type);
3208+
if (type == SESSION_TRACK_TYPE && va_arg(ap, int) == SESSION_TRACK_SCHEMA)
3209+
{
3210+
MARIADB_CONST_STRING *val= va_arg(ap, MARIADB_CONST_STRING *);
3211+
my_free(current_db);
3212+
if (val->length)
3213+
current_db= my_strndup(PSI_NOT_INSTRUMENTED, val->str, val->length, MYF(MY_FAE));
3214+
else
3215+
current_db= NULL;
3216+
}
3217+
va_end(ap);
3218+
}
3219+
#else
3220+
#define mysql_optionsv(A,B,C,D) do { } while(0)
3221+
#endif
3222+
32033223
static void get_current_db()
32043224
{
32053225
MYSQL_RES *res;
@@ -4972,6 +4992,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
49724992
mysql_close(&mysql);
49734993
}
49744994
mysql_init(&mysql);
4995+
if (!one_database)
4996+
mysql_optionsv(&mysql, MARIADB_OPT_STATUS_CALLBACK, status_info_cb, NULL);
49754997
if (opt_init_command)
49764998
mysql_options(&mysql, MYSQL_INIT_COMMAND, opt_init_command);
49774999
if (opt_connect_timeout)

mysql-test/main/mysql-interactive.result

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,41 @@ MariaDB [(none)]> select 1;
2424

2525
MariaDB [(none)]> exit
2626
Bye
27+
# End of 10.4 tests
28+
#
29+
# MDEV-36701 command line client doesn't check session_track information
30+
#
31+
create database db1;
32+
use db1;
33+
drop database db1;
34+
create database db1;
35+
execute immediate "use db1";
36+
execute immediate "drop database db1";
37+
exit
38+
Welcome to the MariaDB monitor. Commands end with ; or \g.
39+
Your MariaDB connection id is X
40+
Server version: Y
41+
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
42+
43+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
44+
45+
MariaDB [(none)]> create database db1;
46+
Query OK, 1 row affected
47+
48+
MariaDB [(none)]> use db1;
49+
Database changed
50+
MariaDB [db1]> drop database db1;
51+
Query OK, 0 rows affected
52+
53+
MariaDB [(none)]> create database db1;
54+
Query OK, 1 row affected
55+
56+
MariaDB [(none)]> execute immediate "use db1";
57+
Query OK, 0 rows affected
58+
59+
MariaDB [db1]> execute immediate "drop database db1";
60+
Query OK, 0 rows affected
61+
62+
MariaDB [(none)]> exit
63+
Bye
64+
# End of 10.11 tests

mysql-test/main/mysql-interactive.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,27 @@ if ($sys_errno == 127)
2222
skip no socat;
2323
}
2424
remove_file $MYSQL_TMP_DIR/mysql_in;
25+
26+
--echo # End of 10.4 tests
27+
28+
--echo #
29+
--echo # MDEV-36701 command line client doesn't check session_track information
30+
--echo #
31+
# test old behavior (make sure session tracking didn't break it)
32+
# and new one, that didn't work before
33+
write_file $MYSQL_TMP_DIR/mysql_in;
34+
create database db1;
35+
use db1;
36+
drop database db1;
37+
create database db1;
38+
execute immediate "use db1";
39+
execute immediate "drop database db1";
40+
exit
41+
EOF
42+
let TERM=dumb;
43+
replace_regex /id is \d+/id is X/ /Server version: .*/Server version: Y/ / \(\d+\.\d+ sec\)//;
44+
error 0,127;
45+
exec socat -t10 EXEC:"$MYSQL",pty STDIO < $MYSQL_TMP_DIR/mysql_in;
46+
remove_file $MYSQL_TMP_DIR/mysql_in;
47+
48+
--echo # End of 10.11 tests

0 commit comments

Comments
 (0)