~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/embedded_innodb/embedded_innodb_engine.cc

  • Committer: Joseph Daly
  • Date: 2010-09-28 01:43:36 UTC
  • mfrom: (1799 staging)
  • mto: (1799.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1800.
  • Revision ID: jdaly@rx7-20100928014336-wxjexq5c8js3cs8v
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
 
82
82
#include <string>
83
83
#include <boost/algorithm/string.hpp>
 
84
#include <boost/unordered_set.hpp>
 
85
#include <boost/foreach.hpp>
84
86
#include <map>
85
87
#include <fstream>
86
88
#include <drizzled/message/table.pb.h>
130
132
const char INNODB_TABLE_DEFINITIONS_TABLE[]= "data_dictionary/innodb_table_definitions";
131
133
const string statement_savepoint_name("STATEMENT");
132
134
 
 
135
static boost::unordered_set<std::string> innodb_system_table_names;
 
136
 
133
137
 
134
138
static const char *EmbeddedInnoDBCursor_exts[] = {
135
139
  NULL
698
702
static const char* table_path_to_innodb_name(const char* name)
699
703
{
700
704
  size_t l= strlen(name);
 
705
  static string datadict_path("data_dictionary/");
 
706
  static string sys_prefix("data_dictionary/innodb_");
 
707
  static string sys_table_prefix("INNODB_");
 
708
 
 
709
  if (strncmp(name, sys_prefix.c_str(), sys_prefix.length()) == 0)
 
710
  {
 
711
    string find_name(name+datadict_path.length());
 
712
    std::transform(find_name.begin(), find_name.end(), find_name.begin(), ::toupper);
 
713
    boost::unordered_set<string>::iterator iter= innodb_system_table_names.find(find_name);
 
714
    if (iter != innodb_system_table_names.end())
 
715
      return (*iter).c_str()+sys_table_prefix.length();
 
716
  }
701
717
 
702
718
  int slashes= 2;
703
719
  while(slashes>0 && l > 0)
834
850
                                  column_attr, 0, sizeof(double));
835
851
    break;
836
852
  case message::Table::Field::ENUM:
837
 
  {
838
 
    message::Table::Field::EnumerationValues field_options=
839
 
      field.enumeration_values();
840
 
 
841
 
    if (field_options.field_value_size() <= 256)
842
 
      *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
843
 
                                    column_attr, 0, 1);
844
 
    else if (field_options.field_value_size() > 256)
845
 
      *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
846
 
                                    column_attr, 0, 2);
847
 
    else
848
 
    {
849
 
      assert(field_options.field_value_size() <= Field_enum::max_supported_elements);
850
 
    }
 
853
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
 
854
                                  column_attr, 0, 4);
851
855
    break;
852
 
  }
853
856
  case message::Table::Field::DATE:
854
857
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
855
858
                                  column_attr, 0, 4);
1457
1460
  ib_err_t innodb_err= ib_schema_lock_exclusive(transaction);
1458
1461
  assert(innodb_err == DB_SUCCESS); /* FIXME: doGetTableNames needs to be able to return error */
1459
1462
 
 
1463
  if (search_string.compare("data_dictionary/") == 0)
 
1464
  {
 
1465
    if (set_of_names)
 
1466
    {
 
1467
      BOOST_FOREACH(std::string table_name, innodb_system_table_names)
 
1468
      {
 
1469
        set_of_names->insert(table_name);
 
1470
      }
 
1471
    }
 
1472
    if (identifiers)
 
1473
    {
 
1474
      BOOST_FOREACH(std::string table_name, innodb_system_table_names)
 
1475
      {
 
1476
        identifiers->push_back(TableIdentifier(schema.getSchemaName(),
 
1477
                                               table_name));
 
1478
      }
 
1479
    }
 
1480
  }
1460
1481
 
1461
1482
  innodb_err= ib_cursor_open_table("SYS_TABLES", transaction, &cursor);
1462
1483
  assert(innodb_err == DB_SUCCESS); /* FIXME */
1659
1680
 
1660
1681
  assert (err == DB_SUCCESS);
1661
1682
 
1662
 
  read_table_message_from_innodb(innodb_table_name.c_str(), &table);
 
1683
  if (read_table_message_from_innodb(innodb_table_name.c_str(), &table) != 0)
 
1684
  {
 
1685
    if (get_innodb_system_table_message(innodb_table_name.c_str(), &table) == 0)
 
1686
      return EEXIST;
 
1687
  }
1663
1688
 
1664
1689
  return EEXIST;
1665
1690
}
1672
1697
 
1673
1698
  TableIdentifier_to_innodb_name(identifier, &innodb_table_name);
1674
1699
 
 
1700
  boost::unordered_set<string>::iterator iter= innodb_system_table_names.find(identifier.getTableName());
 
1701
  if (iter != innodb_system_table_names.end())
 
1702
    return true;
 
1703
 
1675
1704
  if (ib_cursor_open_table(innodb_table_name.c_str(), NULL, &innodb_cursor) != DB_SUCCESS)
1676
1705
    return false;
1677
1706
 
1716
1745
    }
1717
1746
    else if ((**field).type() == DRIZZLE_TYPE_ENUM)
1718
1747
    {
1719
 
      if ((*field)->data_length() == 1)
1720
 
        err= ib_tuple_write_u8(tuple, colnr, *((ib_u8_t*)(*field)->ptr));
1721
 
      else if ((*field)->data_length() == 2)
1722
 
        err= ib_tuple_write_u16(tuple, colnr, *((ib_u16_t*)(*field)->ptr));
1723
 
      else
1724
 
      {
1725
 
        assert((*field)->data_length() <= 2);
1726
 
      }
 
1748
      err= ib_tuple_write_u32(tuple, colnr, *((ib_u32_t*)(*field)->ptr));
1727
1749
    }
1728
1750
    else if ((**field).type() == DRIZZLE_TYPE_DATE)
1729
1751
    {
2750
2772
 
2751
2773
static int embedded_innodb_init(drizzled::module::Context &context)
2752
2774
{
 
2775
  innodb_system_table_names.insert(std::string("INNODB_SYS_TABLES"));
 
2776
  innodb_system_table_names.insert(std::string("INNODB_SYS_COLUMNS"));
 
2777
  innodb_system_table_names.insert(std::string("INNODB_SYS_INDEXES"));
 
2778
  innodb_system_table_names.insert(std::string("INNODB_SYS_FIELDS"));
 
2779
  innodb_system_table_names.insert(std::string("INNODB_SYS_FOREIGN"));
 
2780
  innodb_system_table_names.insert(std::string("INNODB_SYS_FOREIGN_COLS"));
2753
2781
 
2754
2782
  const module::option_map &vm= context.getOptions();
2755
2783