diff options
author | unknown <konstantin@mysql.com> | 2005-03-24 15:12:53 +0300 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2005-03-24 15:12:53 +0300 |
commit | 3b236b1dfd1fdc34548e296dc63e75735becd61d (patch) | |
tree | ec4df54ab1b5ce7db1d531ed35940a9f42ceecd6 /sql/sql_prepare.cc | |
parent | 648d40ea663aecb584c832380a4309a127d7c2a5 (diff) | |
download | mariadb-git-3b236b1dfd1fdc34548e296dc63e75735becd61d.tar.gz |
Fixes and test cases for Bug#8880 "Commands out of sync error with cursors"
and Bug#9159 "Server crash during mysql_stmt_close".
The patch adds support for single-row result sets in cursors.
libmysql/libmysql.c:
If we wanted a cursor, and the server wasn't able to create one,
buffer all rows on client. Currently this is possible only for
single row result sets and some SHOW commands.
sql/sql_prepare.cc:
Properly free resources if there was a request to open a cursor which
wasn't fullfilled.
Give error on attempt to open a cursor for a statement not returning
a result set.
sql/sql_select.h:
Initialize Item_arena of Cursor object. A case when a cursor object
is created but not used is possible with single-row result sets.
tests/mysql_client_test.c:
Test cases for Bug#8880 and Bug#9159
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7862717bb18..75027b3bb0a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1970,6 +1970,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) { ulong stmt_id= uint4korr(packet); ulong flags= (ulong) ((uchar) packet[4]); + Cursor *cursor= 0; /* Query text for binary log, or empty string if the query is not put into binary log. @@ -2007,15 +2008,17 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) statement: we can't open a cursor for it. */ flags= 0; + my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0)); + goto err; } else { DBUG_PRINT("info",("Using READ_ONLY cursor")); if (!stmt->cursor && - !(stmt->cursor= new (&stmt->main_mem_root) Cursor())) + !(cursor= stmt->cursor= new (&stmt->main_mem_root) Cursor())) DBUG_VOID_RETURN; /* If lex->result is set, mysql_execute_command will use it */ - stmt->lex->result= &stmt->cursor->result; + stmt->lex->result= &cursor->result; } } #ifndef EMBEDDED_LIBRARY @@ -2061,11 +2064,10 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) my_pthread_setprio(pthread_self(), WAIT_PRIOR); thd->protocol= &thd->protocol_simple; // Use normal protocol - if (flags & (ulong) CURSOR_TYPE_READ_ONLY) + if (cursor && cursor->is_open()) { - if (stmt->cursor->is_open()) - stmt->cursor->init_from_thd(thd); - stmt->cursor->state= stmt->state; + cursor->init_from_thd(thd); + cursor->state= stmt->state; } else { |