~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.cc

  • Committer: Brian Aker
  • Date: 2011-01-05 16:29:27 UTC
  • mto: (2060.2.1 clean)
  • mto: This revision was merged to the branch mainline in revision 2063.
  • Revision ID: brian@tangent.org-20110105162927-fi2gnmlz35qcagik
Add additional gperf for non-reserved SQL keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
/* Basic functions needed by many modules */
28
 
#include <config.h>
 
28
#include "config.h"
29
29
 
30
30
#include <pthread.h>
31
31
#include <float.h>
37
37
 
38
38
#include <cassert>
39
39
 
40
 
#include <drizzled/error.h>
41
 
#include <drizzled/gettext.h>
42
 
#include <drizzled/sql_base.h>
43
 
#include <drizzled/pthread_globals.h>
44
 
#include <drizzled/internal/my_pthread.h>
45
 
 
46
 
#include <drizzled/table.h>
47
 
#include <drizzled/table/shell.h>
48
 
 
49
 
#include <drizzled/session.h>
50
 
 
51
 
#include <drizzled/charset.h>
52
 
#include <drizzled/internal/m_string.h>
53
 
#include <drizzled/internal/my_sys.h>
54
 
 
55
 
#include <drizzled/item/string.h>
56
 
#include <drizzled/item/int.h>
57
 
#include <drizzled/item/decimal.h>
58
 
#include <drizzled/item/float.h>
59
 
#include <drizzled/item/null.h>
60
 
#include <drizzled/temporal.h>
61
 
 
62
 
#include <drizzled/field.h>
63
 
#include <drizzled/field/str.h>
64
 
#include <drizzled/field/num.h>
65
 
#include <drizzled/field/blob.h>
66
 
#include <drizzled/field/boolean.h>
67
 
#include <drizzled/field/enum.h>
68
 
#include <drizzled/field/null.h>
69
 
#include <drizzled/field/date.h>
70
 
#include <drizzled/field/decimal.h>
71
 
#include <drizzled/field/real.h>
72
 
#include <drizzled/field/double.h>
73
 
#include <drizzled/field/int32.h>
74
 
#include <drizzled/field/int64.h>
75
 
#include <drizzled/field/size.h>
76
 
#include <drizzled/field/num.h>
77
 
#include <drizzled/field/time.h>
78
 
#include <drizzled/field/epoch.h>
79
 
#include <drizzled/field/datetime.h>
80
 
#include <drizzled/field/microtime.h>
81
 
#include <drizzled/field/varstring.h>
82
 
#include <drizzled/field/uuid.h>
83
 
 
84
 
#include <drizzled/plugin/storage_engine.h>
85
 
 
86
 
#include <drizzled/definition/cache.h>
87
 
#include <drizzled/typelib.h>
88
 
 
89
 
#include <drizzled/refresh_version.h>
 
40
#include "drizzled/error.h"
 
41
#include "drizzled/gettext.h"
 
42
#include "drizzled/sql_base.h"
 
43
#include "drizzled/pthread_globals.h"
 
44
#include "drizzled/internal/my_pthread.h"
 
45
#include "drizzled/plugin/event_observer.h"
 
46
 
 
47
#include "drizzled/table.h"
 
48
#include "drizzled/table/shell.h"
 
49
 
 
50
#include "drizzled/session.h"
 
51
 
 
52
#include "drizzled/charset.h"
 
53
#include "drizzled/internal/m_string.h"
 
54
#include "drizzled/internal/my_sys.h"
 
55
 
 
56
#include "drizzled/item/string.h"
 
57
#include "drizzled/item/int.h"
 
58
#include "drizzled/item/decimal.h"
 
59
#include "drizzled/item/float.h"
 
60
#include "drizzled/item/null.h"
 
61
#include "drizzled/temporal.h"
 
62
 
 
63
#include "drizzled/field.h"
 
64
#include "drizzled/field/str.h"
 
65
#include "drizzled/field/num.h"
 
66
#include "drizzled/field/blob.h"
 
67
#include "drizzled/field/enum.h"
 
68
#include "drizzled/field/null.h"
 
69
#include "drizzled/field/date.h"
 
70
#include "drizzled/field/decimal.h"
 
71
#include "drizzled/field/real.h"
 
72
#include "drizzled/field/double.h"
 
73
#include "drizzled/field/int32.h"
 
74
#include "drizzled/field/int64.h"
 
75
#include "drizzled/field/size.h"
 
76
#include "drizzled/field/num.h"
 
77
#include "drizzled/field/time.h"
 
78
#include "drizzled/field/epoch.h"
 
79
#include "drizzled/field/datetime.h"
 
80
#include "drizzled/field/varstring.h"
 
81
#include "drizzled/field/uuid.h"
 
82
 
 
83
#include "drizzled/definition/cache.h"
90
84
 
91
85
using namespace std;
92
86
 
95
89
 
96
90
extern size_t table_def_size;
97
91
 
98
 
 
99
 
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
100
 
