~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
35
37
namespace drizzled
36
38
{
37
39
 
1461
1463
                                      DrizzleLock **lock,
1462
1464
                                      TableIdentifier &identifier)
1463
1465
{
1464
 
  Table tmp_table;              // Used during 'CreateField()'
1465
1466
  TableShare share(message::Table::INTERNAL);
1466
 
  Table *table= 0;
1467
1467
  uint32_t select_field_count= items->elements;
1468
1468
  /* Add selected items to field list */
1469
1469
  List_iterator_fast<Item> it(*items);
1487
1487
    return NULL;
1488
1488
  }
1489
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++))
1507
1490
  {
1508
 
    CreateField *cr_field;
1509
 
    Field *field, *def_field;
1510
 
    if (item->type() == Item::FUNC_ITEM)
 
1491
    table::Shell tmp_table(share);              // Used during 'CreateField()'
 
1492
    tmp_table.timestamp_field= 0;
 
1493
 
 
1494
    tmp_table.getMutableShare()->db_create_options= 0;
 
1495
    tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1496
 
 
1497
    if (not table_proto.engine().name().compare("MyISAM"))
 
1498
      tmp_table.getMutableShare()->db_low_byte_first= true;
 
1499
    else if (not table_proto.engine().name().compare("MEMORY"))
 
1500
      tmp_table.getMutableShare()->db_low_byte_first= true;
 
1501
 
 
1502
    tmp_table.null_row= false;
 
1503
    tmp_table.maybe_null= false;
 
1504
 
 
1505
    tmp_table.in_use= session;
 
1506
 
 
1507
    while ((item=it++))
1511
1508
    {
1512
 
      if (item->result_type() != STRING_RESULT)
 
1509
      CreateField *cr_field;
 
1510
      Field *field, *def_field;
 
1511
      if (item->type() == Item::FUNC_ITEM)
1513
1512
      {
1514
 
        field= item->tmp_table_field(&tmp_table);
 
1513
        if (item->result_type() != STRING_RESULT)
 
1514
        {
 
1515
          field= item->tmp_table_field(&tmp_table);
 
1516
        }
 
1517
        else
 
1518
        {
 
1519
          field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1520
        }
1515
1521
      }
1516
1522
      else
1517
1523
      {
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);
 
1524
        field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1525
                                (Item ***) 0, &tmp_field, &def_field, false,
 
1526
                                false, false, 0);
 
1527
      }
 
1528
 
 
1529
      if (!field ||
 
1530
          !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1531
                                            ((Item_field *)item)->field :
 
1532
                                            (Field*) 0))))
 
1533
      {
 
1534
        return NULL;
 
1535
      }
 
1536
 
 
1537
      if (item->maybe_null)
 
1538
      {
 
1539
        cr_field->flags &= ~NOT_NULL_FLAG;
 
1540
      }
 
1541
 
 
1542
      alter_info->create_list.push_back(cr_field);
 
1543
    }
1542
1544
  }
1543
1545
 
1544
1546
  /*
1548
1550
    creating base table on which name we have exclusive lock. So code below
1549
1551
    should not cause deadlocks or races.
1550
1552
  */
 
1553
  Table *table= 0;
1551
1554
  {
1552
1555
    if (not mysql_create_table_no_lock(session,
1553
1556
                                       identifier,
1572
1575
      if (not identifier.isTmp())
1573
1576
      {
1574
1577
        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))
 
1578
        if (session->reopen_name_locked_table(create_table))
1576
1579
        {
1577
1580
          quick_rm_table(*session, identifier);
1578
1581
        }
1579
1582
        else
 
1583
        {
1580
1584
          table= create_table->table;
 
1585
        }
1581
1586
        LOCK_open.unlock();
1582
1587
      }
1583
1588
      else
1595
1600
        }
1596
1601
      }
1597
1602
    }
1598
 
    if (!table)                                   // open failed
 
1603
    if (not table)                                   // open failed
1599
1604
      return NULL;
1600
1605
  }
1601
1606