~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.cc

  • Committer: Brian Aker
  • Date: 2010-12-19 06:20:54 UTC
  • mfrom: (2005.1.1 bug673105)
  • Revision ID: brian@tangent.org-20101219062054-1kt0l3dxs4z2z8md
Merge Dave.

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"
45
46
 
46
47
#include "drizzled/table.h"
47
48
#include "drizzled/table/shell.h"
63
64
#include "drizzled/field/str.h"
64
65
#include "drizzled/field/num.h"
65
66
#include "drizzled/field/blob.h"
66
 
#include "drizzled/field/boolean.h"
67
67
#include "drizzled/field/enum.h"
68
68
#include "drizzled/field/null.h"
69
69
#include "drizzled/field/date.h"
72
72
#include "drizzled/field/double.h"
73
73
#include "drizzled/field/int32.h"
74
74
#include "drizzled/field/int64.h"
75
 
#include "drizzled/field/size.h"
76
75
#include "drizzled/field/num.h"
77
 
#include "drizzled/field/time.h"
78
 
#include "drizzled/field/epoch.h"
 
76
#include "drizzled/field/timestamp.h"
79
77
#include "drizzled/field/datetime.h"
80
 
#include "drizzled/field/microtime.h"
81
78
#include "drizzled/field/varstring.h"
82
79
#include "drizzled/field/uuid.h"
83
80
 
84
 
#include "drizzled/plugin/storage_engine.h"
85
 
 
86
81
#include "drizzled/definition/cache.h"
87
82
 
88
 
#include <drizzled/refresh_version.h>
89
 
 
90
83
using namespace std;
91
84
 
92
85
namespace drizzled
94
87
 
95
88
extern size_t table_def_size;
96
89
 
97
 
 
98
 
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
99
 