{
101
 
  switch(field.type())
 
92
/*****************************************************************************
 
93
  Functions to handle table definition cach (TableShare)
 
94
 *****************************************************************************/
 
95
 
 
96
/*
 
97
  Mark that we are not using table share anymore.
 
98
 
 
99
  SYNOPSIS
 
100
  release()
 
101
  share         Table share
 
102
 
 
103
  IMPLEMENTATION
 
104
  If ref_count goes to zero and (we have done a refresh or if we have
 
105
  already too many open table shares) then delete the definition.
 
106
*/
 
107
 
 
108
void TableShare::release(TableShare *share)
 
109
{
 
110
  bool to_be_deleted= false;
 
111
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
112
 
 
113
  share->lock();
 
114
  if (!--share->ref_count)
 
115
  {
 
116
    to_be_deleted= true;
 
117
  }
 
118
  share->unlock();
 
119
 
 
120
  if (to_be_deleted)
 
121
  {
 
122
    definition::Cache::singleton().erase(share->getCacheKey());
 
123
  }
 
124
}
 
125
 
 
126
void TableShare::release(TableShare::shared_ptr &share)
 
127
{
 
128
  bool to_be_deleted= false;
 
129
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
130
 
 
131
  share->lock();
 
132
  if (!--share->ref_count)
 
133
  {
 
134
    to_be_deleted= true;
 
135
  }
 
136
  share->unlock();
 
137
 
 
138
  if (to_be_deleted)
 
139
  {
 
140
    definition::Cache::singleton().erase(share->getCacheKey());
 
141
  }
 
142
}
 
143
 
 
144
void TableShare::release(const TableIdentifier &identifier)
 
145
{
 
146
  TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
 
147
  if (share)
 
148
  {
 
149
    share->version= 0;                          // Mark for delete
 
150
    if (share->ref_count == 0)
 
151
    {
 
152
      definition::Cache::singleton().erase(identifier.getKey());
 
153
    }
 
154
  }
 
155
}
 
156
 
 
157
 
 
158
static TableShare::shared_ptr foundTableShare(TableShare::shared_ptr share)
 
159
{
 
160
  /*
 
161
    We found an existing table definition. Return it if we didn't get
 
162
    an error when reading the table definition from file.
 
163
  */
 
164
 
 
165
  /* We must do a lock to ensure that the structure is initialized */
 
166
  if (share->error)
 
167
  {
 
168
    /* Table definition contained an error */
 
169
    share->open_table_error(share->error, share->open_errno, share->errarg);
 
170
 
 
171
    return TableShare::shared_ptr();
 
172
  }
 
173
 
 
174
  share->incrementTableCount();
 
175
 
 
176
  return share;
 
177
}
 
178
 
 
179
/*
 
180
  Get TableShare for a table.
 
181
 
 
182
  get_table_share()
 
183
  session                       Thread handle
 
184
  table_list            Table that should be opened
 
185
  key                   Table cache key
 
186
  key_length            Length of key
 
187
  error                 out: Error code from open_table_def()
 
188
 
 
189
  IMPLEMENTATION
 
190
  Get a table definition from the table definition cache.
 
191
  If it doesn't exist, create a new from the table definition file.
 
192
 
 
193
  NOTES
 
194
  We must have wrlock on table::Cache::singleton().mutex() when we come here
 
195
  (To be changed later)
 
196
 
 
197
  RETURN
 
198
  0  Error
 
199
#  Share for table
 
200
*/
 
201
 
 
202
TableShare::shared_ptr TableShare::getShareCreate(Session *session, 
 
203
                                                  const TableIdentifier &identifier,
 
204
                                                  int &in_error)
 
205
{
 
206
  TableShare::shared_ptr share;
 
207
 
 
208
  in_error= 0;
 
209
 
 
210
  /* Read table definition from cache */
 
211
  if ((share= definition::Cache::singleton().find(identifier.getKey())))
 
212
    return foundTableShare(share);
 
213
 
 
214
  share.reset(new TableShare(message::Table::STANDARD, identifier));
 
215
  
 
216
  if (share->open_table_def(*session, identifier))
 
217
  {
 
218
    in_error= share->error;
 
219
 
 
220
    return TableShare::shared_ptr();
 
221
  }
 
222
  share->ref_count++;                           // Mark in use
 
223
  
 
224
  plugin::EventObserver::registerTableEvents(*share);
 
225
 
 
226
  bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
 
227
 
 
228
  if (not ret)
 
229
    return TableShare::shared_ptr();
 
230
 
 
231
  return share;
 
232
}
 
233
 
 
234
static enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
 
235
{
 
236
  enum_field_types field_type;
 
237
 
 
238
  switch(proto_field_type)
102
239
  {
103
240
  case message::Table::Field::INTEGER:
104
 
    return DRIZZLE_TYPE_LONG;
105
 
 
 
241
    field_type= DRIZZLE_TYPE_LONG;
 
242
    break;
106
243
  case message::Table::Field::DOUBLE:
107
 
    return DRIZZLE_TYPE_DOUBLE;
108
 
 
 
244
    field_type= DRIZZLE_TYPE_DOUBLE;
 
245
    break;
109
246
  case message::Table::Field::EPOCH:
110
 
    if (field.has_time_options() and field.time_options().microseconds())
111
 
      return DRIZZLE_TYPE_MICROTIME;
112
 
 
113
 
    return DRIZZLE_TYPE_TIMESTAMP;
114
 
 
 
247
    field_type= DRIZZLE_TYPE_TIMESTAMP;
 
248
    break;
115
249
  case message::Table::Field::BIGINT:
116
 
    return DRIZZLE_TYPE_LONGLONG;
117
 
 
 
250
    field_type= DRIZZLE_TYPE_LONGLONG;
 
251
    break;
118
252
  case message::Table::Field::DATETIME:
119
 
    return DRIZZLE_TYPE_DATETIME;
120
 
 
 
253
    field_type= DRIZZLE_TYPE_DATETIME;
 
254
    break;
121
255
  case message::Table::Field::DATE:
122
 
    return DRIZZLE_TYPE_DATE;
123
 
 
 
256
    field_type= DRIZZLE_TYPE_DATE;
 
257
    break;
124
258
  case message::Table::Field::VARCHAR:
125
 
    return DRIZZLE_TYPE_VARCHAR;
126
 
 
 
259
    field_type= DRIZZLE_TYPE_VARCHAR;
 
260
    break;
127
261
  case message::Table::Field::DECIMAL:
128
 
    return DRIZZLE_TYPE_DECIMAL;
129
 
 
 
262
    field_type= DRIZZLE_TYPE_DECIMAL;
 
263
    break;
130
264
  case message::Table::Field::ENUM:
131
 
    return DRIZZLE_TYPE_ENUM;
132
 
 
 
265
    field_type= DRIZZLE_TYPE_ENUM;
 
266
    break;
133
267
  case message::Table::Field::BLOB:
134
 
    return DRIZZLE_TYPE_BLOB;
135
 
 
 
268
    field_type= DRIZZLE_TYPE_BLOB;
 
269
    break;
136
270
  case message::Table::Field::UUID:
137
 
    return  DRIZZLE_TYPE_UUID;
138
 
 
139
 
  case message::Table::Field::BOOLEAN:
140
 
    return DRIZZLE_TYPE_BOOLEAN;
141
 
 
 
271
    field_type= DRIZZLE_TYPE_UUID;
 
272
    break;
142
273
  case message::Table::Field::TIME:
143
 
    return DRIZZLE_TYPE_TIME;
 
274
    field_type= DRIZZLE_TYPE_TIME;
 
275
    break;
 
276
  default:
 
277
    assert(0);
 
278
    abort(); // Programming error
144
279
  }
145
280
 
146
 
  abort();
 
281
  return field_type;
147
282
}
148
283
 
149
284
static Item *default_value_item(enum_field_types field_type,
182
317
  case DRIZZLE_TYPE_DATE:
183
318
  case DRIZZLE_TYPE_ENUM:
184
319
  case DRIZZLE_TYPE_UUID:
185
 
  case DRIZZLE_TYPE_MICROTIME:
186
 
  case DRIZZLE_TYPE_BOOLEAN:
187
320
    default_item= new Item_string(default_value->c_str(),
188
321
                                  default_value->length(),
189
322
                                  system_charset_info);
222
355
 */
223
356
bool TableShare::fieldInPrimaryKey(Field *in_field) const
224
357
{
225
 
  assert(getTableMessage());
 
358
  assert(table_proto != NULL);
226
359
 
227
 
  size_t num_indexes= getTableMessage()->indexes_size();
 
360
  size_t num_indexes= table_proto->indexes_size();
228
361
 
229
362
  for (size_t x= 0; x < num_indexes; ++x)
230
363
  {
231
 
    const message::Table::Index &index= getTableMessage()->indexes(x);
 
364
    const message::Table::Index &index= table_proto->indexes(x);
232
365
    if (index.is_primary())
233
366
    {
234
367
      size_t num_parts= index.index_part_size();
242
375
  return false;
243
376
}
244
377
 
245
 
TableShare::TableShare(const identifier::Table::Type type_arg) :
 
378
TableShare::TableShare(const TableIdentifier::Type type_arg) :
246
379
  table_category(TABLE_UNKNOWN_CATEGORY),
247
380
  found_next_number_field(NULL),
248
381
  timestamp_field(NULL),
249
382
  key_info(NULL),
250
383
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
251
384
  all_set(),
252
 
  db(NULL_LEX_STRING),
253
 
  table_name(NULL_LEX_STRING),
254
 
  path(NULL_LEX_STRING),
255
 
  normalized_path(NULL_LEX_STRING),
256
385
  block_size(0),
257
386
  version(0),
258
387
  timestamp_offset(0),
259
388
  reclength(0),
260
389
  stored_rec_length(0),
261
390
  max_rows(0),
262
 
  _table_message(NULL),
 
391
  table_proto(NULL),
263
392
  storage_engine(NULL),
264
393
  tmp_table(type_arg),
265
 
  _ref_count(0),
 
394
  ref_count(0),
266
395
  null_bytes(0),
267
396
  last_null_bit_pos(0),
268
 
  _field_size(0),
 
397
  fields(0),
269
398
  rec_buff_length(0),
270
399
  keys(0),
271
400
  key_parts(0),
287
416
  error(0),
288
417
  open_errno(0),
289
418
  errarg(0),
290
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
419
  blob_ptr_size(0),
291
420
  db_low_byte_first(false),
292
421
  keys_in_use(0),
293
 
  keys_for_keyread(0)
 
422
  keys_for_keyread(0),
 
423
  event_observers(NULL)
294
424
{
 
425
 
 
426
  table_charset= 0;
 
427
  memset(&db, 0, sizeof(LEX_STRING));
 
428
  memset(&table_name, 0, sizeof(LEX_STRING));
 
429
  memset(&path, 0, sizeof(LEX_STRING));
 
430
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
431
 
295
432
  if (type_arg == message::Table::INTERNAL)
296
433
  {
297
 
    identifier::Table::build_tmptable_filename(private_key_for_cache.vectorPtr());
 
434
    TableIdentifier::build_tmptable_filename(private_key_for_cache.vectorPtr());
298
435
    init(private_key_for_cache.vector(), private_key_for_cache.vector());
299
436
  }
300
437
  else
303
440
  }
304
441
}
305
442
 
306
 
TableShare::TableShare(const identifier::Table &identifier, const identifier::Table::Key &key) :// Used by placeholder
 
443
TableShare::TableShare(const TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
307
444
  table_category(TABLE_UNKNOWN_CATEGORY),
308
445
  found_next_number_field(NULL),
309
446
  timestamp_field(NULL),
310
447
  key_info(NULL),
311
448
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
312
 
  table_charset(0),
313
449
  all_set(),
314
 
  db(NULL_LEX_STRING),
315
 
  table_name(NULL_LEX_STRING),
316
 
  path(NULL_LEX_STRING),
317
 
  normalized_path(NULL_LEX_STRING),
318
450
  block_size(0),
319
451
  version(0),
320
452
  timestamp_offset(0),
321
453
  reclength(0),
322
454
  stored_rec_length(0),
323
455
  max_rows(0),
324
 
  _table_message(NULL),
 
456
  table_proto(NULL),
325
457
  storage_engine(NULL),
326
458
  tmp_table(message::Table::INTERNAL),
327
 
  _ref_count(0),
 
459
  ref_count(0),
328
460
  null_bytes(0),
329
461
  last_null_bit_pos(0),
330
 
  _field_size(0),
 
462
  fields(0),
331
463
  rec_buff_length(0),
332
464
  keys(0),
333
465
  key_parts(0),
349
481
  error(0),
350
482
  open_errno(0),
351
483
  errarg(0),
352
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
484
  blob_ptr_size(0),
353
485
  db_low_byte_first(false),
354
486
  keys_in_use(0),
355
 
  keys_for_keyread(0)
 
487
  keys_for_keyread(0),
 
488
  event_observers(NULL)
356
489
{
357
490
  assert(identifier.getKey() == key);
358
491
 
 
492
  table_charset= 0;
 
493
  memset(&path, 0, sizeof(LEX_STRING));
 
494
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
495
 
359
496
  private_key_for_cache= key;
360
497
 
361
498
  table_category=         TABLE_CATEGORY_TEMPORARY;
378
515
}
379
516
 
380
517
 
381
 
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
 
518
TableShare::TableShare(const TableIdentifier &identifier) : // Just used during createTable()
382
519
  table_category(TABLE_UNKNOWN_CATEGORY),
383
520
  found_next_number_field(NULL),
384
521
  timestamp_field(NULL),
385
522
  key_info(NULL),
386
523
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
387
 
  table_charset(0),
388
524
  all_set(),
389
 
  db(NULL_LEX_STRING),
390
 
  table_name(NULL_LEX_STRING),
391
 
  path(NULL_LEX_STRING),
392
 
  normalized_path(NULL_LEX_STRING),
393
525
  block_size(0),
394
526
  version(0),
395
527
  timestamp_offset(0),
396
528
  reclength(0),
397
529
  stored_rec_length(0),
398
530
  max_rows(0),
399
 
  _table_message(NULL),
 
531
  table_proto(NULL),
400
532
  storage_engine(NULL),
401
533
  tmp_table(identifier.getType()),
402
 
  _ref_count(0),
 
534
  ref_count(0),
403
535
  null_bytes(0),
404
536
  last_null_bit_pos(0),
405
 
  _field_size(0),
 
537
  fields(0),
406
538
  rec_buff_length(0),
407
539
  keys(0),
408
540
  key_parts(0),
424
556
  error(0),
425
557
  open_errno(0),
426
558
  errarg(0),
427
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
559
  blob_ptr_size(0),
428
560
  db_low_byte_first(false),
429
561
  keys_in_use(0),
430
 
  keys_for_keyread(0)
 
562
  keys_for_keyread(0),
 
563
  event_observers(NULL)
431
564
{
 
565
  table_charset= 0;
 
566
  memset(&db, 0, sizeof(LEX_STRING));
 
567
  memset(&table_name, 0, sizeof(LEX_STRING));
 
568
  memset(&path, 0, sizeof(LEX_STRING));
 
569
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
570
 
432
571
  private_key_for_cache= identifier.getKey();
433
572
  assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
434
573
  private_normalized_path.resize(identifier.getPath().size() + 1);
451
590
/*
452
591
  Used for shares that will go into the cache.
453
592
*/
454
 
TableShare::TableShare(const identifier::Table::Type type_arg,
455
 
                       const identifier::Table &identifier,
 
593
TableShare::TableShare(const TableIdentifier::Type type_arg,
 
594
                       const TableIdentifier &identifier,
456
595
                       char *path_arg,
457
596
                       uint32_t path_length_arg) :
458
597
  table_category(TABLE_UNKNOWN_CATEGORY),
460
599
  timestamp_field(NULL),
461
600
  key_info(NULL),
462
601
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
463
 
  table_charset(0),
464
602
  all_set(),
465
 
  db(NULL_LEX_STRING),
466
 
  table_name(NULL_LEX_STRING),
467
 
  path(NULL_LEX_STRING),
468
 
  normalized_path(NULL_LEX_STRING),
469
603
  block_size(0),
470
604
  version(0),
471
605
  timestamp_offset(0),
472
606
  reclength(0),
473
607
  stored_rec_length(0),
474
608
  max_rows(0),
475
 
  _table_message(NULL),
 
609
  table_proto(NULL),
476
610
  storage_engine(NULL),
477
611
  tmp_table(type_arg),
478
 
  _ref_count(0),
 
612
  ref_count(0),
479
613
  null_bytes(0),
480
614
  last_null_bit_pos(0),
481
 
  _field_size(0),
 
615
  fields(0),
482
616
  rec_buff_length(0),
483
617
  keys(0),
484
618
  key_parts(0),
500
634
  error(0),
501
635
  open_errno(0),
502
636
  errarg(0),
503
 
  blob_ptr_size(portable_sizeof_char_ptr),
 
637
  blob_ptr_size(0),
504
638
  db_low_byte_first(false),
505
639
  keys_in_use(0),
506
 
  keys_for_keyread(0)
 
640
  keys_for_keyread(0),
 
641
  event_observers(NULL)
507
642
{
 
643
  table_charset= 0;
 
644
  memset(&db, 0, sizeof(LEX_STRING));
 
645
  memset(&table_name, 0, sizeof(LEX_STRING));
 
646
  memset(&path, 0, sizeof(LEX_STRING));
 
647
  memset(&normalized_path, 0, sizeof(LEX_STRING));
 
648
 
508
649
  char *path_buff;
509
650
  std::string _path;
510
651
 
524
665
  }
525
666
  else
526
667
  {
527
 
    identifier::Table::build_table_filename(_path, db.str, table_name.str, false);
 
668
    TableIdentifier::build_table_filename(_path, db.str, table_name.str, false);
528
669
  }
529
670
 
530
671
  if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
559
700
 
560
701
TableShare::~TableShare() 
561
702
{
 
703
  assert(ref_count == 0);
 
704
 
562
705
  storage_engine= NULL;
563
706
 
 
707
  delete table_proto;
 
708
  table_proto= NULL;
 
709
 
 
710
  plugin::EventObserver::deregisterTableEvents(*this);
 
711
 
564
712
  mem_root.free_root(MYF(0));                 // Free's share
565
713
}
566
714
 
567
 
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
 
715
void TableShare::setIdentifier(const TableIdentifier &identifier_arg)
568
716
{
569
717
  private_key_for_cache= identifier_arg.getKey();
570
718
 
577
725
  table_name.str=    db.str + db.length + 1;
578
726
  table_name.length= strlen(table_name.str);
579
727
 
580
 
  getTableMessage()->set_name(identifier_arg.getTableName());
581
 
  getTableMessage()->set_schema(identifier_arg.getSchemaName());
 
728
  table_proto->set_name(identifier_arg.getTableName());
 
729
  table_proto->set_schema(identifier_arg.getSchemaName());
582
730
}
583
731
 
584
 
bool TableShare::parse_table_proto(Session& session, message::Table &table)
 
732
int TableShare::inner_parse_table_proto(Session& session, message::Table &table)
585
733
{
586
 
  drizzled::error_t local_error= EE_OK;
 
734
  int local_error= 0;
587
735
 
588
736
  if (! table.IsInitialized())
589
737
  {
594
742
    return ER_CORRUPT_TABLE_DEFINITION;
595
743
  }
596
744
 
597
 
  setTableMessage(table);
 
745
  setTableProto(new(nothrow) message::Table(table));
598
746
 
599
747
  storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
600
748
  assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
620
768
 
621
769
  table_charset= get_charset(table_options.collation_id());
622
770
 
623
 
  if (not table_charset)
 
771
  if (! table_charset)
624
772
  {
625
773
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
626
774
             table_options.collation().c_str(),
631
779
 
632
780
  db_record_offset= 1;
633
781
 
 
782
  blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
 
783
 
634
784
  keys= table.indexes_size();
635
785
 
636
786
  key_parts= 0;
780
930
  keys_for_keyread.reset();
781
931
  set_prefix(keys_in_use, keys);
782
932
 
783
 
  _field_size= table.field_size();
 
933
  fields= table.field_size();
784
934
 
785
 
  setFields(_field_size + 1);
786
 
  _fields[_field_size]= NULL;
 
935
  setFields(fields + 1);
 
936
  field[fields]= NULL;
787
937
 
788
938
  uint32_t local_null_fields= 0;
789
939
  reclength= 0;
791
941
  std::vector<uint32_t> field_offsets;
792
942
  std::vector<uint32_t> field_pack_length;
793
943
 
794
 
  field_offsets.resize(_field_size);
795
 
  field_pack_length.resize(_field_size);
 
944
  field_offsets.resize(fields);
 
945
  field_pack_length.resize(fields);
796
946
 
797
947
  uint32_t interval_count= 0;
798
948
  uint32_t interval_parts= 0;
799
949
 
800
950
  uint32_t stored_columns_reclength= 0;
801
951
 
802
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
952
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
803
953
  {
804
954
    message::Table::Field pfield= table.field(fieldnr);
805
 
    if (pfield.constraints().is_nullable()) // Historical reference
806
 
    {
807
 
      local_null_fields++;
808
 
    }
809
 
    else if (not pfield.constraints().is_notnull())
810
 
    {
811
 
      local_null_fields++;
812
 
    }
 
955
    if (pfield.constraints().is_nullable())
 
956
      local_null_fields++;
813
957
 
814
 
    enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
 
958
    enum_field_types drizzle_field_type=
 
959
      proto_field_type_to_drizzle_type(pfield.type());
815
960
 
816
961
    field_offsets[fieldnr]= stored_columns_reclength;
817
962
 
850
995
      {
851
996
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
852
997
 
853
 
        field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
 
998
        field_pack_length[fieldnr]= my_decimal_get_binary_size(fo.precision(), fo.scale());
854
999
      }
855
1000
      break;
856
1001
    default:
900
1045
 
901
1046
  uint32_t interval_nr= 0;
902
1047
 
903
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1048
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
904
1049
  {
905
1050
    message::Table::Field pfield= table.field(fieldnr);
906
1051
 
957
1102
  /* and read the fields */
958
1103
  interval_nr= 0;
959
1104
 
960
 
  bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
 
1105
  bool use_hash= fields >= MAX_FIELDS_BEFORE_HASH;
961
1106
 
962
1107
  unsigned char* null_pos= getDefaultValues();
963
1108
  int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
964
1109
 
965
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1110
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
966
1111
  {
967
1112
    message::Table::Field pfield= table.field(fieldnr);
968
1113
 
1017
1162
 
1018
1163
    enum_field_types field_type;
1019
1164
 
1020
 
    field_type= proto_field_type_to_drizzle_type(pfield);
 
1165
    field_type= proto_field_type_to_drizzle_type(pfield.type());
1021
1166
 
1022
1167
    const CHARSET_INFO *charset= &my_charset_bin;
1023
1168
 
1062
1207
      {
1063
1208
        if (fo.scale() > DECIMAL_MAX_SCALE)
1064
1209
        {
1065
 
          local_error= ER_NOT_FORM_FILE;
 
1210
          local_error= 4;
1066
1211
 
1067
 
          return true;
 
1212
          return local_error;
1068
1213
        }
1069
1214
        decimals= static_cast<uint8_t>(fo.scale());
1070
1215
      }
1084
1229
    }
1085
1230
 
1086
1231
 
 
1232
    blob_ptr_size= portable_sizeof_char_ptr;
 
1233
 
1087
1234
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1088
1235
 
1089
1236
    // We set field_length in this loop.
1118
1265
            decimals != NOT_FIXED_DEC)
1119
1266
        {
1120
1267
          my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1121
 
          local_error= ER_M_BIGGER_THAN_D;
1122
 
          return true;
 
1268
          local_error= 1;
 
1269
 
 
1270
          return local_error;
1123
1271
        }
1124
1272
        break;
1125
1273
      }
1127
1275
      {
1128
1276
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1129
1277
 
1130
 
        field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
 
1278
        field_length= my_decimal_precision_to_length(fo.precision(), fo.scale(),
1131
1279
                                                     false);
1132
1280
        break;
1133
1281
      }
1163
1311
      }
1164
1312
      break;
1165
1313
    case DRIZZLE_TYPE_LONGLONG:
1166
 
      {
1167
 
        uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1168
 
        field_length= MAX_BIGINT_WIDTH+sign_len;
1169
 
      }
 
1314
      field_length= MAX_BIGINT_WIDTH;
1170
1315
      break;
1171
1316
    case DRIZZLE_TYPE_UUID:
1172
1317
      field_length= field::Uuid::max_string_length();
1173
1318
      break;
1174
 
    case DRIZZLE_TYPE_BOOLEAN:
1175
 
      field_length= field::Boolean::max_string_length();
1176
 
      break;
1177
 
    case DRIZZLE_TYPE_MICROTIME:
1178
 
      field_length= field::Microtime::max_string_length();
1179
 
      break;
1180
1319
    case DRIZZLE_TYPE_TIMESTAMP:
1181
1320
      field_length= field::Epoch::max_string_length();
1182
1321
      break;
1187
1326
      abort(); // Programming error
1188
1327
    }
1189
1328
 
1190
 
    bool is_not_null= false;
1191
 
 
1192
 
    if (not pfield.constraints().is_nullable())
1193
 
    {
1194
 
      is_not_null= true;
1195
 
    }
1196
 
    else if (pfield.constraints().is_notnull())
1197
 
    {
1198
 
      is_not_null= true;
1199
 
    }
 
1329
    assert(enum_field_types_size == 13);
1200
1330
 
1201
1331
    Field* f= make_field(pfield,
1202
1332
                         record + field_offsets[fieldnr] + data_offset,
1203
1333
                         field_length,
1204
 
                         not is_not_null,
 
1334
                         pfield.constraints().is_nullable(),
1205
1335
                         null_pos,
1206
1336
                         null_bit_pos,
1207
1337
                         decimals,
1209
1339
                         charset,
1210
1340
                         MTYP_TYPENR(unireg_type),
1211
1341
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
1212
 
                         getTableMessage()->field(fieldnr).name().c_str());
 
1342
                         getTableProto()->field(fieldnr).name().c_str());
1213
1343
 
1214
 
    _fields[fieldnr]= f;
 
1344
    field[fieldnr]= f;
1215
1345
 
1216
1346
    // Insert post make_field code here.
1217
1347
    switch (field_type)
1223
1353
    case DRIZZLE_TYPE_TIMESTAMP:
1224
1354
    case DRIZZLE_TYPE_TIME:
1225
1355
    case DRIZZLE_TYPE_DATETIME:
1226
 
    case DRIZZLE_TYPE_MICROTIME:
1227
1356
    case DRIZZLE_TYPE_DATE:
1228
1357
    case DRIZZLE_TYPE_ENUM:
1229
1358
    case DRIZZLE_TYPE_LONG:
1230
1359
    case DRIZZLE_TYPE_LONGLONG:
1231
1360
    case DRIZZLE_TYPE_NULL:
1232
1361
    case DRIZZLE_TYPE_UUID:
1233
 
    case DRIZZLE_TYPE_BOOLEAN:
1234
1362
      break;
1235
1363
    }
1236
1364
 
1258
1386
      if (res != 0 && res != 3) /* @TODO Huh? */
1259
1387
      {
1260
1388
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1261
 
        local_error= ER_INVALID_DEFAULT;
 
1389
        local_error= 1;
1262
1390
 
1263
 
        return true;
 
1391
        return local_error;
1264
1392
      }
1265
1393
    }
1266
1394
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1279
1407
 
1280
1408
    f->setPosition(fieldnr);
1281
1409
    f->comment= comment;
1282
 
    if (not default_value &&
1283
 
        not (f->unireg_check==Field::NEXT_NUMBER) &&
 
1410
    if (! default_value &&
 
1411
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1284
1412
        (f->flags & NOT_NULL_FLAG) &&
1285
 
        (not f->is_timestamp()))
 
1413
        (f->real_type() != DRIZZLE_TYPE_TIMESTAMP))
1286
1414
    {
1287
1415
      f->flags|= NO_DEFAULT_VALUE_FLAG;
1288
1416
    }
1289
1417
 
1290
1418
    if (f->unireg_check == Field::NEXT_NUMBER)
1291
 
      found_next_number_field= &(_fields[fieldnr]);
 
1419
      found_next_number_field= &(field[fieldnr]);
1292
1420
 
1293
1421
    if (use_hash) /* supposedly this never fails... but comments lie */
1294
1422
    {
1295
 
      const char *local_field_name= _fields[fieldnr]->field_name;
1296
 
      name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
 
1423
      const char *local_field_name= field[fieldnr]->field_name;
 
1424
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1297
1425
    }
1298
1426
  }
1299
1427
 
1349
1477
        for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1350
1478
        {
1351
1479
          uint32_t fieldnr= key_part[i].fieldnr;
1352
 
          if (not fieldnr ||
1353
 
              _fields[fieldnr-1]->null_ptr ||
1354
 
              _fields[fieldnr-1]->key_length() != key_part[i].length)
 
1480
          if (! fieldnr ||
 
1481
              field[fieldnr-1]->null_ptr ||
 
1482
              field[fieldnr-1]->key_length() != key_part[i].length)
1355
1483
          {
1356
1484
            local_primary_key= MAX_KEY; // Can't be used
1357
1485
            break;
1366
1494
        {
1367
1495
          return ENOMEM;
1368
1496
        }
1369
 
        local_field= key_part->field= _fields[key_part->fieldnr-1];
 
1497
        local_field= key_part->field= field[key_part->fieldnr-1];
1370
1498
        key_part->type= local_field->key_type();
1371
1499
        if (local_field->null_ptr)
1372
1500
        {
1472
1600
                            &next_number_keypart)) < 0)
1473
1601
    {
1474
1602
      /* Wrong field definition */
1475
 
      local_error= ER_NOT_FORM_FILE;
 
1603
      local_error= 4;
1476
1604
 
1477
 
      return true;
 
1605
      return local_error;
1478
1606
    }
1479
1607
    else
1480
1608
    {
1488
1616
    blob_field.resize(blob_fields);
1489
1617
    uint32_t *save= &blob_field[0];
1490
1618
    uint32_t k= 0;
1491
 
    for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
 
1619
    for (Fields::iterator iter= field.begin(); iter != field.end()-1; iter++, k++)
1492
1620
    {
1493
1621
      if ((*iter)->flags & BLOB_FLAG)
1494
1622
        (*save++)= k;
1496
1624
  }
1497
1625
 
1498
1626
  all_set.clear();
1499
 
  all_set.resize(_field_size);
 
1627
  all_set.resize(fields);
1500
1628
  all_set.set();
1501
1629
 
1502
 
  return local_error != EE_OK;
1503
 
}
 
1630
  return local_error;
 
1631
}
 
1632
 
 
1633
int TableShare::parse_table_proto(Session& session, message::Table &table)
 
1634
{
 
1635
  int local_error= inner_parse_table_proto(session, table);
 
1636
 
 
1637
  if (not local_error)
 
1638
    return 0;
 
1639
 
 
1640
  error= local_error;
 
1641
  open_errno= errno;
 
1642
  errarg= 0;
 
1643
  open_table_error(local_error, open_errno, 0);
 
1644
 
 
1645
  return local_error;
 
1646
}
 
1647
 
1504
1648
 
1505
1649
/*
1506
1650
  Read table definition from a binary / text based .frm cursor
1526
1670
  6    Unknown .frm version
1527
1671
*/
1528
1672
 
1529
 
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
 
1673
int TableShare::open_table_def(Session& session, const TableIdentifier &identifier)
1530
1674
{
1531
 
  drizzled::error_t local_error= EE_OK;
1532
 
 
1533
 
  message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1534
 
 
1535
 
  if (table and table->IsInitialized())
1536
 
  {
1537
 
    if (parse_table_proto(session, *table))
1538
 
    {
1539
 
      local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1540
 
      my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1541
 
    }
1542
 
    else
1543
 
    {
1544
 
      setTableCategory(TABLE_CATEGORY_USER);
1545
 
      local_error= EE_OK;
1546
 
    }
1547
 
  }
1548
 
  else if (table and not table->IsInitialized())
1549
 
  {
1550
 
    local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1551
 
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1552
 
  }
1553
 
  else
1554
 
  {
1555
 
    local_error= ER_TABLE_UNKNOWN;
1556
 
    my_error(ER_TABLE_UNKNOWN, identifier);
1557
 
  }
1558
 
 
1559
 
  return static_cast<int>(local_error);
 
1675
  int local_error;
 
1676
  bool error_given;
 
1677
 
 
1678
  local_error= 1;
 
1679
  error_given= 0;
 
1680
 
 
1681
  message::table::shared_ptr table;
 
1682
 
 
1683
  local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
 
1684
 
 
1685
  do {
 
1686
    if (local_error != EEXIST)
 
1687
    {
 
1688
      if (local_error > 0)
 
1689
      {
 
1690
        errno= local_error;
 
1691
        local_error= 1;
 
1692
      }
 
1693
      else
 
1694
      {
 
1695
        if (not table->IsInitialized())
 
1696
        {
 
1697
          local_error= 4;
 
1698
        }
 
1699
      }
 
1700
      break;
 
1701
    }
 
1702
 
 
1703
    local_error= parse_table_proto(session, *table);
 
1704
 
 
1705
    setTableCategory(TABLE_CATEGORY_USER);
 
1706
  } while (0);
 
1707
 
 
1708
  if (local_error && !error_given)
 
1709
  {
 
1710
    error= local_error;
 
1711
    open_table_error(error, (open_errno= errno), 0);
 
1712
  }
 
1713
 
 
1714
  return(error);
1560
1715
}
1561
1716
 
1562
1717
 
1584
1739
  7    Table definition has changed in engine
1585
1740
*/
1586
1741
int TableShare::open_table_from_share(Session *session,
1587
 
                                      const identifier::Table &identifier,
 
1742
                                      const TableIdentifier &identifier,
1588
1743
                                      const char *alias,
1589
1744
                                      uint32_t db_stat, uint32_t ha_open_flags,
1590
1745
                                      Table &outparam)
1601
1756
  if (not error_reported)
1602
1757
    open_table_error(ret, errno, 0);
1603
1758
 
1604
 
  boost::checked_delete(outparam.cursor);
 
1759
  delete outparam.cursor;
1605
1760
  outparam.cursor= 0;                           // For easier error checking
1606
1761
  outparam.db_stat= 0;
1607
1762
  outparam.getMemRoot()->free_root(MYF(0));       // Safe to call on zeroed root
1620
1775
  unsigned char *record= NULL;
1621
1776
  Field **field_ptr;
1622
1777
 
 
1778
  /* Parsing of partitioning information from .frm needs session->lex set up. */
 
1779
  assert(session->lex->is_lex_started);
 
1780
 
1623
1781
  local_error= 1;
1624
1782
  outparam.resetTable(session, this, db_stat);
1625
1783
 
1671
1829
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1672
1830
  }
