1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

A fix and test case for Bug#10729 "mysql_stmt_attr_set

CURSOR_TYPE_READ_ONLY". The bug was that we (me) don't perform proper
cleanups of the prepared statement when done fetching from a cursor.
Another patch.
This commit is contained in:
konstantin@mysql.com
2005-06-09 18:17:45 +04:00
parent d08d1a88e0
commit 95e620485c
6 changed files with 112 additions and 49 deletions

View File

@ -1709,10 +1709,11 @@ Cursor::init_from_thd(THD *thd)
We need to save and reset thd->mem_root, otherwise it'll be freed
later in mysql_parse.
We can't just change the thd->mem_root here as we want to keep the things
that is already allocated in thd->mem_root for Cursor::fetch()
We can't just change the thd->mem_root here as we want to keep the
things that are already allocated in thd->mem_root for Cursor::fetch()
*/
main_mem_root= *thd->mem_root;
state= thd->current_arena->state;
/* Allocate new memory root for thd */
init_sql_alloc(thd->mem_root,
thd->variables.query_alloc_block_size,
@ -1735,24 +1736,6 @@ Cursor::init_from_thd(THD *thd)
What problems can we have with it if cursor is open?
TODO: must be fixed because of the prelocked mode.
*/
/*
TODO: grab thd->free_list here?
*/
}
void
Cursor::init_thd(THD *thd)
{
DBUG_ASSERT(thd->derived_tables == 0);
thd->derived_tables= derived_tables;
DBUG_ASSERT(thd->open_tables == 0);
thd->open_tables= open_tables;
DBUG_ASSERT(thd->lock== 0);
thd->lock= lock;
thd->query_id= query_id;
}
@ -1828,6 +1811,13 @@ Cursor::fetch(ulong num_rows)
DBUG_ENTER("Cursor::fetch");
DBUG_PRINT("enter",("rows: %lu", num_rows));
DBUG_ASSERT(thd->derived_tables == 0 && thd->open_tables == 0 &&
thd->lock == 0);
thd->derived_tables= derived_tables;
thd->open_tables= open_tables;
thd->lock= lock;
thd->query_id= query_id;
/* save references to memory, allocated during fetch */
thd->set_n_backup_item_arena(this, &thd->stmt_backup);
@ -1846,6 +1836,9 @@ Cursor::fetch(ulong num_rows)
#endif
thd->restore_backup_item_arena(this, &thd->stmt_backup);
DBUG_ASSERT(thd->free_list == 0);
reset_thd(thd);
if (error == NESTED_LOOP_CURSOR_LIMIT)
{
/* Fetch limit worked, possibly more rows are there */
@ -1886,8 +1879,8 @@ Cursor::close()
join->cleanup();
delete join;
}
/* XXX: Another hack: closing tables used in the cursor */
{
/* XXX: Another hack: closing tables used in the cursor */
DBUG_ASSERT(lock || open_tables || derived_tables);
TABLE *tmp_derived_tables= thd->derived_tables;