~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-10-15 01:23:36 UTC
  • mfrom: (1835.1.7 staging)
  • Revision ID: brian@tangent.org-20101015012336-8w5lox9kj0hkv0a1
MergeĀ inĀ mutable/execute

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/sql_base.h>
27
27
#include <drizzled/sql_load.h>
28
 
#include <drizzled/field/epoch.h>
 
28
#include <drizzled/field/timestamp.h>
29
29
#include <drizzled/lock.h>
30
30
#include "drizzled/sql_table.h"
31
31
#include "drizzled/pthread_globals.h"
32
32
#include "drizzled/transaction_services.h"
33
33
#include "drizzled/plugin/transactional_storage_engine.h"
34
34
 
35
 
#include "drizzled/table/shell.h"
36
 
 
37
35
namespace drizzled
38
36
{
39
37
 
129
127
      }
130
128
      else
131
129
      {
132
 
        table->setWriteSet(table->timestamp_field->position());
 
130
        table->setWriteSet(table->timestamp_field->field_index);
133
131
      }
134
132
    }
135
133
  }
170
168
      Unmark the timestamp field so that we can check if this is modified
171
169
      by update_fields
172
170
    */
173
 
    timestamp_mark= table->write_set->test(table->timestamp_field->position());
174
 
    table->write_set->reset(table->timestamp_field->position());
 
171
    timestamp_mark= table->write_set->test(table->timestamp_field->field_index);
 
172
    table->write_set->reset(table->timestamp_field->field_index);
175
173
  }
176
174
 
177
175
  /* Check the fields we are going to modify */
189
187
 
190
188
    if (timestamp_mark)
191
189
    {
192
 
      table->setWriteSet(table->timestamp_field->position());
 
190
      table->setWriteSet(table->timestamp_field->field_index);
193
191
    }
194
192
  }
195
193
  return 0;
227
225
  end of dispatch_command().
228
226
*/
229
227
 
230
 
bool insert_query(Session *session,TableList *table_list,
 
228
bool mysql_insert(Session *session,TableList *table_list,
231
229
                  List<Item> &fields,
232
230
                  List<List_item> &values_list,
233
231
                  List<Item> &update_fields,
271
269
  values= its++;
272
270
  value_count= values->elements;
273
271
 
274
 
  if (prepare_insert(session, table_list, table, fields, values,
 
272
  if (mysql_prepare_insert(session, table_list, table, fields, values,
275
273
                           update_fields, update_values, duplic, &unused_conds,
276
274
                           false,
277
275
                           (fields.elements || !value_count ||
278
276
                            (0) != 0), !ignore))
279
 
  {
280
 
    if (table != NULL)
281
 
      table->cursor->ha_release_auto_increment();
282
 
    if (!joins_freed)
283
 
      free_underlaid_joins(session, &session->lex->select_lex);
284
 
    session->setAbortOnWarning(false);
285
 
    DRIZZLE_INSERT_DONE(1, 0);
286
 
    return true;
287
 
  }
 
277
    goto abort;
288
278
 
289
279
  /* mysql_prepare_insert set table_list->table if it was not set */
290
280
  table= table_list->table;
315
305
    if (values->elements != value_count)
316
306
    {
317
307
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
318
 
 
319
 
      if (table != NULL)
320
 
        table->cursor->ha_release_auto_increment();
321
 
      if (!joins_freed)
322
 
        free_underlaid_joins(session, &session->lex->select_lex);
323
 
      session->setAbortOnWarning(false);
324
 
      DRIZZLE_INSERT_DONE(1, 0);
325
 
 
326
 
      return true;
 
308
      goto abort;
327
309
    }
328
310
    if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
329
 
    {
330
 
      if (table != NULL)
331
 
        table->cursor->ha_release_auto_increment();
332
 
      if (!joins_freed)
333
 
        free_underlaid_joins(session, &session->lex->select_lex);
334
 
      session->setAbortOnWarning(false);
335
 
      DRIZZLE_INSERT_DONE(1, 0);
336
 
      return true;
337
 
    }
 
311
      goto abort;
338
312
  }
339
313
  its.rewind ();
340
314
 
372
346
  }
373
347
 
374
348
 
375
 
  session->setAbortOnWarning(not ignore);
 
349
  session->abort_on_warning= !ignore;
376
350
 
377
351
  table->mark_columns_needed_for_insert();
378
352
 
478
452
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
479
453
 
480
454
  if (error)
481
 
  {
482
 
    if (table != NULL)
483
 
      table->cursor->ha_release_auto_increment();
484
 
    if (!joins_freed)
485
 
      free_underlaid_joins(session, &session->lex->select_lex);
486
 
    session->setAbortOnWarning(false);
487
 
    DRIZZLE_INSERT_DONE(1, 0);
488
 
    return true;
489
 
  }
490
 
 
 
455
    goto abort;
491
456
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
457
                                    !session->cuted_fields))