{
100
 
  switch(field.type())
 
90
/*****************************************************************************
 
91
  Functions to handle table definition cach (TableShare)
 
92
 *****************************************************************************/
 
93
 
 
94
/*
 
95
  Mark that we are not using table share anymore.
 
96
 
 
97
  SYNOPSIS
 
98
  release()
 
99
  share         Table share
 
100
 
 
101
  IMPLEMENTATION
 
102
  If ref_count goes to zero and (we have done a refresh or if we have
 
103
  already too many open table shares) then delete the definition.
 
104
*/
 
105
 
 
106
void TableShare::release(TableShare *share)
 
107
{
 
108
  bool to_be_deleted= false;
 
109
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
110
 
 
111
  share->lock();
 
112
  if (!--share->ref_count)
 
113
  {
 
114
    to_be_deleted= true;
 
115
  }
 
116
  share->unlock();
 
117
 
 
118
  if (to_be_deleted)
 
119
  {
 
120
    definition::Cache::singleton().erase(share->getCacheKey());
 
121
  }
 
122
}
 
123
 
 
124
void TableShare::release(TableShare::shared_ptr &share)
 
125
{
 
126
  bool to_be_deleted= false;
 
127
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
128
 
 
129
  share->lock();
 
130
  if (!--share->ref_count)
 
131
  {
 
132
    to_be_deleted= true;
 
133
  }
 
134
  share->unlock();
 
135
 
 
136
  if (to_be_deleted)
 
137
  {
 
138
    definition::Cache::singleton().erase(share->getCacheKey());
 
139
  }
 
140
}
 
141
 
 
142
void TableShare::release(const TableIdentifier &identifier)
 
143
{
 
144
  TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
 
145
  if (share)
 
146
  {
 
147
    share->version= 0;                          // Mark for delete
 
148
    if (share->ref_count == 0)
 
149
    {
 
150
      definition::Cache::singleton().erase(identifier.getKey());
 
151
    }
 
152
  }
 
153
}
 
154
 
 
155
 
 
156
static TableShare::shared_ptr foundTableShare(TableShare::shared_ptr share)
 
157
{
 
158
  /*
 
159
    We found an existing table definition. Return it if we didn't get
 
160
    an error when reading the table definition from file.
 
161
  */
 
162
 
 
163
  /* We must do a lock to ensure that the structure is initialized */
 
164
  if (share->error)
 
165
  {
 
166
    /* Table definition contained an error */
 
167
    share->open_table_error(share->error, share->open_errno, share->errarg);
 
168
 
 
169
    return TableShare::shared_ptr();
 
170
  }
 
171
 
 
172
  share->incrementTableCount();
 
173
 
 
174
  return share;
 
175
}
 
176
 
 
177
/*
 
178
  Get TableShare for a table.
 
179
 
 
180
  get_table_share()
 
181
  session                       Thread handle
 
182
  table_list            Table that should be opened
 
183
  key                   Table cache key
 
184
  key_length            Length of key
 
185
  error                 out: Error code from open_table_def()
 
186
 
 
187
  IMPLEMENTATION
 
188
  Get a table definition from the table definition cache.
 
189
  If it doesn't exist, create a new from the table definition file.
 
190
 
 
191
  NOTES
 
192
  We must have wrlock on table::Cache::singleton().mutex() when we come here
 
193
  (To be changed later)
 
194
 
 
195
  RETURN
 
196
  0  Error
 
197
#  Share for table
 
198
*/
 
199
 
 
200
TableShare::shared_ptr TableShare::getShareCreate(Session *session, 
 
201
                                                  const TableIdentifier &identifier,
 
202
                                                  int &in_error)
 
203
{
 
204
  TableShare::shared_ptr share;
 
205
 
 
206
  in_error= 0;
 
207
 
 
208
  /* Read table definition from cache */
 
209
  if ((share= definition::Cache::singleton().find(identifier.getKey())))
 
210
    return foundTableShare(share);
 
211
 
 
212
  share.reset(new TableShare(message::Table::STANDARD, identifier));
 
213
  
 
214
  if (share->open_table_def(*session, identifier))
 
215
  {
 
216
    in_error= share->error;
 
217
 
 
218
    return TableShare::shared_ptr();
 
219
  }
 
220
  share->ref_count++;                           // Mark in use
 
221
  
 
222
  plugin::EventObserver::registerTableEvents(*share);
 
223
 
 
224
  bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
 
225
 
 
226
  if (not ret)
 
227
    return TableShare::shared_ptr();
 
228
 
 
229
  return share;
 
230
}
 
231
 
 
232
static enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
 
233
{
 
234
  enum_field_types field_type;
 
235
 
 
236
  switch(proto_field_type)
101
237
  {
102
238
  case message::Table::Field::INTEGER:
103
 
    return DRIZZLE_TYPE_LONG;
104
 
 
 
239
    field_type= DRIZZLE_TYPE_LONG;
 
240
    break;
105
241
  case message::Table::Field::DOUBLE:
106
 
    return DRIZZLE_TYPE_DOUBLE;
107
 
 
108
 
  case message::Table::Field::EPOCH:
109
 
    if (field.has_time_options() and field.time_options().microseconds())
110
 
      return DRIZZLE_TYPE_MICROTIME;
111
 
 
112
 
    return DRIZZLE_TYPE_TIMESTAMP;
113
 
 
 
242
    field_type= DRIZZLE_TYPE_DOUBLE;
 
243
    break;
 
244
  case message::Table::Field::TIMESTAMP:
 
245
    field_type= DRIZZLE_TYPE_TIMESTAMP;
 
246
    break;
114
247
  case message::Table::Field::BIGINT:
115
 
    return DRIZZLE_TYPE_LONGLONG;
116
 
 
 
248
    field_type= DRIZZLE_TYPE_LONGLONG;
 
249
    break;
117
250
  case message::Table::Field::DATETIME:
118
 
    return DRIZZLE_TYPE_DATETIME;
119
 
 
 
251
    field_type= DRIZZLE_TYPE_DATETIME;
 
252
    break;
120
253
  case message::Table::Field::DATE:
121
 
    return DRIZZLE_TYPE_DATE;
122
 
 
 
254
    field_type= DRIZZLE_TYPE_DATE;
 
255
    break;
123
256
  case message::Table::Field::VARCHAR:
124
 
    return DRIZZLE_TYPE_VARCHAR;
125
 
 
 
257
    field_type= DRIZZLE_TYPE_VARCHAR;
 
258
    break;
126
259
  case message::Table::Field::DECIMAL:
127
 
    return DRIZZLE_TYPE_DECIMAL;
128
 
 
 
260
    field_type= DRIZZLE_TYPE_DECIMAL;
 
261
    break;
129
262
  case message::Table::Field::ENUM:
130
 
    return DRIZZLE_TYPE_ENUM;
131
 
 
 
263
    field_type= DRIZZLE_TYPE_ENUM;
 
264
    break;
132
265
  case message::Table::Field::BLOB:
133
 
    return DRIZZLE_TYPE_BLOB;
134
 
 
 
266
    field_type= DRIZZLE_TYPE_BLOB;
 
267
    break;
135
268
  case message::Table::Field::UUID:
136
 
    return  DRIZZLE_TYPE_UUID;
137
 
 
138
 
  case message::Table::Field::BOOLEAN:
139
 
    return DRIZZLE_TYPE_BOOLEAN;
140
 
 
141
 
  case message::Table::Field::TIME:
142
 
    return DRIZZLE_TYPE_TIME;
 
269
    field_type= DRIZZLE_TYPE_UUID;
 
270
    break;
 
271
  default:
 
272
    assert(0);
 
273
    abort(); // Programming error
143
274
  }
144
275
 
145
 
  abort();
 
276
  return field_type;
146
277
}
147
278
 
148
279
static Item *default_value_item(enum_field_types field_type,
177
308
    abort();
178
309
  case DRIZZLE_TYPE_TIMESTAMP:
179
310
  case DRIZZLE_TYPE_DATETIME:
180
 
  case DRIZZLE_TYPE_TIME:
181
311
  case DRIZZLE_TYPE_DATE:
182
312
  case DRIZZLE_TYPE_ENUM:
183
313
  case DRIZZLE_TYPE_UUID:
184
 
  case DRIZZLE_TYPE_MICROTIME:
185
 
  case DRIZZLE_TYPE_BOOLEAN:
186
314
    default_item= new Item_string(default_value->c_str(),
187
315
                                  default_value->length(),
188
316
                                  system_charset_info);
221
349
 */
222
350
bool TableShare::fieldInPrimaryKey(Field *in_field) const
223
351
{
224
 
  assert(getTableMessage());
 
352
  assert(table_proto != NULL);
225
353
 
226
 
  size_t num_indexes= getTableMessage()->indexes_size();
 
354
  size_t num_indexes= table_proto->indexes_size();
227
355
 
228
356
  for (size_t x= 0; x < num_indexes; ++x)
229
357
  {
230
 
    const message::Table::Index &index= getTableMessage()->indexes(x);
 
358
    const message::Table::Index &index= table_proto->indexes(x);
231
359
    if (index.is_primary())
232
360
    {
233
361
      size_t num_parts= index.index_part_size();
241
369
  return false;
242
370
}
243
371
 
244
 
TableShare::TableShare(const identifier::Table::Type type_arg) :
 
372
TableShare::TableShare(const TableIdentifier::Type type_arg) :
245
373
  table_category(TABLE_UNKNOWN_CATEGORY),
246
374
  found_next_number_field(NULL),
247
375
  timestamp_field(NULL),
248
376
  key_info(NULL),
249
377
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
250
378
  all_set(),
251
 
  db(NULL_LEX_STRING),
252
 
  table_name(NULL_LEX_STRING),
253
 
  path(NULL_LEX_STRING),
254
 
  normalized_path(NULL_LEX_STRING),
255
379
  block_size(0),
256
380
  version(0),
257
381
  timestamp_offset(0),
258
382
  reclength(0),
259
383
  stored_rec_length(0),
260
384
  max_rows(0),
261
 
  _table_message(NULL),
 
385
  table_proto(NULL),
262
386
  storage_engine(NULL),
263
387
  tmp_table(type_arg),
264
 
  _ref_count(0),
 
388
  ref_count(0),
265
389
  null_bytes(0),
266
390
  last_null_bit_pos(0),
267
 
  _field_size(0),
 
391
  fields(0),
268
392
  rec_buff_length(0),
269
393
  keys(0),
270
394
  key_parts(0),
286
410
  error(0),
287
411
  open_errno(0),
288
412
  errarg(0),
289
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
413
  blob_ptr_size(0),
290
414
  db_low_byte_first(false),
291
415
  keys_in_use(0),
292
 
  keys_for_keyread(0)
 
416
  keys_for_keyread(0),
 
417
  event_observers(NULL)
293
418
{
 
419
 
 
420
  table_charset= 0;
 
421
  memset(&db, 0, sizeof(LEX_STRING));
 
422
  memset(&table_name, 0, sizeof(LEX_STRING));
 
423
  memset(&path, 0, sizeof(LEX_STRING));
 
424
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
425
 
294
426
  if (type_arg == message::Table::INTERNAL)
295
427
  {
296
 
    identifier::Table::build_tmptable_filename(private_key_for_cache.vectorPtr());
 
428
    TableIdentifier::build_tmptable_filename(private_key_for_cache.vectorPtr());
297
429
    init(private_key_for_cache.vector(), private_key_for_cache.vector());
298
430
  }
299
431
  else
302
434
  }
303
435
}
304
436
 
305
 
TableShare::TableShare(const identifier::Table &identifier, const identifier::Table::Key &key) :// Used by placeholder
 
437
TableShare::TableShare(const TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
306
438
  table_category(TABLE_UNKNOWN_CATEGORY),
307
439
  found_next_number_field(NULL),
308
440
  timestamp_field(NULL),
309
441
  key_info(NULL),
310
442
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
311
 
  table_charset(0),
312
443
  all_set(),
313
 
  db(NULL_LEX_STRING),
314
 
  table_name(NULL_LEX_STRING),
315
 
  path(NULL_LEX_STRING),
316
 
  normalized_path(NULL_LEX_STRING),
317
444
  block_size(0),
318
445
  version(0),
319
446
  timestamp_offset(0),
320
447
  reclength(0),
321
448
  stored_rec_length(0),
322
449
  max_rows(0),
323
 
  _table_message(NULL),
 
450
  table_proto(NULL),
324
451
  storage_engine(NULL),
325
452
  tmp_table(message::Table::INTERNAL),
326
 
  _ref_count(0),
 
453
  ref_count(0),
327
454
  null_bytes(0),
328
455
  last_null_bit_pos(0),
329
 
  _field_size(0),
 
456
  fields(0),
330
457
  rec_buff_length(0),
331
458
  keys(0),
332
459
  key_parts(0),
348
475
  error(0),
349
476
  open_errno(0),
350
477
  errarg(0),
351
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
478
  blob_ptr_size(0),
352
479
  db_low_byte_first(false),
353
480
  keys_in_use(0),
354
 
  keys_for_keyread(0)
 
481
  keys_for_keyread(0),
 
482
  event_observers(NULL)
355
483
{
356
484
  assert(identifier.getKey() == key);
357
485
 
 
486
  table_charset= 0;
 
487
  memset(&path, 0, sizeof(LEX_STRING));
 
488
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
489
 
358
490
  private_key_for_cache= key;
359
491
 
360
492
  table_category=         TABLE_CATEGORY_TEMPORARY;
377
509
}
378
510
 
379
511
 
380
 
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
 
512
TableShare::TableShare(const TableIdentifier &identifier) : // Just used during createTable()
381
513
  table_category(TABLE_UNKNOWN_CATEGORY),
382
514
  found_next_number_field(NULL),
383
515
  timestamp_field(NULL),
384
516
  key_info(NULL),
385
517
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
386
 
  table_charset(0),
387
518
  all_set(),
388
 
  db(NULL_LEX_STRING),
389
 
  table_name(NULL_LEX_STRING),
390
 
  path(NULL_LEX_STRING),
391
 
  normalized_path(NULL_LEX_STRING),
392
519
  block_size(0),
393
520
  version(0),
394
521
  timestamp_offset(0),
395
522
  reclength(0),
396
523
  stored_rec_length(0),
397
524
  max_rows(0),
398
 
  _table_message(NULL),
 
525
  table_proto(NULL),
399
526
  storage_engine(NULL),
400
527
  tmp_table(identifier.getType()),
401
 
  _ref_count(0),
 
528
  ref_count(0),
402
529
  null_bytes(0),
403
530
  last_null_bit_pos(0),
404
 
  _field_size(0),
 
531
  fields(0),
405
532
  rec_buff_length(0),
406
533
  keys(0),
407
534
  key_parts(0),
423
550
  error(0),
424
551
  open_errno(0),
425
552
  errarg(0),
426
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
553
  blob_ptr_size(0),
427
554
  db_low_byte_first(false),
428
555
  keys_in_use(0),
429
 
  keys_for_keyread(0)
 
556
  keys_for_keyread(0),
 
557
  event_observers(NULL)
430
558
{
 
559
  table_charset= 0;
 
560
  memset(&db, 0, sizeof(LEX_STRING));
 
561
  memset(&table_name, 0, sizeof(LEX_STRING));
 
562
  memset(&path, 0, sizeof(LEX_STRING));
 
563
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
564
 
431
565
  private_key_for_cache= identifier.getKey();
432
566
  assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
433
567
  private_normalized_path.resize(identifier.getPath().size() + 1);
450
584
/*
451
585
  Used for shares that will go into the cache.
452
586
*/
453
 
TableShare::TableShare(const identifier::Table::Type type_arg,
454
 
                       const identifier::Table &identifier,
 
587
TableShare::TableShare(const TableIdentifier::Type type_arg,
 
588
                       const TableIdentifier &identifier,
455
589
                       char *path_arg,
456
590
                       uint32_t path_length_arg) :
457
591
  table_category(TABLE_UNKNOWN_CATEGORY),
459
593
  timestamp_field(NULL),
460
594
  key_info(NULL),
461
595
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
462
 
  table_charset(0),
463
596
  all_set(),
464
 
  db(NULL_LEX_STRING),
465
 
  table_name(NULL_LEX_STRING),
466
 
  path(NULL_LEX_STRING),
467
 
  normalized_path(NULL_LEX_STRING),
468
597
  block_size(0),
469
598
  version(0),
470
599
  timestamp_offset(0),
471
600
  reclength(0),
472
601
  stored_rec_length(0),
473
602
  max_rows(0),
474
 
  _table_message(NULL),
 
603
  table_proto(NULL),
475
604
  storage_engine(NULL),
476
605
  tmp_table(type_arg),
477
 
  _ref_count(0),
 
606
  ref_count(0),
478
607
  null_bytes(0),
479
608
  last_null_bit_pos(0),
480
 
  _field_size(0),
 
609
  fields(0),
481
610
  rec_buff_length(0),
482
611
  keys(0),
483
612
  key_parts(0),
499
628
  error(0),
500
629
  open_errno(0),
501
630
  errarg(0),
502
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
631
  blob_ptr_size(0),
503
632
  db_low_byte_first(false),
504
633
  keys_in_use(0),
505
 
  keys_for_keyread(0)
 
634
  keys_for_keyread(0),
 
635
  event_observers(NULL)
506
636
{
 
637
  table_charset= 0;
 
638
  memset(&db, 0, sizeof(LEX_STRING));
 
639
  memset(&table_name, 0, sizeof(LEX_STRING));
 
640
  memset(&path, 0, sizeof(LEX_STRING));
 
641
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
642
 
507
643
  char *path_buff;
508
644
  std::string _path;
509
645
 
523
659
  }
524
660
  else
525
661
  {
526
 
    identifier::Table::build_table_filename(_path, db.str, table_name.str, false);
 
662
    TableIdentifier::build_table_filename(_path, db.str, table_name.str, false);
527
663
  }
528
664
 
529
665
  if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
558
694
 
559
695
TableShare::~TableShare() 
560
696
{
 
697
  assert(ref_count == 0);
 
698
 
561
699
  storage_engine= NULL;
562
700
 
 
701
  delete table_proto;
 
702
  table_proto= NULL;
 
703
 
 
704
  plugin::EventObserver::deregisterTableEvents(*this);
 
705
 
563
706
  mem_root.free_root(MYF(0));                 // Free's share
564
707
}
565
708
 
566
 
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
 
709
void TableShare::setIdentifier(const TableIdentifier &identifier_arg)
567
710
{
568
711
  private_key_for_cache= identifier_arg.getKey();
569
712
 
576
719
  table_name.str=    db.str + db.length + 1;
577
720
  table_name.length= strlen(table_name.str);
578
721
 
579
 
  getTableMessage()->set_name(identifier_arg.getTableName());
580
 
  getTableMessage()->set_schema(identifier_arg.getSchemaName());
 
722
  table_proto->set_name(identifier_arg.getTableName());
 
723
  table_proto->set_schema(identifier_arg.getSchemaName());
581
724
}
582
725
 
583
 
bool TableShare::parse_table_proto(Session& session, message::Table &table)
 
726
int TableShare::inner_parse_table_proto(Session& session, message::Table &table)
584
727
{
585
 
  drizzled::error_t local_error= EE_OK;
 
728
  int local_error= 0;
586
729
 
587
730
  if (! table.IsInitialized())
588
731
  {
589
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
590
 
             table.name().empty() ? " " :  table.name().c_str(),
591
 
             table.InitializationErrorString().c_str());
592
 
 
 
732
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table.InitializationErrorString().c_str());
593
733
    return ER_CORRUPT_TABLE_DEFINITION;
594
734
  }
595
735
 
596
 
  setTableMessage(table);
 
736
  setTableProto(new(nothrow) message::Table(table));
597
737
 
598
738
  storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
599
739
  assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
619
759
 
620
760
  table_charset= get_charset(table_options.collation_id());
621
761
 
622
 
  if (not table_charset)
 
762
  if (! table_charset)
623
763
  {
624
 
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
625
 
             table_options.collation().c_str(),
626
 
             table.name().c_str());
 
764
    char errmsg[100];
 
765
    snprintf(errmsg, sizeof(errmsg),
 
766
             _("Table %s has invalid/unknown collation: %d,%s"),
 
767
             getPath(),
 
768
             table_options.collation_id(),
 
769
             table_options.collation().c_str());
 
770
    errmsg[99]='\0';
627
771
 
628
 
    return ER_CORRUPT_TABLE_DEFINITION; // Historical
 
772
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), errmsg);
 
773
    return ER_CORRUPT_TABLE_DEFINITION;
629
774
  }
630
775
 
631
776
  db_record_offset= 1;
632
777
 
 
778
  blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
 
779
 
633
780
  keys= table.indexes_size();
634
781
 
635
782
  key_parts= 0;
779
926
  keys_for_keyread.reset();
780
927
  set_prefix(keys_in_use, keys);
781
928
 
782
 
  _field_size= table.field_size();
 
929
  fields= table.field_size();
783
930
 
784
 
  setFields(_field_size + 1);
785
 
  _fields[_field_size]= NULL;
 
931
  setFields(fields + 1);
 
932
  field[fields]= NULL;
786
933
 
787
934
  uint32_t local_null_fields= 0;
788
935
  reclength= 0;
790
937
  std::vector<uint32_t> field_offsets;
791
938
  std::vector<uint32_t> field_pack_length;
792
939
 
793
 
  field_offsets.resize(_field_size);
794
 
  field_pack_length.resize(_field_size);
 
940
  field_offsets.resize(fields);
 
941
  field_pack_length.resize(fields);
795
942
 
796
943
  uint32_t interval_count= 0;
797
944
  uint32_t interval_parts= 0;
798
945
 
799
946
  uint32_t stored_columns_reclength= 0;
800
947
 
801
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
948
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
802
949
  {
803
950
    message::Table::Field pfield= table.field(fieldnr);
804
 
    if (pfield.constraints().is_nullable()) // Historical reference
805
 
    {
806
 
      local_null_fields++;
807
 
    }
808
 
    else if (not pfield.constraints().is_notnull())
809
 
    {
810
 
      local_null_fields++;
811
 
    }
 
951
    if (pfield.constraints().is_nullable())
 
952
      local_null_fields++;
812
953
 
813
 
    enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
 
954
    enum_field_types drizzle_field_type=
 
955
      proto_field_type_to_drizzle_type(pfield.type());
814
956
 
815
957
    field_offsets[fieldnr]= stored_columns_reclength;
816
958
 
849
991
      {
850
992
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
851
993
 
852
 
        field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
 
994
        field_pack_length[fieldnr]= my_decimal_get_binary_size(fo.precision(), fo.scale());
853
995
      }
854
996
      break;
855
997
    default:
899
1041
 
900
1042
  uint32_t interval_nr= 0;
901
1043
 
902
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1044
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
903
1045
  {
904
1046
    message::Table::Field pfield= table.field(fieldnr);
905
1047
 
911
1053
 
912
1054
    if (field_options.field_value_size() > Field_enum::max_supported_elements)
913
1055
    {
914
 
      my_error(ER_CORRUPT_TABLE_DEFINITION_ENUM, MYF(0), table.name().c_str());
 
1056
      char errmsg[100];
 
1057
      snprintf(errmsg, sizeof(errmsg),
 
1058
               _("ENUM column %s has greater than %d possible values"),
 
1059
               pfield.name().c_str(),
 
1060
               Field_enum::max_supported_elements);
 
1061
      errmsg[99]='\0';
915
1062
 
916
 
      return ER_CORRUPT_TABLE_DEFINITION_ENUM; // Historical
 
1063
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), errmsg);
 
1064
      return ER_CORRUPT_TABLE_DEFINITION;
917
1065
    }
918
1066
 
919
1067
 
956
1104
  /* and read the fields */
957
1105
  interval_nr= 0;
958
1106
 
959
 
  bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
 
1107
  bool use_hash= fields >= MAX_FIELDS_BEFORE_HASH;
960
1108
 
961
1109
  unsigned char* null_pos= getDefaultValues();
962
1110
  int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
963
1111
 
964
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1112
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
965
1113
  {
966
1114
    message::Table::Field pfield= table.field(fieldnr);
967
1115
 
1016
1164
 
1017
1165
    enum_field_types field_type;
1018
1166
 
1019
 
    field_type= proto_field_type_to_drizzle_type(pfield);
 
1167
    field_type= proto_field_type_to_drizzle_type(pfield.type());
1020
1168
 
1021
1169
    const CHARSET_INFO *charset= &my_charset_bin;
1022
1170
 
1061
1209
      {
1062
1210
        if (fo.scale() > DECIMAL_MAX_SCALE)
1063
1211
        {
1064
 
          local_error= ER_NOT_FORM_FILE;
 
1212
          local_error= 4;
1065
1213
 
1066
 
          return true;
 
1214
          return local_error;
1067
1215
        }
1068
1216
        decimals= static_cast<uint8_t>(fo.scale());
1069
1217
      }
1083
1231
    }
1084
1232
 
1085
1233
 
 
1234
    blob_ptr_size= portable_sizeof_char_ptr;
 
1235
 
1086
1236
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1087
1237
 
1088
 
    // We set field_length in this loop.
1089
1238
    switch (field_type)
1090
1239
    {
1091
1240
    case DRIZZLE_TYPE_BLOB:
1117
1266
            decimals != NOT_FIXED_DEC)
1118
1267
        {
1119
1268
          my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1120
 
          local_error= ER_M_BIGGER_THAN_D;
1121
 
          return true;
 
1269
          local_error= 1;
 
1270
 
 
1271
          return local_error;
1122
1272
        }
1123
1273
        break;
1124
1274
      }
1126
1276
      {
1127
1277
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1128
1278
 
1129
 
        field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
 
1279
        field_length= my_decimal_precision_to_length(fo.precision(), fo.scale(),
1130
1280
                                                     false);
1131
1281
        break;
1132
1282
      }
 
1283
    case DRIZZLE_TYPE_TIMESTAMP:
1133
1284
    case DRIZZLE_TYPE_DATETIME:
1134
1285
      field_length= DateTime::MAX_STRING_LENGTH;
1135
1286
      break;
1162
1313
      }
