Commit 348bd98e authored by hf@deer.(none)'s avatar hf@deer.(none)

Fix for #2208 (multi-query returns wrong result in embedded library)

now we execute only one first select during mysql_real_query
others - during 'mysql_next_result'
parent d200443b
...@@ -575,6 +575,7 @@ typedef struct st_mysql_methods ...@@ -575,6 +575,7 @@ typedef struct st_mysql_methods
int (*unbuffered_fetch)(MYSQL *mysql, char **row); int (*unbuffered_fetch)(MYSQL *mysql, char **row);
void (*free_embedded_thd)(MYSQL *mysql); void (*free_embedded_thd)(MYSQL *mysql);
const char *(*read_statistic)(MYSQL *mysql); const char *(*read_statistic)(MYSQL *mysql);
int (*next_result)(MYSQL *mysql);
#endif #endif
} MYSQL_METHODS; } MYSQL_METHODS;
......
...@@ -58,6 +58,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt); ...@@ -58,6 +58,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt);
MYSQL_DATA * cli_read_binary_rows(MYSQL_STMT *stmt); MYSQL_DATA * cli_read_binary_rows(MYSQL_STMT *stmt);
int cli_unbuffered_fetch(MYSQL *mysql, char **row); int cli_unbuffered_fetch(MYSQL *mysql, char **row);
const char * cli_read_statistic(MYSQL *mysql); const char * cli_read_statistic(MYSQL *mysql);
int cli_next_result(MYSQL *mysql);
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
int init_embedded_server(int argc, char **argv, char **groups); int init_embedded_server(int argc, char **argv, char **groups);
......
...@@ -3511,6 +3511,21 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql) ...@@ -3511,6 +3511,21 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql)
Reads and returns the next query results Reads and returns the next query results
*/ */
int cli_next_result(MYSQL *mysql)
{
DBUG_ENTER("cli_next_result");
mysql->net.last_error[0]= 0;
mysql->net.last_errno= 0;
strmov(mysql->net.sqlstate, not_error_sqlstate);
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
DBUG_RETURN((*mysql->methods->read_query_result)(mysql));
DBUG_RETURN(-1); /* No more results */
}
int STDCALL mysql_next_result(MYSQL *mysql) int STDCALL mysql_next_result(MYSQL *mysql)
{ {
DBUG_ENTER("mysql_next_result"); DBUG_ENTER("mysql_next_result");
...@@ -3523,15 +3538,7 @@ int STDCALL mysql_next_result(MYSQL *mysql) ...@@ -3523,15 +3538,7 @@ int STDCALL mysql_next_result(MYSQL *mysql)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
mysql->net.last_error[0]= 0; DBUG_RETURN((*mysql->methods->next_result)(mysql));
mysql->net.last_errno= 0;
strmov(mysql->net.sqlstate, not_error_sqlstate);
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
DBUG_RETURN((*mysql->methods->read_query_result)(mysql));
DBUG_RETURN(-1); /* No more results */
} }
......
...@@ -245,6 +245,18 @@ static MYSQL_RES * emb_mysql_store_result(MYSQL *mysql) ...@@ -245,6 +245,18 @@ static MYSQL_RES * emb_mysql_store_result(MYSQL *mysql)
return mysql_store_result(mysql); return mysql_store_result(mysql);
} }
int emb_next_result(MYSQL *mysql)
{
THD *thd= (THD*)mysql->thd;
DBUG_ENTER("emb_next_result");
if (emb_advanced_command(mysql, COM_QUERY,0,0,
thd->query_rest,thd->query_rest_length,1)
|| emb_mysql_read_query_result(mysql))
DBUG_RETURN(1);
DBUG_RETURN(0); /* No more results */
}
MYSQL_METHODS embedded_methods= MYSQL_METHODS embedded_methods=
{ {
...@@ -259,7 +271,8 @@ MYSQL_METHODS embedded_methods= ...@@ -259,7 +271,8 @@ MYSQL_METHODS embedded_methods=
emb_read_binary_rows, emb_read_binary_rows,
emb_unbuffered_fetch, emb_unbuffered_fetch,
emb_free_embedded_thd, emb_free_embedded_thd,
emb_read_statistic emb_read_statistic,
emb_next_result
}; };
C_MODE_END C_MODE_END
...@@ -749,6 +762,11 @@ bool Protocol::net_store_data(const char *from, uint length) ...@@ -749,6 +762,11 @@ bool Protocol::net_store_data(const char *from, uint length)
return false; return false;
} }
char *memdup_mysql(struct st_mysql *mysql, const char*data, int length)
{
return memdup_root(&mysql->field_alloc, data, length);
}
#if 0 #if 0
/* The same as Protocol::net_store_data but does the converstion /* The same as Protocol::net_store_data but does the converstion
*/ */
......
...@@ -565,6 +565,8 @@ public: ...@@ -565,6 +565,8 @@ public:
struct st_mysql_bind *client_params; struct st_mysql_bind *client_params;
char *extra_data; char *extra_data;
ulong extra_length; ulong extra_length;
char *query_rest;
uint32 query_rest_length;
#endif #endif
NET net; // client connection descriptor NET net; // client connection descriptor
MEM_ROOT warn_root; // For warnings and errors MEM_ROOT warn_root; // For warnings and errors
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
extern "C" int gethostname(char *name, int namelen); extern "C" int gethostname(char *name, int namelen);
#endif #endif
char *memdup_mysql(struct st_mysql *mysql, const char*data, int length);
static int check_for_max_user_connections(THD *thd, USER_CONN *uc); static int check_for_max_user_connections(THD *thd, USER_CONN *uc);
static void decrease_user_connections(USER_CONN *uc); static void decrease_user_connections(USER_CONN *uc);
static bool check_db_used(THD *thd,TABLE_LIST *tables); static bool check_db_used(THD *thd,TABLE_LIST *tables);
...@@ -1397,11 +1398,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1397,11 +1398,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char *packet= thd->lex->found_colon; char *packet= thd->lex->found_colon;
/* /*
Multiple queries exits, execute them individually Multiple queries exits, execute them individually
in embedded server - just store them to be executed later
*/ */
#ifndef EMBEDDED_LIBRARY
if (thd->lock || thd->open_tables || thd->derived_tables) if (thd->lock || thd->open_tables || thd->derived_tables)
close_thread_tables(thd); close_thread_tables(thd);
#endif
ulong length= thd->query_length-(ulong)(thd->lex->found_colon-thd->query); ulong length= thd->query_length-(ulong)(packet-thd->query);
/* Remove garbage at start of query */ /* Remove garbage at start of query */
while (my_isspace(thd->charset(), *packet) && length > 0) while (my_isspace(thd->charset(), *packet) && length > 0)
...@@ -1414,7 +1417,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1414,7 +1417,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id= query_id++; thd->query_id= query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
#ifndef EMBEDDED_LIBRARY
mysql_parse(thd, packet, length); mysql_parse(thd, packet, length);
#else
thd->query_rest= (char*)memdup_mysql(thd->mysql, packet, length);
thd->query_rest_length= length;
break;
#endif /*EMBEDDED_LIBRARY*/
} }
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
......
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