diff options
author | unknown <sergefp@mysql.com> | 2004-04-13 01:58:48 +0400 |
---|---|---|
committer | unknown <sergefp@mysql.com> | 2004-04-13 01:58:48 +0400 |
commit | e69f8367b853b531b0229ac0820419eed247693f (patch) | |
tree | a06347135e007909b42a04e6faa700d9b5241206 /sql/sql_class.cc | |
parent | 26aa6e0f536b72a0356bef06b92518ba9e0bf8d7 (diff) | |
download | mariadb-git-e69f8367b853b531b0229ac0820419eed247693f.tar.gz |
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
sql/mysql_priv.h:
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes.
sql/sql_class.cc:
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes.
sql/sql_class.h:
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes.
sql/sql_parse.cc:
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes.
sql/sql_prepare.cc:
WL#1622 "SQL Syntax for Prepared Statements": post-review fixes.
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r-- | sql/sql_class.cc | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 49fa0455a30..87b6c49a4b7 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -79,24 +79,6 @@ extern "C" void free_user_var(user_var_entry *entry) } /**************************************************************************** -** 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); |