~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance/base.cc

  • Committer: Andrew Hutchings
  • Date: 2011-02-07 17:20:59 UTC
  • mfrom: (2148 staging)
  • mto: (2148.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 2149.
  • Revision ID: andrew@linuxjedi.co.uk-20110207172059-dyeahrgzrlincoe3
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "drizzled/sql_base.h"
43
43
#include "drizzled/pthread_globals.h"
44
44
#include "drizzled/internal/my_pthread.h"
45
 
#include "drizzled/plugin/event_observer.h"
46
45
 
47
46
#include "drizzled/table.h"
48
47
#include "drizzled/table/shell.h"
286
285
  blob_ptr_size(portable_sizeof_char_ptr),
287
286
  db_low_byte_first(false),
288
287
  keys_in_use(0),
289
 
  keys_for_keyread(0),
290
 
  event_observers(NULL)
 
288
  keys_for_keyread(0)
291
289
{
292
290
  if (type_arg == message::Table::INTERNAL)
293
291
  {
349
347
  blob_ptr_size(portable_sizeof_char_ptr),
350
348
  db_low_byte_first(false),
351
349
  keys_in_use(0),
352
 
  keys_for_keyread(0),
353
 
  event_observers(NULL)
 
350
  keys_for_keyread(0)
354
351
{
355
352
  assert(identifier.getKey() == key);
356
353
 
425
422
  blob_ptr_size(portable_sizeof_char_ptr),
426
423
  db_low_byte_first(false),
427
424
  keys_in_use(0),
428
 
  keys_for_keyread(0),
429
 
  event_observers(NULL)
 
425
  keys_for_keyread(0)
430
426
{
431
427
  private_key_for_cache= identifier.getKey();
432
428
  assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
502
498
  blob_ptr_size(portable_sizeof_char_ptr),
503
499
  db_low_byte_first(false),
504
500
  keys_in_use(0),
505
 
  keys_for_keyread(0),
506
 
  event_observers(NULL)
 
501
  keys_for_keyread(0)
507
502
{
508
503
  char *path_buff;
509
504
  std::string _path;
561
556
{
562
557
  storage_engine= NULL;
563
558
 
564
 
  plugin::EventObserver::deregisterTableEvents(*this);
565
 
 
566
559
  mem_root.free_root(MYF(0));                 // Free's share
567
560
}
568
561
 
583
576
  getTableMessage()->set_schema(identifier_arg.getSchemaName());
584
577
}
585
578
 
586
 
int TableShare::inner_parse_table_proto(Session& session, message::Table &table)
 
579
bool TableShare::parse_table_proto(Session& session, message::Table &table)
587
580
{
588
 
  int local_error= 0;
 
581
  drizzled::error_t local_error= EE_OK;
589
582
 
590
583
  if (! table.IsInitialized())
591
584
  {
1064
1057
      {
1065
1058
        if (fo.scale() > DECIMAL_MAX_SCALE)
1066
1059
        {
1067
 
          local_error= 4;
 
1060
          local_error= ER_NOT_FORM_FILE;
1068
1061
 
1069
 
          return local_error;
 
1062
          return true;
1070
1063
        }
1071
1064
        decimals= static_cast<uint8_t>(fo.scale());
1072
1065
      }
1120
1113
            decimals != NOT_FIXED_DEC)
1121
1114
        {
1122
1115
          my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1123
 
          local_error= 1;
1124
 
 
1125
 
          return local_error;
 
1116
          local_error= ER_M_BIGGER_THAN_D;
 
1117
          return true;
1126
1118
        }
1127
1119
        break;
1128
1120
      }
1261
1253
      if (res != 0 && res != 3) /* @TODO Huh? */
1262
1254
      {
1263
1255
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1264
 
        local_error= 1;
 
1256
        local_error= ER_INVALID_DEFAULT;
1265
1257
 
1266
 
        return local_error;
 
1258
        return true;
1267
1259
      }
1268
1260
    }
1269
1261
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1475
1467
                            &next_number_keypart)) < 0)
1476
1468
    {
1477
1469
      /* Wrong field definition */
1478
 
      local_error= 4;
 
1470
      local_error= ER_NOT_FORM_FILE;
1479
1471
 
1480
 
      return local_error;
 
1472
      return true;
1481
1473
    }
1482
1474
    else
1483
1475
    {
1502
1494
  all_set.resize(_field_size);
1503
1495
  all_set.set();
1504
1496
 
1505
 
  return local_error;
1506
 
}
1507
 
 
1508
 
int TableShare::parse_table_proto(Session& session, message::Table &table)
1509
 
{
1510
 
  int local_error= inner_parse_table_proto(session, table);
1511
 
 
1512
 
  if (not local_error)
1513
 
    return 0;
1514
 
 
1515
 
  error= local_error;
1516
 
  open_errno= errno;
1517
 
  errarg= 0;
1518
 
  open_table_error(local_error, open_errno, 0);
1519
 
 
1520
 
  return local_error;
1521
 
}
1522
 
 
 
1497
  return local_error != EE_OK;
 
1498
}
1523
1499
 
