~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.cc

  • Committer: Monty Taylor
  • Date: 2010-12-27 18:39:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101227183911-atgh0kcubflay0b9
Added back INNOBASE_SKIP_WARNINGS for solaris. Also dealt with unused params.

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
  {
590
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
591
 
             table.name().empty() ? " " :  table.name().c_str(),
592
 
             table.InitializationErrorString().c_str());
593
 
 
 
738
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table.InitializationErrorString().c_str());
594
739
    return ER_CORRUPT_TABLE_DEFINITION;
595
740
  }
596
741
 
597
 
  setTableMessage(table);
 
742
  setTableProto(new(nothrow) message::Table(table));
598
743
 
599
744
  storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
600
745
  assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
620
765
 
621
766
  table_charset= get_charset(table_options.collation_id());
622
767
 
623
 
  if (not table_charset)
 
768
  if (! table_charset)
624
769
  {
625
 
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
626
 
             table_options.collation().c_str(),
627
 
             table.name().c_str());
 
770
    char errmsg[100];
 
771
    snprintf(errmsg, sizeof(errmsg),
 
772
             _("Table %s has invalid/unknown collation: %d,%s"),
 
773
             getPath(),
 
774
             table_options.collation_id(),
 
775
             table_options.collation().c_str());
 
776
    errmsg[99]='\0';
628
777
 
629
 
    return ER_CORRUPT_TABLE_DEFINITION; // Historical
 
778
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), errmsg);
 
779
    return ER_CORRUPT_TABLE_DEFINITION;
630
780
  }
631
781
 
632
782
  db_record_offset= 1;
633
783
 
 
784
  blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
 
785
 
634
786
  keys= table.indexes_size();
635
787
 
636
788
  key_parts= 0;
780
932
  keys_for_keyread.reset();
781
933
  set_prefix(keys_in_use, keys);
782
934
 
783
 
  _field_size= table.field_size();
 
935
  fields= table.field_size();
784
936
 
785
 
  setFields(_field_size + 1);
786
 
  _fields[_field_size]= NULL;
 
937
  setFields(fields + 1);
 
938
  field[fields]= NULL;
787
939
 
788
940
  uint32_t local_null_fields= 0;
789
941
  reclength= 0;
791
943
  std::vector<uint32_t> field_offsets;
792
944
  std::vector<uint32_t> field_pack_length;
793
945
 
794
 
  field_offsets.resize(_field_size);
795
 
  field_pack_length.resize(_field_size);
 
946
  field_offsets.resize(fields);
 
947
  field_pack_length.resize(fields);
796
948
 
797
949
  uint32_t interval_count= 0;
798
950
  uint32_t interval_parts= 0;
799
951
 
800
952
  uint32_t stored_columns_reclength= 0;
801
953
 
802
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
954
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
803
955
  {
804
956
    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
 
    }
 
957
    if (pfield.constraints().is_nullable())
 
958
      local_null_fields++;
813
959
 
814
 
    enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
 
960
    enum_field_types drizzle_field_type=
 
961
      proto_field_type_to_drizzle_type(pfield.type());
815
962
 
816
963
    field_offsets[fieldnr]= stored_columns_reclength;
817
964
 
850
997
      {
851
998
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
852
999
 
853
 
        field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
 
1000
        field_pack_length[fieldnr]= my_decimal_get_binary_size(fo.precision(), fo.scale());
854
1001
      }
855
1002
      break;
856
1003
    default:
900
1047
 
901
1048
  uint32_t interval_nr= 0;
902
1049
 
903
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1050
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
904
1051
  {
905
1052
    message::Table::Field pfield= table.field(fieldnr);
906
1053
 
912
1059
 
913
1060
    if (field_options.field_value_size() > Field_enum::max_supported_elements)
914
1061
    {
915
 
      my_error(ER_CORRUPT_TABLE_DEFINITION_ENUM, MYF(0), table.name().c_str());
 
1062
      char errmsg[100];
 
1063
      snprintf(errmsg, sizeof(errmsg),
 
1064
               _("ENUM column %s has greater than %d possible values"),
 
1065
               pfield.name().c_str(),
 
1066
               Field_enum::max_supported_elements);
 
1067
      errmsg[99]='\0';
916
1068
 
917
 
      return ER_CORRUPT_TABLE_DEFINITION_ENUM; // Historical
 
1069
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), errmsg);
 
