diff options
author | unknown <anozdrin/alik@ibm.> | 2007-06-14 18:35:59 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@ibm.> | 2007-06-14 18:35:59 +0400 |
commit | efaaeecaa82710f51516f255105ee973f820f9b9 (patch) | |
tree | 5df007e2bd85f5bc10349ac41c610c1d6a36654d | |
parent | e615aaff689d0ba939f4b253f4b1ba92eb04d275 (diff) | |
download | mariadb-git-efaaeecaa82710f51516f255105ee973f820f9b9.tar.gz |
The second cleanup patch in scope of BUG#11986.
1. Introduce parse_sql() as a high-level replacement for MYSQLparse().
parse_sql() is responsible to switch and restore "parser context"
(THD::m_lip for now).
2. Fix typo in sp.cc: THD::spcont should be reset *before* calling
the parser.
sql/event_data_objects.cc:
Use parse_sql() instead of MYSQLparse().
sql/mysql_priv.h:
Introduce parse_sql() instead of auto-generated MYSQLparse.
sql/sp.cc:
1. Use parse_sql() instead of MYSQLparse().
2. THD::spcont should be reset before calling the parser.
sql/sql_class.cc:
Reset THD::m_lip.
sql/sql_parse.cc:
1. Introduce parse_sql() instead of auto-generated MYSQLparse().
2. Backup, switch and restore THD::m_lip inside parse_sql().
3. Use parse_sql() instead of MYSQLparse().
sql/sql_partition.cc:
Use parse_sql() instead of MYSQLparse().
sql/sql_prepare.cc:
Use parse_sql() instead of MYSQLparse().
sql/sql_trigger.cc:
Use parse_sql() instead of MYSQLparse().
sql/sql_view.cc:
Use parse_sql() instead of MYSQLparse().
-rw-r--r-- | sql/event_data_objects.cc | 4 | ||||
-rw-r--r-- | sql/mysql_priv.h | 3 | ||||
-rw-r--r-- | sql/sp.cc | 40 | ||||
-rw-r--r-- | sql/sql_class.cc | 3 | ||||
-rw-r--r-- | sql/sql_parse.cc | 44 | ||||
-rw-r--r-- | sql/sql_partition.cc | 3 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 7 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 4 | ||||
-rw-r--r-- | sql/sql_view.cc | 7 |
9 files changed, 69 insertions, 46 deletions
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index c95a6c5dd3c..727aecfa7bb 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -1875,11 +1875,9 @@ Event_job_data::execute(THD *thd, bool drop) { Lex_input_stream lip(thd, thd->query, thd->query_length); - thd->m_lip= &lip; lex_start(thd); - int err= MYSQLparse(thd); - if (err || thd->is_fatal_error) + if (parse_sql(thd, &lip)) { sql_print_error("Event Scheduler: " "%serror during compilation of %s.%s", diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1c961cf917f..9b9f9340c3f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -618,6 +618,8 @@ bool check_string_char_length(LEX_STRING *str, const char *err_msg, uint max_char_length, CHARSET_INFO *cs, bool no_error); +bool parse_sql(THD *thd, class Lex_input_stream *lip); + enum enum_mysql_completiontype { ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7, COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 @@ -1953,7 +1955,6 @@ void free_list(I_List <i_string_pair> *list); void free_list(I_List <i_string> *list); /* sql_yacc.cc */ -extern int MYSQLparse(void *thd); #ifndef DBUG_OFF extern void turn_parser_debug_on(); #endif diff --git a/sql/sp.cc b/sql/sp.cc index 8fcc80a1504..a8e6c2844a2 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -384,32 +384,32 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged))) goto end; + thd->spcont= NULL; + { Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length()); - thd->m_lip= &lip; lex_start(thd); - ret= MYSQLparse(thd); - } - thd->spcont= 0; - if (ret || thd->is_fatal_error || newlex.sphead == NULL) - { - sp_head *sp= newlex.sphead; + if (parse_sql(thd, &lip) || newlex.sphead == NULL) + { + sp_head *sp= newlex.sphead; - if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE))) - goto end; - delete sp; - ret= SP_PARSE_ERROR; - } - else - { - if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE))) - goto end; - *sphp= newlex.sphead; - (*sphp)->set_definer(&definer_user_name, &definer_host_name); - (*sphp)->set_info(created, modified, &chistics, sql_mode); - (*sphp)->optimize(); + if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE))) + goto end; + delete sp; + ret= SP_PARSE_ERROR; + } + else + { + if (dbchanged && (ret= mysql_change_db(thd, &old_db, TRUE))) + goto end; + *sphp= newlex.sphead; + (*sphp)->set_definer(&definer_user_name, &definer_host_name); + (*sphp)->set_info(created, modified, &chistics, sql_mode); + (*sphp)->optimize(); + } } + end: lex_end(thd->lex); thd->spcont= old_spcont; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 66959940d90..62f6706d717 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -342,7 +342,8 @@ THD::THD() in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE), - spcont(NULL) + spcont(NULL), + m_lip(NULL) { ulong tmp; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f904404171d..cbe3c4363cf 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5343,12 +5343,11 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, sp_cache_flush_obsolete(&thd->sp_func_cache); Lex_input_stream lip(thd, inBuf, length); - thd->m_lip= &lip; - int err= MYSQLparse(thd); + bool err= parse_sql(thd, &lip); *found_semicolon= lip.found_semicolon; - if (!err && ! thd->is_fatal_error) + if (!err) { #ifndef NO_EMBEDDED_ACCESS_CHECKS if (mqh_used && thd->user_connect && @@ -5371,8 +5370,8 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, PROCESSLIST. Note that we don't need LOCK_thread_count to modify query_length. */ - if (lip.found_semicolon && - (thd->query_length= (ulong)(lip.found_semicolon - thd->query))) + if (*found_semicolon && + (thd->query_length= (ulong)(*found_semicolon - thd->query))) thd->query_length--; /* Actually execute the query */ mysql_execute_command(thd); @@ -5426,12 +5425,10 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length) DBUG_ENTER("mysql_test_parse_for_slave"); Lex_input_stream lip(thd, inBuf, length); - thd->m_lip= &lip; lex_start(thd); mysql_reset_thd_for_next_command(thd); - int err= MYSQLparse((void*) thd); - if (!err && ! thd->is_fatal_error && + if (!parse_sql(thd, &lip) && all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first)) error= 1; /* Ignore question */ thd->end_statement(); @@ -7123,3 +7120,34 @@ bool check_string_char_length(LEX_STRING *str, const char *err_msg, my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length); return TRUE; } + + +extern int MYSQLparse(void *thd); // from sql_yacc.cc + + +/** + This is a wrapper of MYSQLparse(). All the code should call parse_sql() + instead of MYSQLparse(). + + @param thd Thread context. + @param lip Lexer context. + + @return Error status. + @retval FALSE on success. + @retval TRUE on parsing error. +*/ + +bool parse_sql(THD *thd, Lex_input_stream *lip) +{ + bool err_status; + + DBUG_ASSERT(thd->m_lip == NULL); + + thd->m_lip= lip; + + err_status= MYSQLparse(thd) != 0 || thd->is_fatal_error; + + thd->m_lip= NULL; + + return err_status; +} diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index d47aacee924..05e85b34a9c 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -3696,7 +3696,6 @@ bool mysql_unpack_partition(THD *thd, thd->variables.character_set_client= system_charset_info; Lex_input_stream lip(thd, part_buf, part_info_len); - thd->m_lip= &lip; lex_start(thd); /* @@ -3725,7 +3724,7 @@ bool mysql_unpack_partition(THD *thd, lex.part_info->part_state= part_state; lex.part_info->part_state_len= part_state_len; DBUG_PRINT("info", ("Parse: %s", part_buf)); - if (MYSQLparse((void*)thd) || thd->is_fatal_error) + if (parse_sql(thd, &lip)) { thd->free_items(); goto end; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 716ca08beb1..2031f4b2448 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2858,12 +2858,11 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len) Lex_input_stream lip(thd, thd->query, thd->query_length); lip.stmt_prepare_mode= TRUE; - thd->m_lip= &lip; lex_start(thd); - int err= MYSQLparse((void *)thd); - error= err || thd->is_fatal_error || - thd->net.report_error || init_param_array(this); + error= parse_sql(thd, &lip) || + thd->net.report_error || + init_param_array(this); /* While doing context analysis of the query (in check_prepared_statement) diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index f63fcab04bb..ded3a0a6e24 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -981,12 +981,10 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, thd->variables.sql_mode= (ulong)*trg_sql_mode; Lex_input_stream lip(thd, trg_create_str->str, trg_create_str->length); - thd->m_lip= &lip; lex_start(thd); thd->spcont= 0; - int err= MYSQLparse((void *)thd); - if (err || thd->is_fatal_error) + if (parse_sql(thd, &lip)) { /* Currently sphead is always deleted in case of a parse error */ DBUG_ASSERT(lex.sphead == 0); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index a2d6e080763..dd17024aee0 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -893,7 +893,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, LEX *old_lex, *lex; Query_arena *arena, backup; TABLE_LIST *top_view= table->top_table(); - int res; + bool res; bool result, view_is_mergeable; TABLE_LIST *view_main_select_tables; DBUG_ENTER("mysql_make_view"); @@ -1005,7 +1005,6 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, { Lex_input_stream lip(thd, table->query.str, table->query.length); - thd->m_lip= &lip; lex_start(thd); view_select= &lex->select_lex; view_select->select_number= ++thd->select_number; @@ -1039,7 +1038,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, MODE_IGNORE_SPACE | MODE_NO_BACKSLASH_ESCAPES); CHARSET_INFO *save_cs= thd->variables.character_set_client; thd->variables.character_set_client= system_charset_info; - res= MYSQLparse((void *)thd); + res= parse_sql(thd, &lip); if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) || (old_lex->sql_command == SQLCOM_SHOW_CREATE)) @@ -1048,7 +1047,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, thd->variables.character_set_client= save_cs; thd->variables.sql_mode= save_mode; } - if (!res && !thd->is_fatal_error) + if (!res) { TABLE_LIST *view_tables= lex->query_tables; TABLE_LIST *view_tables_tail= 0; |