493
458
  {
494
459
    session->row_count_func= info.copied + info.deleted + info.updated;
495
 
    session->my_ok((ulong) session->rowCount(),
 
460
    session->my_ok((ulong) session->row_count_func,
496
461
                   info.copied + info.deleted + info.touched, id);
497
462
  }
498
463
  else
505
470
      snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
506
471
              (ulong) (info.deleted + info.updated), (ulong) session->cuted_fields);
507
472
    session->row_count_func= info.copied + info.deleted + info.updated;
508
 
    session->my_ok((ulong) session->rowCount(),
 
473
    session->my_ok((ulong) session->row_count_func,
509
474
                   info.copied + info.deleted + info.touched, id, buff);
510
475
  }
511
 
  session->status_var.inserted_row_count+= session->rowCount();
512
 
  session->setAbortOnWarning(false);
513
 
  DRIZZLE_INSERT_DONE(0, session->rowCount());
514
 
 
 
476
  session->status_var.inserted_row_count+= session->row_count_func;
 
477
  session->abort_on_warning= 0;
 
478
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
515
479
  return false;
 
480
 
 
481
abort:
 
482
  if (table != NULL)
 
483
    table->cursor->ha_release_auto_increment();
 
484
  if (!joins_freed)
 
485
    free_underlaid_joins(session, &session->lex->select_lex);
 
486
  session->abort_on_warning= 0;
 
487
  DRIZZLE_INSERT_DONE(1, 0);
 
488
  return true;
516
489
}
517
490
 
518
491
 
520
493
  Check if table can be updated
521
494
 
522
495
  SYNOPSIS
523
 
     prepare_insert_check_table()
 
496
     mysql_prepare_insert_check_table()
524
497
     session            Thread handle
525
498
     table_list         Table list
526
499
     fields             List of fields to be updated
532
505
     true  ERROR
533
506
*/
534
507
 
535
 
