summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2009-11-03 01:19:37 +0100
committerVladislav Vaintroub <vvaintroub@mysql.com>2009-11-03 01:19:37 +0100
commit2377eed362f9b9b3c4a360d75f112ac2ac627539 (patch)
tree7efbc2b00daea46ee33727295265e0752f0385b4 /tests
parente080080711793006e26104a44838e1e5de806c78 (diff)
downloadmariadb-git-2377eed362f9b9b3c4a360d75f112ac2ac627539.tar.gz
Bug #47423 mtr connects to wrong database
The reason for the bug is that mysqtest as well as other client tools running in test suite (mysqlbinlog, mysqldump) will first try to connect whatever database has created shared memory with default base name "MySQL" and use this. (Same effect could be seen on Unix if mtr would not care to calculate "port" and "socket" parameter). The fix ensures that all client tools and running in mtr use unique per-database shared memory base parameters, so there is no possibility to clash with already installed one. We use socket name for shared memory base (it's known to be unique). This shared-memory-base is written to the MTR config file to the [client] and [mysqld] sections. Fix made also made sure all client tools understand and correctly handle --shared-memory-base. Prior to this patch it was not the case for mysqltest, mysqlbinlog and mysql_client_test. All new connections done from mtr scripts via connect() will by default set shared-memory-base. And finally, there is a possibility to force shared memory or pipe connection and overwrite shared memory/pipe base name from within mtr scripts via optional PIPE or SHM modifier. This functionality was manually backported from 6.0 (original patch http://lists.mysql.com/commits/74749)
Diffstat (limited to 'tests')
-rw-r--r--tests/mysql_client_test.c94
1 files changed, 61 insertions, 33 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 9394b0df40b..f65e549fd96 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -46,6 +46,9 @@ static char *opt_user= 0;
static char *opt_password= 0;
static char *opt_host= 0;
static char *opt_unix_socket= 0;
+#ifdef HAVE_SMEM
+static char *shared_memory_base_name= 0;
+#endif
static unsigned int opt_port;
static my_bool tty_password= 0, opt_silent= 0;
@@ -230,6 +233,26 @@ static void print_st_error(MYSQL_STMT *stmt, const char *msg)
}
}
+/*
+ Enhanced version of mysql_client_init(), which may also set shared memory
+ base on Windows.
+*/
+static MYSQL *mysql_client_init(MYSQL* con)
+{
+ MYSQL* res = mysql_init(con);
+#ifdef HAVE_SMEM
+ if (res && shared_memory_base_name)
+ mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name);
+#endif
+ return res;
+}
+
+/*
+ Disable direct calls of mysql_init, as it disregards shared memory base.
+*/
+#define mysql_init(A) Please use mysql_client_init instead of mysql_init
+
+
/* Check if the connection has InnoDB tables */
static my_bool check_have_innodb(MYSQL *conn)
@@ -293,10 +316,10 @@ static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect)
fprintf(stdout, "\n Establishing a connection to '%s' ...",
opt_host ? opt_host : "");
- if (!(mysql= mysql_init(NULL)))
+ if (!(mysql= mysql_client_init(NULL)))
{
opt_silent= 0;
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
/* enable local infile, in non-binary builds often disabled by default */
@@ -1160,9 +1183,9 @@ static my_bool thread_query(char *query)
error= 0;
if (!opt_silent)
fprintf(stdout, "\n in thread_query(%s)", query);
- if (!(l_mysql= mysql_init(NULL)))
+ if (!(l_mysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
return 1;
}
if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
@@ -2512,9 +2535,9 @@ static void test_ps_query_cache()
case TEST_QCACHE_ON_WITH_OTHER_CONN:
if (!opt_silent)
fprintf(stdout, "\n Establishing a test connection ...");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- printf("mysql_init() failed");
+ printf("mysql_client_init() failed");
DIE_UNLESS(0);
}
if (!(mysql_real_connect(lmysql, opt_host, opt_user,
@@ -4960,9 +4983,9 @@ static void test_stmt_close()
if (!opt_silent)
fprintf(stdout, "\n Establishing a test connection ...");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
if (!(mysql_real_connect(lmysql, opt_host, opt_user,
@@ -5851,9 +5874,9 @@ DROP TABLE IF EXISTS test_multi_tab";
rc= mysql_more_results(mysql);
DIE_UNLESS(rc == 0);
- if (!(mysql_local= mysql_init(NULL)))
+ if (!(mysql_local= mysql_client_init(NULL)))
{
- fprintf(stdout, "\n mysql_init() failed");
+ fprintf(stdout, "\n mysql_client_init() failed");
exit(1);
}
@@ -5976,9 +5999,9 @@ static void test_prepare_multi_statements()
char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_multi_statements");
- if (!(mysql_local= mysql_init(NULL)))
+ if (!(mysql_local= mysql_client_init(NULL)))
{
- fprintf(stderr, "\n mysql_init() failed");
+ fprintf(stderr, "\n mysql_client_init() failed");
exit(1);
}
@@ -7459,9 +7482,9 @@ static void test_prepare_grant()
if (!opt_silent)
fprintf(stdout, "\n Establishing a test connection ...");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
if (!(mysql_real_connect(lmysql, opt_host, "test_grant",
@@ -7915,9 +7938,9 @@ static void test_drop_temp()
if (!opt_silent)
fprintf(stdout, "\n Establishing a test connection ...");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
@@ -13159,7 +13182,7 @@ static void test_bug15518()
int rc;
myheader("test_bug15518");
- mysql1= mysql_init(NULL);
+ mysql1= mysql_client_init(NULL);
if (!mysql_real_connect(mysql1, opt_host, opt_user, opt_password,
opt_db ? opt_db : "test", opt_port, opt_unix_socket,
@@ -13315,9 +13338,9 @@ static void test_bug8378()
if (!opt_silent)
fprintf(stdout, "\n Establishing a test connection ...");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
if (mysql_options(lmysql, MYSQL_SET_CHARSET_NAME, "gbk"))
@@ -13856,7 +13879,7 @@ static void test_bug9992()
if (!opt_silent)
printf("Establishing a connection with option CLIENT_MULTI_STATEMENTS..\n");
- mysql1= mysql_init(NULL);
+ mysql1= mysql_client_init(NULL);
if (!mysql_real_connect(mysql1, opt_host, opt_user, opt_password,
opt_db ? opt_db : "test", opt_port, opt_unix_socket,
@@ -14445,9 +14468,9 @@ static void test_bug12001()
myheader("test_bug12001");
- if (!(mysql_local= mysql_init(NULL)))
+ if (!(mysql_local= mysql_client_init(NULL)))
{
- fprintf(stdout, "\n mysql_init() failed");
+ fprintf(stdout, "\n mysql_client_init() failed");
exit(1);
}
@@ -15172,9 +15195,9 @@ static void test_opt_reconnect()
myheader("test_opt_reconnect");
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
exit(1);
}
@@ -15209,9 +15232,9 @@ static void test_opt_reconnect()
mysql_close(lmysql);
- if (!(lmysql= mysql_init(NULL)))
+ if (!(lmysql= mysql_client_init(NULL)))
{
- myerror("mysql_init() failed");
+ myerror("mysql_client_init() failed");
DIE_UNLESS(0);
}
@@ -15246,7 +15269,7 @@ static void test_bug12744()
int rc;
myheader("test_bug12744");
- lmysql= mysql_init(NULL);
+ lmysql= mysql_client_init(NULL);
DIE_UNLESS(lmysql);
if (!mysql_real_connect(lmysql, opt_host, opt_user, opt_password,
@@ -15819,7 +15842,7 @@ static void test_bug15752()
rc= mysql_query(mysql, "create procedure p1() select 1");
myquery(rc);
- mysql_init(&mysql_local);
+ mysql_client_init(&mysql_local);
if (! mysql_real_connect(&mysql_local, opt_host, opt_user,
opt_password, current_db, opt_port,
opt_unix_socket,
@@ -16705,7 +16728,7 @@ static void test_bug29692()
{
MYSQL* conn;
- if (!(conn= mysql_init(NULL)))
+ if (!(conn= mysql_client_init(NULL)))
{
myerror("test_bug29692 init failed");
exit(1);
@@ -16840,7 +16863,7 @@ static void test_bug30472()
/* Create a new connection. */
- DIE_UNLESS(mysql_init(&con));
+ DIE_UNLESS(mysql_client_init(&con));
DIE_UNLESS(mysql_real_connect(&con,
opt_host,
@@ -17014,7 +17037,7 @@ static void test_bug20023()
/* Create a new connection. */
- DIE_UNLESS(mysql_init(&con));
+ DIE_UNLESS(mysql_client_init(&con));
DIE_UNLESS(mysql_real_connect(&con,
opt_host,
@@ -17151,7 +17174,7 @@ static void bug31418_impl()
/* Create a new connection. */
- DIE_UNLESS(mysql_init(&con));
+ DIE_UNLESS(mysql_client_init(&con));
DIE_UNLESS(mysql_real_connect(&con,
opt_host,
@@ -18001,7 +18024,7 @@ static void test_bug44495()
"END;");
myquery(rc);
- DIE_UNLESS(mysql_init(&con));
+ DIE_UNLESS(mysql_client_init(&con));
DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
current_db, opt_port, opt_unix_socket,
@@ -18064,6 +18087,11 @@ static struct my_option client_test_long_options[] =
0, 0, 0, 0, 0, 0},
{"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0,
0},
+#ifdef HAVE_SMEM
+ {"shared-memory-base-name", 'm', "Base name of shared memory.",
+ (uchar**) &shared_memory_base_name, (uchar**)&shared_memory_base_name, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#endif
{"socket", 'S', "Socket file to use for connection",
(uchar **) &opt_unix_socket, (uchar **) &opt_unix_socket, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},