* Magne Mahre <Magne.Mahre@stripped> [08/10/10 15:26]:
> #At file:///home/mm136784/z/mysql-6.0-runtime-fix33831/
>
> 2728 Magne Mahre 2008-10-10
> Fix for bug# 33831
> Added a new error message to indicate that the session is already connected.
Please add bug synopsis to the changeset comment:
Fixed Bug#33831 mysql_real_connect() connects again if given an
already connected MYSQL handle.
> + "Already connected",
> ""
Could you please com up with a bit more elaborate error message?
You have space to provide a suggestion to the user.
"The handle is already connected. Use a new MYSQL handle for each
connection".
You could check the error message with the docs team (Paul, others
on #docs).
> };
>
> @@ -151,6 +152,7 @@
> "Lost connection to MySQL server at '%s', system error: %d",
> "Statement closed indirectly because of a preceeding %s() call",
> "The number of columns in the result set differs from the number of bound buffers.
> You must reset the statement, rebind the result set columns, and execute the statement
> again",
> + "Already connected",
> ""
> };
>
> @@ -215,6 +217,7 @@
> "Lost connection to MySQL server at '%s', system error: %d",
> "Statement closed indirectly because of a preceeding %s() call",
> "The number of columns in the result set differs from the number of bound buffers.
> You must reset the statement, rebind the result set columns, and execute the statement
> again",
> + "Already connected",
> ""
> };
> #endif
>
> === modified file 'sql-common/client.c'
> --- a/sql-common/client.c 2008-05-08 16:01:15 +0000
> +++ b/sql-common/client.c 2008-10-10 11:10:20 +0000
> @@ -1836,6 +1836,13 @@
> db ? db : "(Null)",
> user ? user : "(Null)"));
>
> + /* Test whether we're already connected */
> + if (net->vio)
> + {
> + set_mysql_error(mysql, CR_ALREADY_CONNECTED, unknown_sqlstate);
> + DBUG_RETURN(0);
> + }
> +
There is an embedded version of mysql_real_connect, in
libmysqld/lib_sql.cc.
You should patch it as well.
The embedded test is becoming part of the test suite.
I tried ./mtr --embedded mysql_client_test, and for some reason
it's still skipped. But you can always run it manually, the
program is located in libmysqld/exeamles/mysql_client_test. Let's
chat on IRC if you encounter a problem running it.
> +
> +/**
> + Bug# 33831 mysql_real_connect() connects again if given an already connected
> MYSQL handle
> +*/
Lines should fit 80 characters (I use 66 characters for comments
personally, there was some ancient D. Knuth recommendation about
it), terminated with a dot.
> +static void test_bug33831(void)
> +{
> + MYSQL *l_mysql;
> + my_bool error;
> +
> + DBUG_ENTER("test_bug33831");
> +
> + error= 0;
> +
> + if (!(l_mysql= mysql_init(NULL)))
> + {
> + myerror("mysql_init() failed");
> + DIE_UNLESS(0);
> + }
> + if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
> + opt_password, current_db, opt_port,
> + opt_unix_socket, 0)))
> + {
> + myerror("connection failed");
> + DIE_UNLESS(0);
> + }
> +
> + if (mysql_real_connect(l_mysql, opt_host, opt_user,
> + opt_password, current_db, opt_port,
> + opt_unix_socket, 0))
> + {
> + myerror("connection should have failed");
> + DIE_UNLESS(0);
> + }
> +
> + mysql_close (l_mysql);
No space before ( for a function call.
> + DBUG_VOID_RETURN;
> +}
Thank you for looking into this bug,
-kostja