static bool prepare_insert_check_table(Session *session, TableList *table_list,
 
508
static bool mysql_prepare_insert_check_table(Session *session, TableList *table_list,
536
509
                                             List<Item> &,
537
510
                                             bool select_insert)
538
511
{
560
533
  Prepare items in INSERT statement
561
534
 
562
535
  SYNOPSIS
563
 
    prepare_insert()
 
536
    mysql_prepare_insert()
564
537
    session                     Thread handler
565
538
    table_list          Global/local table list
566
539
    table               Table to insert into (can be NULL if table should
587
560
    true  error
588
561
*/
589
562
 
590
 
bool prepare_insert(Session *session, TableList *table_list,
 
563
bool mysql_prepare_insert(Session *session, TableList *table_list,
591
564
                          Table *table, List<Item> &fields, List_item *values,
592
565
                          List<Item> &update_fields, List<Item> &update_values,
593
566
                          enum_duplicates duplic,
610
583
    inserting (for INSERT ... SELECT this is done by changing table_list,
611
584
    because INSERT ... SELECT share Select_Lex it with SELECT.
612
585
  */
613
 
  if (not select_insert)
 
586
  if (!select_insert)
614
587
  {
615
588
    for (Select_Lex_Unit *un= select_lex->first_inner_unit();
616
589
         un;
632
605
      return(true);
633
606
  }
634
607
 
635
 
  if (prepare_insert_check_table(session, table_list, fields, select_insert))
 
608
  if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
636
609
    return(true);
637
610
 
638
611
 
658
631
 
659
632
    if (!res && check_fields)
660
633
    {
661
 
      bool saved_abort_on_warning= session->abortOnWarning();
662
 
 
663
 
      session->setAbortOnWarning(abort_on_warning);
 
634
      bool saved_abort_on_warning= session->abort_on_warning;
 
635
      session->abort_on_warning= abort_on_warning;
664
636
      res= check_that_all_fields_are_given_values(session,
665
637
                                                  table ? table :
666
638
                                                  context->table_list->table,
667
639
                                                  context->table_list);
668
 
      session->setAbortOnWarning(saved_abort_on_warning);
 
640
      session->abort_on_warning= saved_abort_on_warning;
669
641
    }
670
642
 
671
643
    if (!res && duplic == DUP_UPDATE)
676
648
    /* Restore the current context. */
677
649
    ctx_state.restore_state(context, table_list);
678
650
 
679
 
    if (not res)
 
651
    if (!res)
680
652
      res= setup_fields(session, 0, update_values, MARK_COLUMNS_READ, 0, 0);
681
653
  }
682
654
 
683
655
  if (res)
684
656
    return(res);
685
657
 
686
 
  if (not table)
 
658
  if (!table)
687
659
    table= table_list->table;
688
660
 
689
 
  if (not select_insert)
 
661
  if (!select_insert)
690
662
  {
691
663
    TableList *duplicate;
692
664
    if ((duplicate= unique_table(table_list, table_list->next_global, true)))
696
668
      return true;
697
669
    }
698
670
  }
699
 
 
700
671
  if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
701
672
    table->prepare_for_position();
702
673
 
848
819
          table->cursor->adjust_next_insert_id_after_explicit_value(
849
820
            table->next_number_field->val_int());
850
821
        info->touched++;
851
 
 
852
 
        if (! table->records_are_comparable() || table->compare_records())
 
822
        if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
823
            ! table->write_set->is_subset_of(*table->read_set)) ||
 
824
            table->compare_record())
853
825
        {
854
826
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
855
827
                                                table->getInsertRecord())) &&
870
842
          /*
871
843
            If ON DUP KEY UPDATE updates a row instead of inserting one, it's
872
844
            like a regular UPDATE statement: it should not affect the value of a
873
 
            next SELECT LAST_INSERT_ID() or insert_id().
 
845
            next SELECT LAST_INSERT_ID() or mysql_insert_id().
874
846
            Except if LAST_INSERT_ID(#) was in the INSERT query, which is
875
847
            handled separately by Session::arg_of_last_insert_id_function.
876
848
          */
1016
988
      }
1017
989
    }
1018
990
  }
1019
 
  return session->abortOnWarning() ? err : 0;
 
991
  return session->abort_on_warning ? err : 0;
1020
992
}
1021
993
 
1022
994
/***************************************************************************
1028
1000
  make insert specific preparation and checks after opening tables
1029
1001
 
1030
1002
  SYNOPSIS
1031
 
    insert_select_prepare()
 
1003
    mysql_insert_select_prepare()
1032
1004
    session         thread handler
1033
1005
 
1034
1006
  RETURN
1036
1008
    true  Error
1037
1009
*/
1038
1010
 
1039
 
bool insert_select_prepare(Session *session)
 
