summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.local>2006-07-24 14:56:53 +0400
committerunknown <kostja@bodhi.local>2006-07-24 14:56:53 +0400
commit36510232aa5ab3788de36d17202254e3789441f4 (patch)
tree9e665cae0cf874da93929345fdbe6d3d6d97debb /include
parent12d6b9c7f131cd623e384b8f176806d5e5dac7e2 (diff)
downloadmariadb-git-36510232aa5ab3788de36d17202254e3789441f4.tar.gz
A fix and a test case for Bug#15752 "Lost connection to MySQL server
when calling a SP from C API" The bug was caused by lack of checks for misuse in mysql_real_query. A stored procedure always returns at least one result, which is the status of execution of the procedure itself. This result, or so-called OK packet, is similar to a result returned by INSERT/UPDATE/CREATE operations: it contains the overall status of execution, the number of affected rows and the number of warnings. The client test program attached to the bug did not read this result and ivnoked the next query. In turn, libmysql had no check for such scenario and mysql_real_query was simply trying to send that query without reading the pending response, thus messing up the communication protocol. The fix is to return an error from mysql_real_query when it's called prior to retrieval of all pending results. client/mysqlbinlog.cc: net_safe_read -> cli_safe_read include/mysql.h: Remove a private function from the public header. include/mysql_com.h: Remove a define that is never used. include/sql_common.h: Add a declaration for cli_safe_read - a function that reads one packet from the server. libmysql/libmysql.c: net_safe_read -> cli_safe_read Return CR_COMMANDS_OUT_OF_SYNC on attempt to execute a statement using a connection which has pending result sets. sql-common/client.c: Actual fix for Bug#15752: if the server has pending result sets for the client, return CR_COMMANDS_OUT_OF_SYNC on attempt to execute another query. Similarly to the behaviour of mysql_use_result(), multiple result sets block the connection and must be fetched before it can be used for another query. This uncovered an error in the protocol: the server doesn't drop SERVER_MORE_RESULTS_EXISTS status flag upon an error, so in case of a multi-query like SELECT 1; SELECT syntax_error; SELECT 2; the client has no way to know that the server won't ever come to execution of the third query and won't return any result sets for it. For now, fix it in cli_safe_read, as a proper fix requires extension of the client-server protocol. sql/protocol.cc: Remove a name that is never used. sql/slave.cc: net_safe_read -> cli_safe_read tests/mysql_client_test.c: Make 'query' a local variable to avoid name clash. Add a test case for Bug#15752 "Lost connection to MySQL server when calling an SP from C API"
Diffstat (limited to 'include')
-rw-r--r--include/mysql.h1
-rw-r--r--include/mysql_com.h1
-rw-r--r--include/sql_common.h2
3 files changed, 1 insertions, 3 deletions
diff --git a/include/mysql.h b/include/mysql.h
index 3a71e47f414..ae5cf670ec9 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -837,7 +837,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
#define simple_command(mysql, command, arg, length, skip_check) \
(*(mysql)->methods->advanced_command)(mysql, command, \
NullS, 0, arg, length, skip_check)
-unsigned long net_safe_read(MYSQL* mysql);
#ifdef __NETWARE__
#pragma pack(pop) /* restore alignment */
diff --git a/include/mysql_com.h b/include/mysql_com.h
index ec1c133799f..60e726396cb 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -140,7 +140,6 @@ enum enum_server_command
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
-#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */
#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
#define SERVER_QUERY_NO_INDEX_USED 32
diff --git a/include/sql_common.h b/include/sql_common.h
index 9fc8d4f457b..c77a905aeb1 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -35,7 +35,7 @@ my_bool
cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
const char *header, ulong header_length,
const char *arg, ulong arg_length, my_bool skip_check);
-
+unsigned long cli_safe_read(MYSQL *mysql);
void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode,
const char *sqlstate);
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);