1673
1831
 
1674
 
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
 
1832
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1675
1833
  {
1676
1834
    return local_error;
1677
1835
  }
1683
1841
  outparam.null_flags= (unsigned char*) record+1;
1684
1842
 
1685
1843
  /* Setup copy of fields from share, but use the right alias and record */
1686
 
  for (uint32_t i= 0 ; i < _field_size; i++, field_ptr++)
 
1844
  for (uint32_t i= 0 ; i < fields; i++, field_ptr++)
1687
1845
  {
1688
 
    if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
 
1846
    if (!((*field_ptr)= field[i]->clone(outparam.getMemRoot(), &outparam)))
1689
1847
      return local_error;
1690
1848
  }
1691
1849
  (*field_ptr)= 0;                              // End marker
1743
1901
 
1744
1902
  /* Allocate bitmaps */
1745
1903
 
1746
 
  outparam.def_read_set.resize(_field_size);
1747
 
  outparam.def_write_set.resize(_field_size);
1748
 
  outparam.tmp_set.resize(_field_size);
 
1904
  outparam.def_read_set.resize(fields);
 
1905
  outparam.def_write_set.resize(fields);
 
1906
  outparam.tmp_set.resize(fields);
1749
1907
  outparam.default_column_bitmaps();
1750
1908
 
