diff options
author | unknown <konstantin@mysql.com> | 2004-08-24 20:17:11 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-08-24 20:17:11 +0400 |
commit | 49bd559eb8f041de97e4ef55f280f3806d1b6c42 (patch) | |
tree | abcc02d1c616c2795f2ca78dd7032b01d865d0ce /sql/sql_class.h | |
parent | 83e3d3f9a3ab6888292b8bcb15e0f77f00249289 (diff) | |
download | mariadb-git-49bd559eb8f041de97e4ef55f280f3806d1b6c42.tar.gz |
Fix for Bug#5034 "prepared "select 1 into @arg15", second
execute crashes server": we were deleting lex->result
after each execute, but prepared statements assumed that
it's left intact.
The fix adds cleanup() method to select_result hierarchy,
so that result objects can be reused.
Plus we now need to delete result objects more wisely.
mysql-test/r/ps.result:
Test results fixed: test case for bug#5034
mysql-test/t/ps.test:
A test case for bug#5034, few followups
sql/sql_class.cc:
- fix warning in THD::THD
- implementation of cleanup() for select_result hierarchy
- select_export::send_eof was identical to
select_dump::send_eof: moved to the base class select_to_file.
- Statement::end_statement() to end lex, free items, and
delete possible select_result
sql/sql_class.h:
- select_result::cleanup() declaration
-
sql/sql_insert.cc:
- implementation of select_insert::cleanup(): currently
we always create a new instance of select_insert/
select_create on each execute.
sql/sql_lex.cc:
- with more complicated logic of freeing lex->result it's
easier to have it non-zero only if it points to a valid
result.
sql/sql_lex.h:
Now st_lex::st_lex is not empty.
sql/sql_parse.cc:
mysql_execute_command():
- delete select_result *result only if it was created in
this function.
- use end_statement() to cleanup lex and thd in the end of
each statement.
- no need to save THD::lock if this is explain. This save
apparently left from times when derived tables were
materialized here, not in open_and_lock_tables.
sql/sql_prepare.cc:
- call result->cleanup() in reset_stmt_for_execute
- now Statement is responsible for freeing its lex->result.
sql/sql_select.cc:
handle_select():
- don't delete result, it might be needed
for next executions
- result is never null
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r-- | sql/sql_class.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h index 83fdb4c7d76..c18bf969ab9 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -547,6 +547,12 @@ public: void restore_backup_statement(Statement *stmt, Statement *backup); /* return class type */ virtual Type type() const; + + /* + Cleanup statement parse state (parse tree, lex) after execution of + a non-prepared SQL statement. + */ + void end_statement(); }; @@ -1029,10 +1035,13 @@ public: ~Disable_binlog(); }; + /* Used to hold information about file and file structure in exchainge via non-DB file (...INTO OUTFILE..., ...LOAD DATA...) + XXX: We never call destructor for objects of this class. */ + class sql_exchange :public Sql_alloc { public: @@ -1042,7 +1051,6 @@ public: bool dumpfile; ulong skip_lines; sql_exchange(char *name,bool dumpfile_flag); - ~sql_exchange() {} }; #include "log_event.h" @@ -1073,6 +1081,11 @@ public: virtual void send_error(uint errcode,const char *err); virtual bool send_eof()=0; virtual void abort() {} + /* + Cleanup instance of this class for next execution of a prepared + statement/stored procedure. + */ + virtual void cleanup(); }; @@ -1099,6 +1112,8 @@ public: ~select_to_file(); bool send_fields(List<Item> &list, uint flag) { return 0; } void send_error(uint errcode,const char *err); + bool send_eof(); + void cleanup(); }; @@ -1111,7 +1126,6 @@ public: ~select_export(); int prepare(List<Item> &list, SELECT_LEX_UNIT *u); bool send_data(List<Item> &items); - bool send_eof(); }; @@ -1120,7 +1134,6 @@ public: select_dump(sql_exchange *ex) :select_to_file(ex) {} int prepare(List<Item> &list, SELECT_LEX_UNIT *u); bool send_data(List<Item> &items); - bool send_eof(); }; @@ -1145,6 +1158,8 @@ class select_insert :public select_result { bool send_data(List<Item> &items); void send_error(uint errcode,const char *err); bool send_eof(); + /* not implemented: select_insert is never re-used in prepared statements */ + void cleanup(); }; @@ -1445,4 +1460,5 @@ public: bool send_fields(List<Item> &list, uint flag) {return 0;} bool send_data(List<Item> &items); bool send_eof(); + void cleanup(); }; |