1070
      return ER_CORRUPT_TABLE_DEFINITION;
918
1071
    }
919
1072
 
920
1073
 
957
1110
  /* and read the fields */
958
1111
  interval_nr= 0;
959
1112
 
960
 
  bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
 
1113
  bool use_hash= fields >= MAX_FIELDS_BEFORE_HASH;
961
1114
 
962
1115
  unsigned char* null_pos= getDefaultValues();
963
1116
  int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
964
1117
 
965
 
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
 
1118
  for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
966
1119
  {
967
1120
    message::Table::Field pfield= table.field(fieldnr);
968
1121
 
1017
1170
 
1018
1171
    enum_field_types field_type;
1019
1172
 
1020
 
    field_type= proto_field_type_to_drizzle_type(pfield);
 
1173
    field_type= proto_field_type_to_drizzle_type(pfield.type());
1021
1174
 
1022
1175
    const CHARSET_INFO *charset= &my_charset_bin;
1023
1176
 
1062
1215
      {
1063
1216
        if (fo.scale() > DECIMAL_MAX_SCALE)
1064
1217
        {
1065
 
          local_error= ER_NOT_FORM_FILE;
 
1218
          local_error= 4;
1066
1219
 
1067
 
          return true;
 
1220
          return local_error;
1068
1221
        }
1069
1222
        decimals= static_cast<uint8_t>(fo.scale());
1070
1223
      }
1084
1237
    }
1085
1238
 
1086
1239
 
 
1240
    blob_ptr_size= portable_sizeof_char_ptr;
 
1241
 
1087
1242
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1088
1243
 
1089
1244
    // We set field_length in this loop.
1118
1273
            decimals != NOT_FIXED_DEC)
1119
1274
        {
1120
1275
          my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1121
 
          local_error= ER_M_BIGGER_THAN_D;
1122
 
          return true;
 
1276
          local_error= 1;
 
1277
 
 
1278
          return local_error;
1123
1279
        }
1124
1280
        break;
1125
1281
      }
1127
1283
      {
1128
1284
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1129
1285
 
1130
 
        field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
 
1286
        field_length= my_decimal_precision_to_length(fo.precision(), fo.scale(),
1131
1287
                                                     false);
1132
1288
        break;
1133
1289
      }
1163
1319
      }
1164
1320
      break;
1165
1321
    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
 
      }
 
1322
      field_length= MAX_BIGINT_WIDTH;
1170
1323
      break;
1171
1324
    case DRIZZLE_TYPE_UUID:
1172
1325
      field_length= field::Uuid::max_string_length();
1173
1326
      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
1327
    case DRIZZLE_TYPE_TIMESTAMP:
1181
1328
      field_length= field::Epoch::max_string_length();
1182
1329
      break;
1187
1334
      abort(); // Programming error
1188
1335
    }
1189
1336
 
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
 
    }
 
1337
    assert(enum_field_types_size == 13);
1200
1338
 
1201
1339
    Field* f= make_field(pfield,
1202
1340
                         record + field_offsets[fieldnr] + data_offset,
1203
1341
                         field_length,
1204
 
                         not is_not_null,
 
1342
                         pfield.constraints().is_nullable(),
1205
1343
                         null_pos,
1206
1344
                         null_bit_pos,
1207
1345
                         decimals,
1209
1347
                         charset,
1210
1348
                         MTYP_TYPENR(unireg_type),
1211
1349
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
1212
 
                         getTableMessage()->field(fieldnr).name().c_str());
 
1350
                         getTableProto()->field(fieldnr).name().c_str());
1213
1351
 
1214
 
    _fields[fieldnr]= f;
 
1352
    field[fieldnr]= f;