1011
bool mysql_insert_select_prepare(Session *session)
1040
1012
{
1041
1013
  LEX *lex= session->lex;
1042
1014
  Select_Lex *select_lex= &lex->select_lex;
1046
1018
    clause if table is VIEW
1047
1019
  */
1048
1020
 
1049
 
  if (prepare_insert(session, lex->query_tables,
 
1021
  if (mysql_prepare_insert(session, lex->query_tables,
1050
1022
                           lex->query_tables->table, lex->field_list, 0,
1051
1023
                           lex->update_list, lex->value_list,
1052
1024
                           lex->duplicates,
1105
1077
 
1106
1078
  if (!res && fields->elements)
1107
1079
  {
1108
 
    bool saved_abort_on_warning= session->abortOnWarning();
1109
 
    session->setAbortOnWarning(not info.ignore);
 
1080
    bool saved_abort_on_warning= session->abort_on_warning;
 
1081
    session->abort_on_warning= !info.ignore;
1110
1082
    res= check_that_all_fields_are_given_values(session, table_list->table,
1111
1083
                                                table_list);
1112
 
    session->setAbortOnWarning(saved_abort_on_warning);
 
1084
    session->abort_on_warning= saved_abort_on_warning;
1113
1085
  }
1114
1086
 
1115
1087
  if (info.handle_duplicates == DUP_UPDATE && !res)
1202
1174
  table->next_number_field=table->found_next_number_field;
1203
1175
 
1204
1176
  session->cuted_fields=0;
1205
 
 
1206
1177
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1207
1178
    table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1208
 
 
1209
1179
  if (info.handle_duplicates == DUP_REPLACE)
1210
1180
    table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1211
 
 
1212
1181
  if (info.handle_duplicates == DUP_UPDATE)
1213
1182
    table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1214
 
 
1215
 
  session->setAbortOnWarning(not info.ignore);
 
1183
  session->abort_on_warning= !info.ignore;
1216
1184
  table->mark_columns_needed_for_insert();
1217
1185
 
1218
1186
 
1261
1229
    table->cursor->ha_reset();
1262
1230
  }
1263
1231
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
1264
 
  session->setAbortOnWarning(false);
 
1232
  session->abort_on_warning= 0;
1265
1233
  return;
1266
1234
}
1267
1235
 
1274
1242
  if (unit->offset_limit_cnt)
1275
1243
  {                                             // using limit offset,count
1276
1244
    unit->offset_limit_cnt--;
1277
 
    return false;
 
1245
    return(0);
1278
1246
  }
1279
1247
 
1280
1248
  session->count_cuted_fields= CHECK_FIELD_WARN;        // Calculate cuted fields
1281
1249
  store_values(values);
1282
1250
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
1283
1251
  if (session->is_error())
1284
 
    return true;
 
1252
    return(1);
1285
1253
 
1286
1254
  // Release latches in case bulk insert takes a long time
1287
1255
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1331
1299
    fill_record(session, table->getFields(), values, true);
1332
1300
}
1333
1301
 
1334
 
void select_insert::send_error(drizzled::error_t errcode,const char *err)
 
1302
void select_insert::send_error(uint32_t errcode,const char *err)
1335
1303
{
 
1304
 
 
1305
 
1336
1306
  my_message(errcode, err, MYF(0));
 
1307
 
 
1308
  return;
1337
1309
}
1338
1310
 
1339
1311
 
1382
1354
    (session->arg_of_last_insert_id_function ?
1383
1355
     session->first_successful_insert_id_in_prev_stmt :
1384
1356
     (info.copied ? autoinc_value_of_last_inserted_row : 0));
1385
 
  session->my_ok((ulong) session->rowCount(),
 
1357
  session->my_ok((ulong) session->row_count_func,
1386
1358
                 info.copied + info.deleted + info.touched, id, buff);
1387
 
  session->status_var.inserted_row_count+= session->rowCount(); 
1388
 
  DRIZZLE_INSERT_SELECT_DONE(0, session->rowCount());
 
1359
  session->status_var.inserted_row_count+= session->row_count_func; 
 
1360
  DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
1389
1361
  return 0;
1390
1362
}
1391
1363
 
1487
1459
                                      List<Item> *items,
1488
1460
                                      bool is_if_not_exists,
1489
1461
                                      DrizzleLock **lock,
1490
 
                                      identifier::Table::const_reference identifier)
 
1462
                                      TableIdentifier &identifier)
1491
1463
{
 
1464
  Table tmp_table;              // Used during 'CreateField()'
1492
1465
  TableShare share(message::Table::INTERNAL);
 
1466
  Table *table= 0;
1493
1467
  uint32_t select_field_count= items->elements;
1494
1468
  /* Add selected items to field list */
1495
1469
  List_iterator_fast<Item> it(*items);
1496
1470
  Item *item;
1497
1471
  Field *tmp_field;
 
1472
  bool not_used;
1498
1473
 
1499
1474
  if (not (identifier.isTmp()) && create_table->table->db_stat)
1500
1475
  {
1504
1479
      create_info->table_existed= 1;            // Mark that table existed
1505
1480
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1506
1481
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1507
 
                          create_table->getTableName());
 
1482
                          create_table->table_name);
1508
1483
      return create_table->table;
1509
1484
    }
1510
1485
 
1511
 
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1486
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1512
1487
    return NULL;
1513
1488
  }
1514
1489
 
 
1490
  tmp_table.timestamp_field= 0;
 
1491
  tmp_table.setShare(&share);
 
1492
 
 
1493
  tmp_table.getMutableShare()->db_create_options= 0;
 
1494
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1495
 
 
1496
  if (not table_proto.engine().name().compare("MyISAM"))
 
1497
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1498
  else if (not table_proto.engine().name().compare("MEMORY"))
 
1499
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1500
 
 
1501
  tmp_table.null_row= false;
 
1502
  tmp_table.maybe_null= false;
 
1503
 
 
1504
  tmp_table.in_use= session;
 
1505
 
 
1506
  while ((item=it++))
