~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/insert_select.cc

  • Committer: Brian Aker
  • Date: 2011-01-22 18:52:16 UTC
  • mfrom: (2098.4.1 catalogs)
  • Revision ID: brian@tangent.org-20110122185216-18and6vncipd7x72
Session encapsulation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
bool statement::InsertSelect::execute()
32
32
{
33
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
 
  TableList *all_tables= session->lex->query_tables;
 
33
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
 
34
  TableList *all_tables= getSession()->lex->query_tables;
35
35
  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;
 
36
  Select_Lex *select_lex= &getSession()->lex->select_lex;
 
37
  Select_Lex_Unit *unit= &getSession()->lex->unit;
38
38
  select_result *sel_result= NULL;
39
39
  bool res= false;
40
40
  bool need_start_waiting= false;
41
41
 
42
 
  if (insert_precheck(session, all_tables))
 
42
  if (insert_precheck(getSession(), all_tables))
43
43
  {
44
44
    return true;
45
45
  }
49
49
 
50
50
  unit->set_limit(select_lex);
51
51
 
52
 
  if (! (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
 
52
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
53
53
  {
54
54
    return true;
55
55
  }
56
56
 
57
 
  if (! (res= session->openTablesLock(all_tables)))
 
57
  if (! (res= getSession()->openTablesLock(all_tables)))
58
58
  {
59
 
    DRIZZLE_INSERT_SELECT_START(session->getQueryString()->c_str());
 
59
    DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
60
60
    /* Skip first table, which is the table we are inserting in */
61
61
    TableList *second_table= first_table->next_local;
62
62
    select_lex->table_list.first= (unsigned char*) second_table;
63
63
    select_lex->context.table_list=
64
64
      select_lex->context.first_name_resolution_table= second_table;
65
 
    res= insert_select_prepare(session);
 
65
    res= insert_select_prepare(getSession());
66
66
    if (! res && (sel_result= new select_insert(first_table,
67
67
                                                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)))
 
68
                                                &getSession()->lex->field_list,
 
69
                                                &getSession()->lex->update_list,
 
70
                                                &getSession()->lex->value_list,
 
71
                                                getSession()->lex->duplicates,
 
72
                                                getSession()->lex->ignore)))
73
73
    {
74
 
      res= handle_select(session, 
75
 
                         session->lex, 
 
74
      res= handle_select(getSession(), 
 
75
                         getSession()->lex, 
76
76
                         sel_result, 
77
77
                         OPTION_SETUP_TABLES_DONE);
78
78
 
82
82
         TODO: this is a workaround. right way will be move invalidating in
83
83
         the unlock procedure.
84
84
       */
85
 
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
86
 
          session->lock)
 
85
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
87
86
      {
88
87
        /* INSERT ... SELECT should invalidate only the very first table */
89
88
        TableList *save_table= first_table->next_local;
100
99
     Release the protection against the global read lock and wake
101
100
     everyone, who might want to set a global read lock.
102
101
   */
103
 
  session->startWaitingGlobalReadLock();
 
102
  getSession()->startWaitingGlobalReadLock();
104
103
 
105
104
  return res;
106
105
}