1215
1353
 
1216
1354
    // Insert post make_field code here.
1217
1355
    switch (field_type)
1223
1361
    case DRIZZLE_TYPE_TIMESTAMP:
1224
1362
    case DRIZZLE_TYPE_TIME:
1225
1363
    case DRIZZLE_TYPE_DATETIME:
1226
 
    case DRIZZLE_TYPE_MICROTIME:
1227
1364
    case DRIZZLE_TYPE_DATE:
1228
1365
    case DRIZZLE_TYPE_ENUM:
1229
1366
    case DRIZZLE_TYPE_LONG:
1230
1367
    case DRIZZLE_TYPE_LONGLONG:
1231
1368
    case DRIZZLE_TYPE_NULL:
1232
1369
    case DRIZZLE_TYPE_UUID:
1233
 
    case DRIZZLE_TYPE_BOOLEAN:
1234
1370
      break;
1235
1371
    }
1236
1372
 
1258
1394
      if (res != 0 && res != 3) /* @TODO Huh? */
1259
1395
      {
1260
1396
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1261
 
        local_error= ER_INVALID_DEFAULT;
 
1397
        local_error= 1;
1262
1398
 
1263
 
        return true;
 
1399
        return local_error;
1264
1400
      }
1265
1401
    }
1266
1402
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1279
1415
 
1280
1416
    f->setPosition(fieldnr);
1281
1417
    f->comment= comment;
1282
 
    if (not default_value &&
1283
 
        not (f->unireg_check==Field::NEXT_NUMBER) &&
 
1418
    if (! default_value &&
 
1419
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1284
1420
        (f->flags & NOT_NULL_FLAG) &&
1285
 
        (not f->is_timestamp()))
 
1421
        (f->real_type() != DRIZZLE_TYPE_TIMESTAMP))
1286
1422
    {
1287
1423
      f->flags|= NO_DEFAULT_VALUE_FLAG;
1288
1424
    }
1289
1425
 
1290
1426
    if (f->unireg_check == Field::NEXT_NUMBER)
1291
 
      found_next_number_field= &(_fields[fieldnr]);
 
1427
      found_next_number_field= &(field[fieldnr]);
1292
1428
 
1293
1429
    if (use_hash) /* supposedly this never fails... but comments lie */
1294
1430
    {
1295
 
      const char *local_field_name= _fields[fieldnr]->field_name;
1296
 
      name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
 
1431
      const char *local_field_name= field[fieldnr]->field_name;
 
1432
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1297
1433
    }
1298
1434
  }
1299
1435
 
1349
1485
        for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1350
1486
        {
1351
1487
          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)
 
1488
          if (! fieldnr ||
 
1489
              field[fieldnr-1]->null_ptr ||
 
1490
              field[fieldnr-1]->key_length() != key_part[i].length)
1355
1491
          {
1356
1492
            local_primary_key= MAX_KEY; // Can't be used
1357
1493
            break;
1366
1502
        {
1367
1503
          return ENOMEM;
1368
1504
        }
1369
 
        local_field= key_part->field= _fields[key_part->fieldnr-1];
 
1505
        local_field= key_part->field= field[key_part->fieldnr-1];
1370
1506
        key_part->type= local_field->key_type();
1371
1507
        if (local_field->null_ptr)
1372
1508
        {
1472
1608
                            &next_number_keypart)) < 0)
1473
1609
    {
1474
1610
      /* Wrong field definition */
1475
 
      local_error= ER_NOT_FORM_FILE;
 
1611
      local_error= 4;
1476
1612
 
1477
 
      return true;
 
1613
      return local_error;
1478
1614
    }
1479
1615
    else
1480
1616
    {
1488
1624
    blob_field.resize(blob_fields);
1489
1625
    uint32_t *save= &blob_field[0];
1490
1626
    uint32_t k= 0;
1491
 
    for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
 
1627
    for (Fields::iterator iter= field.begin(); iter != field.end()-1; iter++, k++)
1492
1628
    {
1493
1629
      if ((*iter)->flags & BLOB_FLAG)
1494
1630
        (*save++)= k;
1496
1632
  }
1497
1633
 
1498
1634
  all_set.clear();
1499
 
  all_set.resize(_field_size);
 
1635
  all_set.resize(fields);
1500
1636
  all_set.set();
1501
1637
 
1502
 
  return local_error != EE_OK;
1503
 
}
 