1163
1314
      break;
1164
1315
    case DRIZZLE_TYPE_LONGLONG:
1165
 
      {
1166
 
        uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1167
 
        field_length= MAX_BIGINT_WIDTH+sign_len;
1168
 
      }
 
1316
      field_length= MAX_BIGINT_WIDTH;
1169
1317
      break;
1170
1318
    case DRIZZLE_TYPE_UUID:
1171
1319
      field_length= field::Uuid::max_string_length();
1172
1320
      break;
1173
 
    case DRIZZLE_TYPE_BOOLEAN:
1174
 
      field_length= field::Boolean::max_string_length();
1175
 
      break;
1176
 
    case DRIZZLE_TYPE_MICROTIME:
1177
 
      field_length= field::Microtime::max_string_length();
1178
 
      break;
1179
 
    case DRIZZLE_TYPE_TIMESTAMP:
1180
 
      field_length= field::Epoch::max_string_length();
1181
 
      break;
1182
 
    case DRIZZLE_TYPE_TIME:
1183
 
      field_length= field::Time::max_string_length();
1184
 
      break;
1185
1321
    case DRIZZLE_TYPE_NULL:
1186
1322
      abort(); // Programming error
1187
1323
    }
1188
1324
 
1189
 
    bool is_not_null= false;
