~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-10-21 08:55:44 UTC
  • mto: (1866.1.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1867.
  • Revision ID: brian@tangent.org-20101021085544-chpce06zm4tdaqdi
This creates a function for seeing which catalog you are in. It also
refactors some of the functions to be in the utility_function collect.

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
      }
130
130
      else
131
131
      {
132
 
        table->setWriteSet(table->timestamp_field->position());
 
132
        table->setWriteSet(table->timestamp_field->field_index);
133
133
      }
134
134
    }
135
135
  }
170
170
      Unmark the timestamp field so that we can check if this is modified
171
171
      by update_fields
172
172
    */
173
 
    timestamp_mark= table->write_set->test(table->timestamp_field->position());
174
 
    table->write_set->reset(table->timestamp_field->position());
 
173
    timestamp_mark= table->write_set->test(table->timestamp_field->field_index);
 
174
    table->write_set->reset(table->timestamp_field->field_index);
175
175
  }
176
176
 
177
177
  /* Check the fields we are going to modify */
189
189
 
190
190
    if (timestamp_mark)
191
191
    {
192
 
      table->setWriteSet(table->timestamp_field->position());
 
192
      table->setWriteSet(table->timestamp_field->field_index);
193
193
    }
194
194
  }
195
195
  return 0;
276
276
                           false,
277
277
                           (fields.elements || !value_count ||
278
278
                            (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->abort_on_warning= 0;
285
 
    DRIZZLE_INSERT_DONE(1, 0);
286
 
    return true;
287
 
  }
 
279
    goto abort;
288
280
 
289
281
  /* mysql_prepare_insert set table_list->table if it was not set */
290
282
  table= table_list->table;
315
307
    if (values->elements != value_count)
316
308
    {
317
309
      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->abort_on_warning= 0;
324
 
      DRIZZLE_INSERT_DONE(1, 0);
325
 
 
326
 
      return true;
 
310
      goto abort;
327
311
    }
328
312
    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->abort_on_warning= 0;
335
 
      DRIZZLE_INSERT_DONE(1, 0);
336
 
      return true;
337
 
    }
 
313
      goto abort;
338
314
  }
339
315
  its.rewind ();
340
316
 
478
454
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
479
455
 
480
456
  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->abort_on_warning= 0;
487
 
    DRIZZLE_INSERT_DONE(1, 0);
488
 
    return true;
489
 
  }
490
 
 
 
457
    goto abort;
491
458
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
459
                                    !session->cuted_fields))
493
460
  {
511
478
  session->status_var.inserted_row_count+= session->row_count_func;
512
479
  session->abort_on_warning= 0;
513
480
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
514
 
 
515
481
  return false;
 
482
 
 
483
abort:
 
484
  if (table != NULL)
 
485
    table->cursor->ha_release_auto_increment();
 
486
  if (!joins_freed)
 
487
    free_underlaid_joins(session, &session->lex->select_lex);
 
488
  session->abort_on_warning= 0;
 
489
  DRIZZLE_INSERT_DONE(1, 0);
 
490
  return true;
516
491
}
517
492
 
518
493
 
846
821
          table->cursor->adjust_next_insert_id_after_explicit_value(
847
822
            table->next_number_field->val_int());
848
823
        info->touched++;
849
 
 
850
 
        if (! table->records_are_comparable() || table->compare_records())
 
824
        if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
825
            ! table->write_set->is_subset_of(*table->read_set)) ||
 
826
            table->compare_record())
851
827
        {
852
828
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
853
829
                                                table->getInsertRecord())) &&
1503
1479
      create_info->table_existed= 1;            // Mark that table existed
1504
1480
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1505
1481
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1506
 
                          create_table->getTableName());
 
1482
                          create_table->table_name);
1507
1483
      return create_table->table;
1508
1484
    }
1509
1485
 
1510
 
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1486
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1511
1487
    return NULL;
1512
1488
  }
1513
1489
 
1592
1568
          or it was created via different mysqld front-end to the
1593
1569
          cluster. We don't have much options but throw an error.
1594
1570
        */
1595
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1571
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1596
1572
        return NULL;
1597
1573
      }
1598
1574
 
1599
1575
      if (not identifier.isTmp())
1600
1576
      {
1601
 
        /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1602
 
        boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
1603
 
 
1604
 
        if (create_table->table)
 
1577
        LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1578
        if (session->reopen_name_locked_table(create_table))
1605
1579
        {
1606
 
          table::Concurrent *concurrent_table= static_cast<table::Concurrent *>(create_table->table);
1607
 
 
1608
 
          if (concurrent_table->reopen_name_locked_table(create_table, session))
1609
 
          {
1610
 
            plugin::StorageEngine::dropTable(*session, identifier);
1611
 
          }
1612
 
          else
1613
 
          {
1614
 
            table= create_table->table;
1615
 
          }
 
1580
          quick_rm_table(*session, identifier);
1616
1581
        }
1617
1582
        else
1618
1583
        {
1619
 
          plugin::StorageEngine::dropTable(*session, identifier);
 
1584
          table= create_table->table;
1620
1585
        }
 
1586
        LOCK_open.unlock();
1621
1587
      }
1622
1588
      else
1623
1589
      {
1630
1596
            it preparable for open. But let us do close_temporary_table() here
1631
1597
            just in case.
1632
1598
          */
1633
 
          session->drop_temporary_table(identifier);
 
1599
          session->drop_temporary_table(create_table);
1634
1600
        }
1635
1601
      }
1636
1602
    }
1639
1605
  }
1640
1606
 
1641
1607
  table->reginfo.lock_type=TL_WRITE;
1642
 
  if (! ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
 
1608
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
 
1609
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
1643
1610
  {
1644
1611
    if (*lock)
1645
1612
    {
1646
 
      session->unlockTables(*lock);
 
1613
      mysql_unlock_tables(session, *lock);
1647
1614
      *lock= 0;
1648
1615
    }
1649
1616
 
1704
1671
 
1705
1672
  /* Mark all fields that are given values */
1706
1673
  for (Field **f= field ; *f ; f++)
1707
 
  {
1708
 
    table->setWriteSet((*f)->position());
1709
 
  }
 
1674
    table->setWriteSet((*f)->field_index);
1710
1675
 
1711
1676
  /* Don't set timestamp if used */
1712
1677
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1777
1742
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1778
1743
    if (m_plock)
1779
1744
    {
1780
 
      session->unlockTables(*m_plock);
 
1745
      mysql_unlock_tables(session, *m_plock);
1781
1746
      *m_plock= NULL;
1782
1747
      m_plock= NULL;
1783
1748
    }
1807
1772
 
1808
1773
  if (m_plock)
1809
1774
  {
1810
 
    session->unlockTables(*m_plock);
 
1775
    mysql_unlock_tables(session, *m_plock);
1811
1776
    *m_plock= NULL;
1812
1777
    m_plock= NULL;
1813
1778
  }