1638
  return local_error;
 
1639
}
 
1640
 
 
1641
int TableShare::parse_table_proto(Session& session, message::Table &table)
 
1642
{
 
1643
  int local_error= inner_parse_table_proto(session, table);
 
1644
 
 
1645
  if (not local_error)
 
1646
    return 0;
 
1647
 
 
1648
  error= local_error;
 
1649
  open_errno= errno;
 
1650
  errarg= 0;
 
1651
  open_table_error(local_error, open_errno, 0);
 
1652
 
 
1653
  return local_error;
 
1654
}
 
1655
 
1504
1656
 
1505
1657
/*
1506
1658
  Read table definition from a binary / text based .frm cursor
1526
1678
  6    Unknown .frm version
1527
1679
*/
1528
1680
 
1529
 
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
 
1681
int TableShare::open_table_def(Session& session, const TableIdentifier &identifier)
1530
1682
{
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())
 
1683
  int local_error;
 
1684
  bool error_given;
 
1685
 
 
1686
  local_error= 1;
 
1687
  error_given= 0;
 
1688
 
 
1689
  message::table::shared_ptr table;
 
1690
 
 
1691
  local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
 
1692
 
 
1693
  if (local_error != EEXIST)
1536
1694
  {
1537
 
    if (parse_table_proto(session, *table))
 
1695
    if (local_error > 0)
1538
1696
    {
1539
 
      local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1540
 
      my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
 
1697
      errno= local_error;
 
1698
      local_error= 1;
1541
1699
    }
1542
1700
    else
1543
1701
    {
1544
 
      setTableCategory(TABLE_CATEGORY_USER);
1545
 
      local_error= EE_OK;
 
1702
      if (not table->IsInitialized())
 
1703
      {
 
1704
        local_error= 4;
 
1705
      }
1546
1706
    }
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);
 
1707
    goto err_not_open;
 
1708
  }
 
1709
 
 
1710
  local_error= parse_table_proto(session, *table);
 
1711
 
 
1712
  setTableCategory(TABLE_CATEGORY_USER);
 
1713
 
 
1714
err_not_open:
 
1715
  if (local_error && !error_given)
 
1716
  {
 
1717
    error= local_error;
 
1718
    open_table_error(error, (open_errno= errno), 0);
 
1719
  }
 
1720
 
 
1721
  return(error);
1560
1722
}
1561
1723
 
1562
1724
 
1584
1746
  7    Table definition has changed in engine
1585
1747
*/
1586
1748
int TableShare::open_table_from_share(Session *session,
1587
 
                                      const identifier::Table &identifier,
 
1749
                                      const TableIdentifier &identifier,
1588
1750
                                      const char *alias,
1589
1751
                                      uint32_t db_stat, uint32_t ha_open_flags,
1590
1752
                                      Table &outparam)
1601
1763
  if (not error_reported)
1602
1764
    open_table_error(ret, errno, 0);
1603
1765
 
1604
 
  boost::checked_delete(outparam.cursor);
 
1766
  delete outparam.cursor;
1605
1767
  outparam.cursor= 0;                           // For easier error checking
1606
1768
  outparam.db_stat= 0;
1607
1769
  outparam.getMemRoot()->free_root(MYF(0));       // Safe to call on zeroed root
1620
1782
  unsigned char *record= NULL;
1621
1783
  Field **field_ptr;
1622
1784
 
 
1785
  /* Parsing of partitioning information from .frm needs session->lex set up. */
 
1786
  assert(session->lex->is_lex_started);
 
1787
 
1623
1788
  local_error= 1;
1624
1789
  outparam.resetTable(session, this, db_stat);
1625
1790
 
1671
1836
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1672
1837
  }