1190
 
 
1191
 
    if (not pfield.constraints().is_nullable())
1192
 
    {
1193
 
      is_not_null= true;
1194
 
    }
1195
 
    else if (pfield.constraints().is_notnull())
1196
 
    {
1197
 
      is_not_null= true;
1198
 
    }
1199
 
 
1200
 
    Field* f= make_field(pfield,
1201
 
                         record + field_offsets[fieldnr] + data_offset,
 
1325
    assert(enum_field_types_size == 12);
 
1326
 
 
1327
    Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1202
1328
                         field_length,
1203
 
                         not is_not_null,
 
1329
                         pfield.constraints().is_nullable(),
1204
1330
                         null_pos,
1205
1331
                         null_bit_pos,
1206
1332
                         decimals,
1208
1334
                         charset,
1209
1335
                         MTYP_TYPENR(unireg_type),
1210
1336
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
1211
 
                         getTableMessage()->field(fieldnr).name().c_str());
 
1337
                         getTableProto()->field(fieldnr).name().c_str());
1212
1338
 
1213
 
    _fields[fieldnr]= f;
 
1339
    field[fieldnr]= f;
1214
1340
 
1215
1341
    // Insert post make_field code here.
1216
1342
    switch (field_type)
1220
1346
    case DRIZZLE_TYPE_DOUBLE:
