00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <drizzled/show.h>
00023 #include <drizzled/lock.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/statement/replace_select.h>
00026 #include <drizzled/select_insert.h>
00027 #include <drizzled/sql_lex.h>
00028 #include <drizzled/open_tables_state.h>
00029
00030 namespace drizzled {
00031
00032 bool statement::ReplaceSelect::execute()
00033 {
00034 TableList *first_table= (TableList *) lex().select_lex.table_list.first;
00035 TableList *all_tables= lex().query_tables;
00036 assert(first_table == all_tables && first_table != 0);
00037 Select_Lex *select_lex= &lex().select_lex;
00038
00039 if (insert_precheck(&session(), all_tables))
00040 {
00041 return true;
00042 }
00043
00044
00045 select_lex->options|= SELECT_NO_UNLOCK;
00046
00047 lex().unit.set_limit(select_lex);
00048
00049 if (session().wait_if_global_read_lock(false, true))
00050 {
00051 return true;
00052 }
00053
00054 bool res;
00055 if (! (res= session().openTablesLock(all_tables)))
00056 {
00057
00058 TableList *second_table= first_table->next_local;
00059 select_lex->table_list.first= (unsigned char*) second_table;
00060 select_lex->context.table_list= select_lex->context.first_name_resolution_table= second_table;
00061 res= insert_select_prepare(&session());
00062 if (not res)
00063 {
00064 select_insert sel_result(first_table, first_table->table, &lex().field_list, &lex().update_list,&lex().value_list, lex().duplicates, lex().ignore);
00065 res= handle_select(&session(), &lex(), &sel_result, OPTION_SETUP_TABLES_DONE);
00066
00067
00068
00069
00070
00071
00072 if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && session().open_tables.lock)
00073 {
00074
00075 TableList *save_table= first_table->next_local;
00076 first_table->next_local= 0;
00077 first_table->next_local= save_table;
00078 }
00079 }
00080
00081 select_lex->table_list.first= (unsigned char*) first_table;
00082 }
00083
00084
00085
00086
00087
00088 session().startWaitingGlobalReadLock();
00089
00090 return res;
00091 }
00092
00093 }
00094