~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/insert_select.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
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
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/statement/insert_select.h>
 
27
#include <drizzled/select_insert.h>
27
28
 
28
29
namespace drizzled
29
30
{
30
31
 
31
32
bool statement::InsertSelect::execute()
32
33
{
33
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
 
  TableList *all_tables= session->lex->query_tables;
 
34
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
 
35
  TableList *all_tables= getSession()->getLex()->query_tables;
35
36
  assert(first_table == all_tables && first_table != 0);
36
 
  Select_Lex *select_lex= &session->lex->select_lex;
37
 
  Select_Lex_Unit *unit= &session->lex->unit;
 
37
  Select_Lex *select_lex= &getSession()->getLex()->select_lex;
 
38
  Select_Lex_Unit *unit= &getSession()->getLex()->unit;
38
39
  select_result *sel_result= NULL;
39
40
  bool res= false;
40
41
  bool need_start_waiting= false;
41
42
 
42
 
  if (insert_precheck(session, all_tables))
 
43
  if (insert_precheck(getSession(), all_tables))
43
44
  {
44
45
    return true;
45
46
  }
49
50
 
50
51
  unit->set_limit(select_lex);
51
52
 
52
 
  if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
 
53
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
53
54
  {
54
55
    return true;
55
56
  }
56
57
 
57
 
  if (! (res= session->openTablesLock(all_tables)))
 
58
  if (! (res= getSession()->openTablesLock(all_tables)))
58
59
  {
59
 
    DRIZZLE_INSERT_SELECT_START(session->query.c_str());
 
60
    DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
60
61
    /* Skip first table, which is the table we are inserting in */
61
62
    TableList *second_table= first_table->next_local;
62
63
    select_lex->table_list.first= (unsigned char*) second_table;
63
64
    select_lex->context.table_list=
64
65
      select_lex->context.first_name_resolution_table= second_table;
65
 
    res= mysql_insert_select_prepare(session);
 
66
    res= insert_select_prepare(getSession());
66
67
    if (! res && (sel_result= new select_insert(first_table,
67
68
                                                first_table->table,
68
 
                                                &session->lex->field_list,
69
 
                                                &session->lex->update_list,
70
 
                                                &session->lex->value_list,
71
 
                                                session->lex->duplicates,
72
 
                                                session->lex->ignore)))
 
69
                                                &getSession()->getLex()->field_list,
 
70
                                                &getSession()->getLex()->update_list,
 
71
                                                &getSession()->getLex()->value_list,
 
72
                                                getSession()->getLex()->duplicates,
 
73
                                                getSession()->getLex()->ignore)))
73
74
    {
74
 
      res= handle_select(session, 
75
 
                         session->lex, 
 
75
      res= handle_select(getSession(), 
 
76
                         getSession()->getLex(), 
76
77
                         sel_result, 
77
78
                         OPTION_SETUP_TABLES_DONE);
78
79
 
82
83
         TODO: this is a workaround. right way will be move invalidating in
83
84
         the unlock procedure.
84
85
       */
85
 
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
86
 
          session->lock)
 
86
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
87
87
      {
88
88
        /* INSERT ... SELECT should invalidate only the very first table */
89
89
        TableList *save_table= first_table->next_local;
100
100
     Release the protection against the global read lock and wake
101
101
     everyone, who might want to set a global read lock.
102
102
   */
103
 
  start_waiting_global_read_lock(session);
 
103
  getSession()->startWaitingGlobalReadLock();
104
104
 
105
105
  return res;
106
106
}