1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
4
* Copyright (C) 2009 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
30
30
bool statement::ReplaceSelect::execute()
32
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
33
TableList *all_tables= getSession()->lex->query_tables;
32
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
33
TableList *all_tables= session->lex->query_tables;
34
34
assert(first_table == all_tables && first_table != 0);
35
Select_Lex *select_lex= &getSession()->lex->select_lex;
36
Select_Lex_Unit *unit= &getSession()->lex->unit;
35
Select_Lex *select_lex= &session->lex->select_lex;
36
Select_Lex_Unit *unit= &session->lex->unit;
37
37
select_result *sel_result= NULL;
39
bool need_start_waiting= false;
40
if (insert_precheck(getSession(), all_tables))
41
if (insert_precheck(session, all_tables))
48
49
unit->set_limit(select_lex);
50
if (getSession()->wait_if_global_read_lock(false, true))
51
if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
55
if (! (res= getSession()->openTablesLock(all_tables)))
56
if (! (res= session->openTablesLock(all_tables)))
57
58
/* Skip first table, which is the table we are inserting in */
58
59
TableList *second_table= first_table->next_local;
59
60
select_lex->table_list.first= (unsigned char*) second_table;
60
61
select_lex->context.table_list=
61
62
select_lex->context.first_name_resolution_table= second_table;
62
res= insert_select_prepare(getSession());
63
res= mysql_insert_select_prepare(session);
63
64
if (! res && (sel_result= new select_insert(first_table,
64
65
first_table->table,
65
&getSession()->lex->field_list,
66
&getSession()->lex->update_list,
67
&getSession()->lex->value_list,
68
getSession()->lex->duplicates,
69
getSession()->lex->ignore)))
66
&session->lex->field_list,
67
&session->lex->update_list,
68
&session->lex->value_list,
69
session->lex->duplicates,
70
session->lex->ignore)))
71
res= handle_select(getSession(),
72
res= handle_select(session,
74
75
OPTION_SETUP_TABLES_DONE);
76
77
Invalidate the table in the query cache if something changed
96
97
Release the protection against the global read lock and wake
97
98
everyone, who might want to set a global read lock.
99
getSession()->startWaitingGlobalReadLock();
100
start_waiting_global_read_lock(session);