1
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
5
* Copyright (C) 2009 Sun Microsystems, Inc.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
This class is shared between different table objects. There is one
24
instance of table share per one table in the database.
27
/* Basic functions needed by many modules */
33
#include <sys/types.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"
46
#include "drizzled/table.h"
47
#include "drizzled/table/shell.h"
49
#include "drizzled/session.h"
51
#include "drizzled/charset.h"
52
#include "drizzled/internal/m_string.h"
53
#include "drizzled/internal/my_sys.h"
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"
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"
84
#include "drizzled/plugin/storage_engine.h"
86
#include "drizzled/definition/cache.h"
88
#include <drizzled/refresh_version.h>
95
extern size_t table_def_size;
98
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
102
case message::Table::Field::INTEGER:
103
return DRIZZLE_TYPE_LONG;
105
case message::Table::Field::DOUBLE:
106
return DRIZZLE_TYPE_DOUBLE;
108
case message::Table::Field::EPOCH:
109
if (field.has_time_options() and field.time_options().microseconds())
110
return DRIZZLE_TYPE_MICROTIME;
112
return DRIZZLE_TYPE_TIMESTAMP;
114
case message::Table::Field::BIGINT:
115
return DRIZZLE_TYPE_LONGLONG;
117
case message::Table::Field::DATETIME:
118
return DRIZZLE_TYPE_DATETIME;
120
case message::Table::Field::DATE:
121
return DRIZZLE_TYPE_DATE;
123
case message::Table::Field::VARCHAR:
124
return DRIZZLE_TYPE_VARCHAR;
126
case message::Table::Field::DECIMAL:
127
return DRIZZLE_TYPE_DECIMAL;
129
case message::Table::Field::ENUM:
130
return DRIZZLE_TYPE_ENUM;
132
case message::Table::Field::BLOB:
133
return DRIZZLE_TYPE_BLOB;
135
case message::Table::Field::UUID:
136
return DRIZZLE_TYPE_UUID;
138
case message::Table::Field::BOOLEAN:
139
return DRIZZLE_TYPE_BOOLEAN;
141
case message::Table::Field::TIME:
142
return DRIZZLE_TYPE_TIME;
148
static Item *default_value_item(enum_field_types field_type,
149
const CHARSET_INFO *charset,
150
bool default_null, const string *default_value,
151
const string *default_bin_value)
153
Item *default_item= NULL;
158
return new Item_null();
163
case DRIZZLE_TYPE_LONG:
164
case DRIZZLE_TYPE_LONGLONG:
165
default_item= new Item_int(default_value->c_str(),
166
(int64_t) internal::my_strtoll10(default_value->c_str(),
169
default_value->length());
171
case DRIZZLE_TYPE_DOUBLE:
172
default_item= new Item_float(default_value->c_str(),
173
default_value->length());
175
case DRIZZLE_TYPE_NULL:
178
case DRIZZLE_TYPE_TIMESTAMP:
179
case DRIZZLE_TYPE_DATETIME:
180
case DRIZZLE_TYPE_TIME:
181
case DRIZZLE_TYPE_DATE:
182
case DRIZZLE_TYPE_ENUM:
183
case DRIZZLE_TYPE_UUID:
184
case DRIZZLE_TYPE_MICROTIME:
185
case DRIZZLE_TYPE_BOOLEAN:
186
default_item= new Item_string(default_value->c_str(),
187
default_value->length(),
188
system_charset_info);
190
case DRIZZLE_TYPE_VARCHAR:
191
case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
192
if (charset==&my_charset_bin)
194
default_item= new Item_string(default_bin_value->c_str(),
195
default_bin_value->length(),
200
default_item= new Item_string(default_value->c_str(),
201
default_value->length(),
202
system_charset_info);
205
case DRIZZLE_TYPE_DECIMAL:
206
default_item= new Item_decimal(default_value->c_str(),
207
default_value->length(),
208
system_charset_info);
220
* Precache this stuff....
222
bool TableShare::fieldInPrimaryKey(Field *in_field) const
224
assert(getTableMessage());
226
size_t num_indexes= getTableMessage()->indexes_size();
228
for (size_t x= 0; x < num_indexes; ++x)
230
const message::Table::Index &index= getTableMessage()->indexes(x);
231
if (index.is_primary())
233
size_t num_parts= index.index_part_size();
234
for (size_t y= 0; y < num_parts; ++y)
236
if (index.index_part(y).fieldnr() == in_field->position())
244
TableShare::TableShare(const identifier::Table::Type type_arg) :
245
table_category(TABLE_UNKNOWN_CATEGORY),
246
found_next_number_field(NULL),
247
timestamp_field(NULL),
249
mem_root(TABLE_ALLOC_BLOCK_SIZE),
252
table_name(NULL_LEX_STRING),
253
path(NULL_LEX_STRING),
254
normalized_path(NULL_LEX_STRING),
259
stored_rec_length(0),
261
_table_message(NULL),
262
storage_engine(NULL),
266
last_null_bit_pos(0),
272
max_unique_length(0),
277
has_variable_width(false),
278
db_create_options(0),
279
db_options_in_use(0),
281
rowid_field_offset(0),
282
primary_key(MAX_KEY),
283
next_number_index(0),
284
next_number_key_offset(0),
285
next_number_keypart(0),
289
blob_ptr_size(portable_sizeof_char_ptr),
290
db_low_byte_first(false),
294
if (type_arg == message::Table::INTERNAL)
296
identifier::Table::build_tmptable_filename(private_key_for_cache.vectorPtr());
297
init(private_key_for_cache.vector(), private_key_for_cache.vector());
305
TableShare::TableShare(const identifier::Table &identifier, const identifier::Table::Key &key) :// Used by placeholder
306
table_category(TABLE_UNKNOWN_CATEGORY),
307
found_next_number_field(NULL),
308
timestamp_field(NULL),
310
mem_root(TABLE_ALLOC_BLOCK_SIZE),
314
table_name(NULL_LEX_STRING),
315
path(NULL_LEX_STRING),
316
normalized_path(NULL_LEX_STRING),
321
stored_rec_length(0),
323
_table_message(NULL),
324
storage_engine(NULL),
325
tmp_table(message::Table::INTERNAL),
328
last_null_bit_pos(0),
334
max_unique_length(0),
339
has_variable_width(false),
340
db_create_options(0),
341
db_options_in_use(0),
343
rowid_field_offset(0),
344
primary_key(MAX_KEY),
345
next_number_index(0),
346
next_number_key_offset(0),
347
next_number_keypart(0),
351
blob_ptr_size(portable_sizeof_char_ptr),
352
db_low_byte_first(false),
356
assert(identifier.getKey() == key);
358
private_key_for_cache= key;
360
table_category= TABLE_CATEGORY_TEMPORARY;
361
tmp_table= message::Table::INTERNAL;
363
db.str= const_cast<char *>(private_key_for_cache.vector());
364
db.length= strlen(private_key_for_cache.vector());
366
table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
367
table_name.length= strlen(table_name.str);
368
path.str= (char *)"";
369
normalized_path.str= path.str;
370
path.length= normalized_path.length= 0;
372
std::string tb_name(identifier.getTableName());
373
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
374
assert(strcmp(tb_name.c_str(), table_name.str) == 0);
376
assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
380
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
381
table_category(TABLE_UNKNOWN_CATEGORY),
382
found_next_number_field(NULL),
383
timestamp_field(NULL),
385
mem_root(TABLE_ALLOC_BLOCK_SIZE),
389
table_name(NULL_LEX_STRING),
390
path(NULL_LEX_STRING),
391
normalized_path(NULL_LEX_STRING),
396
stored_rec_length(0),
398
_table_message(NULL),
399
storage_engine(NULL),
400
tmp_table(identifier.getType()),
403
last_null_bit_pos(0),
409
max_unique_length(0),
414
has_variable_width(false),
415
db_create_options(0),
416
db_options_in_use(0),
418
rowid_field_offset(0),
419
primary_key(MAX_KEY),
420
next_number_index(0),
421
next_number_key_offset(0),
422
next_number_keypart(0),
426
blob_ptr_size(portable_sizeof_char_ptr),
427
db_low_byte_first(false),
431
private_key_for_cache= identifier.getKey();
432
assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
433
private_normalized_path.resize(identifier.getPath().size() + 1);
434
memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
437
table_category= TABLE_CATEGORY_TEMPORARY;
438
tmp_table= message::Table::INTERNAL;
439
db.str= const_cast<char *>(private_key_for_cache.vector());
440
db.length= strlen(private_key_for_cache.vector());
441
table_name.str= db.str + 1;
442
table_name.length= strlen(table_name.str);
443
path.str= &private_normalized_path[0];
444
normalized_path.str= path.str;
445
path.length= normalized_path.length= private_normalized_path.size();
451
Used for shares that will go into the cache.
453
TableShare::TableShare(const identifier::Table::Type type_arg,
454
const identifier::Table &identifier,
456
uint32_t path_length_arg) :
457
table_category(TABLE_UNKNOWN_CATEGORY),
458
found_next_number_field(NULL),
459
timestamp_field(NULL),
461
mem_root(TABLE_ALLOC_BLOCK_SIZE),
465
table_name(NULL_LEX_STRING),
466
path(NULL_LEX_STRING),
467
normalized_path(NULL_LEX_STRING),
472
stored_rec_length(0),
474
_table_message(NULL),
475
storage_engine(NULL),
479
last_null_bit_pos(0),
485
max_unique_length(0),
490
has_variable_width(false),
491
db_create_options(0),
492
db_options_in_use(0),
494
rowid_field_offset(0),
495
primary_key(MAX_KEY),
496
next_number_index(0),
497
next_number_key_offset(0),
498
next_number_keypart(0),
502
blob_ptr_size(portable_sizeof_char_ptr),
503
db_low_byte_first(false),
510
private_key_for_cache= identifier.getKey();
512
Let us use the fact that the key is "db/0/table_name/0" + optional
513
part for temporary tables.
515
db.str= const_cast<char *>(private_key_for_cache.vector());
516
db.length= strlen(db.str);
517
table_name.str= db.str + db.length + 1;
518
table_name.length= strlen(table_name.str);
522
_path.append(path_arg, path_length_arg);
526
identifier::Table::build_table_filename(_path, db.str, table_name.str, false);
529
if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
531
setPath(path_buff, _path.length());
532
strcpy(path_buff, _path.c_str());
533
setNormalizedPath(path_buff, _path.length());
535
version= refresh_version;
539
assert(0); // We should throw here.
544
void TableShare::init(const char *new_table_name,
545
const char *new_path)
548
table_category= TABLE_CATEGORY_TEMPORARY;
549
tmp_table= message::Table::INTERNAL;
552
table_name.str= (char*) new_table_name;
553
table_name.length= strlen(new_table_name);
554
path.str= (char*) new_path;
555
normalized_path.str= (char*) new_path;
556
path.length= normalized_path.length= strlen(new_path);
559
TableShare::~TableShare()
561
storage_engine= NULL;
563
mem_root.free_root(MYF(0)); // Free's share
566
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
568
private_key_for_cache= identifier_arg.getKey();
571
Let us use the fact that the key is "db/0/table_name/0" + optional
572
part for temporary tables.
574
db.str= const_cast<char *>(private_key_for_cache.vector());
575
db.length= strlen(db.str);
576
table_name.str= db.str + db.length + 1;
577
table_name.length= strlen(table_name.str);
579
getTableMessage()->set_name(identifier_arg.getTableName());
580
getTableMessage()->set_schema(identifier_arg.getSchemaName());
583
bool TableShare::parse_table_proto(Session& session, message::Table &table)
585
drizzled::error_t local_error= EE_OK;
587
if (! table.IsInitialized())
589
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
590
table.name().empty() ? " " : table.name().c_str(),
591
table.InitializationErrorString().c_str());
593
return ER_CORRUPT_TABLE_DEFINITION;
596
setTableMessage(table);
598
storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
599
assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
601
message::Table::TableOptions table_options;
603
if (table.has_options())
604
table_options= table.options();
606
uint32_t local_db_create_options= 0;
608
if (table_options.pack_record())
609
local_db_create_options|= HA_OPTION_PACK_RECORD;
611
/* local_db_create_options was stored as 2 bytes in FRM
612
Any HA_OPTION_ that doesn't fit into 2 bytes was silently truncated away.
614
db_create_options= (local_db_create_options & 0x0000FFFF);
615
db_options_in_use= db_create_options;
617
block_size= table_options.has_block_size() ?
618
table_options.block_size() : 0;
620
table_charset= get_charset(table_options.collation_id());
622
if (not table_charset)
624
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
625
table_options.collation().c_str(),
626
table.name().c_str());
628
return ER_CORRUPT_TABLE_DEFINITION; // Historical
633
keys= table.indexes_size();
636
for (int indx= 0; indx < table.indexes_size(); indx++)
637
key_parts+= table.indexes(indx).index_part_size();
639
key_info= (KeyInfo*) alloc_root( table.indexes_size() * sizeof(KeyInfo) +key_parts*sizeof(KeyPartInfo));
641
KeyPartInfo *key_part;
643
key_part= reinterpret_cast<KeyPartInfo*>
644
(key_info+table.indexes_size());
647
ulong *rec_per_key= (ulong*) alloc_root(sizeof(ulong*)*key_parts);
649
KeyInfo* keyinfo= key_info;
650
for (int keynr= 0; keynr < table.indexes_size(); keynr++, keyinfo++)
652
message::Table::Index indx= table.indexes(keynr);
657
if (indx.is_unique())
658
keyinfo->flags|= HA_NOSAME;
660
if (indx.has_options())
662
message::Table::Index::Options indx_options= indx.options();
663
if (indx_options.pack_key())
664
keyinfo->flags|= HA_PACK_KEY;
666
if (indx_options.var_length_key())
667
keyinfo->flags|= HA_VAR_LENGTH_PART;
669
if (indx_options.null_part_key())
670
keyinfo->flags|= HA_NULL_PART_KEY;
672
if (indx_options.binary_pack_key())
673
keyinfo->flags|= HA_BINARY_PACK_KEY;
675
if (indx_options.has_partial_segments())
676
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
678
if (indx_options.auto_generated_key())
679
keyinfo->flags|= HA_GENERATED_KEY;
681
if (indx_options.has_key_block_size())
683
keyinfo->flags|= HA_USES_BLOCK_SIZE;
684
keyinfo->block_size= indx_options.key_block_size();
688
keyinfo->block_size= 0;
694
case message::Table::Index::UNKNOWN_INDEX:
695
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
697
case message::Table::Index::BTREE:
698
keyinfo->algorithm= HA_KEY_ALG_BTREE;
700
case message::Table::Index::HASH:
701
keyinfo->algorithm= HA_KEY_ALG_HASH;
705
/* TODO: suitable warning ? */
706
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
710
keyinfo->key_length= indx.key_length();
712
keyinfo->key_parts= indx.index_part_size();
714
keyinfo->key_part= key_part;
715
keyinfo->rec_per_key= rec_per_key;
717
for (unsigned int partnr= 0;
718
partnr < keyinfo->key_parts;
719
partnr++, key_part++)
721
message::Table::Index::IndexPart part;
722
part= indx.index_part(partnr);
726
key_part->field= NULL;
727
key_part->fieldnr= part.fieldnr() + 1; // start from 1.
728
key_part->null_bit= 0;
729
/* key_part->null_offset is only set if null_bit (see later) */
730
/* key_part->key_type= */ /* I *THINK* this may be okay.... */
731
/* key_part->type ???? */
732
key_part->key_part_flag= 0;
733
if (part.has_in_reverse_order())
734
key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
736
key_part->length= part.compare_length();
740
if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
741
|| table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
743
uint32_t collation_id;
745
if (table.field(part.fieldnr()).string_options().has_collation_id())
746
collation_id= table.field(part.fieldnr()).string_options().collation_id();
748
collation_id= table.options().collation_id();
750
const CHARSET_INFO *cs= get_charset(collation_id);
752
mbmaxlen= cs->mbmaxlen;
754
key_part->length*= mbmaxlen;
756
key_part->store_length= key_part->length;
758
/* key_part->offset is set later */
759
key_part->key_type= 0;
762
if (! indx.has_comment())
764
keyinfo->comment.length= 0;
765
keyinfo->comment.str= NULL;
769
keyinfo->flags|= HA_USES_COMMENT;
770
keyinfo->comment.length= indx.comment().length();
771
keyinfo->comment.str= strmake_root(indx.comment().c_str(), keyinfo->comment.length);
774
keyinfo->name= strmake_root(indx.name().c_str(), indx.name().length());
776
addKeyName(string(keyinfo->name, indx.name().length()));
779
keys_for_keyread.reset();
780
set_prefix(keys_in_use, keys);
782
_field_size= table.field_size();
784
setFields(_field_size + 1);
785
_fields[_field_size]= NULL;
787
uint32_t local_null_fields= 0;
790
std::vector<uint32_t> field_offsets;
791
std::vector<uint32_t> field_pack_length;
793
field_offsets.resize(_field_size);
794
field_pack_length.resize(_field_size);
796
uint32_t interval_count= 0;
797
uint32_t interval_parts= 0;
799
uint32_t stored_columns_reclength= 0;
801
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
803
message::Table::Field pfield= table.field(fieldnr);
804
if (pfield.constraints().is_nullable()) // Historical reference
808
else if (not pfield.constraints().is_notnull())
813
enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
815
field_offsets[fieldnr]= stored_columns_reclength;
817
/* the below switch is very similar to
818
CreateField::create_length_to_internal_length in field.cc
819
(which should one day be replace by just this code)
821
switch(drizzle_field_type)
823
case DRIZZLE_TYPE_BLOB:
824
case DRIZZLE_TYPE_VARCHAR:
826
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
828
const CHARSET_INFO *cs= get_charset(field_options.has_collation_id() ?
829
field_options.collation_id() : 0);
832
cs= default_charset_info;
834
field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type,
835
field_options.length() * cs->mbmaxlen);
838
case DRIZZLE_TYPE_ENUM:
840
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
842
field_pack_length[fieldnr]= 4;
845
interval_parts+= field_options.field_value_size();
848
case DRIZZLE_TYPE_DECIMAL:
850
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
852
field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
856
/* Zero is okay here as length is fixed for other types. */
857
field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type, 0);
860
reclength+= field_pack_length[fieldnr];
861
stored_columns_reclength+= field_pack_length[fieldnr];
864
/* data_offset added to stored_rec_length later */
865
stored_rec_length= stored_columns_reclength;
867
null_fields= local_null_fields;
869
ulong null_bits= local_null_fields;
870
if (! table_options.pack_record())
872
ulong data_offset= (null_bits + 7)/8;
875
reclength+= data_offset;
876
stored_rec_length+= data_offset;
878
ulong local_rec_buff_length;
880
local_rec_buff_length= ALIGN_SIZE(reclength + 1);
881
rec_buff_length= local_rec_buff_length;
883
resizeDefaultValues(local_rec_buff_length);
884
unsigned char* record= getDefaultValues();
887
if (! table_options.pack_record())
889
null_count++; // one bit for delete mark.
894
intervals.resize(interval_count);
896
/* Now fix the TYPELIBs for the intervals (enum values)
900
uint32_t interval_nr= 0;
902
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
904
message::Table::Field pfield= table.field(fieldnr);
907
if (pfield.type() != message::Table::Field::ENUM)
910
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
912
if (field_options.field_value_size() > Field_enum::max_supported_elements)
914
my_error(ER_CORRUPT_TABLE_DEFINITION_ENUM, MYF(0), table.name().c_str());
916
return ER_CORRUPT_TABLE_DEFINITION_ENUM; // Historical
920
const CHARSET_INFO *charset= get_charset(field_options.has_collation_id() ?
921
field_options.collation_id() : 0);
924
charset= default_charset_info;
926
TYPELIB *t= (&intervals[interval_nr]);
928
t->type_names= (const char**)alloc_root((field_options.field_value_size() + 1) * sizeof(char*));
930
t->type_lengths= (unsigned int*) alloc_root((field_options.field_value_size() + 1) * sizeof(unsigned int));
932
t->type_names[field_options.field_value_size()]= NULL;
933
t->type_lengths[field_options.field_value_size()]= 0;
935
t->count= field_options.field_value_size();
938
for (int n= 0; n < field_options.field_value_size(); n++)
940
t->type_names[n]= strmake_root(field_options.field_value(n).c_str(), field_options.field_value(n).length());
943
* Go ask the charset what the length is as for "" length=1
944
* and there's stripping spaces or some other crack going on.
947
lengthsp= charset->cset->lengthsp(charset,
949
field_options.field_value(n).length());
950
t->type_lengths[n]= lengthsp;
956
/* and read the fields */
959
bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
961
unsigned char* null_pos= getDefaultValues();
962
int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
964
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
966
message::Table::Field pfield= table.field(fieldnr);
968
Field::utype unireg_type= Field::NONE;
970
if (pfield.has_numeric_options() &&
971
pfield.numeric_options().is_autoincrement())
973
unireg_type= Field::NEXT_NUMBER;
976
if (pfield.has_options() &&
977
pfield.options().has_default_expression() &&
978
pfield.options().default_expression().compare("CURRENT_TIMESTAMP") == 0)
980
if (pfield.options().has_update_expression() &&
981
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
983
unireg_type= Field::TIMESTAMP_DNUN_FIELD;
985
else if (! pfield.options().has_update_expression())
987
unireg_type= Field::TIMESTAMP_DN_FIELD;
991
assert(0); // Invalid update value.
995
else if (pfield.has_options() &&
996
pfield.options().has_update_expression() &&
997
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
999
unireg_type= Field::TIMESTAMP_UN_FIELD;
1003
if (!pfield.has_comment())
1005
comment.str= (char*)"";
1010
size_t len= pfield.comment().length();
1011
const char* str= pfield.comment().c_str();
1013
comment.str= strmake_root(str, len);
1014
comment.length= len;
1017
enum_field_types field_type;
1019
field_type= proto_field_type_to_drizzle_type(pfield);
1021
const CHARSET_INFO *charset= &my_charset_bin;
1023
if (field_type == DRIZZLE_TYPE_BLOB ||
1024
field_type == DRIZZLE_TYPE_VARCHAR)
1026
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
1028
charset= get_charset(field_options.has_collation_id() ?
1029
field_options.collation_id() : 0);
1032
charset= default_charset_info;
1035
if (field_type == DRIZZLE_TYPE_ENUM)
1037
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
1039
charset= get_charset(field_options.has_collation_id()?
1040
field_options.collation_id() : 0);
1043
charset= default_charset_info;
1046
uint8_t decimals= 0;
1047
if (field_type == DRIZZLE_TYPE_DECIMAL
1048
|| field_type == DRIZZLE_TYPE_DOUBLE)
1050
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1052
if (! pfield.has_numeric_options() || ! fo.has_scale())
1055
We don't write the default to table proto so
1056
if no decimals specified for DOUBLE, we use the default.
1058
decimals= NOT_FIXED_DEC;
1062
if (fo.scale() > DECIMAL_MAX_SCALE)
1064
local_error= ER_NOT_FORM_FILE;
1068
decimals= static_cast<uint8_t>(fo.scale());
1072
Item *default_value= NULL;
1074
if (pfield.options().has_default_value() ||
1075
pfield.options().default_null() ||
1076
pfield.options().has_default_bin_value())
1078
default_value= default_value_item(field_type,
1080
pfield.options().default_null(),
1081
&pfield.options().default_value(),
1082
&pfield.options().default_bin_value());
1086
uint32_t field_length= 0; //Assignment is for compiler complaint.
1088
// We set field_length in this loop.
1091
case DRIZZLE_TYPE_BLOB:
1092
case DRIZZLE_TYPE_VARCHAR:
1094
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
1096
charset= get_charset(field_options.has_collation_id() ?
1097
field_options.collation_id() : 0);
1100
charset= default_charset_info;
1102
field_length= field_options.length() * charset->mbmaxlen;
1105
case DRIZZLE_TYPE_DOUBLE:
1107
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1108
if (!fo.has_precision() && !fo.has_scale())
1110
field_length= DBL_DIG+7;
1114
field_length= fo.precision();
1116
if (field_length < decimals &&
1117
decimals != NOT_FIXED_DEC)
1119
my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1120
local_error= ER_M_BIGGER_THAN_D;
1125
case DRIZZLE_TYPE_DECIMAL:
1127
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1129
field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
1133
case DRIZZLE_TYPE_DATETIME:
1134
field_length= DateTime::MAX_STRING_LENGTH;
1136
case DRIZZLE_TYPE_DATE:
1137
field_length= Date::MAX_STRING_LENGTH;
1139
case DRIZZLE_TYPE_ENUM:
1143
message::Table::Field::EnumerationValues fo= pfield.enumeration_values();
1145
for (int valnr= 0; valnr < fo.field_value_size(); valnr++)
1147
if (fo.field_value(valnr).length() > field_length)
1149
field_length= charset->cset->numchars(charset,
1150
fo.field_value(valnr).c_str(),
1151
fo.field_value(valnr).c_str()
1152
+ fo.field_value(valnr).length())
1153
* charset->mbmaxlen;
1158
case DRIZZLE_TYPE_LONG:
1160
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1161
field_length= MAX_INT_WIDTH+sign_len;
1164
case DRIZZLE_TYPE_LONGLONG:
1166
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1167
field_length= MAX_BIGINT_WIDTH+sign_len;
1170
case DRIZZLE_TYPE_UUID:
1171
field_length= field::Uuid::max_string_length();
1173
case DRIZZLE_TYPE_BOOLEAN:
1174
field_length= field::Boolean::max_string_length();
1176
case DRIZZLE_TYPE_MICROTIME:
1177
field_length= field::Microtime::max_string_length();
1179
case DRIZZLE_TYPE_TIMESTAMP:
1180
field_length= field::Epoch::max_string_length();
1182
case DRIZZLE_TYPE_TIME:
1183
field_length= field::Time::max_string_length();
1185
case DRIZZLE_TYPE_NULL:
1186
abort(); // Programming error
1189
bool is_not_null= false;
1191
if (not pfield.constraints().is_nullable())
1195
else if (pfield.constraints().is_notnull())
1200
Field* f= make_field(pfield,
1201
record + field_offsets[fieldnr] + data_offset,
1209
MTYP_TYPENR(unireg_type),
1210
((field_type == DRIZZLE_TYPE_ENUM) ? &intervals[interval_nr++] : (TYPELIB*) 0),
1211
getTableMessage()->field(fieldnr).name().c_str());
1213
_fields[fieldnr]= f;
1215
// Insert post make_field code here.
1218
case DRIZZLE_TYPE_BLOB:
1219
case DRIZZLE_TYPE_VARCHAR:
1220
case DRIZZLE_TYPE_DOUBLE:
1221
case DRIZZLE_TYPE_DECIMAL:
1222
case DRIZZLE_TYPE_TIMESTAMP:
1223
case DRIZZLE_TYPE_TIME:
1224
case DRIZZLE_TYPE_DATETIME:
1225
case DRIZZLE_TYPE_MICROTIME:
1226
case DRIZZLE_TYPE_DATE:
1227
case DRIZZLE_TYPE_ENUM:
1228
case DRIZZLE_TYPE_LONG:
1229
case DRIZZLE_TYPE_LONGLONG:
1230
case DRIZZLE_TYPE_NULL:
1231
case DRIZZLE_TYPE_UUID:
1232
case DRIZZLE_TYPE_BOOLEAN:
1236
// This needs to go, we should be setting the "use" on the field so that
1237
// it does not reference the share/table.
1238
table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1239
temp_table.in_use= &session;
1241
f->init(&temp_table); /* blob default values need table obj */
1243
if (! (f->flags & NOT_NULL_FLAG))
1245
*f->null_ptr|= f->null_bit;
1246
if (! (null_bit_pos= (null_bit_pos + 1) & 7)) /* @TODO Ugh. */
1253
enum_check_fields old_count_cuted_fields= session.count_cuted_fields;
1254
session.count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
1255
int res= default_value->save_in_field(f, 1);
1256
session.count_cuted_fields= old_count_cuted_fields;
1257
if (res != 0 && res != 3) /* @TODO Huh? */
1259
my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1260
local_error= ER_INVALID_DEFAULT;
1265
else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1268
f->store((int64_t) 1, true);
1275
/* hack to undo f->init() */
1277
f->orig_table= NULL;
1279
f->setPosition(fieldnr);
1280
f->comment= comment;
1281
if (not default_value &&
1282
not (f->unireg_check==Field::NEXT_NUMBER) &&
1283
(f->flags & NOT_NULL_FLAG) &&
1284
(not f->is_timestamp()))
1286
f->flags|= NO_DEFAULT_VALUE_FLAG;
1289
if (f->unireg_check == Field::NEXT_NUMBER)
1290
found_next_number_field= &(_fields[fieldnr]);
1292
if (use_hash) /* supposedly this never fails... but comments lie */
1294
const char *local_field_name= _fields[fieldnr]->field_name;
1295
name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
1300
for (unsigned int keynr= 0; keynr < keys; keynr++, keyinfo++)
1302
key_part= keyinfo->key_part;
1304
for (unsigned int partnr= 0;
1305
partnr < keyinfo->key_parts;
1306
partnr++, key_part++)
1309
* Fix up key_part->offset by adding data_offset.
1310
* We really should compute offset as well.
1311
* But at least this way we are a little better.
1313
key_part->offset= field_offsets[key_part->fieldnr-1] + data_offset;
1318
We need to set the unused bits to 1. If the number of bits is a multiple
1319
of 8 there are no unused bits.
1322
*(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1324
null_bytes= (null_pos - (unsigned char*) record + (null_bit_pos + 7) / 8);
1326
last_null_bit_pos= null_bit_pos;
1331
uint32_t local_primary_key= 0;
1332
doesKeyNameExist("PRIMARY", local_primary_key);
1335
key_part= keyinfo->key_part;
1337
for (uint32_t key= 0; key < keys; key++,keyinfo++)
1339
uint32_t usable_parts= 0;
1341
if (local_primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME))
1344
If the UNIQUE key doesn't have NULL columns and is not a part key
1345
declare this as a primary key.
1347
local_primary_key=key;
1348
for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1350
uint32_t fieldnr= key_part[i].fieldnr;
1352
_fields[fieldnr-1]->null_ptr ||
1353
_fields[fieldnr-1]->key_length() != key_part[i].length)
1355
local_primary_key= MAX_KEY; // Can't be used
1361
for (uint32_t i= 0 ; i < keyinfo->key_parts ; key_part++,i++)
1364
if (! key_part->fieldnr)
1368
local_field= key_part->field= _fields[key_part->fieldnr-1];
1369
key_part->type= local_field->key_type();
1370
if (local_field->null_ptr)
1372
key_part->null_offset=(uint32_t) ((unsigned char*) local_field->null_ptr - getDefaultValues());
1373
key_part->null_bit= local_field->null_bit;
1374
key_part->store_length+=HA_KEY_NULL_LENGTH;
1375
keyinfo->flags|=HA_NULL_PART_KEY;
1376
keyinfo->extra_length+= HA_KEY_NULL_LENGTH;
1377
keyinfo->key_length+= HA_KEY_NULL_LENGTH;
1379
if (local_field->type() == DRIZZLE_TYPE_BLOB ||
1380
local_field->real_type() == DRIZZLE_TYPE_VARCHAR)
1382
if (local_field->type() == DRIZZLE_TYPE_BLOB)
1383
key_part->key_part_flag|= HA_BLOB_PART;
1385
key_part->key_part_flag|= HA_VAR_LENGTH_PART;
1386
keyinfo->extra_length+=HA_KEY_BLOB_LENGTH;
1387
key_part->store_length+=HA_KEY_BLOB_LENGTH;
1388
keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
1390
if (i == 0 && key != local_primary_key)
1391
local_field->flags |= (((keyinfo->flags & HA_NOSAME) &&
1392
(keyinfo->key_parts == 1)) ?
1393
UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
1395
local_field->key_start.set(key);
1396
if (local_field->key_length() == key_part->length &&
1397
!(local_field->flags & BLOB_FLAG))
1399
enum ha_key_alg algo= key_info[key].algorithm;
1400
if (db_type()->index_flags(algo) & HA_KEYREAD_ONLY)
1402
keys_for_keyread.set(key);
1403
local_field->part_of_key.set(key);
1404
local_field->part_of_key_not_clustered.set(key);
1406
if (db_type()->index_flags(algo) & HA_READ_ORDER)
1407
local_field->part_of_sortkey.set(key);
1409
if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
1411
usable_parts++; // For FILESORT
1412
local_field->flags|= PART_KEY_FLAG;
1413
if (key == local_primary_key)
1415
local_field->flags|= PRI_KEY_FLAG;
1417
If this field is part of the primary key and all keys contains
1418
the primary key, then we can use any key to find this column
1420
if (storage_engine->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX))
1422
local_field->part_of_key= keys_in_use;
1423
if (local_field->part_of_sortkey.test(key))
1424
local_field->part_of_sortkey= keys_in_use;
1427
if (local_field->key_length() != key_part->length)
1429
key_part->key_part_flag|= HA_PART_KEY_SEG;
1432
keyinfo->usable_key_parts= usable_parts; // Filesort
1434
set_if_bigger(max_key_length,keyinfo->key_length+
1435
keyinfo->key_parts);
1436
total_key_length+= keyinfo->key_length;
1438
if (keyinfo->flags & HA_NOSAME)
1440
set_if_bigger(max_unique_length,keyinfo->key_length);
1443
if (local_primary_key < MAX_KEY &&
1444
(keys_in_use.test(local_primary_key)))
1446
primary_key= local_primary_key;
1448
If we are using an integer as the primary key then allow the user to
1449
refer to it as '_rowid'
1451
if (key_info[local_primary_key].key_parts == 1)
1453
Field *local_field= key_info[local_primary_key].key_part[0].field;
1454
if (local_field && local_field->result_type() == INT_RESULT)
1456
/* note that fieldnr here (and rowid_field_offset) starts from 1 */
1457
rowid_field_offset= (key_info[local_primary_key].key_part[0].
1464
if (found_next_number_field)
1466
Field *reg_field= *found_next_number_field;
1467
if ((int) (next_number_index= (uint32_t)
1468
find_ref_key(key_info, keys,
1469
getDefaultValues(), reg_field,
1470
&next_number_key_offset,
1471
&next_number_keypart)) < 0)
1473
/* Wrong field definition */
1474
local_error= ER_NOT_FORM_FILE;
1480
reg_field->flags |= AUTO_INCREMENT_FLAG;
1486
/* Store offsets to blob fields to find them fast */
1487
blob_field.resize(blob_fields);
1488
uint32_t *save= &blob_field[0];
1490
for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
1492
if ((*iter)->flags & BLOB_FLAG)
1498
all_set.resize(_field_size);
1501
return local_error != EE_OK;
1505
Read table definition from a binary / text based .frm cursor
1509
session Thread Cursor
1510
share Fill this with table definition
1513
This function is called when the table definition is not cached in
1514
definition::Cache::singleton().getCache()
1515
The data is returned in 'share', which is alloced by
1516
alloc_table_share().. The code assumes that share is initialized.
1520
1 Error (see open_table_error)
1521
2 Error (see open_table_error)
1522
3 Wrong data in .frm cursor
1523
4 Error (see open_table_error)
1524
5 Error (see open_table_error: charset unavailable)
1525
6 Unknown .frm version
1528
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
1530
drizzled::error_t local_error= EE_OK;
1532
message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1534
if (table and table->IsInitialized())
1536
if (parse_table_proto(session, *table))
1538
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1539
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1543
setTableCategory(TABLE_CATEGORY_USER);
1547
else if (table and not table->IsInitialized())
1549
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1550
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1554
local_error= ER_TABLE_UNKNOWN;
1555
my_error(ER_TABLE_UNKNOWN, identifier);
1558
return static_cast<int>(local_error);
1563
Open a table based on a TableShare
1566
open_table_from_share()
1567
session Thread Cursor
1568
share Table definition
1569
alias Alias for table
1570
db_stat open flags (for example HA_OPEN_KEYFILE|
1571
HA_OPEN_RNDFILE..) can be 0 (example in
1573
ha_open_flags HA_OPEN_ABORT_IF_LOCKED etc..
1574
outparam result table
1578
1 Error (see open_table_error)
1579
2 Error (see open_table_error)
1580
3 Wrong data in .frm cursor
1581
4 Error (see open_table_error)
1582
5 Error (see open_table_error: charset unavailable)
1583
7 Table definition has changed in engine
1585
int TableShare::open_table_from_share(Session *session,
1586
const identifier::Table &identifier,
1588
uint32_t db_stat, uint32_t ha_open_flags,
1591
bool error_reported= false;
1592
int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1595
ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1600
if (not error_reported)
1601
open_table_error(ret, errno, 0);
1603
boost::checked_delete(outparam.cursor);
1604
outparam.cursor= 0; // For easier error checking
1605
outparam.db_stat= 0;
1606
outparam.getMemRoot()->free_root(MYF(0)); // Safe to call on zeroed root
1607
outparam.clearAlias();
1612
int TableShare::open_table_from_share_inner(Session *session,
1619
unsigned char *record= NULL;
1623
outparam.resetTable(session, this, db_stat);
1625
outparam.setAlias(alias);
1627
/* Allocate Cursor */
1628
if (not (outparam.cursor= db_type()->getCursor(outparam)))
1633
if ((db_stat & HA_OPEN_KEYFILE))
1638
if (!(record= (unsigned char*) outparam.alloc_root(rec_buff_length * records)))
1643
/* We are probably in hard repair, and the buffers should not be used */
1644
outparam.record[0]= outparam.record[1]= getDefaultValues();
1648
outparam.record[0]= record;
1650
outparam.record[1]= record+ rec_buff_length;
1652
outparam.record[1]= outparam.getInsertRecord(); // Safety
1655
#ifdef HAVE_VALGRIND
1657
We need this because when we read var-length rows, we are not updating
1658
bytes after end of varchar
1662
memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1663
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1665
memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
1670
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1673
if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
1678
outparam.setFields(field_ptr);
1680
record= (unsigned char*) outparam.getInsertRecord()-1; /* Fieldstart = 1 */
1682
outparam.null_flags= (unsigned char*) record+1;
1684
/* Setup copy of fields from share, but use the right alias and record */
1685
for (uint32_t i= 0 ; i < _field_size; i++, field_ptr++)
1687
if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
1690
(*field_ptr)= 0; // End marker
1692
if (found_next_number_field)
1693
outparam.found_next_number_field=
1694
outparam.getField(positionFields(found_next_number_field));
1695
if (timestamp_field)
1696
outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
1698
/* Fix key->name and key_part->field */
1701
KeyInfo *local_key_info, *key_info_end;
1702
KeyPartInfo *key_part;
1704
n_length= keys*sizeof(KeyInfo) + key_parts*sizeof(KeyPartInfo);
1705
if (!(local_key_info= (KeyInfo*) outparam.alloc_root(n_length)))
1707
outparam.key_info= local_key_info;
1708
key_part= (reinterpret_cast<KeyPartInfo*> (local_key_info+keys));
1710
memcpy(local_key_info, key_info, sizeof(*local_key_info)*keys);
1711
memcpy(key_part, key_info[0].key_part, (sizeof(*key_part) *
1714
for (key_info_end= local_key_info + keys ;
1715
local_key_info < key_info_end ;
1718
KeyPartInfo *key_part_end;
1720
local_key_info->table= &outparam;
1721
local_key_info->key_part= key_part;
1723
for (key_part_end= key_part+ local_key_info->key_parts ;
1724
key_part < key_part_end ;
1727
Field *local_field= key_part->field= outparam.getField(key_part->fieldnr-1);
1729
if (local_field->key_length() != key_part->length &&
1730
!(local_field->flags & BLOB_FLAG))
1733
We are using only a prefix of the column as a key:
1734
Create a new field for the key part that matches the index
1736
local_field= key_part->field= local_field->new_field(outparam.getMemRoot(), &outparam, 0);
1737
local_field->field_length= key_part->length;
1743
/* Allocate bitmaps */
1745
outparam.def_read_set.resize(_field_size);
1746
outparam.def_write_set.resize(_field_size);
1747
outparam.tmp_set.resize(_field_size);
1748
outparam.default_column_bitmaps();
1753
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
1754
uint32_t db_stat, uint32_t ha_open_flags,
1756
bool &error_reported)
1758
/* The table struct is now initialized; Open the table */
1762
assert(!(db_stat & HA_WAIT_IF_LOCKED));
1765
if ((ha_err= (outparam.cursor->ha_open(identifier,
1766
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1767
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1771
case HA_ERR_NO_SUCH_TABLE:
1773
The table did not exists in storage engine, use same error message
1774
as if the .frm cursor didn't exist
1781
Too many files opened, use same error message as if the .frm
1788
outparam.print_error(ha_err, MYF(0));
1789
error_reported= true;
1790
if (ha_err == HA_ERR_TABLE_DEF_CHANGED)
1801
/* error message when opening a form cursor */
1802
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1804
char buff[FN_REFLEN];
1805
myf errortype= ME_ERROR+ME_WAITTANG;
1807
switch (pass_error) {
1810
if (db_errno == ENOENT)
1812
identifier::Table identifier(db.str, table_name.str);
1813
my_error(ER_TABLE_UNKNOWN, identifier);
1817
snprintf(buff, sizeof(buff), "%s",normalized_path.str);
1818
my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND,
1819
errortype, buff, db_errno);
1824
drizzled::error_t err_no;
1826
err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1827
ER_FILE_USED : ER_CANT_OPEN_FILE;
1829
my_error(err_no, errortype, normalized_path.str, db_errno);
1834
const char *csname= get_charset_name((uint32_t) pass_errarg);
1836
if (!csname || csname[0] =='?')
1838
snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
1841
my_printf_error(ER_UNKNOWN_COLLATION,
1842
_("Unknown collation '%s' in table '%-.64s' definition"),
1843
MYF(0), csname, table_name.str);
1847
snprintf(buff, sizeof(buff), "%s", normalized_path.str);
1848
my_printf_error(ER_NOT_FORM_FILE,
1849
_("Table '%-.64s' was created with a different version "
1850
"of Drizzle and cannot be read"),
1855
default: /* Better wrong error than none */
1857
snprintf(buff, sizeof(buff), "%s", normalized_path.str);
1858
my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
1862
} /* open_table_error */
1864
Field *TableShare::make_field(const message::Table::Field &pfield,
1866
uint32_t field_length,
1868
unsigned char *null_pos,
1869
unsigned char null_bit,
1871
enum_field_types field_type,
1872
const CHARSET_INFO * field_charset,
1873
Field::utype unireg_check,
1875
const char *field_name)
1877
return make_field(pfield,
1889
pfield.constraints().is_unsigned());
1892
Field *TableShare::make_field(const message::Table::Field &,
1894
uint32_t field_length,
1896
unsigned char *null_pos,
1897
unsigned char null_bit,
1899
enum_field_types field_type,
1900
const CHARSET_INFO * field_charset,
1901
Field::utype unireg_check,
1903
const char *field_name,
1913
null_bit= ((unsigned char) 1) << null_bit;
1918
case DRIZZLE_TYPE_DATE:
1919
case DRIZZLE_TYPE_DATETIME:
1920
case DRIZZLE_TYPE_UUID:
1921
field_charset= &my_charset_bin;
1927
case DRIZZLE_TYPE_ENUM:
1928
return new (&mem_root) Field_enum(ptr,
1935
case DRIZZLE_TYPE_VARCHAR:
1937
return new (&mem_root) Field_varstring(ptr,field_length,
1938
ha_varchar_packlength(field_length),
1942
case DRIZZLE_TYPE_BLOB:
1943
return new (&mem_root) Field_blob(ptr,
1949
case DRIZZLE_TYPE_DECIMAL:
1950
return new (&mem_root) Field_decimal(ptr,
1957
case DRIZZLE_TYPE_DOUBLE:
1958
return new (&mem_root) Field_double(ptr,
1966
false /* is_unsigned */);
1967
case DRIZZLE_TYPE_UUID:
1968
return new (&mem_root) field::Uuid(ptr,
1973
case DRIZZLE_TYPE_BOOLEAN:
1974
return new (&mem_root) field::Boolean(ptr,
1980
case DRIZZLE_TYPE_LONG:
1981
return new (&mem_root) field::Int32(ptr,
1987
case DRIZZLE_TYPE_LONGLONG:
1991
return new (&mem_root) field::Size(ptr,
1999
return new (&mem_root) field::Int64(ptr,
2006
case DRIZZLE_TYPE_MICROTIME:
2007
return new (&mem_root) field::Microtime(ptr,
2013
case DRIZZLE_TYPE_TIMESTAMP:
2014
return new (&mem_root) field::Epoch(ptr,
2020
case DRIZZLE_TYPE_TIME:
2021
return new (&mem_root) field::Time(ptr,
2027
case DRIZZLE_TYPE_DATE:
2028
return new (&mem_root) Field_date(ptr,
2033
case DRIZZLE_TYPE_DATETIME:
2034
return new (&mem_root) Field_datetime(ptr,
2039
case DRIZZLE_TYPE_NULL:
2040
return new (&mem_root) Field_null(ptr,
2049
void TableShare::refreshVersion()
2051
version= refresh_version;
2055
} /* namespace drizzled */