1751
1909
  return 0;
1752
1910
}
1753
1911
 
1754
 
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
 
1912
int TableShare::open_table_cursor_inner(const TableIdentifier &identifier,
1755
1913
                                        uint32_t db_stat, uint32_t ha_open_flags,
1756
1914
                                        Table &outparam,
1757
1915
                                        bool &error_reported)
1802
1960
/* error message when opening a form cursor */
1803
1961
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1804
1962
{
 
1963
  int err_no;
1805
1964
  char buff[FN_REFLEN];
1806
1965
  myf errortype= ME_ERROR+ME_WAITTANG;
1807
1966
 
1810
1969
  case 1:
1811
1970
    if (db_errno == ENOENT)
1812
1971
    {
1813
 
      identifier::Table identifier(db.str, table_name.str);
1814
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
1972
      my_error(ER_NO_SUCH_TABLE, MYF(0), db.str, table_name.str);
1815
1973
    }
1816
1974
    else
1817
1975
    {
1822
1980
    break;
1823
1981
  case 2:
1824
1982
    {
1825
 
      drizzled::error_t err_no;
1826
 
 
1827
1983
      err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1828
1984
        ER_FILE_USED : ER_CANT_OPEN_FILE;
1829
 
 
1830
1985
      my_error(err_no, errortype, normalized_path.str, db_errno);
1831
1986
      break;
1832
1987
    }
1862
2017
  return;
1863
2018
} /* open_table_error */
1864
2019
 
1865
 
Field *TableShare::make_field(const message::Table::Field &pfield,
 
2020
Field *TableShare::make_field(message::Table::Field &pfield,
1866
2021
                              unsigned char *ptr,
1867
2022
                              uint32_t field_length,
1868
2023
                              bool is_nullable,
1875
2030
                              TYPELIB *interval,
1876
2031
                              const char *field_name)
1877
2032
{
1878
 
  return make_field(pfield,
1879
 
                    ptr,
 
2033
  return make_field(ptr,
1880
2034
                    field_length,
1881
2035
                    is_nullable,
1882
2036
                    null_pos,
1890
2044
                    pfield.constraints().is_unsigned());
1891
2045
}
1892
2046
 
1893
 
Field *TableShare::make_field(const message::Table::Field &,
1894
 
                              unsigned char *ptr,
 
2047
Field *TableShare::make_field(unsigned char *ptr,
1895
2048
                              uint32_t field_length,
1896
2049
                              bool is_nullable,
1897
2050
                              unsigned char *null_pos,
1914
2067
    null_bit= ((unsigned char) 1) << null_bit;
1915
2068
  }
1916
2069
 
 
2070
  switch (field_type) 
 
2071
  {
 
2072
  case DRIZZLE_TYPE_DATE:
 
2073
  case DRIZZLE_TYPE_DATETIME:
 
2074
  case DRIZZLE_TYPE_TIMESTAMP:
 
2075
  case DRIZZLE_TYPE_UUID:
 
2076
    field_charset= &my_charset_bin;
 
2077
  default: break;
 
2078
  }
 
2079
 
1917
2080
  switch (field_type)
1918
2081
  {
1919
2082
  case DRIZZLE_TYPE_ENUM:
1933
2096
                                      field_charset);
1934
2097
  case DRIZZLE_TYPE_BLOB:
1935
2098
    return new (&mem_root) Field_blob(ptr,
1936
 
                                      null_pos,
1937
 
                                      null_bit,
1938
 
                                      field_name,
1939
 
                                      this,
1940
 
                                      field_charset);
 
2099
                                 null_pos,
 
2100
                                 null_bit,
 
2101
                                 field_name,
 
2102
                                 this,
 
2103
                                 field_charset);
1941
2104
  case DRIZZLE_TYPE_DECIMAL:
1942
2105
    return new (&mem_root) Field_decimal(ptr,
1943
 
                                         field_length,
1944
 
                                         null_pos,
1945
 
                                         null_bit,
1946
 
                                         unireg_check,
1947
 
                                         field_name,
1948
 
                                         decimals);
 
2106
                                    field_length,
 
2107
                                    null_pos,
 
2108
                                    null_bit,
 
2109
                                    unireg_check,
 
2110
                                    field_name,
 
2111
                                    decimals,
 
2112
                                    false,
 
2113
                                    false /* is_unsigned */);
1949
2114
  case DRIZZLE_TYPE_DOUBLE:
1950
2115
    return new (&mem_root) Field_double(ptr,
1951
2116
                                   field_length,
1962
2127
                                       null_pos,
1963
2128
                                       null_bit,
1964
2129
                                       field_name);
1965
 
  case DRIZZLE_TYPE_BOOLEAN:
1966
 
    return new (&mem_root) field::Boolean(ptr,
1967
 
                                          field_length,
1968
 
                                          null_pos,
1969
 
                                          null_bit,
1970
 
                                          field_name,
1971
 
                                          is_unsigned);
1972
2130
  case DRIZZLE_TYPE_LONG:
1973
2131
    return new (&mem_root) field::Int32(ptr,
1974
2132
                                        field_length,
1995
2153
                                          unireg_check,
1996
2154
                                          field_name);
1997
2155
    }
1998
 
  case DRIZZLE_TYPE_MICROTIME:
1999
 
    return new (&mem_root) field::Microtime(ptr,
2000
 
                                            null_pos,
2001
 
                                            null_bit,
2002
 
                                            unireg_check,
2003
 
                                            field_name,
2004
 
                                            this);
2005
2156
  case DRIZZLE_TYPE_TIMESTAMP:
2006
2157
    return new (&mem_root) field::Epoch(ptr,
 
2158
                                        field_length,
2007
2159
                                        null_pos,
2008
2160
                                        null_bit,
2009
2161
                                        unireg_check,
2010
2162
                                        field_name,
2011
 
                                        this);
 
2163
                                        this,
 
2164
                                        field_charset);
