~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
458
458
  {
459
459
    char buff[160];
460
460
    if (ignore)
461
 
      sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 
461
      snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
462
462
              (ulong) (info.records - info.copied), (ulong) session->cuted_fields);
463
463
    else
464
 
      sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 
464
      snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
465
465
              (ulong) (info.deleted + info.updated), (ulong) session->cuted_fields);
466
466
    session->row_count_func= info.copied + info.deleted + info.updated;
467
467
    session->my_ok((ulong) session->row_count_func,
1325
1325
  {
1326
1326
    /*
1327
1327
      We must invalidate the table in the query cache before binlog writing
1328
 
      and ha_autocommit_or_rollback.
 
1328
      and autocommitOrRollback.
1329
1329
    */
1330
1330
    if (session->transaction.stmt.hasModifiedNonTransData())
1331
1331
      session->transaction.all.markModifiedNonTransData();
1343
1343
  }
1344
1344
  char buff[160];
1345
1345
  if (info.ignore)
1346
 
    sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 
1346
    snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
1347
1347
            (ulong) (info.records - info.copied), (ulong) session->cuted_fields);
1348
1348
  else
1349
 
    sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 
1349
    snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
1350
1350
            (ulong) (info.deleted+info.updated), (ulong) session->cuted_fields);
1351
1351
  session->row_count_func= info.copied + info.deleted + info.updated;
1352
1352
 
1458
1458
                                      AlterInfo *alter_info,
1459
1459
                                      List<Item> *items,
1460
1460
                                      bool is_if_not_exists,
1461
 
                                      DRIZZLE_LOCK **lock)
 
1461
                                      DRIZZLE_LOCK **lock,
 
1462
                                      TableIdentifier &identifier)
1462
1463
{
1463
1464
  Table tmp_table;              // Used during 'CreateField()'
1464
1465
  TableShare share;
1470
1471
  Field *tmp_field;
1471
1472
  bool not_used;
1472
1473
 
1473
 
  bool lex_identified_temp_table= (table_proto.type() == message::Table::TEMPORARY);
1474
 
 
1475
 
  if (not (lex_identified_temp_table) &&
1476
 
      create_table->table->db_stat)
 
1474
  if (not (identifier.isTmp()) && create_table->table->db_stat)
1477
1475
  {
1478
1476
    /* Table already exists and was open at openTablesLock() stage. */
1479
1477
    if (is_if_not_exists)
1527
1525
    alter_info->create_list.push_back(cr_field);
1528
1526
  }
1529
1527
 
1530
 
  TableIdentifier identifier(create_table->db,
1531
 
                             create_table->table_name,
1532
 
                             lex_identified_temp_table ?  TEMP_TABLE :
1533
 
                             STANDARD_TABLE);
1534
 
 
1535
 
 
1536
1528
  /*
1537
1529
    Create and lock table.
1538
1530
 
1542
1534
  */
1543
1535
  {
1544
1536
    if (not mysql_create_table_no_lock(session,
1545
 
                                    identifier,
1546
 
                                    create_info,
1547
 
                                    table_proto,
1548
 
                                    alter_info,
1549
 
                                    false,
1550
 
                                    select_field_count,
1551
 
                                    is_if_not_exists))
 
1537
                                       identifier,
 
1538
                                       create_info,
 
1539
                                       table_proto,
 
1540
                                       alter_info,
 
1541
                                       false,
 
1542
                                       select_field_count,
 
1543
                                       is_if_not_exists))
1552
1544
    {
1553
 
      if (create_info->table_existed &&
1554
 
          !(lex_identified_temp_table))
 
1545
      if (create_info->table_existed && not identifier.isTmp())
1555
1546
      {
1556
1547
        /*
1557
1548
          This means that someone created table underneath server
1562
1553
        return NULL;
1563
1554
      }
1564
1555
 
1565
 
      if (not lex_identified_temp_table)
 
1556
      if (not identifier.isTmp())
1566
1557
      {
1567
1558
        pthread_mutex_lock(&LOCK_open); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1568
1559
        if (session->reopen_name_locked_table(create_table, false))
1602
1593
      *lock= 0;
1603
1594
    }
1604
1595
 
1605
 
    if (!create_info->table_existed)
1606
 
      session->drop_open_table(table, create_table->db, create_table->table_name);
 
1596
    if (not create_info->table_existed)
 
1597
      session->drop_open_table(table, identifier);
1607
1598
    return NULL;
1608
1599
  }
1609
1600
 
1614
1605
int
1615
1606
select_create::prepare(List<Item> &values, Select_Lex_Unit *u)
1616
1607
{
1617
 
  bool lex_identified_temp_table= (table_proto.type() == message::Table::TEMPORARY);
1618
 
 
1619
1608
  DRIZZLE_LOCK *extra_lock= NULL;
1620
1609
  /*
1621
1610
    For replication, the CREATE-SELECT statement is written
1629
1618
 
1630
1619
  unit= u;
1631
1620
 
1632
 
  if (!(table= create_table_from_items(session, create_info, create_table,
1633
 
                                       table_proto,
1634
 
                                       alter_info, &values,
1635
 
                                       is_if_not_exists,
1636
 
                                       &extra_lock)))
 
1621
  if (not (table= create_table_from_items(session, create_info, create_table,
 
1622
                                          table_proto,
 
1623
                                          alter_info, &values,
 
1624
                                          is_if_not_exists,
 
1625
                                          &extra_lock, identifier)))
1637
1626
    return(-1);                         // abort() deletes table
1638
1627
 
1639
1628
  if (extra_lock)
1640
1629
  {
1641
1630
    assert(m_plock == NULL);
1642
1631
 
1643
 
    if (lex_identified_temp_table)
 
1632
    if (identifier.isTmp())
1644
1633
      m_plock= &m_lock;
1645
1634
    else
1646
1635
      m_plock= &session->extra_lock;
1722
1711
    if (!table->s->tmp_table)
1723
1712
    {
1724
1713
      TransactionServices &transaction_services= TransactionServices::singleton();
1725
 
      transaction_services.ha_autocommit_or_rollback(session, 0);
 
1714
      transaction_services.autocommitOrRollback(session, 0);
1726
1715
      (void) session->endActiveTransaction();
1727
1716
    }
1728
1717
 
1769
1758
  {
1770
1759
    table->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1771
1760
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1772
 
    if (!create_info->table_existed)
1773
 
      session->drop_open_table(table, create_table->db, create_table->table_name);
 
1761
    if (not create_info->table_existed)
 
1762
      session->drop_open_table(table, identifier);
1774
1763
    table= NULL;                                    // Safety
1775
1764
  }
1776
1765
}