1673
1838
 
1674
 
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
 
1839
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1675
1840
  {
1676
1841
    return local_error;
1677
1842
  }
1683
1848
  outparam.null_flags= (unsigned char*) record+1;
1684
1849
 
1685
1850
  /* 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++)
 
1851
  for (uint32_t i= 0 ; i < fields; i++, field_ptr++)
1687
1852
  {
1688
 
    if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
 
1853
    if (!((*field_ptr)= field[i]->clone(outparam.getMemRoot(), &outparam)))
1689
1854
      return local_error;
1690
1855
  }
1691
1856
  (*field_ptr)= 0;                              // End marker
1743
1908
 
1744
1909
  /* Allocate bitmaps */
1745
1910
 
1746
 
  outparam.def_read_set.resize(_field_size);
1747
 
  outparam.def_write_set.resize(_field_size);
1748
 
  outparam.tmp_set.resize(_field_size);
 
1911
  outparam.def_read_set.resize(fields);
 
1912
  outparam.def_write_set.resize(fields);
 
1913
  outparam.tmp_set.resize(fields);
1749
1914
  outparam.default_column_bitmaps();
1750
1915
 
1751
1916
  return 0;
1752
1917
}
1753
1918
 
1754
 
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
 
1919
int TableShare::open_table_cursor_inner(const TableIdentifier &identifier,
1755
1920
                                        uint32_t db_stat, uint32_t ha_open_flags,
1756
1921
                                        Table &outparam,
1757
1922
                                        bool &error_reported)