2012
2165
  case DRIZZLE_TYPE_TIME:
2013
2166
    return new (&mem_root) field::Time(ptr,
2014
2167
                                       field_length,
2015
2168
                                       null_pos,
2016
2169
                                       null_bit,
2017
 
                                       field_name);
 
2170
                                       field_name,
 
2171
                                       field_charset);
2018
2172
  case DRIZZLE_TYPE_DATE:
2019
2173
    return new (&mem_root) Field_date(ptr,
2020
2174
                                 null_pos,
2021
2175
                                 null_bit,
2022
 
                                 field_name);
 
2176
                                 field_name,
 
2177
                                 field_charset);
2023
2178
  case DRIZZLE_TYPE_DATETIME:
2024
2179
    return new (&mem_root) Field_datetime(ptr,
2025
2180
                                     null_pos,
2026
2181
                                     null_bit,
2027
 
                                     field_name);
 
2182
                                     field_name,
 
2183
                                     field_charset);
2028
2184
  case DRIZZLE_TYPE_NULL:
2029
2185
    return new (&mem_root) Field_null(ptr,
2030
 
                                      field_length,
2031
 
                                      field_name);
 
2186
                                 field_length,
 
2187
                                 field_name,
 
2188
                                 field_charset);
2032
2189
  }
2033
2190
  assert(0);
2034
2191
  abort();
2035
2192
}
2036
2193
 
2037
 
void TableShare::refreshVersion()
2038
 
{
2039
 
  version= refresh_version;
2040
 
}
2041
 
 
2042
2194
 
2043
2195
} /* namespace drizzled */