mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes:
Moved PS name to Statement class, Statement_map now handles name-to-statement resolution. Both named and unnamed statements are now executed in one function (sql_prepare.cc:execute_stmt) Fixed a problem: Malformed sequence of commands from client could cause server to use previously deleted objects. Some code cleanup and small fixes
This commit is contained in:
@ -78,24 +78,6 @@ extern "C" void free_user_var(user_var_entry *entry)
|
||||
my_free((char*) entry,MYF(0));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** SQL syntax names for Prepared Statements
|
||||
****************************************************************************/
|
||||
|
||||
extern "C" byte *get_stmt_key(SQL_PREP_STMT_ENTRY *entry, uint *length,
|
||||
my_bool not_used __attribute__((unused)))
|
||||
{
|
||||
*length=(uint) entry->name.length;
|
||||
return (byte*) entry->name.str;
|
||||
}
|
||||
|
||||
extern "C" void free_sql_stmt(SQL_PREP_STMT_ENTRY *entry)
|
||||
{
|
||||
char *pos= (char*) entry+ALIGN_SIZE(sizeof(*entry));
|
||||
my_free((char*) entry,MYF(0));
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
** Thread specific functions
|
||||
****************************************************************************/
|
||||
@ -178,9 +160,6 @@ THD::THD():user_time(0), current_statement(0), is_fatal_error(0),
|
||||
else
|
||||
bzero((char*) &user_var_events, sizeof(user_var_events));
|
||||
|
||||
hash_init(&sql_prepared_stmts, &my_charset_bin, USER_VARS_HASH_SIZE, 0, 0,
|
||||
(hash_get_key) get_stmt_key,
|
||||
(hash_free_key) free_sql_stmt,0);
|
||||
/* Protocol */
|
||||
protocol= &protocol_simple; // Default protocol
|
||||
protocol_simple.init(this);
|
||||
@ -299,7 +278,6 @@ void THD::cleanup(void)
|
||||
my_free((char*) variables.datetime_format, MYF(MY_ALLOW_ZERO_PTR));
|
||||
delete_dynamic(&user_var_events);
|
||||
hash_free(&user_vars);
|
||||
hash_free(&sql_prepared_stmts);
|
||||
if (global_read_lock)
|
||||
unlock_global_read_lock(this);
|
||||
if (ull)
|
||||
@ -1220,6 +1198,7 @@ Statement::Statement(THD *thd)
|
||||
query_length(0),
|
||||
free_list(0)
|
||||
{
|
||||
name.str= NULL;
|
||||
init_sql_alloc(&mem_root,
|
||||
thd->variables.query_alloc_block_size,
|
||||
thd->variables.query_prealloc_size);
|
||||
@ -1303,17 +1282,52 @@ static void delete_statement_as_hash_key(void *key)
|
||||
delete (Statement *) key;
|
||||
}
|
||||
|
||||
byte *get_stmt_name_hash_key(Statement *entry, uint *length,
|
||||
my_bool not_used __attribute__((unused)))
|
||||
{
|
||||
*length=(uint) entry->name.length;
|
||||
return (byte*) entry->name.str;
|
||||
}
|
||||
|
||||
C_MODE_END
|
||||
|
||||
Statement_map::Statement_map() :
|
||||
last_found_statement(0)
|
||||
{
|
||||
enum { START_HASH_SIZE = 16 };
|
||||
hash_init(&st_hash, default_charset_info, START_HASH_SIZE, 0, 0,
|
||||
enum
|
||||
{
|
||||
START_STMT_HASH_SIZE = 16,
|
||||
START_NAME_HASH_SIZE = 16
|
||||
};
|
||||
hash_init(&st_hash, default_charset_info, START_STMT_HASH_SIZE, 0, 0,
|
||||
get_statement_id_as_hash_key,
|
||||
delete_statement_as_hash_key, MYF(0));
|
||||
hash_init(&names_hash, &my_charset_bin, START_NAME_HASH_SIZE, 0, 0,
|
||||
(hash_get_key) get_stmt_name_hash_key,
|
||||
NULL,MYF(0));
|
||||
}
|
||||
|
||||
int Statement_map::insert(Statement *statement)
|
||||
{
|
||||
int rc= my_hash_insert(&st_hash, (byte *) statement);
|
||||
if (rc == 0)
|
||||
last_found_statement= statement;
|
||||
if (statement->name.str)
|
||||
{
|
||||
/*
|
||||
If there is a statement with the same name, remove it. It is ok to
|
||||
remove old and fail to insert new one at the same time.
|
||||
*/
|
||||
Statement *old_stmt;
|
||||
if ((old_stmt= find_by_name(&statement->name)))
|
||||
erase(old_stmt);
|
||||
if ((rc= my_hash_insert(&names_hash, (byte*)statement)))
|
||||
hash_delete(&st_hash, (byte*)statement);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool select_dumpvar::send_data(List<Item> &items)
|
||||
{
|
||||
List_iterator_fast<Item_func_set_user_var> li(vars);
|
||||
|
Reference in New Issue
Block a user