1802
1967
/* error message when opening a form cursor */
1803
1968
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1804
1969
{
 
1970
  int err_no;
1805
1971
  char buff[FN_REFLEN];
1806
1972
  myf errortype= ME_ERROR+ME_WAITTANG;
1807
1973
 
1810
1976
  case 1:
1811
1977
    if (db_errno == ENOENT)
1812
1978
    {
1813
 
      identifier::Table identifier(db.str, table_name.str);
1814
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
1979
      my_error(ER_NO_SUCH_TABLE, MYF(0), db.str, table_name.str);
1815
1980
    }
1816
1981
    else
1817
1982
    {
1822
1987
    break;
1823
1988
  case 2:
1824
1989
    {
1825
 
      drizzled::error_t err_no;
1826
 
 
1827
1990
      err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1828
1991
        ER_FILE_USED : ER_CANT_OPEN_FILE;
1829
 
 
1830
1992
      my_error(err_no, errortype, normalized_path.str, db_errno);
1831
1993
      break;
1832
1994
    }
1862
2024
  return;
1863
2025
} /* open_table_error */
1864
2026
 
1865
 
Field *TableShare::make_field(const message::Table::Field &pfield,
 
2027
Field *TableShare::make_field(message::Table::Field &pfield,
1866
2028
                              unsigned char *ptr,
1867
2029
                              uint32_t field_length,
1868
2030
                              bool is_nullable,
1875
2037
                              TYPELIB *interval,
1876
2038
                              const char *field_name)
1877
2039
{
1878
 
  return make_field(pfield,
1879
 
                    ptr,
 
2040
  return make_field(ptr,
1880
2041
                    field_length,
1881
2042
                    is_nullable,
1882
2043
                    null_pos,
1890
2051
                    pfield.constraints().is_unsigned());
1891
2052
}
1892
2053
 
1893
 
Field *TableShare::make_field(const message::Table::Field &,
1894
 
                              unsigned char *ptr,
 
2054
Field *TableShare::make_field(unsigned char *ptr,
1895
2055
                              uint32_t field_length,
1896
2056
                              bool is_nullable,
1897
2057
                              unsigned char *null_pos,
1914
2074
    null_bit= ((unsigned char) 1) << null_bit;
1915
2075
  }
1916
2076
 
 
2077
  switch (field_type) 
 
2078
  {
 
2079
  case DRIZZLE_TYPE_DATE:
 
2080
  case DRIZZLE_TYPE_DATETIME:
 
2081
  case DRIZZLE_TYPE_TIMESTAMP:
 
2082
  case DRIZZLE_TYPE_UUID:
 
2083
    field_charset= &my_charset_bin;
 
2084
  default: break;
 
2085
  }
 
2086
 
1917
2087
  switch (field_type)
1918
2088
  {
1919
2089
  case DRIZZLE_TYPE_ENUM:
1933
2103
                                      field_charset);
1934
2104
  case DRIZZLE_TYPE_BLOB:
1935
2105
    return new (&mem_root) Field_blob(ptr,
1936
 
                                      null_pos,
1937
 
                                      null_bit,
1938
 
                                      field_name,
1939
 
                                      this,
1940
 
                                      field_charset);
 
2106
                                 null_pos,
 
2107
                                 null_bit,
 
2108
                                 field_name,
 
2109
                                 this,
 
2110
                                 field_charset);
1941
2111
  case DRIZZLE_TYPE_DECIMAL:
1942
2112
    return new (&mem_root) Field_decimal(ptr,
1943
 
                                         field_length,
1944
 
                                         null_pos,
1945
 
                                         null_bit,
1946
 
                                         unireg_check,
1947
 
                                         field_name,
1948
 
                                         decimals);
 
2113
                                    field_length,
 
2114
                                    null_pos,
 
2115
                                    null_bit,
 
2116
                                    unireg_check,
 
2117
                                    field_name,
 
2118
                                    decimals,
 
2119
                                    false,
 
2120
                                    false /* is_unsigned */);
1949
2121
  case DRIZZLE_TYPE_DOUBLE:
1950
2122
    return new (&mem_root) Field_double(ptr,
1951
2123
                                   field_length,
1962
2134
                                       null_pos,
1963
2135
                                       null_bit,
1964
2136
                                       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
2137
  case DRIZZLE_TYPE_LONG:
1973
2138
    return new (&mem_root) field::Int32(ptr,
1974
2139
                                        field_length,
1995
2160
                                          unireg_check,
1996
2161
                                          field_name);
1997
2162
    }
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
2163
  case DRIZZLE_TYPE_TIMESTAMP:
2006
2164
    return new (&mem_root) field::Epoch(ptr,
 
2165
                                        field_length,
2007
2166
                                        null_pos,
2008
2167
                                        null_bit,
2009
2168
                                        unireg_check,
2010
2169
                                        field_name,
2011
 
                                        this);
 
2170
                                        this,
 
2171
                                        field_charset);
2012
2172
  case DRIZZLE_TYPE_TIME:
2013
2173
    return new (&mem_root) field::Time(ptr,
2014
2174
                                       field_length,
2015
2175
                                       null_pos,
2016
2176
                                       null_bit,
2017
 
                                       field_name);
 
2177
                                       field_name,
 
2178
                                       field_charset);
2018
2179
  case DRIZZLE_TYPE_DATE:
2019
2180
    return new (&mem_root) Field_date(ptr,
2020
2181
                                 null_pos,
2021
2182
                                 null_bit,
2022
 
                                 field_name);
 
2183
                                 field_name,
 
2184
                                 field_charset);
2023
2185
  case DRIZZLE_TYPE_DATETIME:
2024
2186
    return new (&mem_root) Field_datetime(ptr,
2025
2187
                                     null_pos,
2026
2188
                                     null_bit,
2027
 
                                     field_name);
 
2189
                                     field_name,
 
2190
                                     field_charset);
2028
2191
  case DRIZZLE_TYPE_NULL:
2029
2192
    return new (&mem_root) Field_null(ptr,
2030
 
                                      field_length,
2031
 
                                      field_name);
 
2193
                                 field_length,
 
2194
                                 field_name,
 
2195
                                 field_charset);
2032
2196
  }
2033
2197
  assert(0);
2034
2198
  abort();
2035
2199
}
2036
2200
 
2037
 
void TableShare::refreshVersion()
2038
 
{
2039
 
  version= refresh_version;
2040
 
}
2041
 
 
2042
2201
 
2043
2202
} /* namespace drizzled */