1515
1507
  {
1516
 
    table::Shell tmp_table(share);              // Used during 'CreateField()'
1517
 
 
1518
 
    if (not table_proto.engine().name().compare("MyISAM"))
1519
 
      tmp_table.getMutableShare()->db_low_byte_first= true;
1520
 
    else if (not table_proto.engine().name().compare("MEMORY"))
1521
 
      tmp_table.getMutableShare()->db_low_byte_first= true;
1522
 
 
1523
 
    tmp_table.in_use= session;
1524
 
 
1525
 
    while ((item=it++))
 
1508
    CreateField *cr_field;
 
1509
    Field *field, *def_field;
 
1510
    if (item->type() == Item::FUNC_ITEM)
1526
1511
    {
1527
 
      CreateField *cr_field;
1528
 
      Field *field, *def_field;
1529
 
      if (item->type() == Item::FUNC_ITEM)
 
1512
      if (item->result_type() != STRING_RESULT)
1530
1513
      {
1531
 
        if (item->result_type() != STRING_RESULT)
1532
 
        {
1533
 
          field= item->tmp_table_field(&tmp_table);
1534
 
        }
1535
 
        else
1536
 
        {
1537
 
          field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1538
 
        }
 
1514
        field= item->tmp_table_field(&tmp_table);
1539
1515
      }
1540
1516
      else
1541
1517
      {
1542
 
        field= create_tmp_field(session, &tmp_table, item, item->type(),
1543
 
                                (Item ***) 0, &tmp_field, &def_field, false,
1544
 
                                false, false, 0);
1545
 
      }
1546
 
 
1547
 
      if (!field ||
1548
 
          !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1549
 
                                            ((Item_field *)item)->field :
1550
 
                                            (Field*) 0))))
1551
 
      {
1552
 
        return NULL;
1553
 
      }
1554
 
 
1555
 
      if (item->maybe_null)
1556
 
      {
1557
 
        cr_field->flags &= ~NOT_NULL_FLAG;
1558
 
      }
1559
 
 
1560
 
      alter_info->create_list.push_back(cr_field);
1561
 
    }
 
1518
        field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1519
      }
 
1520
    }
 
1521
    else
 
1522
    {
 
1523
      field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1524
                              (Item ***) 0, &tmp_field, &def_field, false,
 
1525
                              false, false, 0);
 
1526
    }
 
1527
 
 
1528
    if (!field ||
 
1529
        !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1530
                                           ((Item_field *)item)->field :
 
1531
                                           (Field*) 0))))
 
1532
    {
 
1533
      return NULL;
 
1534
    }
 
1535
 
 
1536
    if (item->maybe_null)
 
1537
    {
 
1538
      cr_field->flags &= ~NOT_NULL_FLAG;
 
1539
    }
 
1540
 
 
1541
    alter_info->create_list.push_back(cr_field);
1562
1542
  }
1563
1543
 
1564
1544
  /*
1568
1548
    creating base table on which name we have exclusive lock. So code below
1569
1549
    should not cause deadlocks or races.
1570
1550
  */
1571
 
  Table *table= 0;
1572
1551
  {
1573
 
    if (not create_table_no_lock(session,
1574
 
                                 identifier,
1575
 
                                 create_info,
1576
 
                                 table_proto,
1577
 
                                 alter_info,
1578
 
                                 false,
1579
 
                                 select_field_count,
1580
 
                                 is_if_not_exists))
 
1552
    if (not mysql_create_table_no_lock(session,
 
1553
                                       identifier,
 
1554
                                       create_info,
 
1555
                                       table_proto,
 
1556
                                       alter_info,
 
1557
                                       false,
 
1558
                                       select_field_count,
 
1559
                                       is_if_not_exists))
1581
1560
    {
1582
1561
      if (create_info->table_existed && not identifier.isTmp())
1583
1562
      {
1586
1565
          or it was created via different mysqld front-end to the
1587
1566
          cluster. We don't have much options but throw an error.
1588
1567
        */
1589
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1568
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1590
1569
        return NULL;
1591
1570
      }
1592
1571
 
1593
1572
      if (not identifier.isTmp())
1594
1573
      {
1595
 
        /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1596
 
        boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
1597
 
 
1598
 
        if (create_table->table)
 
1574
        LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1575
        if (session->reopen_name_locked_table(create_table, false))
1599
1576
        {
1600
 
          table::Concurrent *concurrent_table= static_cast<table::Concurrent *>(create_table->table);
1601
 
 
1602
 
          if (concurrent_table->reopen_name_locked_table(create_table, session))
1603
 
          {
1604
 
            (void)plugin::StorageEngine::dropTable(*session, identifier);
1605
 
          }
1606
 
          else
1607
 
          {
1608
 
            table= create_table->table;
1609
 
          }
 
1577
          quick_rm_table(*session, identifier);
1610
1578
        }
1611
1579
        else
1612
 
        {
1613
 
          (void)plugin::StorageEngine::dropTable(*session, identifier);
1614
 
        }
 
1580
          table= create_table->table;
 
1581
        LOCK_open.unlock();
1615
1582
      }
1616
1583
      else
1617
1584
      {
1624
1591
            it preparable for open. But let us do close_temporary_table() here
1625
1592
            just in case.
1626
1593
          */
1627
 
          session->drop_temporary_table(identifier);
 
1594
          session->drop_temporary_table(create_table);
1628
1595
        }
1629
1596
      }
1630
1597
    }