1221
1347
    case DRIZZLE_TYPE_DECIMAL:
1222
1348
    case DRIZZLE_TYPE_TIMESTAMP:
1223
 
    case DRIZZLE_TYPE_TIME:
1224
1349
    case DRIZZLE_TYPE_DATETIME:
1225
 
    case DRIZZLE_TYPE_MICROTIME:
1226
1350
    case DRIZZLE_TYPE_DATE:
1227
1351
    case DRIZZLE_TYPE_ENUM:
1228
1352
    case DRIZZLE_TYPE_LONG:
1229
1353
    case DRIZZLE_TYPE_LONGLONG:
1230
1354
    case DRIZZLE_TYPE_NULL:
1231
1355
    case DRIZZLE_TYPE_UUID:
1232
 
    case DRIZZLE_TYPE_BOOLEAN:
1233
1356
      break;
1234
1357
    }
1235
1358
 
1257
1380
      if (res != 0 && res != 3) /* @TODO Huh? */
1258
1381
      {
1259
1382
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1260
 
        local_error= ER_INVALID_DEFAULT;
 
1383
        local_error= 1;
1261
1384
 
1262
 
        return true;
 
1385
        return local_error;
1263
1386
      }
1264
1387
    }
1265
1388
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1278
1401
 
1279
1402
    f->setPosition(fieldnr);
