~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

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>
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/sql_base.h>
27
27
#include <drizzled/sql_load.h>
28
 
#include <drizzled/field/timestamp.h>
 
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
 
 
35
 
#include "drizzled/table/shell.h"
36
 
 
37
 
namespace drizzled
38
 
{
 
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>
 
36
#include <drizzled/table/shell.h>
 
37
#include <drizzled/alter_info.h>
 
38
#include <drizzled/sql_parse.h>
 
39
#include <drizzled/sql_lex.h>
 
40
#include <drizzled/statistics_variables.h>
 
41
#include <drizzled/session/transactions.h>
 
42
 
 
43
namespace drizzled {
39
44
 
40
45
extern plugin::StorageEngine *heap_engine;
41
46
extern plugin::StorageEngine *myisam_engine;
68
73
{
69
74
  Table *table= table_list->table;
70
75
 
71
 
  if (fields.elements == 0 && values.elements != 0)
 
76
  if (fields.size() == 0 && values.size() != 0)
72
77
  {
73
 
    if (values.elements != table->getShare()->sizeFields())
 
78
    if (values.size() != table->getShare()->sizeFields())
74
79
    {
75
80
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
76
81
      return -1;
85
90
  }
86
91
  else
87
92
  {                                             // Part field list
88
 
    Select_Lex *select_lex= &session->lex->select_lex;
 
93
    Select_Lex *select_lex= &session->lex().select_lex;
89
94
    Name_resolution_context *context= &select_lex->context;
90
95
    Name_resolution_context_state ctx_state;
91
96
    int res;
92
97
 
93
 
    if (fields.elements != values.elements)
 
98
    if (fields.size() != values.size())
94
99
    {
95
100
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
96
101
      return -1;
227
232
  end of dispatch_command().
228
233
*/
229
234
 
230
 
bool mysql_insert(Session *session,TableList *table_list,
 
235
bool insert_query(Session *session,TableList *table_list,
231
236
                  List<Item> &fields,
232
237
                  List<List_item> &values_list,
233
238
                  List<Item> &update_fields,
243
248
  uint64_t id;
244
249
  CopyInfo info;
245
250
  Table *table= 0;
246
 
  List_iterator_fast<List_item> its(values_list);
 
251
  List<List_item>::iterator its(values_list.begin());
247
252
  List_item *values;
248
253
  Name_resolution_context *context;
249
254
  Name_resolution_context_state ctx_state;
250
 
  thr_lock_type lock_type;
251
255
  Item *unused_conds= 0;
252
256
 
253
257
 
256
260
    the current connection mode or table operation.
257
261
  */
258
262
  upgrade_lock_type(session, &table_list->lock_type, duplic,
259
 
                    values_list.elements > 1);
 
263
                    values_list.size() > 1);
260
264
 
261
265
  if (session->openTablesLock(table_list))
262
266
  {
264
268
    return true;
265
269
  }
266
270
 
267
 
  lock_type= table_list->lock_type;
268
 
 
269
271
  session->set_proc_info("init");
270
272
  session->used_tables=0;
271
273
  values= its++;
272
 
  value_count= values->elements;
 
274
  value_count= values->size();
273
275
 
274
 
  if (mysql_prepare_insert(session, table_list, table, fields, values,
 
276
  if (prepare_insert(session, table_list, table, fields, values,
275
277
                           update_fields, update_values, duplic, &unused_conds,
276
278
                           false,
277
 
                           (fields.elements || !value_count ||
 
279
                           (fields.size() || !value_count ||
278
280
                            (0) != 0), !ignore))
279
281
  {
280
282
    if (table != NULL)
281
283
      table->cursor->ha_release_auto_increment();
282
284
    if (!joins_freed)
283
 
      free_underlaid_joins(session, &session->lex->select_lex);
284
 
    session->abort_on_warning= 0;
 
285
      free_underlaid_joins(session, &session->lex().select_lex);
 
286
    session->setAbortOnWarning(false);
285
287
    DRIZZLE_INSERT_DONE(1, 0);
286
288
    return true;
287
289
  }
289
291
  /* mysql_prepare_insert set table_list->table if it was not set */
290
292
  table= table_list->table;
291
293
 
292
 
  context= &session->lex->select_lex.context;
 
294
  context= &session->lex().select_lex.context;
293
295
  /*
294
296
    These three asserts test the hypothesis that the resetting of the name
295
297
    resolution context below is not necessary at all since the list of local
312
314
  while ((values= its++))
313
315
  {
314
316
    counter++;
315
 
    if (values->elements != value_count)
 
317
    if (values->size() != value_count)
316
318
    {
317
319
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
318
320
 
319
321
      if (table != NULL)
320
322
        table->cursor->ha_release_auto_increment();
321
323
      if (!joins_freed)
322
 
        free_underlaid_joins(session, &session->lex->select_lex);
323
 
      session->abort_on_warning= 0;
 
324
        free_underlaid_joins(session, &session->lex().select_lex);
 
325
      session->setAbortOnWarning(false);
324
326
      DRIZZLE_INSERT_DONE(1, 0);
325
327
 
326
328
      return true;
330
332
      if (table != NULL)
331
333
        table->cursor->ha_release_auto_increment();
332
334
      if (!joins_freed)
333
 
        free_underlaid_joins(session, &session->lex->select_lex);
334
 
      session->abort_on_warning= 0;
 
335
        free_underlaid_joins(session, &session->lex().select_lex);
 
336
      session->setAbortOnWarning(false);
335
337
      DRIZZLE_INSERT_DONE(1, 0);
336
338
      return true;
337
339
    }
338
340
  }
339
 
  its.rewind ();
 
341
  its= values_list.begin();
340
342
 
341
343
  /* Restore the current context. */
342
344
  ctx_state.restore_state(context, table_list);
368
370
  {
369
371
    if (duplic != DUP_ERROR || ignore)
370
372
      table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
371
 
    table->cursor->ha_start_bulk_insert(values_list.elements);
 
373
    table->cursor->ha_start_bulk_insert(values_list.size());
372
374
  }
373
375
 
374
376
 
375
 
  session->abort_on_warning= !ignore;
 
377
  session->setAbortOnWarning(not ignore);
376
378
 
377
379
  table->mark_columns_needed_for_insert();
378
380
 
379
381
  while ((values= its++))
380
382
  {
381
 
    if (fields.elements || !value_count)
 
383
    if (fields.size() || !value_count)
382
384
    {
383
385
      table->restoreRecordAsDefault();  // Get empty record
384
386
      if (fill_record(session, fields, *values))
385
387
      {
386
 
        if (values_list.elements != 1 && ! session->is_error())
 
388
        if (values_list.size() != 1 && ! session->is_error())
387
389
        {
388
390
          info.records++;
389
391
          continue;
403
405
 
404
406
      if (fill_record(session, table->getFields(), *values))
405
407
      {
406
 
        if (values_list.elements != 1 && ! session->is_error())
 
408
        if (values_list.size() != 1 && ! session->is_error())
407
409
        {
408
410
          info.records++;
409
411
          continue;
422
424
    session->row_count++;
423
425
  }
424
426
 
425
 
  free_underlaid_joins(session, &session->lex->select_lex);
 
427
  free_underlaid_joins(session, &session->lex().select_lex);
426
428
  joins_freed= true;
427
429
 
428
430
  /*
482
484
    if (table != NULL)
483
485
      table->cursor->ha_release_auto_increment();
484
486
    if (!joins_freed)
485
 
      free_underlaid_joins(session, &session->lex->select_lex);
486
 
    session->abort_on_warning= 0;
 
487
      free_underlaid_joins(session, &session->lex().select_lex);
 
488
    session->setAbortOnWarning(false);
487
489
    DRIZZLE_INSERT_DONE(1, 0);
488
490
    return true;
489
491
  }
490
492
 
491
 
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
 
493
  if (values_list.size() == 1 && (!(session->options & OPTION_WARNINGS) ||
492
494
                                    !session->cuted_fields))
493
495
  {
494
496
    session->row_count_func= info.copied + info.deleted + info.updated;
495
 
    session->my_ok((ulong) session->row_count_func,
 
497
    session->my_ok((ulong) session->rowCount(),
496
498
                   info.copied + info.deleted + info.touched, id);
497
499
  }
498
500
  else
505
507
      snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
506
508
              (ulong) (info.deleted + info.updated), (ulong) session->cuted_fields);
507
509
    session->row_count_func= info.copied + info.deleted + info.updated;
508
 
    session->my_ok((ulong) session->row_count_func,
 
510
    session->my_ok((ulong) session->rowCount(),
509
511
                   info.copied + info.deleted + info.touched, id, buff);
510
512
  }
511
 
  session->status_var.inserted_row_count+= session->row_count_func;
512
 
  session->abort_on_warning= 0;
513
 
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
 
513
  session->status_var.inserted_row_count+= session->rowCount();
 
514
  session->setAbortOnWarning(false);
 
515
  DRIZZLE_INSERT_DONE(0, session->rowCount());
514
516
 
515
517
  return false;
516
518
}
520
522
  Check if table can be updated
521
523
 
522
524
  SYNOPSIS
523
 
     mysql_prepare_insert_check_table()
 
525
     prepare_insert_check_table()
524
526
     session            Thread handle
525
527
     table_list         Table list
526
528
     fields             List of fields to be updated
532
534
     true  ERROR
533
535
*/
534
536
 
535
 
static bool mysql_prepare_insert_check_table(Session *session, TableList *table_list,
 
537
static bool prepare_insert_check_table(Session *session, TableList *table_list,
536
538
                                             List<Item> &,
537
539
                                             bool select_insert)
538
540
{
545
547
     than INSERT.
546
548
  */
547
549
 
548
 
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
549
 
                                    &session->lex->select_lex.top_join_list,
 
550
  if (setup_tables_and_check_access(session, &session->lex().select_lex.context,
 
551
                                    &session->lex().select_lex.top_join_list,
550
552
                                    table_list,
551
 
                                    &session->lex->select_lex.leaf_tables,
 
553
                                    &session->lex().select_lex.leaf_tables,
552
554
                                    select_insert))
553
555
    return(true);
554
556
 
560
562
  Prepare items in INSERT statement
561
563
 
562
564
  SYNOPSIS
563
 
    mysql_prepare_insert()
 
565
    prepare_insert()
564
566
    session                     Thread handler
565
567
    table_list          Global/local table list
566
568
    table               Table to insert into (can be NULL if table should
587
589
    true  error
588
590
*/
589
591
 
590
 
bool mysql_prepare_insert(Session *session, TableList *table_list,
 
592
bool prepare_insert(Session *session, TableList *table_list,
591
593
                          Table *table, List<Item> &fields, List_item *values,
592
594
                          List<Item> &update_fields, List<Item> &update_values,
593
595
                          enum_duplicates duplic,
595
597
                          bool select_insert,
596
598
                          bool check_fields, bool abort_on_warning)
597
599
{
598
 
  Select_Lex *select_lex= &session->lex->select_lex;
 
600
  Select_Lex *select_lex= &session->lex().select_lex;
599
601
  Name_resolution_context *context= &select_lex->context;
600
602
  Name_resolution_context_state ctx_state;
601
603
  bool insert_into_view= (0 != 0);
610
612
    inserting (for INSERT ... SELECT this is done by changing table_list,
611
613
    because INSERT ... SELECT share Select_Lex it with SELECT.
612
614
  */
613
 
  if (!select_insert)
 
615
  if (not select_insert)
614
616
  {
615
617
    for (Select_Lex_Unit *un= select_lex->first_inner_unit();
616
618
         un;
632
634
      return(true);
633
635
  }
634
636
 
635
 
  if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
 
637
  if (prepare_insert_check_table(session, table_list, fields, select_insert))
636
638
    return(true);
637
639
 
638
640
 
658
660
 
659
661
    if (!res && check_fields)
660
662
    {
661
 
      bool saved_abort_on_warning= session->abort_on_warning;
662
 
      session->abort_on_warning= abort_on_warning;
 
663
      bool saved_abort_on_warning= session->abortOnWarning();
 
664
 
 
665
      session->setAbortOnWarning(abort_on_warning);
663
666
      res= check_that_all_fields_are_given_values(session,
664
667
                                                  table ? table :
665
668
                                                  context->table_list->table,
666
669
                                                  context->table_list);
667
 
      session->abort_on_warning= saved_abort_on_warning;
 
670
      session->setAbortOnWarning(saved_abort_on_warning);
668
671
    }
669
672
 
670
673
    if (!res && duplic == DUP_UPDATE)
675
678
    /* Restore the current context. */
676
679
    ctx_state.restore_state(context, table_list);
677
680
 
678
 
    if (!res)
 
681
    if (not res)
679
682
      res= setup_fields(session, 0, update_values, MARK_COLUMNS_READ, 0, 0);
680
683
  }
681
684
 
682
685
  if (res)
683
686
    return(res);
684
687
 
685
 
  if (!table)
 
688
  if (not table)
686
689
    table= table_list->table;
687
690
 
688
 
  if (!select_insert)
 
691
  if (not select_insert)
689
692
  {
690
693
    TableList *duplicate;
691
694
    if ((duplicate= unique_table(table_list, table_list->next_global, true)))
695
698
      return true;
696
699
    }
697
700
  }
 
701
 
698
702
  if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
699
703
    table->prepare_for_position();
700
704
 
834
838
        assert(table->insert_values.size());
835
839
        table->storeRecordAsInsert();
836
840
        table->restoreRecord();
837
 
        assert(info->update_fields->elements ==
838
 
                    info->update_values->elements);
 
841
        assert(info->update_fields->size() ==
 
842
                    info->update_values->size());
839
843
        if (fill_record(session, *info->update_fields,
840
844
                                                 *info->update_values,
841
845
                                                 info->ignore))
868
872
          /*
869
873
            If ON DUP KEY UPDATE updates a row instead of inserting one, it's
870
874
            like a regular UPDATE statement: it should not affect the value of a
871
 
            next SELECT LAST_INSERT_ID() or mysql_insert_id().
 
875
            next SELECT LAST_INSERT_ID() or insert_id().
872
876
            Except if LAST_INSERT_ID(#) was in the INSERT query, which is
873
877
            handled separately by Session::arg_of_last_insert_id_function.
874
878
          */
960
964
err:
961
965
  info->last_errno= error;
962
966
  /* current_select is NULL if this is a delayed insert */
963
 
  if (session->lex->current_select)
964
 
    session->lex->current_select->no_error= 0;        // Give error
 
967
  if (session->lex().current_select)
 
968
    session->lex().current_select->no_error= 0;        // Give error
965
969
  table->print_error(error,MYF(0));
966
970
 
967
971
before_err:
1000
1004
    {
1001
1005
      /*
1002
1006
       * However, if an actual NULL value was specified
1003
 
       * for the field and the field is a NOT NULL field, 
 
1007
       * for the field and the field is a NOT NULL field,
1004
1008
       * throw ER_BAD_NULL_ERROR.
1005
1009
       *
1006
1010
       * Per the SQL standard, inserting NULL into a NOT NULL
1014
1018
      }
1015
1019
    }
1016
1020
  }
1017
 
  return session->abort_on_warning ? err : 0;
 
1021
  return session->abortOnWarning() ? err : 0;
1018
1022
}
1019
1023
 
1020
1024
/***************************************************************************
1026
1030
  make insert specific preparation and checks after opening tables
1027
1031
 
1028
1032
  SYNOPSIS
1029
 
    mysql_insert_select_prepare()
 
1033
    insert_select_prepare()
1030
1034
    session         thread handler
1031
1035
 
1032
1036
  RETURN
1034
1038
    true  Error
1035
1039
*/
1036
1040
 
1037
 
bool mysql_insert_select_prepare(Session *session)
 
1041
bool insert_select_prepare(Session *session)
1038
1042
{
1039
 
  LEX *lex= session->lex;
 
1043
  LEX *lex= &session->lex();
1040
1044
  Select_Lex *select_lex= &lex->select_lex;
1041
1045
 
1042
1046
  /*
1044
1048
    clause if table is VIEW
1045
1049
  */
1046
1050
 
1047
 
  if (mysql_prepare_insert(session, lex->query_tables,
 
1051
  if (prepare_insert(session, lex->query_tables,
1048
1052
                           lex->query_tables->table, lex->field_list, 0,
1049
1053
                           lex->update_list, lex->value_list,
1050
1054
                           lex->duplicates,
1083
1087
int
1084
1088
select_insert::prepare(List<Item> &values, Select_Lex_Unit *u)
1085
1089
{
1086
 
  LEX *lex= session->lex;
1087
1090
  int res;
1088
1091
  table_map map= 0;
1089
 
  Select_Lex *lex_current_select_save= lex->current_select;
 
1092
  Select_Lex *lex_current_select_save= session->lex().current_select;
1090
1093
 
1091
1094
 
1092
1095
  unit= u;
1096
1099
    select, LEX::current_select should point to the first select while
1097
1100
    we are fixing fields from insert list.
1098
1101
  */
1099
 
  lex->current_select= &lex->select_lex;
 
1102
  session->lex().current_select= &session->lex().select_lex;
1100
1103
  res= check_insert_fields(session, table_list, *fields, values,
1101
1104
                           !insert_into_view, &map) ||
1102
1105
       setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0);
1103
1106
 
1104
 
  if (!res && fields->elements)
 
1107
  if (!res && fields->size())
1105
1108
  {
1106
 
    bool saved_abort_on_warning= session->abort_on_warning;
1107
 
    session->abort_on_warning= !info.ignore;
 
1109
    bool saved_abort_on_warning= session->abortOnWarning();
 
1110
    session->setAbortOnWarning(not info.ignore);
1108
1111
    res= check_that_all_fields_are_given_values(session, table_list->table,
1109
1112
                                                table_list);
1110
 
    session->abort_on_warning= saved_abort_on_warning;
 
1113
    session->setAbortOnWarning(saved_abort_on_warning);
1111
1114
  }
1112
1115
 
1113
1116
  if (info.handle_duplicates == DUP_UPDATE && !res)
1114
1117
  {
1115
 
    Name_resolution_context *context= &lex->select_lex.context;
 
1118
    Name_resolution_context *context= &session->lex().select_lex.context;
1116
1119
    Name_resolution_context_state ctx_state;
1117
1120
 
1118
1121
    /* Save the state of the current name resolution context. */
1130
1133
      We use next_name_resolution_table descructively, so check it first (views?)
1131
1134
    */
1132
1135
    assert (!table_list->next_name_resolution_table);
1133
 
    if (lex->select_lex.group_list.elements == 0 &&
1134
 
        !lex->select_lex.with_sum_func)
 
1136
    if (session->lex().select_lex.group_list.elements == 0 and
 
1137
        not session->lex().select_lex.with_sum_func)
1135
1138
      /*
1136
1139
        We must make a single context out of the two separate name resolution contexts :
1137
1140
        the INSERT table and the tables in the SELECT part of INSERT ... SELECT.
1150
1153
        order to get correct values from those fields when the select
1151
1154
        employs a temporary table.
1152
1155
      */
1153
 
      List_iterator<Item> li(*info.update_values);
 
1156
      List<Item>::iterator li(info.update_values->begin());
1154
1157
      Item *item;
1155
1158
 
1156
1159
      while ((item= li++))
1157
1160
      {
1158
1161
        item->transform(&Item::update_value_transformer,
1159
 
                        (unsigned char*)lex->current_select);
 
1162
                        (unsigned char*)session->lex().current_select);
1160
1163
      }
1161
1164
    }
1162
1165
 
1164
1167
    ctx_state.restore_state(context, table_list);
1165
1168
  }
1166
1169
 
1167
 
  lex->current_select= lex_current_select_save;
 
1170
  session->lex().current_select= lex_current_select_save;
1168
1171
  if (res)
1169
1172
    return(1);
1170
1173
  /*
1180
1183
  if (unique_table(table_list, table_list->next_global))
1181
1184
  {
1182
1185
    /* Using same table for INSERT and SELECT */
1183
 
    lex->current_select->options|= OPTION_BUFFER_RESULT;
1184
 
    lex->current_select->join->select_options|= OPTION_BUFFER_RESULT;
 
1186
    session->lex().current_select->options|= OPTION_BUFFER_RESULT;
 
1187
    session->lex().current_select->join->select_options|= OPTION_BUFFER_RESULT;
1185
1188
  }
1186
 
  else if (!(lex->current_select->options & OPTION_BUFFER_RESULT))
 
1189
  else if (not (session->lex().current_select->options & OPTION_BUFFER_RESULT))
1187
1190
  {
1188
1191
    /*
1189
1192
      We must not yet prepare the result table if it is the same as one of the
1200
1203
  table->next_number_field=table->found_next_number_field;
1201
1204
 
1202
1205
  session->cuted_fields=0;
 
1206
 
1203
1207
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1204
1208
    table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
 
1209
 
1205
1210
  if (info.handle_duplicates == DUP_REPLACE)
1206
1211
    table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
 
1212
 
1207
1213
  if (info.handle_duplicates == DUP_UPDATE)
1208
1214
    table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1209
 
  session->abort_on_warning= !info.ignore;
 
1215
 
 
1216
  session->setAbortOnWarning(not info.ignore);
1210
1217
  table->mark_columns_needed_for_insert();
1211
1218
 
1212
1219
 
1232
1239
 
1233
1240
int select_insert::prepare2(void)
1234
1241
{
1235
 
 
1236
 
  if (session->lex->current_select->options & OPTION_BUFFER_RESULT)
 
1242
  if (session->lex().current_select->options & OPTION_BUFFER_RESULT)
1237
1243
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
 
1244
 
1238
1245
  return(0);
1239
1246
}
1240
1247
 
1255
1262
    table->cursor->ha_reset();
1256
1263
  }
1257
1264
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
1258
 
  session->abort_on_warning= 0;
 
1265
  session->setAbortOnWarning(false);
1259
1266
  return;
1260
1267
}
1261
1268
 
1263
1270
bool select_insert::send_data(List<Item> &values)
1264
1271
{
1265
1272
 
1266
 
  bool error=0;
 
1273
  bool error= false;
1267
1274
 
1268
1275
  if (unit->offset_limit_cnt)
1269
1276
  {                                             // using limit offset,count
1270
1277
    unit->offset_limit_cnt--;
1271
 
    return(0);
 
1278
    return false;
1272
1279
  }
1273
1280
 
1274
1281
  session->count_cuted_fields= CHECK_FIELD_WARN;        // Calculate cuted fields
1275
1282
  store_values(values);
1276
1283
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
1277
1284
  if (session->is_error())
1278
 
    return(1);
 
1285
    return true;
1279
1286
 
1280
1287
  // Release latches in case bulk insert takes a long time
1281
1288
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1319
1326
 
1320
1327
void select_insert::store_values(List<Item> &values)
1321
1328
{
1322
 
  if (fields->elements)
 
1329
  if (fields->size())
1323
1330
    fill_record(session, *fields, values, true);
1324
1331
  else
1325
1332
    fill_record(session, table->getFields(), values, true);
1326
1333
}
1327
1334
 
1328
 
void select_insert::send_error(uint32_t errcode,const char *err)
 
1335
void select_insert::send_error(drizzled::error_t errcode,const char *err)
1329
1336
{
1330
 
 
1331
 
 
1332
1337
  my_message(errcode, err, MYF(0));
1333
 
 
1334
 
  return;
1335
1338
}
1336
1339
 
1337
1340
 
1380
1383
    (session->arg_of_last_insert_id_function ?
1381
1384
     session->first_successful_insert_id_in_prev_stmt :
1382
1385
     (info.copied ? autoinc_value_of_last_inserted_row : 0));
1383
 
  session->my_ok((ulong) session->row_count_func,
 
1386
  session->my_ok((ulong) session->rowCount(),
1384
1387
                 info.copied + info.deleted + info.touched, id, buff);
1385
 
  session->status_var.inserted_row_count+= session->row_count_func; 
1386
 
  DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
 
1388
  session->status_var.inserted_row_count+= session->rowCount();
 
1389
  DRIZZLE_INSERT_SELECT_DONE(0, session->rowCount());
1387
1390
  return 0;
1388
1391
}
1389
1392
 
1485
1488
                                      List<Item> *items,
1486
1489
                                      bool is_if_not_exists,
1487
1490
                                      DrizzleLock **lock,
1488
 
                                      TableIdentifier &identifier)
 
1491
                                      const identifier::Table& identifier)
1489
1492
{
1490
1493
  TableShare share(message::Table::INTERNAL);
1491
 
  uint32_t select_field_count= items->elements;
 
1494
  uint32_t select_field_count= items->size();
1492
1495
  /* Add selected items to field list */
1493
 
  List_iterator_fast<Item> it(*items);
 
1496
  List<Item>::iterator it(items->begin());
1494
1497
  Item *item;
1495
1498
  Field *tmp_field;
1496
 
  bool not_used;
1497
1499
 
1498
1500
  if (not (identifier.isTmp()) && create_table->table->db_stat)
1499
1501
  {
1513
1515
 
1514
1516
  {
1515
1517
    table::Shell tmp_table(share);              // Used during 'CreateField()'
1516
 
    tmp_table.timestamp_field= 0;
1517
 
 
1518
 
    tmp_table.getMutableShare()->db_create_options= 0;
1519
 
    tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1520
1518
 
1521
1519
    if (not table_proto.engine().name().compare("MyISAM"))
1522
1520
      tmp_table.getMutableShare()->db_low_byte_first= true;
1523
1521
    else if (not table_proto.engine().name().compare("MEMORY"))
1524
1522
      tmp_table.getMutableShare()->db_low_byte_first= true;
1525
1523
 
1526
 
    tmp_table.null_row= false;
1527
 
    tmp_table.maybe_null= false;
1528
 
 
1529
1524
    tmp_table.in_use= session;
1530
1525
 
1531
1526
    while ((item=it++))
1576
1571
  */
1577
1572
  Table *table= 0;
1578
1573
  {
1579
 
    if (not mysql_create_table_no_lock(session,
1580
 
                                       identifier,
1581
 
                                       create_info,
1582
 
                                       table_proto,
1583
 
                                       alter_info,
1584
 
                                       false,
1585
 
                                       select_field_count,
1586
 
                                       is_if_not_exists))
 
1574
    if (not create_table_no_lock(session,
 
1575
                                 identifier,
 
1576
                                 create_info,
 
1577
                                 table_proto,
 
1578
                                 alter_info,
 
1579
                                 false,
 
1580
                                 select_field_count,
 
1581
                                 is_if_not_exists))
1587
1582
    {
1588
1583
      if (create_info->table_existed && not identifier.isTmp())
1589
1584
      {
1607
1602
 
1608
1603
          if (concurrent_table->reopen_name_locked_table(create_table, session))
1609
1604
          {
1610
 
            plugin::StorageEngine::dropTable(*session, identifier);
 
1605
            (void)plugin::StorageEngine::dropTable(*session, identifier);
1611
1606
          }
1612
1607
          else
1613
1608
          {
1616
1611
        }
1617
1612
        else
1618
1613
        {
1619
 
          plugin::StorageEngine::dropTable(*session, identifier);
 
1614
          (void)plugin::StorageEngine::dropTable(*session, identifier);
1620
1615
        }
1621
1616
      }
1622
1617
      else
1639
1634
  }
1640
1635
 
1641
1636
  table->reginfo.lock_type=TL_WRITE;
1642
 
  if (! ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
 
1637
  if (not ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH)))
1643
1638
  {
1644
1639
    if (*lock)
1645
1640
    {
1649
1644
 
1650
1645
    if (not create_info->table_existed)
1651
1646
      session->drop_open_table(table, identifier);
 
1647
 
1652
1648
    return NULL;
1653
1649
  }
1654
1650
 
1662
1658
  DrizzleLock *extra_lock= NULL;
1663
1659
  /*
1664
1660
    For replication, the CREATE-SELECT statement is written
1665
 
    in two pieces: the first transaction messsage contains 
 
1661
    in two pieces: the first transaction messsage contains
1666
1662
    the CREATE TABLE statement as a CreateTableStatement message
1667
1663
    necessary to create the table.
1668
 
    
 
1664
 
1669
1665
    The second transaction message contains all the InsertStatement
1670
1666
    and associated InsertRecords that should go into the table.
1671
1667
   */
1693
1689
    *m_plock= extra_lock;
1694
1690
  }
1695
1691
 
1696
 
  if (table->getShare()->sizeFields() < values.elements)
 
1692
  if (table->getShare()->sizeFields() < values.size())
1697
1693
  {
1698
1694
    my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1);
1699
1695
    return(-1);
1700
1696
  }
1701
1697
 
1702
1698
 /* First field to copy */
1703
 
  field= table->getFields() + table->getShare()->sizeFields() - values.elements;
 
1699
  field= table->getFields() + table->getShare()->sizeFields() - values.size();
1704
1700
 
1705
1701
  /* Mark all fields that are given values */
1706
1702
  for (Field **f= field ; *f ; f++)
1716
1712
  session->cuted_fields=0;
1717
1713
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1718
1714
    table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
 
1715
 
1719
1716
  if (info.handle_duplicates == DUP_REPLACE)
1720
1717
    table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
 
1718
 
1721
1719
  if (info.handle_duplicates == DUP_UPDATE)
1722
1720
    table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
 
1721
 
1723
1722
  table->cursor->ha_start_bulk_insert((ha_rows) 0);
1724
 
  session->abort_on_warning= !info.ignore;
 
1723
  session->setAbortOnWarning(not info.ignore);
1725
1724
  if (check_that_all_fields_are_given_values(session, table, table_list))
1726
1725
    return(1);
 
1726
 
1727
1727
  table->mark_columns_needed_for_insert();
1728
1728
  table->cursor->extra(HA_EXTRA_WRITE_CACHE);
1729
1729
  return(0);
1735
1735
}
1736
1736
 
1737
1737
 
1738
 
void select_create::send_error(uint32_t errcode,const char *err)
 
1738
void select_create::send_error(drizzled::error_t errcode,const char *err)
1739
1739
{
1740
1740
  /*
1741
1741
    This will execute any rollbacks that are necessary before writing
1749
1749
 
1750
1750
  */
1751
1751
  select_insert::send_error(errcode, err);
1752
 
 
1753
 
  return;
1754
1752
}
1755
1753
 
1756
1754
 
1769
1767
    if (!table->getShare()->getType())
1770
1768
    {
1771
1769
      TransactionServices &transaction_services= TransactionServices::singleton();
1772
 
      transaction_services.autocommitOrRollback(session, 0);
 
1770
      transaction_services.autocommitOrRollback(*session, 0);
1773
1771
      (void) session->endActiveTransaction();
1774
1772
    }
1775
1773