~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-08-13 17:44:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1709.
  • Revision ID: brian@tangent.org-20100813174418-pq2wr6r6f2okx3gb
Remove myisam_data_pointer_siz

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/* Insert of records */
18
18
 
19
19
#include "config.h"
 
20
#include <cstdio>
20
21
#include <drizzled/sql_select.h>
21
22
#include <drizzled/show.h>
22
23
#include <drizzled/error.h>
67
68
 
68
69
  if (fields.elements == 0 && values.elements != 0)
69
70
  {
70
 
    if (values.elements != table->s->fields)
 
71
    if (values.elements != table->getShare()->sizeFields())
71
72
    {
72
73
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
73
74
      return -1;
120
121
    if (table->timestamp_field) // Don't automaticly set timestamp if used
121
122
    {
122
123
      if (table->timestamp_field->isWriteSet())
 
124
      {
123
125
        clear_timestamp_auto_bits(table->timestamp_field_type,
124
126
                                  TIMESTAMP_AUTO_SET_ON_INSERT);
 
127
      }
125
128
      else
126
129
      {
127
130
        table->setWriteSet(table->timestamp_field->field_index);
176
179
  {
177
180
    /* Don't set timestamp column if this is modified. */
178
181
    if (table->timestamp_field->isWriteSet())
 
182
    {
179
183
      clear_timestamp_auto_bits(table->timestamp_field_type,
180
184
                                TIMESTAMP_AUTO_SET_ON_UPDATE);
 
185
    }
 
186
 
181
187
    if (timestamp_mark)
 
188
    {
182
189
      table->setWriteSet(table->timestamp_field->field_index);
 
190
    }
183
191
  }
184
192
  return 0;
185
193
}
320
328
    For single line insert, generate an error if try to set a NOT NULL field
321
329
    to NULL.
322
330
  */
323
 
  session->count_cuted_fields= ((values_list.elements == 1 &&
324
 
                                 !ignore) ?
325
 
                                CHECK_FIELD_ERROR_FOR_NULL :
326
 
                                CHECK_FIELD_WARN);
 
331
  session->count_cuted_fields= ignore ? CHECK_FIELD_WARN : CHECK_FIELD_ERROR_FOR_NULL;
 
332
 
327
333
  session->cuted_fields = 0L;
328
334
  table->next_number_field=table->found_next_number_field;
329
335
 
369
375
    {
370
376
      table->restoreRecordAsDefault();  // Get empty record
371
377
 
372
 
      if (fill_record(session, table->field, *values))
 
378
      if (fill_record(session, table->getFields(), *values))
373
379
      {
374
380
        if (values_list.elements != 1 && ! session->is_error())
375
381
        {
467
473
    session->my_ok((ulong) session->row_count_func,
468
474
                   info.copied + info.deleted + info.touched, id, buff);
469
475
  }
 
476
  session->status_var.inserted_row_count+= session->row_count_func;
470
477
  session->abort_on_warning= 0;
471
478
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
472
479
  return false;
672
679
 
673
680
static int last_uniq_key(Table *table,uint32_t keynr)
674
681
{
675
 
  while (++keynr < table->s->keys)
 
682
  while (++keynr < table->getShare()->sizeKeys())
676
683
    if (table->key_info[keynr].flags & HA_NOSAME)
677
684
      return 0;
678
685
  return 1;
721
728
 
722
729
  if (info->handle_duplicates == DUP_REPLACE || info->handle_duplicates == DUP_UPDATE)
723
730
  {
724
 
    while ((error=table->cursor->ha_write_row(table->record[0])))
 
731
    while ((error=table->cursor->insertRecord(table->getInsertRecord())))
725
732
    {
726
733
      uint32_t key_nr;
727
734
      /*
764
771
      */
765
772
      if (info->handle_duplicates == DUP_REPLACE &&
766
773
          table->next_number_field &&
767
 
          key_nr == table->s->next_number_index &&
 
774
          key_nr == table->getShare()->next_number_index &&
768
775
          (insert_id_for_cur_row > 0))
769
776
        goto err;
770
777
      if (table->cursor->getEngine()->check_flag(HTON_BIT_DUPLICATE_POS))
771
778
      {
772
 
        if (table->cursor->rnd_pos(table->record[1],table->cursor->dup_ref))
 
779
        if (table->cursor->rnd_pos(table->getUpdateRecord(),table->cursor->dup_ref))
773
780
          goto err;
774
781
      }
775
782
      else
782
789
 
783
790
        if (!key)
784
791
        {
785
 
          if (!(key=(char*) malloc(table->s->max_unique_length)))
 
792
          if (!(key=(char*) malloc(table->getShare()->max_unique_length)))
786
793
          {
787
794
            error=ENOMEM;
788
795
            goto err;
789
796
          }
790
797
        }
791
 
        key_copy((unsigned char*) key,table->record[0],table->key_info+key_nr,0);
792
 
        if ((error=(table->cursor->index_read_idx_map(table->record[1],key_nr,
 
798
        key_copy((unsigned char*) key,table->getInsertRecord(),table->key_info+key_nr,0);
 
799
        if ((error=(table->cursor->index_read_idx_map(table->getUpdateRecord(),key_nr,
793
800
                                                    (unsigned char*) key, HA_WHOLE_KEY,
794
801
                                                    HA_READ_KEY_EXACT))))
795
802
          goto err;
801
808
          that matches, is updated. If update causes a conflict again,
802
809
          an error is returned
803
810
        */
804
 
        assert(table->insert_values != NULL);
 
811
        assert(table->insert_values.size());
805
812
        table->storeRecordAsInsert();
806
813
        table->restoreRecord();
807
814
        assert(info->update_fields->elements ==
820
827
             !bitmap_is_subset(table->write_set, table->read_set)) ||
821
828
            table->compare_record())
822
829
        {
823
 
          if ((error=table->cursor->ha_update_row(table->record[1],
824
 
                                                table->record[0])) &&
 
830
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
 
831
                                                table->getInsertRecord())) &&
825
832
              error != HA_ERR_RECORD_IS_THE_SAME)
826
833
          {
827
834
            if (info->ignore &&
875
882
            (table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET ||
876
883
             table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
877
884
        {
878
 
          if ((error=table->cursor->ha_update_row(table->record[1],
879
 
                                                table->record[0])) &&
 
885
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
 
886
                                                table->getInsertRecord())) &&
880
887
              error != HA_ERR_RECORD_IS_THE_SAME)
881
888
            goto err;
882
889
          if (error != HA_ERR_RECORD_IS_THE_SAME)
892
899
        }
893
900
        else
894
901
        {
895
 
          if ((error=table->cursor->ha_delete_row(table->record[1])))
 
902
          if ((error=table->cursor->deleteRecord(table->getUpdateRecord())))
896
903
            goto err;
897
904
          info->deleted++;
898
905
          if (!table->cursor->has_transactions())
910
917
        table->write_set != save_write_set)
911
918
      table->column_bitmaps_set(save_read_set, save_write_set);
912
919
  }
913
 
  else if ((error=table->cursor->ha_write_row(table->record[0])))
 
920
  else if ((error=table->cursor->insertRecord(table->getInsertRecord())))
914
921
  {
915
922
    if (!info->ignore ||
916
923
        table->cursor->is_fatal_error(error, HA_CHECK_DUP))
955
962
{
956
963
  int err= 0;
957
964
 
958
 
  for (Field **field=entry->field ; *field ; field++)
 
965
  for (Field **field=entry->getFields() ; *field ; field++)
959
966
  {
960
967
    if (((*field)->isWriteSet()) == false)
961
968
    {
1257
1264
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1258
1265
 
1259
1266
  error= write_record(session, table, &info);
 
1267
  table->auto_increment_field_not_null= false;
1260
1268
 
1261
1269
  if (!error)
1262
1270
  {
1297
1305
  if (fields->elements)
1298
1306
    fill_record(session, *fields, values, true);
1299
1307
  else
1300
 
    fill_record(session, table->field, values, true);
 
1308
    fill_record(session, table->getFields(), values, true);
1301
1309
}
1302
1310
 
1303
1311
void select_insert::send_error(uint32_t errcode,const char *err)
1325
1333
  {
1326
1334
    /*
1327
1335
      We must invalidate the table in the query cache before binlog writing
1328
 
      and ha_autocommit_or_rollback.
 
1336
      and autocommitOrRollback.
1329
1337
    */
1330
1338
    if (session->transaction.stmt.hasModifiedNonTransData())
1331
1339
      session->transaction.all.markModifiedNonTransData();
1357
1365
     (info.copied ? autoinc_value_of_last_inserted_row : 0));
1358
1366
  session->my_ok((ulong) session->row_count_func,
1359
1367
                 info.copied + info.deleted + info.touched, id, buff);
 
1368
  session->status_var.inserted_row_count+= session->row_count_func; 
1360
1369
  DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
1361
1370
  return 0;
1362
1371
}
1462
1471
                                      TableIdentifier &identifier)
1463
1472
{
1464
1473
  Table tmp_table;              // Used during 'CreateField()'
1465
 
  TableShare share;
 
1474
  TableShare share(message::Table::INTERNAL);
1466
1475
  Table *table= 0;
1467
1476
  uint32_t select_field_count= items->elements;
1468
1477
  /* Add selected items to field list */
1487
1496
    return NULL;
1488
1497
  }
1489
1498
 
1490
 
  tmp_table.alias= 0;
1491
1499
  tmp_table.timestamp_field= 0;
1492
 
  tmp_table.s= &share;
 
1500
  tmp_table.setShare(&share);
1493
1501
 
1494
 
  tmp_table.s->db_create_options=0;
1495
 
  tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
 
1502
  tmp_table.getMutableShare()->db_create_options= 0;
 
1503
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1496
1504
 
1497
1505
  if (not table_proto.engine().name().compare("MyISAM"))
1498
 
    tmp_table.s->db_low_byte_first= true;
 
1506
    tmp_table.getMutableShare()->db_low_byte_first= true;
1499
1507
  else if (not table_proto.engine().name().compare("MEMORY"))
1500
 
    tmp_table.s->db_low_byte_first= true;
 
1508
    tmp_table.getMutableShare()->db_low_byte_first= true;
1501
1509
 
1502
1510
  tmp_table.null_row= false;
1503
1511
  tmp_table.maybe_null= false;
1555
1563
 
1556
1564
      if (not identifier.isTmp())
1557
1565
      {
1558
 
        pthread_mutex_lock(&LOCK_open); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1566
        LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1559
1567
        if (session->reopen_name_locked_table(create_table, false))
1560
1568
        {
1561
1569
          quick_rm_table(*session, identifier);
1562
1570
        }
1563
1571
        else
1564
1572
          table= create_table->table;
1565
 
        pthread_mutex_unlock(&LOCK_open);
 
1573
        LOCK_open.unlock();
1566
1574
      }
1567
1575
      else
1568
1576
      {
1623
1631
                                          alter_info, &values,
1624
1632
                                          is_if_not_exists,
1625
1633
                                          &extra_lock, identifier)))
 
1634
  {
1626
1635
    return(-1);                         // abort() deletes table
 
1636
  }
1627
1637
 
1628
1638
  if (extra_lock)
1629
1639
  {
1637
1647
    *m_plock= extra_lock;
1638
1648
  }
1639
1649
 
1640
 
  if (table->s->fields < values.elements)
 
1650
  if (table->getShare()->sizeFields() < values.elements)
1641
1651
  {
1642
1652
    my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1);
1643
1653
    return(-1);
1644
1654
  }
1645
1655
 
1646
1656
 /* First field to copy */
1647
 
  field= table->field+table->s->fields - values.elements;
 
1657
  field= table->getFields() + table->getShare()->sizeFields() - values.elements;
1648
1658
 
1649
1659
  /* Mark all fields that are given values */
1650
1660
  for (Field **f= field ; *f ; f++)
1708
1718
      tables.  This can fail, but we should unlock the table
1709
1719
      nevertheless.
1710
1720
    */
1711
 
    if (!table->s->tmp_table)
 
1721
    if (!table->getShare()->getType())
1712
1722
    {
1713
1723
      TransactionServices &transaction_services= TransactionServices::singleton();
1714
 
      transaction_services.ha_autocommit_or_rollback(session, 0);
 
1724
      transaction_services.autocommitOrRollback(session, 0);
1715
1725
      (void) session->endActiveTransaction();
1716
1726
    }
1717
1727