1280
1403
    f->comment= comment;
1281
 
    if (not default_value &&
1282
 
        not (f->unireg_check==Field::NEXT_NUMBER) &&
 
1404
    if (! default_value &&
 
1405
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1283
1406
        (f->flags & NOT_NULL_FLAG) &&
1284
 
        (not f->is_timestamp()))
 
1407
        (f->real_type() != DRIZZLE_TYPE_TIMESTAMP))
1285
1408
    {
1286
1409
      f->flags|= NO_DEFAULT_VALUE_FLAG;
1287
1410
    }
1288
1411
 
1289
1412
    if (f->unireg_check == Field::NEXT_NUMBER)
1290
 
      found_next_number_field= &(_fields[fieldnr]);
 
1413
      found_next_number_field= &(field[fieldnr]);
1291
1414
 
1292
1415
    if (use_hash) /* supposedly this never fails... but comments lie */
1293
1416
    {
1294
 
      const char *local_field_name= _fields[fieldnr]->field_name;
1295
 
      name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
 
1417
      const char *local_field_name= field[fieldnr]->field_name;
 
1418
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1296
1419
    }
1297
1420
  }
1298
1421
 
1348
1471
        for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1349
1472
        {
1350
1473
          uint32_t fieldnr= key_part[i].fieldnr;
1351
 
          if (not fieldnr ||
1352
 
              _fields[fieldnr-1]->null_ptr ||
1353
 
              _fields[fieldnr-1]->key_length() != key_part[i].length)
 
1474
          if (! fieldnr ||
 
1475
              field[fieldnr-1]->null_ptr ||
 
1476
              field[fieldnr-1]->key_length() != key_part[i].length)
1354
1477
          {
1355
1478
            local_primary_key= MAX_KEY; // Can't be used
1356
1479
            break;
1365
1488
        {
1366
1489
          return ENOMEM;
1367
1490
        }
1368
 
        local_field= key_part->field= _fields[key_part->fieldnr-1];
 
1491
        local_field= key_part->field= field[key_part->fieldnr-1];
1369
1492
        key_part->type= local_field->key_type();
1370
1493
        if (local_field->null_ptr)
1371
1494
        {
1471
1594
                            &next_number_keypart)) < 0)
1472
1595
    {
1473
1596
      /* Wrong field definition */
1474
 
      local_error= ER_NOT_FORM_FILE;
 
1597
      local_error= 4;
1475
1598
 
1476
 
      return true;
 
1599
      return local_error;
1477
1600
    }
1478
1601
    else
1479
1602
    {
1487
1610
    blob_field.resize(blob_fields);
1488
1611
    uint32_t *save= &blob_field[0];
1489
1612
    uint32_t k= 0;
1490
 
    for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
 
1613
    for (Fields::iterator iter= field.begin(); iter != field.end()-1; iter++, k++)
1491
1614
    {
1492
1615
      if ((*iter)->flags & BLOB_FLAG)
1493
1616
        (*save++)= k;
1495
1618
  }
1496
1619
 
1497
1620
  all_set.clear();
1498
 
  all_set.resize(_field_size);
 
1621
  all_set.resize(fields);
1499
1622
  all_set.set();
1500
1623
 
1501
 
  return local_error != EE_OK;
1502
 
}
 
1624
  return local_error;
 
1625
}
 
1626
 
 
1627
int TableShare::parse_table_proto(Session& session, message::Table &table)
 
1628
{
 
1629
  int local_error= inner_parse_table_proto(session, table);
 
1630
 
 
1631
  if (not local_error)
 
1632
    return 0;
 
1633
 
 
1634
  error= local_error;
 
1635
  open_errno= errno;
 
1636
  errarg= 0;
 
1637
  open_table_error(local_error, open_errno, 0);
 
1638
 
 
1639
  return local_error;
 
1640
}
 
1641
 
1503
1642
 
1504
1643
/*
1505
1644
  Read table definition from a binary / text based .frm cursor
1525
1664
  6    Unknown .frm version
1526
1665
*/
1527
1666
 
1528
 
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
 
1667
int TableShare::open_table_def(Session& session, const TableIdentifier &identifier)
1529
1668
{
1530
 
  drizzled::error_t local_error= EE_OK;
1531
 
 
1532
 
  message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1533
 
 
1534
 
  if (table and table->IsInitialized())
 
1669
  int local_error;
 
1670
  bool error_given;
 
1671
 
 
1672
  local_error= 1;
 
1673
  error_given= 0;
 
1674
 
 
1675
  message::table::shared_ptr table;
 
1676
 
 
1677
  local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
 
1678
 
 
1679
  if (local_error != EEXIST)
1535
1680
  {
1536
 
    if (parse_table_proto(session, *table))
 
1681
    if (local_error > 0)
1537
1682
    {
1538
 
      local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1539
 
      my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
 
1683
      errno= local_error;
 
1684
      local_error= 1;
1540
1685
    }
1541
1686
    else
1542
1687
    {
1543
 
      setTableCategory(TABLE_CATEGORY_USER);
1544
 
      local_error= EE_OK;
 
1688
      if (not table->IsInitialized())
 
1689
      {
 
1690
        local_error= 4;
 
1691
      }
1545
1692
    }
1546
 
  }
1547
 
  else if (table and not table->IsInitialized())
1548
 
  {
1549
 
    local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1550
 
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1551
 
  }
1552
 
  else
1553
 
  {
1554
 
    local_error= ER_TABLE_UNKNOWN;
1555
 
    my_error(ER_TABLE_UNKNOWN, identifier);
1556
 
  }
1557
 
 
1558
 
  return static_cast<int>(local_error);
 
1693
    goto err_not_open;
 
1694
  }
 
