~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-07-09 20:51:34 UTC
  • mfrom: (1643.4.3 drizzle)
  • Revision ID: brian@gaz-20100709205134-ru4s0889youfrmm5
Merge of Patrick

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
        {
672
678
 
673
679
static int last_uniq_key(Table *table,uint32_t keynr)
674
680
{
675
 
  while (++keynr < table->s->keys)
 
681
  while (++keynr < table->getShare()->sizeKeys())
676
682
    if (table->key_info[keynr].flags & HA_NOSAME)
677
683
      return 0;
678
684
  return 1;
721
727
 
722
728
  if (info->handle_duplicates == DUP_REPLACE || info->handle_duplicates == DUP_UPDATE)
723
729
  {
724
 
    while ((error=table->cursor->ha_write_row(table->record[0])))
 
730
    while ((error=table->cursor->insertRecord(table->record[0])))
725
731
    {
726
732
      uint32_t key_nr;
727
733
      /*
764
770
      */
765
771
      if (info->handle_duplicates == DUP_REPLACE &&
766
772
          table->next_number_field &&
767
 
          key_nr == table->s->next_number_index &&
 
773
          key_nr == table->getShare()->next_number_index &&
768
774
          (insert_id_for_cur_row > 0))
769
775
        goto err;
770
776
      if (table->cursor->getEngine()->check_flag(HTON_BIT_DUPLICATE_POS))
782
788
 
783
789
        if (!key)
784
790
        {
785
 
          if (!(key=(char*) malloc(table->s->max_unique_length)))
 
791
          if (!(key=(char*) malloc(table->getShare()->max_unique_length)))
786
792
          {
787
793
            error=ENOMEM;
788
794
            goto err;
820
826
             !bitmap_is_subset(table->write_set, table->read_set)) ||
821
827
            table->compare_record())
822
828
        {
823
 
          if ((error=table->cursor->ha_update_row(table->record[1],
 
829
          if ((error=table->cursor->updateRecord(table->record[1],
824
830
                                                table->record[0])) &&
825
831
              error != HA_ERR_RECORD_IS_THE_SAME)
826
832
          {
875
881
            (table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET ||
876
882
             table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
877
883
        {
878
 
          if ((error=table->cursor->ha_update_row(table->record[1],
 
884
          if ((error=table->cursor->updateRecord(table->record[1],
879
885
                                                table->record[0])) &&
880
886
              error != HA_ERR_RECORD_IS_THE_SAME)
881
887
            goto err;
892
898
        }
893
899
        else
894
900
        {
895
 
          if ((error=table->cursor->ha_delete_row(table->record[1])))
 
901
          if ((error=table->cursor->deleteRecord(table->record[1])))
896
902
            goto err;
897
903
          info->deleted++;
898
904
          if (!table->cursor->has_transactions())
910
916
        table->write_set != save_write_set)
911
917
      table->column_bitmaps_set(save_read_set, save_write_set);
912
918
  }
913
 
  else if ((error=table->cursor->ha_write_row(table->record[0])))
 
919
  else if ((error=table->cursor->insertRecord(table->record[0])))
914
920
  {
915
921
    if (!info->ignore ||
916
922
        table->cursor->is_fatal_error(error, HA_CHECK_DUP))
955
961
{
956
962
  int err= 0;
957
963
 
958
 
  for (Field **field=entry->field ; *field ; field++)
 
964
  for (Field **field=entry->getFields() ; *field ; field++)
959
965
  {
960
966
    if (((*field)->isWriteSet()) == false)
961
967
    {
1257
1263
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1258
1264
 
1259
1265
  error= write_record(session, table, &info);
 
1266
  table->auto_increment_field_not_null= false;
1260
1267
 
1261
1268
  if (!error)
1262
1269
  {
1297
1304
  if (fields->elements)
1298
1305
    fill_record(session, *fields, values, true);
1299
1306
  else
1300
 
    fill_record(session, table->field, values, true);
 
1307
    fill_record(session, table->getFields(), values, true);
1301
1308
}
1302
1309
 
1303
1310
void select_insert::send_error(uint32_t errcode,const char *err)
1325
1332
  {
1326
1333
    /*
1327
1334
      We must invalidate the table in the query cache before binlog writing
1328
 
      and ha_autocommit_or_rollback.
 
1335
      and autocommitOrRollback.
1329
1336
    */
1330
1337
    if (session->transaction.stmt.hasModifiedNonTransData())
1331
1338
      session->transaction.all.markModifiedNonTransData();
1462
1469
                                      TableIdentifier &identifier)
1463
1470
{
1464
1471
  Table tmp_table;              // Used during 'CreateField()'
1465
 
  TableShare share;
 
1472
  TableShare share(message::Table::INTERNAL);
1466
1473
  Table *table= 0;
1467
1474
  uint32_t select_field_count= items->elements;
1468
1475
  /* Add selected items to field list */
1489
1496
 
1490
1497
  tmp_table.alias= 0;
1491
1498
  tmp_table.timestamp_field= 0;
1492
 
  tmp_table.s= &share;
 
1499
  tmp_table.setShare(&share);
1493
1500
 
1494
 
  tmp_table.s->db_create_options=0;
1495
 
  tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
 
1501
  tmp_table.getMutableShare()->db_create_options= 0;
 
1502
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1496
1503
 
1497
1504
  if (not table_proto.engine().name().compare("MyISAM"))
1498
 
    tmp_table.s->db_low_byte_first= true;
 
1505
    tmp_table.getMutableShare()->db_low_byte_first= true;
1499
1506
  else if (not table_proto.engine().name().compare("MEMORY"))
1500
 
    tmp_table.s->db_low_byte_first= true;
 
1507
    tmp_table.getMutableShare()->db_low_byte_first= true;
1501
1508
 
1502
1509
  tmp_table.null_row= false;
1503
1510
  tmp_table.maybe_null= false;
1623
1630
                                          alter_info, &values,
1624
1631
                                          is_if_not_exists,
1625
1632
                                          &extra_lock, identifier)))
 
1633
  {
1626
1634
    return(-1);                         // abort() deletes table
 
1635
  }
1627
1636
 
1628
1637
  if (extra_lock)
1629
1638
  {
1637
1646
    *m_plock= extra_lock;
1638
1647
  }
1639
1648
 
1640
 
  if (table->s->fields < values.elements)
 
1649
  if (table->getShare()->sizeFields() < values.elements)
1641
1650
  {
1642
1651
    my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1);
1643
1652
    return(-1);
1644
1653
  }
1645
1654
 
1646
1655
 /* First field to copy */
1647
 
  field= table->field+table->s->fields - values.elements;
 
1656
  field= table->getFields() + table->getShare()->sizeFields() - values.elements;
1648
1657
 
1649
1658
  /* Mark all fields that are given values */
1650
1659
  for (Field **f= field ; *f ; f++)
1708
1717
      tables.  This can fail, but we should unlock the table
1709
1718
      nevertheless.
1710
1719
    */
1711
 
    if (!table->s->tmp_table)
 
1720
    if (!table->getShare()->getType())
1712
1721
    {
1713
1722
      TransactionServices &transaction_services= TransactionServices::singleton();
1714
 
      transaction_services.ha_autocommit_or_rollback(session, 0);
 
1723
      transaction_services.autocommitOrRollback(session, 0);
1715
1724
      (void) session->endActiveTransaction();
1716
1725
    }
1717
1726