1524
1500
/*
1525
1501
  Read table definition from a binary / text based .frm cursor
1547
1523
 
1548
1524
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
1549
1525
{
1550
 
  int local_error;
1551
 
  bool error_given;
1552
 
 
1553
 
  local_error= 1;
1554
 
  error_given= 0;
1555
 
 
1556
 
  message::table::shared_ptr table;
1557
 
 
1558
 
  local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
1559
 
 
1560
 
  do {
1561
 
    if (local_error != EEXIST)
1562
 
    {
1563
 
      if (local_error > 0)
1564
 
      {
1565
 
        errno= local_error;
1566
 
        local_error= 1;
1567
 
      }
1568
 
      else
1569
 
      {
1570
 
        if (not table->IsInitialized())
1571
 
        {
1572
 
          local_error= 4;
1573
 
        }
1574
 
      }
1575
 
      break;
1576
 
    }
1577
 
 
1578
 
    local_error= parse_table_proto(session, *table);
1579
 
 
1580
 
    setTableCategory(TABLE_CATEGORY_USER);
1581
 
  } while (0);
1582
 
 
1583
 
  if (local_error && !error_given)
1584
 
  {
1585
 
    error= local_error;
1586
 
    open_table_error(error, (open_errno= errno), 0);
1587
 
  }
1588
 
 
1589
 
  return(error);
 
1526
  drizzled::error_t local_error= EE_OK;
 
1527
 
 
1528
  message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
 
1529
 
 
1530
  if (table and table->IsInitialized())
 
1531
  {
 
1532
    if (parse_table_proto(session, *table))
 
1533
    {
 
1534
      local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
 
1535
      my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
 
1536
    }
 
1537
    else
 
1538
    {
 
1539
      setTableCategory(TABLE_CATEGORY_USER);
 
1540
      local_error= EE_OK;
 
1541
    }
 
1542
  }
 
1543
  else if (table and not table->IsInitialized())
 
1544
  {
 
1545
    local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
 
1546
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
 
1547
  }
 
1548
  else
 
1549
  {
 
1550
    local_error= ER_TABLE_UNKNOWN;
 
1551
    my_error(ER_TABLE_UNKNOWN, identifier);
 
1552
  }
 
1553
 
 
1554
  return static_cast<int>(local_error);
1590
1555
}
1591
1556
 
1592
1557
 
1840
1805
  case 1:
1841
1806
    if (db_errno == ENOENT)
1842
1807
    {
1843
 
      my_error(ER_NO_SUCH_TABLE, MYF(0), db.str, table_name.str);
 
1808
      identifier::Table identifier(db.str, table_name.str);
 
1809
      my_error(ER_TABLE_UNKNOWN, identifier);
1844
1810
    }
1845
1811
    else
1846
1812
    {
1971
1937
                                      field_charset);
1972
1938
  case DRIZZLE_TYPE_BLOB:
1973
1939
    return new (&mem_root) Field_blob(ptr,
1974
 
                                 null_pos,
1975
 
                                 null_bit,
1976
 
                                 field_name,
1977
 
                                 this,
1978
 
                                 field_charset);
 
1940
                                      null_pos,
 
1941
                                      null_bit,
 
1942
                                      field_name,
 
1943
                                      this,
 
1944
                                      field_charset);
1979
1945
  case DRIZZLE_TYPE_DECIMAL:
1980
1946
    return new (&mem_root) Field_decimal(ptr,
1981
 
                                    field_length,
1982
 
                                    null_pos,
1983
 
                                    null_bit,
1984
 
                                    unireg_check,
1985
 
                                    field_name,
1986
 
                                    decimals);
 
1947
                                         field_length,
 
1948
                                         null_pos,
 
1949
                                         null_bit,
 
1950
                                         unireg_check,
 
1951
                                         field_name,
 
1952
                                         decimals);
1987
1953
  case DRIZZLE_TYPE_DOUBLE:
1988
1954
    return new (&mem_root) Field_double(ptr,
1989
1955
                                   field_length,