1695
 
 
1696
  local_error= parse_table_proto(session, *table);
 
1697
 
 
1698
  setTableCategory(TABLE_CATEGORY_USER);
 
1699
 
 
1700
err_not_open:
 
1701
  if (local_error && !error_given)
 
1702
  {
 
1703
    error= local_error;
 
1704
    open_table_error(error, (open_errno= errno), 0);
 
1705
  }
 
1706
 
 
1707
  return(error);
1559
1708
}
1560
1709
 
1561
1710
 
1583
1732
  7    Table definition has changed in engine
1584
1733
*/
1585
1734
int TableShare::open_table_from_share(Session *session,
1586
 
                                      const identifier::Table &identifier,
 
1735
                                      const TableIdentifier &identifier,
1587
1736
                                      const char *alias,
1588
1737
                                      uint32_t db_stat, uint32_t ha_open_flags,
1589
1738
                                      Table &outparam)
1600
1749
  if (not error_reported)
1601
1750
    open_table_error(ret, errno, 0);
1602
1751
 
1603
 
  boost::checked_delete(outparam.cursor);
 
1752
  delete outparam.cursor;
1604
1753
  outparam.cursor= 0;                           // For easier error checking
1605
1754
  outparam.db_stat= 0;
1606
1755
  outparam.getMemRoot()->free_root(MYF(0));       // Safe to call on zeroed root
1619
1768
  unsigned char *record= NULL;
1620
1769
  Field **field_ptr;
1621
1770
 
 
1771
  /* Parsing of partitioning information from .frm needs session->lex set up. */
 
1772
  assert(session->lex->is_lex_started);
 
1773
 
1622
1774
  local_error= 1;
1623
1775
  outparam.resetTable(session, this, db_stat);
1624
1776
 
1670
1822
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1671
1823
  }
1672
1824
 
1673
 
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
 
1825
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1674
1826
  {
1675
1827
    return local_error;
1676
1828
  }
1682
1834
  outparam.null_flags= (unsigned char*) record+1;
1683
1835
 
1684
1836
  /* Setup copy of fields from share, but use the right alias and record */
1685
 
  for (uint32_t i= 0 ; i < _field_size; i++, field_ptr++)
 
1837
  for (uint32_t i= 0 ; i < fields; i++, field_ptr++)
1686
1838
  {
1687
 
    if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
 
1839
    if (!((*field_ptr)= field[i]->clone(outparam.getMemRoot(), &outparam)))
1688
1840
      return local_error;
1689
1841
  }
1690
1842
  (*field_ptr)= 0;                              // End marker
1693
1845
    outparam.found_next_number_field=
1694
1846
      outparam.getField(positionFields(found_next_number_field));
1695
1847
  if (timestamp_field)
1696
 
    outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
 
1848
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
1697
1849
 
1698
1850
  /* Fix key->name and key_part->field */
1699
1851
  if (key_parts)
1742
1894
 
1743
1895
  /* Allocate bitmaps */
1744
1896
 
1745
 
  outparam.def_read_set.resize(_field_size);
1746
 
  outparam.def_write_set.resize(_field_size);
1747
 
  outparam.tmp_set.resize(_field_size);
 
1897
  outparam.def_read_set.resize(fields);
 
1898
  outparam.def_write_set.resize(fields);
 
1899
  outparam.tmp_set.resize(fields);
1748
1900
  outparam.default_column_bitmaps();
1749
1901
 
1750
1902
  return 0;
1751
1903
}
1752
1904
 
1753
 
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
 
1905
int TableShare::open_table_cursor_inner(const TableIdentifier &identifier,
1754
1906
                                        uint32_t db_stat, uint32_t ha_open_flags,
1755
1907
                                        Table &outparam,
1756
1908
                                        bool &error_reported)
