~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2011-02-08 02:06:04 UTC
  • mto: (2152.2.1 alter-table)
  • mto: This revision was merged to the branch mainline in revision 2154.
  • Revision ID: brian@tangent.org-20110208020604-p23mwd9yvamuwbwu
Merge in column varchar build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Insert of records */
18
18
 
19
 
#include <config.h>
 
19
#include "config.h"
20
20
#include <cstdio>
21
21
#include <drizzled/sql_select.h>
22
22
#include <drizzled/show.h>
27
27
#include <drizzled/sql_load.h>
28
28
#include <drizzled/field/epoch.h>
29
29
#include <drizzled/lock.h>
30
 
#include <drizzled/sql_table.h>
31
 
#include <drizzled/pthread_globals.h>
32
 
#include <drizzled/transaction_services.h>
33
 
#include <drizzled/plugin/transactional_storage_engine.h>
34
 
#include <drizzled/select_insert.h>
35
 
#include <drizzled/select_create.h>
 
30
#include "drizzled/sql_table.h"
 
31
#include "drizzled/pthread_globals.h"
 
32
#include "drizzled/transaction_services.h"
 
33
#include "drizzled/plugin/transactional_storage_engine.h"
36
34
 
37
 
#include <drizzled/table/shell.h>
 
35
#include "drizzled/table/shell.h"
38
36
 
39
37
namespace drizzled
40
38
{
87
85
  }
88
86
  else
89
87
  {                                             // Part field list
90
 
    Select_Lex *select_lex= &session->getLex()->select_lex;
 
88
    Select_Lex *select_lex= &session->lex->select_lex;
91
89
    Name_resolution_context *context= &select_lex->context;
92
90
    Name_resolution_context_state ctx_state;
93
91
    int res;
245
243
  uint64_t id;
246
244
  CopyInfo info;
247
245
  Table *table= 0;
248
 
  List<List_item>::iterator its(values_list.begin());
 
246
  List_iterator_fast<List_item> its(values_list);
249
247
  List_item *values;
250
248
  Name_resolution_context *context;
251
249
  Name_resolution_context_state ctx_state;
282
280
    if (table != NULL)
283
281
      table->cursor->ha_release_auto_increment();
284
282
    if (!joins_freed)
285
 
      free_underlaid_joins(session, &session->getLex()->select_lex);
 
283
      free_underlaid_joins(session, &session->lex->select_lex);
286
284
    session->setAbortOnWarning(false);
287
285
    DRIZZLE_INSERT_DONE(1, 0);
288
286
    return true;
291
289
  /* mysql_prepare_insert set table_list->table if it was not set */
292
290
  table= table_list->table;
293
291
 
294
 
  context= &session->getLex()->select_lex.context;
 
292
  context= &session->lex->select_lex.context;
295
293
  /*
296
294
    These three asserts test the hypothesis that the resetting of the name
297
295
    resolution context below is not necessary at all since the list of local
321
319
      if (table != NULL)
322
320
        table->cursor->ha_release_auto_increment();
323
321
      if (!joins_freed)
324
 
        free_underlaid_joins(session, &session->getLex()->select_lex);
 
322
        free_underlaid_joins(session, &session->lex->select_lex);
325
323
      session->setAbortOnWarning(false);
326
324
      DRIZZLE_INSERT_DONE(1, 0);
327
325
 
332
330
      if (table != NULL)
333
331
        table->cursor->ha_release_auto_increment();
334
332
      if (!joins_freed)
335
 
        free_underlaid_joins(session, &session->getLex()->select_lex);
 
333
        free_underlaid_joins(session, &session->lex->select_lex);
336
334
      session->setAbortOnWarning(false);
337
335
      DRIZZLE_INSERT_DONE(1, 0);
338
336
      return true;
339
337
    }
340
338
  }
341
 
  its= values_list.begin();
 
339
  its.rewind ();
342
340
 
343
341
  /* Restore the current context. */
344
342
  ctx_state.restore_state(context, table_list);
424
422
    session->row_count++;
425
423
  }
426
424
 
427
 
  free_underlaid_joins(session, &session->getLex()->select_lex);
 
425
  free_underlaid_joins(session, &session->lex->select_lex);
428
426
  joins_freed= true;
429
427
 
430
428
  /*
484
482
    if (table != NULL)
485
483
      table->cursor->ha_release_auto_increment();
486
484
    if (!joins_freed)
487
 
      free_underlaid_joins(session, &session->getLex()->select_lex);
 
485
      free_underlaid_joins(session, &session->lex->select_lex);
488
486
    session->setAbortOnWarning(false);
489
487
    DRIZZLE_INSERT_DONE(1, 0);
490
488
    return true;
547
545
     than INSERT.
548
546
  */
549
547
 
550
 
  if (setup_tables_and_check_access(session, &session->getLex()->select_lex.context,
551
 
                                    &session->getLex()->select_lex.top_join_list,
 
548
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
 
549
                                    &session->lex->select_lex.top_join_list,
552
550
                                    table_list,
553
 
                                    &session->getLex()->select_lex.leaf_tables,
 
551
                                    &session->lex->select_lex.leaf_tables,
554
552
                                    select_insert))
555
553
    return(true);
556
554
 
597
595
                          bool select_insert,
598
596
                          bool check_fields, bool abort_on_warning)
