~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-10-19 22:17:17 UTC
  • mto: (1864.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1864.
  • Revision ID: brian@tangent.org-20101019221717-clg9disnr5tm2ddg
We add a "shell" table type, used only during field creation.

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;             // Used during 'CreateField()'
 
1492
    tmp_table.timestamp_field= 0;
 
1493
    tmp_table.setShare(&share);
 
1494
 
 
1495
    tmp_table.getMutableShare()->db_create_options= 0;
 
1496
    tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1497
 
 
1498
    if (not table_proto.engine().name().compare("MyISAM"))
 
1499
      tmp_table.getMutableShare()->db_low_byte_first= true;
 
1500
    else if (not table_proto.engine().name().compare("MEMORY"))
 
1501
      tmp_table.getMutableShare()->db_low_byte_first= true;
 
1502
 
 
1503
    tmp_table.null_row= false;
 
1504
    tmp_table.maybe_null= false;
 
1505
 
 
1506
    tmp_table.in_use= session;
 
1507
 
 
1508
    while ((item=it++))
1511
1509
    {
1512
 
      if (item->result_type() != STRING_RESULT)
 
1510
      CreateField *cr_field;
 
1511
      Field *field, *def_field;
 
1512
      if (item->type() == Item::FUNC_ITEM)
1513
1513
      {
1514
 
        field= item->tmp_table_field(&tmp_table);
 
1514
        if (item->result_type() != STRING_RESULT)
 
1515
        {
 
1516
          field= item->tmp_table_field(&tmp_table);
 
1517
        }
 
1518
        else
 
1519
        {
 
1520
          field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1521
        }
1515
1522
      }
1516
1523
      else
1517
1524
      {
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);
 
1525
        field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1526
                                (Item ***) 0, &tmp_field, &def_field, false,
 
1527
                                false, false, 0);
 
1528
      }
 
1529
 
 
1530
      if (!field ||
 
1531
          !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1532
                                            ((Item_field *)item)->field :
 
1533
                                            (Field*) 0))))
 
1534
      {
 
1535
        return NULL;
 
1536
      }
 
1537
 
 
1538
      if (item->maybe_null)
 
1539
      {
 
1540
        cr_field->flags &= ~NOT_NULL_FLAG;
 
1541
      }
 
1542
 
 
1543
      alter_info->create_list.push_back(cr_field);
 
1544
    }
1542
1545
  }
1543
1546
 
1544
1547
  /*
1548
1551
    creating base table on which name we have exclusive lock. So code below
1549
1552
    should not cause deadlocks or races.
1550
1553
  */
 
1554
  Table *table= 0;
1551
1555
  {
1552
1556
    if (not mysql_create_table_no_lock(session,
1553
1557
                                       identifier,
1597
1601
        }
1598
1602
      }
1599
1603
    }
1600
 
    if (!table)                                   // open failed
 
1604
    if (not table)                                   // open failed
1601
1605
      return NULL;
1602
1606
  }
1603
1607