1801
1953
/* error message when opening a form cursor */
1802
1954
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1803
1955
{
 
1956
  int err_no;
1804
1957
  char buff[FN_REFLEN];
1805
1958
  myf errortype= ME_ERROR+ME_WAITTANG;
1806
1959
 
1809
1962
  case 1:
1810
1963
    if (db_errno == ENOENT)
1811
1964
    {
1812
 
      identifier::Table identifier(db.str, table_name.str);
1813
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
1965
      my_error(ER_NO_SUCH_TABLE, MYF(0), db.str, table_name.str);
1814
1966
    }
1815
1967
    else
1816
1968
    {
1821
1973
    break;
1822
1974
  case 2:
1823
1975
    {
1824
 
      drizzled::error_t err_no;
1825
 
 
1826
1976
      err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1827
1977
        ER_FILE_USED : ER_CANT_OPEN_FILE;
1828
 
 
1829
1978
      my_error(err_no, errortype, normalized_path.str, db_errno);
1830
1979
      break;
1831
1980
    }
1861
2010
  return;
1862
2011
} /* open_table_error */
1863
2012
 
1864
 
Field *TableShare::make_field(const message::Table::Field &pfield,
1865
 
                              unsigned char *ptr,
 
2013
Field *TableShare::make_field(unsigned char *ptr,
1866
2014
                              uint32_t field_length,
1867
2015
                              bool is_nullable,
1868
2016
                              unsigned char *null_pos,
1874
2022
                              TYPELIB *interval,
1875
2023
                              const char *field_name)
1876
2024
{
1877
 
  return make_field(pfield,
1878
 
                    ptr,
1879
 
                    field_length,
1880
 
                    is_nullable,
1881
 
                    null_pos,
1882
 
                    null_bit,
1883
 
                    decimals,
1884
 
                    field_type,
1885
 
                    field_charset,
1886
 
                    unireg_check,
1887
 
                    interval,
1888
 
                    field_name,
1889
 
                    pfield.constraints().is_unsigned());
1890
 
}
1891
 
 
1892
 
Field *TableShare::make_field(const message::Table::Field &,
1893
 
                              unsigned char *ptr,
1894
 
                              uint32_t field_length,
1895
 
                              bool is_nullable,
1896
 
                              unsigned char *null_pos,
1897
 
                              unsigned char null_bit,
1898
 
                              uint8_t decimals,
1899
 
                              enum_field_types field_type,
1900
 
                              const CHARSET_INFO * field_charset,
1901
 
                              Field::utype unireg_check,
1902
 
                              TYPELIB *interval,
1903
 
                              const char *field_name, 
1904
 
                              bool is_unsigned)
1905
 
{
1906
2025
  if (! is_nullable)
1907
2026
  {
1908
2027
    null_pos=0;
1917
2036
  {
1918
2037
  case DRIZZLE_TYPE_DATE:
1919
2038
  case DRIZZLE_TYPE_DATETIME:
 
2039
  case DRIZZLE_TYPE_TIMESTAMP:
1920
2040
  case DRIZZLE_TYPE_UUID:
1921
2041
    field_charset= &my_charset_bin;
1922
2042
  default: break;
1926
2046
  {
1927
2047
  case DRIZZLE_TYPE_ENUM:
1928
2048
    return new (&mem_root) Field_enum(ptr,
1929
 
                                      field_length,
1930
 
                                      null_pos,
1931
 
                                      null_bit,
1932
 
                                      field_name,
1933
 
                                      interval,
1934
 
                                      field_charset);
 
2049
                                 field_length,
 
2050
                                 null_pos,
 
2051
                                 null_bit,
 
2052
                                 field_name,
 
2053
                                 interval,
 
2054
                                 field_charset);
1935
2055
  case DRIZZLE_TYPE_VARCHAR:
1936
2056
    setVariableWidth();
1937
2057
    return new (&mem_root) Field_varstring(ptr,field_length,
1941
2061
                                      field_charset);
1942
2062
  case DRIZZLE_TYPE_BLOB:
1943
2063
    return new (&mem_root) Field_blob(ptr,
1944
 
                                      null_pos,
1945
 
                                      null_bit,
1946
 
                                      field_name,
1947
 
                                      this,
1948
 
                                      field_charset);
 
2064
                                 null_pos,
 
2065
                                 null_bit,
 
2066
                                 field_name,
 
2067
                                 this,
 
2068
                                 field_charset);
1949
2069
  case DRIZZLE_TYPE_DECIMAL:
1950
2070
    return new (&mem_root) Field_decimal(ptr,
1951
 
                                         field_length,
1952
 
                                         null_pos,
1953
 
                                         null_bit,
1954
 
                                         unireg_check,
1955
 
                                         field_name,
1956
 
                                         decimals);
 
2071
                                    field_length,
 
2072
                                    null_pos,
 
2073
                                    null_bit,
 
2074
                                    unireg_check,
 
2075
                                    field_name,
 
2076
                                    decimals,
 
2077
                                    false,
 
2078
                                    false /* is_unsigned */);
1957
2079
  case DRIZZLE_TYPE_DOUBLE:
1958
2080
    return new (&mem_root) Field_double(ptr,
1959
2081
                                   field_length,
1970
2092
                                       null_pos,
1971
2093
                                       null_bit,
1972
2094
                                       field_name);
1973
 
  case DRIZZLE_TYPE_BOOLEAN:
1974
 
    return new (&mem_root) field::Boolean(ptr,
1975
 
                                          field_length,
1976
 
                                          null_pos,
1977
 
                                          null_bit,
1978
 
                                          field_name,
1979
 
                                          is_unsigned);
1980
2095
  case DRIZZLE_TYPE_LONG:
1981
2096
    return new (&mem_root) field::Int32(ptr,
1982
2097
                                        field_length,
1985
2100
                                        unireg_check,
1986
2101
                                        field_name);
1987
2102
  case DRIZZLE_TYPE_LONGLONG:
1988
 
    {
1989
 
      if (is_unsigned)
1990
 
      {
1991
 
        return new (&mem_root) field::Size(ptr,
1992
 
                                           field_length,
1993
 
                                           null_pos,
1994
 
                                           null_bit,
1995
 
                                           unireg_check,
1996
 
                                           field_name);
1997
 
      }
1998
 
 
1999
 
      return new (&mem_root) field::Int64(ptr,
2000
 
                                          field_length,
2001
 
                                          null_pos,
2002
 
                                          null_bit,
2003
 
                                          unireg_check,
2004
 
                                          field_name);
2005
 
    }
2006
 
  case DRIZZLE_TYPE_MICROTIME:
2007
 
    return new (&mem_root) field::Microtime(ptr,
2008
 
                                            null_pos,
2009
 
                                            null_bit,
2010
 
                                            unireg_check,
2011
 
                                            field_name,
2012
 
                                            this);
 
2103
    return new (&mem_root) field::Int64(ptr,
 
2104
                                        field_length,
 
2105
                                        null_pos,
 
2106
                                        null_bit,
 
2107
                                        unireg_check,
 
2108
                                        field_name);
2013
2109
  case DRIZZLE_TYPE_TIMESTAMP:
2014
 
    return new (&mem_root) field::Epoch(ptr,
2015
 
                                        null_pos,
2016
 
                                        null_bit,
2017
 
                                        unireg_check,
2018
 
                                        field_name,
2019
 
                                        this);
2020
 
  case DRIZZLE_TYPE_TIME:
2021
 
    return new (&mem_root) field::Time(ptr,
2022
 
                                       field_length,
2023
 
                                       null_pos,
2024
 
                                       null_bit,
2025
 
                                       field_name,
2026
 
                                       field_charset);
 
2110
    return new (&mem_root) Field_timestamp(ptr,
 
2111
                                      field_length,
 
2112
                                      null_pos,
 
2113
                                      null_bit,
 
2114
                                      unireg_check,
 
2115
                                      field_name,
 
2116
                                      this,
 
2117
                                      field_charset);
2027
2118
  case DRIZZLE_TYPE_DATE:
2028
2119
    return new (&mem_root) Field_date(ptr,
2029
2120
                                 null_pos,
2046
2137
  abort();
2047
2138
}
2048
2139
 
2049
 
void TableShare::refreshVersion()
2050
 
{
2051
 
  version= refresh_version;
2052
 
}
2053
 
 
2054
2140
 
2055
2141
} /* namespace drizzled */