1631
 
    if (not table)                                   // open failed
 
1598
    if (!table)                                   // open failed
1632
1599
      return NULL;
1633
1600
  }
1634
1601
 
1635
1602
  table->reginfo.lock_type=TL_WRITE;
1636
 
  if (not ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH)))
 
1603
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
 
1604
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
1637
1605
  {
1638
1606
    if (*lock)
1639
1607
    {
1640
 
      session->unlockTables(*lock);
 
1608
      mysql_unlock_tables(session, *lock);
1641
1609
      *lock= 0;
1642
1610
    }
1643
1611
 
1698
1666
 
1699
1667
  /* Mark all fields that are given values */
1700
1668
  for (Field **f= field ; *f ; f++)
1701
 
  {
1702
 
    table->setWriteSet((*f)->position());
1703
 
  }
 
1669
    table->setWriteSet((*f)->field_index);
1704
1670
 
1705
1671
  /* Don't set timestamp if used */
1706
1672
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1710
1676
  session->cuted_fields=0;
1711
1677
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1712
1678
    table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1713
 
 
1714
1679
  if (info.handle_duplicates == DUP_REPLACE)
1715
1680
    table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1716
 
 
1717
1681
  if (info.handle_duplicates == DUP_UPDATE)
1718
1682
    table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1719
 
 
1720
1683
  table->cursor->ha_start_bulk_insert((ha_rows) 0);
1721
 
  session->setAbortOnWarning(not info.ignore);
 
1684
  session->abort_on_warning= !info.ignore;
1722
1685
  if (check_that_all_fields_are_given_values(session, table, table_list))
1723
1686
    return(1);
1724
 
 
1725
1687
  table->mark_columns_needed_for_insert();
1726
1688
  table->cursor->extra(HA_EXTRA_WRITE_CACHE);
1727
1689
  return(0);
1733
1695
}
1734
1696
 
1735
1697
 
1736
 
void select_create::send_error(drizzled::error_t errcode,const char *err)
 
1698
void select_create::send_error(uint32_t errcode,const char *err)
1737
1699
{
1738
1700
  /*
1739
1701
    This will execute any rollbacks that are necessary before writing
1747
1709
 
1748
1710
  */
1749
1711
  select_insert::send_error(errcode, err);
 
1712
 
 
1713
  return;
1750
1714
}
1751
1715
 
1752
1716
 
1765
1729
    if (!table->getShare()->getType())
1766
1730
    {
1767
1731
      TransactionServices &transaction_services= TransactionServices::singleton();
1768
 
      transaction_services.autocommitOrRollback(*session, 0);
 
1732
      transaction_services.autocommitOrRollback(session, 0);
1769
1733
      (void) session->endActiveTransaction();
1770
1734
    }
1771
1735
 
1773
1737
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1774
1738
    if (m_plock)
1775
1739
    {
1776
 
      session->unlockTables(*m_plock);
 
1740
      mysql_unlock_tables(session, *m_plock);
1777
1741
      *m_plock= NULL;
1778
1742
      m_plock= NULL;
1779
1743
    }
1803
1767
 
1804
1768
  if (m_plock)
1805
1769
  {
1806
 
    session->unlockTables(*m_plock);
 
1770
    mysql_unlock_tables(session, *m_plock);
1807
1771
    *m_plock= NULL;
1808
1772
    m_plock= NULL;
1809
1773
  }