599
597
{
600
 
  Select_Lex *select_lex= &session->getLex()->select_lex;
 
598
  Select_Lex *select_lex= &session->lex->select_lex;
601
599
  Name_resolution_context *context= &select_lex->context;
602
600
  Name_resolution_context_state ctx_state;
603
601
  bool insert_into_view= (0 != 0);
964
962
err:
965
963
  info->last_errno= error;
966
964
  /* current_select is NULL if this is a delayed insert */
967
 
  if (session->getLex()->current_select)
968
 
    session->getLex()->current_select->no_error= 0;        // Give error
 
965
  if (session->lex->current_select)
 
966
    session->lex->current_select->no_error= 0;        // Give error
969
967
  table->print_error(error,MYF(0));
970
968
 
971
969
before_err:
1040
1038
 
1041
1039
bool insert_select_prepare(Session *session)
1042
1040
{
1043
 
  LEX *lex= session->getLex();
 
1041
  LEX *lex= session->lex;
1044
1042
  Select_Lex *select_lex= &lex->select_lex;
1045
1043
 
1046
1044
  /*
1087
1085
int
1088
1086
select_insert::prepare(List<Item> &values, Select_Lex_Unit *u)
1089
1087
{
 
1088
  LEX *lex= session->lex;
1090
1089
  int res;
1091
1090
  table_map map= 0;
1092
 
  Select_Lex *lex_current_select_save= session->getLex()->current_select;
 
1091
  Select_Lex *lex_current_select_save= lex->current_select;
1093
1092
 
1094
1093
 
1095
1094
  unit= u;
1099
1098
    select, LEX::current_select should point to the first select while
1100
1099
    we are fixing fields from insert list.
1101
1100
  */
1102
 
  session->getLex()->current_select= &session->getLex()->select_lex;
 
1101
  lex->current_select= &lex->select_lex;
1103
1102
  res= check_insert_fields(session, table_list, *fields, values,
1104
1103
                           !insert_into_view, &map) ||
1105
1104
       setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0);
1115
1114
 
1116
1115
  if (info.handle_duplicates == DUP_UPDATE && !res)
1117
1116
  {
1118
 
    Name_resolution_context *context= &session->getLex()->select_lex.context;
 
1117
    Name_resolution_context *context= &lex->select_lex.context;
1119
1118
    Name_resolution_context_state ctx_state;
1120
1119
 
1121
1120
    /* Save the state of the current name resolution context. */
1133
1132
      We use next_name_resolution_table descructively, so check it first (views?)
1134
1133
    */
1135
1134
    assert (!table_list->next_name_resolution_table);
1136
 
    if (session->getLex()->select_lex.group_list.elements == 0 and
1137
 
        not session->getLex()->select_lex.with_sum_func)
 
1135
    if (lex->select_lex.group_list.elements == 0 &&
 
1136
        !lex->select_lex.with_sum_func)
1138
1137
      /*
1139
1138
        We must make a single context out of the two separate name resolution contexts :
1140
1139
        the INSERT table and the tables in the SELECT part of INSERT ... SELECT.
1153
1152
        order to get correct values from those fields when the select
1154
1153
        employs a temporary table.
1155
1154
      */
1156
 
      List<Item>::iterator li(info.update_values->begin());
 
1155
      List_iterator<Item> li(*info.update_values);
1157
1156
      Item *item;
1158
1157
 
1159
1158
      while ((item= li++))
1160
1159
      {
1161
1160
        item->transform(&Item::update_value_transformer,
1162
 
                        (unsigned char*)session->getLex()->current_select);
 
1161
                        (unsigned char*)lex->current_select);
1163
1162
      }
1164
1163
    }
1165
1164
 
1167
1166
    ctx_state.restore_state(context, table_list);
1168
1167
  }
1169
1168
 
1170
 
  session->getLex()->current_select= lex_current_select_save;
 
1169
  lex->current_select= lex_current_select_save;
1171
1170
  if (res)
1172
1171
    return(1);
1173
1172
  /*
1183
1182
  if (unique_table(table_list, table_list->next_global))
1184
1183
  {
1185
1184
    /* Using same table for INSERT and SELECT */
1186
 
    session->getLex()->current_select->options|= OPTION_BUFFER_RESULT;
1187
 
    session->getLex()->current_select->join->select_options|= OPTION_BUFFER_RESULT;
 
1185
    lex->current_select->options|= OPTION_BUFFER_RESULT;
 
1186
    lex->current_select->join->select_options|= OPTION_BUFFER_RESULT;
1188
1187
  }
1189
 
  else if (not (session->getLex()->current_select->options & OPTION_BUFFER_RESULT))
 
1188
  else if (!(lex->current_select->options & OPTION_BUFFER_RESULT))
1190
1189
  {
1191
1190
    /*
1192
1191
      We must not yet prepare the result table if it is the same as one of the
1239
1238
 
1240
1239
int select_insert::prepare2(void)
1241
1240
{
1242
 
  if (session->getLex()->current_select->options & OPTION_BUFFER_RESULT)
 
1241
 
 
1242
  if (session->lex->current_select->options & OPTION_BUFFER_RESULT)
1243
1243
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
1244
 
 
1245
1244
  return(0);
1246
1245
}
1247
1246
 
1270
1269
bool select_insert::send_data(List<Item> &values)
1271
1270
{
1272
1271
 
1273
 
  bool error= false;
 
1272
  bool error=0;
1274
1273
 
1275
1274
  if (unit->offset_limit_cnt)
1276
1275
  {                                             // using limit offset,count
1493
1492
  TableShare share(message::Table::INTERNAL);
1494
1493
  uint32_t select_field_count= items->elements;
1495
1494
  /* Add selected items to field list */
1496
 
  List<Item>::iterator it(items->begin());
 
1495
  List_iterator_fast<Item> it(*items);
1497
1496
  Item *item;
1498
1497
  Field *tmp_field;
1499
1498
 
1644
1643
 
1645
1644
    if (not create_info->table_existed)
1646
1645
      session->drop_open_table(table, identifier);
1647
 
 
1648
1646
    return NULL;
1649
1647
  }
1650
1648