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>
87
#include <drizzled/typelib.h>
89
#include <drizzled/refresh_version.h>
96
extern size_t table_def_size;
99
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
103
case message::Table::Field::INTEGER:
104
return DRIZZLE_TYPE_LONG;
106
case message::Table::Field::DOUBLE:
107
return DRIZZLE_TYPE_DOUBLE;
109
case message::Table::Field::EPOCH:
110
if (field.has_time_options() and field.time_options().microseconds())
111
return DRIZZLE_TYPE_MICROTIME;
113
return DRIZZLE_TYPE_TIMESTAMP;
115
case message::Table::Field::BIGINT:
116
return DRIZZLE_TYPE_LONGLONG;
118
case message::Table::Field::DATETIME:
119
return DRIZZLE_TYPE_DATETIME;
121
case message::Table::Field::DATE:
122
return DRIZZLE_TYPE_DATE;
124
case message::Table::Field::VARCHAR:
125
return DRIZZLE_TYPE_VARCHAR;
127
case message::Table::Field::DECIMAL:
128
return DRIZZLE_TYPE_DECIMAL;
130
case message::Table::Field::ENUM:
131
return DRIZZLE_TYPE_ENUM;
133
case message::Table::Field::BLOB:
134
return DRIZZLE_TYPE_BLOB;
136
case message::Table::Field::UUID:
137
return DRIZZLE_TYPE_UUID;
139
case message::Table::Field::BOOLEAN:
140
return DRIZZLE_TYPE_BOOLEAN;
142
case message::Table::Field::TIME:
143
return DRIZZLE_TYPE_TIME;
149
static Item *default_value_item(enum_field_types field_type,
150
const CHARSET_INFO *charset,
151
bool default_null, const string *default_value,
152
const string *default_bin_value)
154
Item *default_item= NULL;
159
return new Item_null();
164
case DRIZZLE_TYPE_LONG:
165
case DRIZZLE_TYPE_LONGLONG:
166
default_item= new Item_int(default_value->c_str(),
167
(int64_t) internal::my_strtoll10(default_value->c_str(),
170
default_value->length());
172
case DRIZZLE_TYPE_DOUBLE:
173
default_item= new Item_float(default_value->c_str(),
174
default_value->length());
176
case DRIZZLE_TYPE_NULL:
179
case DRIZZLE_TYPE_TIMESTAMP:
180
case DRIZZLE_TYPE_DATETIME:
181
case DRIZZLE_TYPE_TIME:
182
case DRIZZLE_TYPE_DATE:
183
case DRIZZLE_TYPE_ENUM:
184
case DRIZZLE_TYPE_UUID:
185
case DRIZZLE_TYPE_MICROTIME:
186
case DRIZZLE_TYPE_BOOLEAN:
187
default_item= new Item_string(default_value->c_str(),
188
default_value->length(),
189
system_charset_info);
191
case DRIZZLE_TYPE_VARCHAR:
192
case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
193
if (charset==&my_charset_bin)
195
default_item= new Item_string(default_bin_value->c_str(),
196
default_bin_value->length(),
201
default_item= new Item_string(default_value->c_str(),
202
default_value->length(),
203
system_charset_info);
206
case DRIZZLE_TYPE_DECIMAL:
207
default_item= new Item_decimal(default_value->c_str(),
208
default_value->length(),
209
system_charset_info);
221
* Precache this stuff....
223
bool TableShare::fieldInPrimaryKey(Field *in_field) const
225
assert(getTableMessage());
227
size_t num_indexes= getTableMessage()->indexes_size();
229
for (size_t x= 0; x < num_indexes; ++x)
231
const message::Table::Index &index= getTableMessage()->indexes(x);
232
if (index.is_primary())
234
size_t num_parts= index.index_part_size();
235
for (size_t y= 0; y < num_parts; ++y)
237
if (index.index_part(y).fieldnr() == in_field->position())
245
TableShare::TableShare(const identifier::Table::Type type_arg) :
246
table_category(TABLE_UNKNOWN_CATEGORY),
247
found_next_number_field(NULL),
248
timestamp_field(NULL),
250
mem_root(TABLE_ALLOC_BLOCK_SIZE),
253
table_name(NULL_LEX_STRING),
254
path(NULL_LEX_STRING),
255
normalized_path(NULL_LEX_STRING),
260
stored_rec_length(0),
262
_table_message(NULL),
263
storage_engine(NULL),
267
last_null_bit_pos(0),
273
max_unique_length(0),
278
has_variable_width(false),
279
db_create_options(0),
280
db_options_in_use(0),
282
rowid_field_offset(0),
283
primary_key(MAX_KEY),
284
next_number_index(0),
285
next_number_key_offset(0),
286
next_number_keypart(0),
290
blob_ptr_size(portable_sizeof_char_ptr),
291
db_low_byte_first(false),
295
if (type_arg == message::Table::INTERNAL)
297
identifier::Table::build_tmptable_filename(private_key_for_cache.vectorPtr());
298
init(private_key_for_cache.vector(), private_key_for_cache.vector());
306
TableShare::TableShare(const identifier::Table &identifier, const identifier::Table::Key &key) :// Used by placeholder
307
table_category(TABLE_UNKNOWN_CATEGORY),
308
found_next_number_field(NULL),
309
timestamp_field(NULL),
311
mem_root(TABLE_ALLOC_BLOCK_SIZE),
315
table_name(NULL_LEX_STRING),
316
path(NULL_LEX_STRING),
317
normalized_path(NULL_LEX_STRING),
322
stored_rec_length(0),
324
_table_message(NULL),
325
storage_engine(NULL),
326
tmp_table(message::Table::INTERNAL),
329
last_null_bit_pos(0),
335
max_unique_length(0),
340
has_variable_width(false),
341
db_create_options(0),
342
db_options_in_use(0),
344
rowid_field_offset(0),
345
primary_key(MAX_KEY),
346
next_number_index(0),
347
next_number_key_offset(0),
348
next_number_keypart(0),
352
blob_ptr_size(portable_sizeof_char_ptr),
353
db_low_byte_first(false),
357
assert(identifier.getKey() == key);
359
private_key_for_cache= key;
361
table_category= TABLE_CATEGORY_TEMPORARY;
362
tmp_table= message::Table::INTERNAL;
364
db.str= const_cast<char *>(private_key_for_cache.vector());
365
db.length= strlen(private_key_for_cache.vector());
367
table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
368
table_name.length= strlen(table_name.str);
369
path.str= (char *)"";
370
normalized_path.str= path.str;
371
path.length= normalized_path.length= 0;
373
std::string tb_name(identifier.getTableName());
374
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
375
assert(strcmp(tb_name.c_str(), table_name.str) == 0);
377
assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
381
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
382
table_category(TABLE_UNKNOWN_CATEGORY),
383
found_next_number_field(NULL),
384
timestamp_field(NULL),
386
mem_root(TABLE_ALLOC_BLOCK_SIZE),
390
table_name(NULL_LEX_STRING),
391
path(NULL_LEX_STRING),
392
normalized_path(NULL_LEX_STRING),
397
stored_rec_length(0),
399
_table_message(NULL),
400
storage_engine(NULL),
401
tmp_table(identifier.getType()),
404
last_null_bit_pos(0),
410
max_unique_length(0),
415
has_variable_width(false),
416
db_create_options(0),
417
db_options_in_use(0),
419
rowid_field_offset(0),
420
primary_key(MAX_KEY),
421
next_number_index(0),
422
next_number_key_offset(0),
423
next_number_keypart(0),
427
blob_ptr_size(portable_sizeof_char_ptr),
428
db_low_byte_first(false),
432
private_key_for_cache= identifier.getKey();
433
assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
434
private_normalized_path.resize(identifier.getPath().size() + 1);
435
memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
438
table_category= TABLE_CATEGORY_TEMPORARY;
439
tmp_table= message::Table::INTERNAL;
440
db.str= const_cast<char *>(private_key_for_cache.vector());
441
db.length= strlen(private_key_for_cache.vector());
442
table_name.str= db.str + 1;
443
table_name.length= strlen(table_name.str);
444
path.str= &private_normalized_path[0];
445
normalized_path.str= path.str;
446
path.length= normalized_path.length= private_normalized_path.size();
452
Used for shares that will go into the cache.
454
TableShare::TableShare(const identifier::Table::Type type_arg,
455
const identifier::Table &identifier,
457
uint32_t path_length_arg) :
458
table_category(TABLE_UNKNOWN_CATEGORY),
459
found_next_number_field(NULL),
460
timestamp_field(NULL),
462
mem_root(TABLE_ALLOC_BLOCK_SIZE),
466
table_name(NULL_LEX_STRING),
467
path(NULL_LEX_STRING),
468
normalized_path(NULL_LEX_STRING),
473
stored_rec_length(0),
475
_table_message(NULL),
476
storage_engine(NULL),
480
last_null_bit_pos(0),
486
max_unique_length(0),
491
has_variable_width(false),
492
db_create_options(0),
493
db_options_in_use(0),
495
rowid_field_offset(0),
496
primary_key(MAX_KEY),
497
next_number_index(0),
498
next_number_key_offset(0),
499
next_number_keypart(0),
503
blob_ptr_size(portable_sizeof_char_ptr),
504
db_low_byte_first(false),
511
private_key_for_cache= identifier.getKey();
513
Let us use the fact that the key is "db/0/table_name/0" + optional
514
part for temporary tables.
516
db.str= const_cast<char *>(private_key_for_cache.vector());
517
db.length= strlen(db.str);
518
table_name.str= db.str + db.length + 1;
519
table_name.length= strlen(table_name.str);
523
_path.append(path_arg, path_length_arg);
527
identifier::Table::build_table_filename(_path, db.str, table_name.str, false);
530
if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
532
setPath(path_buff, _path.length());
533
strcpy(path_buff, _path.c_str());
534
setNormalizedPath(path_buff, _path.length());
536
version= refresh_version;
540
assert(0); // We should throw here.
545
void TableShare::init(const char *new_table_name,
546
const char *new_path)
549
table_category= TABLE_CATEGORY_TEMPORARY;
550
tmp_table= message::Table::INTERNAL;
553
table_name.str= (char*) new_table_name;
554
table_name.length= strlen(new_table_name);
555
path.str= (char*) new_path;
556
normalized_path.str= (char*) new_path;
557
path.length= normalized_path.length= strlen(new_path);
560
TableShare::~TableShare()
562
storage_engine= NULL;
564
mem_root.free_root(MYF(0)); // Free's share
567
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
569
private_key_for_cache= identifier_arg.getKey();
572
Let us use the fact that the key is "db/0/table_name/0" + optional
573
part for temporary tables.
575
db.str= const_cast<char *>(private_key_for_cache.vector());
576
db.length= strlen(db.str);
577
table_name.str= db.str + db.length + 1;
578
table_name.length= strlen(table_name.str);
580
getTableMessage()->set_name(identifier_arg.getTableName());
581
getTableMessage()->set_schema(identifier_arg.getSchemaName());
584
bool TableShare::parse_table_proto(Session& session, message::Table &table)
586
drizzled::error_t local_error= EE_OK;
588
if (! table.IsInitialized())
590
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
591
table.name().empty() ? " " : table.name().c_str(),
592
table.InitializationErrorString().c_str());
594
return ER_CORRUPT_TABLE_DEFINITION;
597
setTableMessage(table);
599
storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
600
assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
602
message::Table::TableOptions table_options;
604
if (table.has_options())
605
table_options= table.options();
607
uint32_t local_db_create_options= 0;
609
if (table_options.pack_record())
610
local_db_create_options|= HA_OPTION_PACK_RECORD;
612
/* local_db_create_options was stored as 2 bytes in FRM
613
Any HA_OPTION_ that doesn't fit into 2 bytes was silently truncated away.
615
db_create_options= (local_db_create_options & 0x0000FFFF);
616
db_options_in_use= db_create_options;
618
block_size= table_options.has_block_size() ?
619
table_options.block_size() : 0;
621
table_charset= get_charset(table_options.collation_id());
623
if (not table_charset)
625
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
626
table_options.collation().c_str(),
627
table.name().c_str());
629
return ER_CORRUPT_TABLE_DEFINITION; // Historical
634
keys= table.indexes_size();
637
for (int indx= 0; indx < table.indexes_size(); indx++)
638
key_parts+= table.indexes(indx).index_part_size();
640
key_info= (KeyInfo*) alloc_root( table.indexes_size() * sizeof(KeyInfo) +key_parts*sizeof(KeyPartInfo));
642
KeyPartInfo *key_part;
644
key_part= reinterpret_cast<KeyPartInfo*>
645
(key_info+table.indexes_size());
648
ulong *rec_per_key= (ulong*) alloc_root(sizeof(ulong*)*key_parts);
650
KeyInfo* keyinfo= key_info;
651
for (int keynr= 0; keynr < table.indexes_size(); keynr++, keyinfo++)
653
message::Table::Index indx= table.indexes(keynr);
658
if (indx.is_unique())
659
keyinfo->flags|= HA_NOSAME;
661
if (indx.has_options())
663
message::Table::Index::Options indx_options= indx.options();
664
if (indx_options.pack_key())
665
keyinfo->flags|= HA_PACK_KEY;
667
if (indx_options.var_length_key())
668
keyinfo->flags|= HA_VAR_LENGTH_PART;
670
if (indx_options.null_part_key())
671
keyinfo->flags|= HA_NULL_PART_KEY;
673
if (indx_options.binary_pack_key())
674
keyinfo->flags|= HA_BINARY_PACK_KEY;
676
if (indx_options.has_partial_segments())
677
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
679
if (indx_options.auto_generated_key())
680
keyinfo->flags|= HA_GENERATED_KEY;
682
if (indx_options.has_key_block_size())
684
keyinfo->flags|= HA_USES_BLOCK_SIZE;
685
keyinfo->block_size= indx_options.key_block_size();
689
keyinfo->block_size= 0;
695
case message::Table::Index::UNKNOWN_INDEX:
696
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
698
case message::Table::Index::BTREE:
699
keyinfo->algorithm= HA_KEY_ALG_BTREE;
701
case message::Table::Index::HASH:
702
keyinfo->algorithm= HA_KEY_ALG_HASH;
706
/* TODO: suitable warning ? */
707
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
711
keyinfo->key_length= indx.key_length();
713
keyinfo->key_parts= indx.index_part_size();
715
keyinfo->key_part= key_part;
716
keyinfo->rec_per_key= rec_per_key;
718
for (unsigned int partnr= 0;
719
partnr < keyinfo->key_parts;
720
partnr++, key_part++)
722
message::Table::Index::IndexPart part;
723
part= indx.index_part(partnr);
727
key_part->field= NULL;
728
key_part->fieldnr= part.fieldnr() + 1; // start from 1.
729
key_part->null_bit= 0;
730
/* key_part->null_offset is only set if null_bit (see later) */
731
/* key_part->key_type= */ /* I *THINK* this may be okay.... */
732
/* key_part->type ???? */
733
key_part->key_part_flag= 0;
734
if (part.has_in_reverse_order())
735
key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
737
key_part->length= part.compare_length();
741
if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
742
|| table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
744
uint32_t collation_id;
746
if (table.field(part.fieldnr()).string_options().has_collation_id())
747
collation_id= table.field(part.fieldnr()).string_options().collation_id();
749
collation_id= table.options().collation_id();
751
const CHARSET_INFO *cs= get_charset(collation_id);
753
mbmaxlen= cs->mbmaxlen;
755
key_part->length*= mbmaxlen;
757
key_part->store_length= key_part->length;
759
/* key_part->offset is set later */
760
key_part->key_type= 0;
763
if (! indx.has_comment())
765
keyinfo->comment.length= 0;
766
keyinfo->comment.str= NULL;
770
keyinfo->flags|= HA_USES_COMMENT;
771
keyinfo->comment.length= indx.comment().length();
772
keyinfo->comment.str= strmake_root(indx.comment().c_str(), keyinfo->comment.length);
775
keyinfo->name= strmake_root(indx.name().c_str(), indx.name().length());
777
addKeyName(string(keyinfo->name, indx.name().length()));
780
keys_for_keyread.reset();
781
set_prefix(keys_in_use, keys);
783
_field_size= table.field_size();
785
setFields(_field_size + 1);
786
_fields[_field_size]= NULL;
788
uint32_t local_null_fields= 0;
791
std::vector<uint32_t> field_offsets;
792
std::vector<uint32_t> field_pack_length;
794
field_offsets.resize(_field_size);
795
field_pack_length.resize(_field_size);
797
uint32_t interval_count= 0;
798
uint32_t interval_parts= 0;
800
uint32_t stored_columns_reclength= 0;
802
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
804
message::Table::Field pfield= table.field(fieldnr);
805
if (pfield.constraints().is_nullable()) // Historical reference
809
else if (not pfield.constraints().is_notnull())
814
enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
816
field_offsets[fieldnr]= stored_columns_reclength;
818
/* the below switch is very similar to
819
CreateField::create_length_to_internal_length in field.cc
820
(which should one day be replace by just this code)
822
switch(drizzle_field_type)
824
case DRIZZLE_TYPE_BLOB:
825
case DRIZZLE_TYPE_VARCHAR:
827
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
829
const CHARSET_INFO *cs= get_charset(field_options.has_collation_id() ?
830
field_options.collation_id() : 0);
833
cs= default_charset_info;
835
field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type,
836
field_options.length() * cs->mbmaxlen);
839
case DRIZZLE_TYPE_ENUM:
841
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
843
field_pack_length[fieldnr]= 4;
846
interval_parts+= field_options.field_value_size();
849
case DRIZZLE_TYPE_DECIMAL:
851
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
853
field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
857
/* Zero is okay here as length is fixed for other types. */
858
field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type, 0);
861
reclength+= field_pack_length[fieldnr];
862
stored_columns_reclength+= field_pack_length[fieldnr];
865
/* data_offset added to stored_rec_length later */
866
stored_rec_length= stored_columns_reclength;
868
null_fields= local_null_fields;
870
ulong null_bits= local_null_fields;
871
if (! table_options.pack_record())
873
ulong data_offset= (null_bits + 7)/8;
876
reclength+= data_offset;
877
stored_rec_length+= data_offset;
879
ulong local_rec_buff_length;
881
local_rec_buff_length= ALIGN_SIZE(reclength + 1);
882
rec_buff_length= local_rec_buff_length;
884
resizeDefaultValues(local_rec_buff_length);
885
unsigned char* record= getDefaultValues();
888
if (! table_options.pack_record())
890
null_count++; // one bit for delete mark.
895
intervals.resize(interval_count);
897
/* Now fix the TYPELIBs for the intervals (enum values)
901
uint32_t interval_nr= 0;
903
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
905
message::Table::Field pfield= table.field(fieldnr);
908
if (pfield.type() != message::Table::Field::ENUM)
911
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
913
if (field_options.field_value_size() > Field_enum::max_supported_elements)
915
my_error(ER_CORRUPT_TABLE_DEFINITION_ENUM, MYF(0), table.name().c_str());
917
return ER_CORRUPT_TABLE_DEFINITION_ENUM; // Historical
921
const CHARSET_INFO *charset= get_charset(field_options.has_collation_id() ?
922
field_options.collation_id() : 0);
925
charset= default_charset_info;
927
TYPELIB *t= (&intervals[interval_nr]);
929
t->type_names= (const char**)alloc_root((field_options.field_value_size() + 1) * sizeof(char*));
931
t->type_lengths= (unsigned int*) alloc_root((field_options.field_value_size() + 1) * sizeof(unsigned int));
933
t->type_names[field_options.field_value_size()]= NULL;
934
t->type_lengths[field_options.field_value_size()]= 0;
936
t->count= field_options.field_value_size();
939
for (int n= 0; n < field_options.field_value_size(); n++)
941
t->type_names[n]= strmake_root(field_options.field_value(n).c_str(), field_options.field_value(n).length());
944
* Go ask the charset what the length is as for "" length=1
945
* and there's stripping spaces or some other crack going on.
948
lengthsp= charset->cset->lengthsp(charset,
950
field_options.field_value(n).length());
951
t->type_lengths[n]= lengthsp;
957
/* and read the fields */
960
bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
962
unsigned char* null_pos= getDefaultValues();
963
int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
965
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
967
message::Table::Field pfield= table.field(fieldnr);
969
Field::utype unireg_type= Field::NONE;
971
if (pfield.has_numeric_options() &&
972
pfield.numeric_options().is_autoincrement())
974
unireg_type= Field::NEXT_NUMBER;
977
if (pfield.has_options() &&
978
pfield.options().has_default_expression() &&
979
pfield.options().default_expression().compare("CURRENT_TIMESTAMP") == 0)
981
if (pfield.options().has_update_expression() &&
982
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
984
unireg_type= Field::TIMESTAMP_DNUN_FIELD;
986
else if (! pfield.options().has_update_expression())
988
unireg_type= Field::TIMESTAMP_DN_FIELD;
992
assert(0); // Invalid update value.
996
else if (pfield.has_options() &&
997
pfield.options().has_update_expression() &&
998
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
1000
unireg_type= Field::TIMESTAMP_UN_FIELD;
1004
if (!pfield.has_comment())
1006
comment.str= (char*)"";
1011
size_t len= pfield.comment().length();
1012
const char* str= pfield.comment().c_str();
1014
comment.str= strmake_root(str, len);
1015
comment.length= len;
1018
enum_field_types field_type;
1020
field_type= proto_field_type_to_drizzle_type(pfield);
1022
const CHARSET_INFO *charset= &my_charset_bin;
1024
if (field_type == DRIZZLE_TYPE_BLOB ||
1025
field_type == DRIZZLE_TYPE_VARCHAR)
1027
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
1029
charset= get_charset(field_options.has_collation_id() ?
1030
field_options.collation_id() : 0);
1033
charset= default_charset_info;
1036
if (field_type == DRIZZLE_TYPE_ENUM)
1038
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
1040
charset= get_charset(field_options.has_collation_id()?
1041
field_options.collation_id() : 0);
1044
charset= default_charset_info;
1047
uint8_t decimals= 0;
1048
if (field_type == DRIZZLE_TYPE_DECIMAL
1049
|| field_type == DRIZZLE_TYPE_DOUBLE)
1051
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1053
if (! pfield.has_numeric_options() || ! fo.has_scale())
1056
We don't write the default to table proto so
1057
if no decimals specified for DOUBLE, we use the default.
1059
decimals= NOT_FIXED_DEC;
1063
if (fo.scale() > DECIMAL_MAX_SCALE)
1065
local_error= ER_NOT_FORM_FILE;
1069
decimals= static_cast<uint8_t>(fo.scale());
1073
Item *default_value= NULL;
1075
if (pfield.options().has_default_value() ||
1076
pfield.options().default_null() ||
1077
pfield.options().has_default_bin_value())
1079
default_value= default_value_item(field_type,
1081
pfield.options().default_null(),
1082
&pfield.options().default_value(),
1083
&pfield.options().default_bin_value());
1087
uint32_t field_length= 0; //Assignment is for compiler complaint.
1089
// We set field_length in this loop.
1092
case DRIZZLE_TYPE_BLOB:
1093
case DRIZZLE_TYPE_VARCHAR:
1095
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
1097
charset= get_charset(field_options.has_collation_id() ?
1098
field_options.collation_id() : 0);
1101
charset= default_charset_info;
1103
field_length= field_options.length() * charset->mbmaxlen;
1106
case DRIZZLE_TYPE_DOUBLE:
1108
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1109
if (!fo.has_precision() && !fo.has_scale())
1111
field_length= DBL_DIG+7;
1115
field_length= fo.precision();
1117
if (field_length < decimals &&
1118
decimals != NOT_FIXED_DEC)
1120
my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
1121
local_error= ER_M_BIGGER_THAN_D;
1126
case DRIZZLE_TYPE_DECIMAL:
1128
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1130
field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
1134
case DRIZZLE_TYPE_DATETIME:
1135
field_length= DateTime::MAX_STRING_LENGTH;
1137
case DRIZZLE_TYPE_DATE:
1138
field_length= Date::MAX_STRING_LENGTH;
1140
case DRIZZLE_TYPE_ENUM:
1144
message::Table::Field::EnumerationValues fo= pfield.enumeration_values();
1146
for (int valnr= 0; valnr < fo.field_value_size(); valnr++)
1148
if (fo.field_value(valnr).length() > field_length)
1150
field_length= charset->cset->numchars(charset,
1151
fo.field_value(valnr).c_str(),
1152
fo.field_value(valnr).c_str()
1153
+ fo.field_value(valnr).length())
1154
* charset->mbmaxlen;
1159
case DRIZZLE_TYPE_LONG:
1161
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1162
field_length= MAX_INT_WIDTH+sign_len;
1165
case DRIZZLE_TYPE_LONGLONG:
1167
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1168
field_length= MAX_BIGINT_WIDTH+sign_len;
1171
case DRIZZLE_TYPE_UUID:
1172
field_length= field::Uuid::max_string_length();
1174
case DRIZZLE_TYPE_BOOLEAN:
1175
field_length= field::Boolean::max_string_length();
1177
case DRIZZLE_TYPE_MICROTIME:
1178
field_length= field::Microtime::max_string_length();
1180
case DRIZZLE_TYPE_TIMESTAMP:
1181
field_length= field::Epoch::max_string_length();
1183
case DRIZZLE_TYPE_TIME:
1184
field_length= field::Time::max_string_length();
1186
case DRIZZLE_TYPE_NULL:
1187
abort(); // Programming error
1190
bool is_not_null= false;
1192
if (not pfield.constraints().is_nullable())
1196
else if (pfield.constraints().is_notnull())
1201
Field* f= make_field(pfield,
1202
record + field_offsets[fieldnr] + data_offset,
1210
MTYP_TYPENR(unireg_type),
1211
((field_type == DRIZZLE_TYPE_ENUM) ? &intervals[interval_nr++] : (TYPELIB*) 0),
1212
getTableMessage()->field(fieldnr).name().c_str());
1214
_fields[fieldnr]= f;
1216
// Insert post make_field code here.
1219
case DRIZZLE_TYPE_BLOB:
1220
case DRIZZLE_TYPE_VARCHAR:
1221
case DRIZZLE_TYPE_DOUBLE:
1222
case DRIZZLE_TYPE_DECIMAL:
1223
case DRIZZLE_TYPE_TIMESTAMP:
1224
case DRIZZLE_TYPE_TIME:
1225
case DRIZZLE_TYPE_DATETIME:
1226
case DRIZZLE_TYPE_MICROTIME:
1227
case DRIZZLE_TYPE_DATE:
1228
case DRIZZLE_TYPE_ENUM:
1229
case DRIZZLE_TYPE_LONG:
1230
case DRIZZLE_TYPE_LONGLONG:
1231
case DRIZZLE_TYPE_NULL:
1232
case DRIZZLE_TYPE_UUID:
1233
case DRIZZLE_TYPE_BOOLEAN:
1237
// This needs to go, we should be setting the "use" on the field so that
1238
// it does not reference the share/table.
1239
table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1240
temp_table.in_use= &session;
1242
f->init(&temp_table); /* blob default values need table obj */
1244
if (! (f->flags & NOT_NULL_FLAG))
1246
*f->null_ptr|= f->null_bit;
1247
if (! (null_bit_pos= (null_bit_pos + 1) & 7)) /* @TODO Ugh. */
1254
enum_check_fields old_count_cuted_fields= session.count_cuted_fields;
1255
session.count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
1256
int res= default_value->save_in_field(f, 1);
1257
session.count_cuted_fields= old_count_cuted_fields;
1258
if (res != 0 && res != 3) /* @TODO Huh? */
1260
my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
1261
local_error= ER_INVALID_DEFAULT;
1266
else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1269
f->store((int64_t) 1, true);
1276
/* hack to undo f->init() */
1278
f->orig_table= NULL;
1280
f->setPosition(fieldnr);
1281
f->comment= comment;
1282
if (not default_value &&
1283
not (f->unireg_check==Field::NEXT_NUMBER) &&
1284
(f->flags & NOT_NULL_FLAG) &&
1285
(not f->is_timestamp()))
1287
f->flags|= NO_DEFAULT_VALUE_FLAG;
1290
if (f->unireg_check == Field::NEXT_NUMBER)
1291
found_next_number_field= &(_fields[fieldnr]);
1293
if (use_hash) /* supposedly this never fails... but comments lie */
1295
const char *local_field_name= _fields[fieldnr]->field_name;
1296
name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
1301
for (unsigned int keynr= 0; keynr < keys; keynr++, keyinfo++)
1303
key_part= keyinfo->key_part;
1305
for (unsigned int partnr= 0;
1306
partnr < keyinfo->key_parts;
1307
partnr++, key_part++)
1310
* Fix up key_part->offset by adding data_offset.
1311
* We really should compute offset as well.
1312
* But at least this way we are a little better.
1314
key_part->offset= field_offsets[key_part->fieldnr-1] + data_offset;
1319
We need to set the unused bits to 1. If the number of bits is a multiple
1320
of 8 there are no unused bits.
1323
*(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1325
null_bytes= (null_pos - (unsigned char*) record + (null_bit_pos + 7) / 8);
1327
last_null_bit_pos= null_bit_pos;
1332
uint32_t local_primary_key= 0;
1333
doesKeyNameExist("PRIMARY", local_primary_key);
1336
key_part= keyinfo->key_part;
1338
for (uint32_t key= 0; key < keys; key++,keyinfo++)
1340
uint32_t usable_parts= 0;
1342
if (local_primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME))
1345
If the UNIQUE key doesn't have NULL columns and is not a part key
1346
declare this as a primary key.
1348
local_primary_key=key;
1349
for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1351
uint32_t fieldnr= key_part[i].fieldnr;
1353
_fields[fieldnr-1]->null_ptr ||
1354
_fields[fieldnr-1]->key_length() != key_part[i].length)
1356
local_primary_key= MAX_KEY; // Can't be used
1362
for (uint32_t i= 0 ; i < keyinfo->key_parts ; key_part++,i++)
1365
if (! key_part->fieldnr)
1369
local_field= key_part->field= _fields[key_part->fieldnr-1];
1370
key_part->type= local_field->key_type();
1371
if (local_field->null_ptr)
1373
key_part->null_offset=(uint32_t) ((unsigned char*) local_field->null_ptr - getDefaultValues());
1374
key_part->null_bit= local_field->null_bit;
1375
key_part->store_length+=HA_KEY_NULL_LENGTH;
1376
keyinfo->flags|=HA_NULL_PART_KEY;
1377
keyinfo->extra_length+= HA_KEY_NULL_LENGTH;
1378
keyinfo->key_length+= HA_KEY_NULL_LENGTH;
1380
if (local_field->type() == DRIZZLE_TYPE_BLOB ||
1381
local_field->real_type() == DRIZZLE_TYPE_VARCHAR)
1383
if (local_field->type() == DRIZZLE_TYPE_BLOB)
1384
key_part->key_part_flag|= HA_BLOB_PART;
1386
key_part->key_part_flag|= HA_VAR_LENGTH_PART;
1387
keyinfo->extra_length+=HA_KEY_BLOB_LENGTH;
1388
key_part->store_length+=HA_KEY_BLOB_LENGTH;
1389
keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
1391
if (i == 0 && key != local_primary_key)
1392
local_field->flags |= (((keyinfo->flags & HA_NOSAME) &&
1393
(keyinfo->key_parts == 1)) ?
1394
UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
1396
local_field->key_start.set(key);
1397
if (local_field->key_length() == key_part->length &&
1398
!(local_field->flags & BLOB_FLAG))
1400
enum ha_key_alg algo= key_info[key].algorithm;
1401
if (db_type()->index_flags(algo) & HA_KEYREAD_ONLY)
1403
keys_for_keyread.set(key);
1404
local_field->part_of_key.set(key);
1405
local_field->part_of_key_not_clustered.set(key);
1407
if (db_type()->index_flags(algo) & HA_READ_ORDER)
1408
local_field->part_of_sortkey.set(key);
1410
if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
1412
usable_parts++; // For FILESORT
1413
local_field->flags|= PART_KEY_FLAG;
1414
if (key == local_primary_key)
1416
local_field->flags|= PRI_KEY_FLAG;
1418
If this field is part of the primary key and all keys contains
1419
the primary key, then we can use any key to find this column
1421
if (storage_engine->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX))
1423
local_field->part_of_key= keys_in_use;
1424
if (local_field->part_of_sortkey.test(key))
1425
local_field->part_of_sortkey= keys_in_use;
1428
if (local_field->key_length() != key_part->length)
1430
key_part->key_part_flag|= HA_PART_KEY_SEG;
1433
keyinfo->usable_key_parts= usable_parts; // Filesort
1435
set_if_bigger(max_key_length,keyinfo->key_length+
1436
keyinfo->key_parts);
1437
total_key_length+= keyinfo->key_length;
1439
if (keyinfo->flags & HA_NOSAME)
1441
set_if_bigger(max_unique_length,keyinfo->key_length);
1444
if (local_primary_key < MAX_KEY &&
1445
(keys_in_use.test(local_primary_key)))
1447
primary_key= local_primary_key;
1449
If we are using an integer as the primary key then allow the user to
1450
refer to it as '_rowid'
1452
if (key_info[local_primary_key].key_parts == 1)
1454
Field *local_field= key_info[local_primary_key].key_part[0].field;
1455
if (local_field && local_field->result_type() == INT_RESULT)
1457
/* note that fieldnr here (and rowid_field_offset) starts from 1 */
1458
rowid_field_offset= (key_info[local_primary_key].key_part[0].
1465
if (found_next_number_field)
1467
Field *reg_field= *found_next_number_field;
1468
if ((int) (next_number_index= (uint32_t)
1469
find_ref_key(key_info, keys,
1470
getDefaultValues(), reg_field,
1471
&next_number_key_offset,
1472
&next_number_keypart)) < 0)
1474
/* Wrong field definition */
1475
local_error= ER_NOT_FORM_FILE;
1481
reg_field->flags |= AUTO_INCREMENT_FLAG;
1487
/* Store offsets to blob fields to find them fast */
1488
blob_field.resize(blob_fields);
1489
uint32_t *save= &blob_field[0];
1491
for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
1493
if ((*iter)->flags & BLOB_FLAG)
1499
all_set.resize(_field_size);
1502
return local_error != EE_OK;
1506
Read table definition from a binary / text based .frm cursor
1510
session Thread Cursor
1511
share Fill this with table definition
1514
This function is called when the table definition is not cached in
1515
definition::Cache::singleton().getCache()
1516
The data is returned in 'share', which is alloced by
1517
alloc_table_share().. The code assumes that share is initialized.
1521
1 Error (see open_table_error)
1522
2 Error (see open_table_error)
1523
3 Wrong data in .frm cursor
1524
4 Error (see open_table_error)
1525
5 Error (see open_table_error: charset unavailable)
1526
6 Unknown .frm version
1529
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
1531
drizzled::error_t local_error= EE_OK;
1533
message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1535
if (table and table->IsInitialized())
1537
if (parse_table_proto(session, *table))
1539
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1540
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1544
setTableCategory(TABLE_CATEGORY_USER);
1548
else if (table and not table->IsInitialized())
1550
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1551
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1555
local_error= ER_TABLE_UNKNOWN;
1556
my_error(ER_TABLE_UNKNOWN, identifier);
1559
return static_cast<int>(local_error);
1564
Open a table based on a TableShare
1567
open_table_from_share()
1568
session Thread Cursor
1569
share Table definition
1570
alias Alias for table
1571
db_stat open flags (for example HA_OPEN_KEYFILE|
1572
HA_OPEN_RNDFILE..) can be 0 (example in
1574
ha_open_flags HA_OPEN_ABORT_IF_LOCKED etc..
1575
outparam result table
1579
1 Error (see open_table_error)
1580
2 Error (see open_table_error)
1581
3 Wrong data in .frm cursor
1582
4 Error (see open_table_error)
1583
5 Error (see open_table_error: charset unavailable)
1584
7 Table definition has changed in engine
1586
int TableShare::open_table_from_share(Session *session,
1587
const identifier::Table &identifier,
1589
uint32_t db_stat, uint32_t ha_open_flags,
1592
bool error_reported= false;
1593
int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1596
ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1601
if (not error_reported)
1602
open_table_error(ret, errno, 0);
1604
boost::checked_delete(outparam.cursor);
1605
outparam.cursor= 0; // For easier error checking
1606
outparam.db_stat= 0;
1607
outparam.getMemRoot()->free_root(MYF(0)); // Safe to call on zeroed root
1608
outparam.clearAlias();
1613
int TableShare::open_table_from_share_inner(Session *session,
1620
unsigned char *record= NULL;
1624
outparam.resetTable(session, this, db_stat);
1626
outparam.setAlias(alias);
1628
/* Allocate Cursor */
1629
if (not (outparam.cursor= db_type()->getCursor(outparam)))
1634
if ((db_stat & HA_OPEN_KEYFILE))
1639
if (!(record= (unsigned char*) outparam.alloc_root(rec_buff_length * records)))
1644
/* We are probably in hard repair, and the buffers should not be used */
1645
outparam.record[0]= outparam.record[1]= getDefaultValues();
1649
outparam.record[0]= record;
1651
outparam.record[1]= record+ rec_buff_length;
1653
outparam.record[1]= outparam.getInsertRecord(); // Safety
1656
#ifdef HAVE_VALGRIND
1658
We need this because when we read var-length rows, we are not updating
1659
bytes after end of varchar
1663
memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1664
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1666
memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
1671
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1674
if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
1679
outparam.setFields(field_ptr);
1681
record= (unsigned char*) outparam.getInsertRecord()-1; /* Fieldstart = 1 */
1683
outparam.null_flags= (unsigned char*) record+1;
1685
/* 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++)
1688
if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
1691
(*field_ptr)= 0; // End marker
1693
if (found_next_number_field)
1694
outparam.found_next_number_field=
1695
outparam.getField(positionFields(found_next_number_field));
1696
if (timestamp_field)
1697
outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
1699
/* Fix key->name and key_part->field */
1702
KeyInfo *local_key_info, *key_info_end;
1703
KeyPartInfo *key_part;
1705
n_length= keys*sizeof(KeyInfo) + key_parts*sizeof(KeyPartInfo);
1706
if (!(local_key_info= (KeyInfo*) outparam.alloc_root(n_length)))
1708
outparam.key_info= local_key_info;
1709
key_part= (reinterpret_cast<KeyPartInfo*> (local_key_info+keys));
1711
memcpy(local_key_info, key_info, sizeof(*local_key_info)*keys);
1712
memcpy(key_part, key_info[0].key_part, (sizeof(*key_part) *
1715
for (key_info_end= local_key_info + keys ;
1716
local_key_info < key_info_end ;
1719
KeyPartInfo *key_part_end;
1721
local_key_info->table= &outparam;
1722
local_key_info->key_part= key_part;
1724
for (key_part_end= key_part+ local_key_info->key_parts ;
1725
key_part < key_part_end ;
1728
Field *local_field= key_part->field= outparam.getField(key_part->fieldnr-1);
1730
if (local_field->key_length() != key_part->length &&
1731
!(local_field->flags & BLOB_FLAG))
1734
We are using only a prefix of the column as a key:
1735
Create a new field for the key part that matches the index
1737
local_field= key_part->field= local_field->new_field(outparam.getMemRoot(), &outparam, 0);
1738
local_field->field_length= key_part->length;
1744
/* Allocate bitmaps */
1746
outparam.def_read_set.resize(_field_size);
1747
outparam.def_write_set.resize(_field_size);
1748
outparam.tmp_set.resize(_field_size);
1749
outparam.default_column_bitmaps();
1754
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
1755
uint32_t db_stat, uint32_t ha_open_flags,
1757
bool &error_reported)
1759
/* The table struct is now initialized; Open the table */
1763
assert(!(db_stat & HA_WAIT_IF_LOCKED));
1766
if ((ha_err= (outparam.cursor->ha_open(identifier,
1767
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1768
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1772
case HA_ERR_NO_SUCH_TABLE:
1774
The table did not exists in storage engine, use same error message
1775
as if the .frm cursor didn't exist
1782
Too many files opened, use same error message as if the .frm
1789
outparam.print_error(ha_err, MYF(0));
1790
error_reported= true;
1791
if (ha_err == HA_ERR_TABLE_DEF_CHANGED)
1802
/* error message when opening a form cursor */
1803
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1805
char buff[FN_REFLEN];
1806
myf errortype= ME_ERROR+ME_WAITTANG;
1808
switch (pass_error) {
1811
if (db_errno == ENOENT)
1813
identifier::Table identifier(db.str, table_name.str);
1814
my_error(ER_TABLE_UNKNOWN, identifier);
1818
snprintf(buff, sizeof(buff), "%s",normalized_path.str);
1819
my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND,
1820
errortype, buff, db_errno);
1825
drizzled::error_t err_no;
1827
err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1828
ER_FILE_USED : ER_CANT_OPEN_FILE;
1830
my_error(err_no, errortype, normalized_path.str, db_errno);
1835
const char *csname= get_charset_name((uint32_t) pass_errarg);
1837
if (!csname || csname[0] =='?')
1839
snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
1842
my_printf_error(ER_UNKNOWN_COLLATION,
1843
_("Unknown collation '%s' in table '%-.64s' definition"),
1844
MYF(0), csname, table_name.str);
1848
snprintf(buff, sizeof(buff), "%s", normalized_path.str);
1849
my_printf_error(ER_NOT_FORM_FILE,
1850
_("Table '%-.64s' was created with a different version "
1851
"of Drizzle and cannot be read"),
1856
default: /* Better wrong error than none */
1858
snprintf(buff, sizeof(buff), "%s", normalized_path.str);
1859
my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
1863
} /* open_table_error */
1865
Field *TableShare::make_field(const message::Table::Field &pfield,
1867
uint32_t field_length,
1869
unsigned char *null_pos,
1870
unsigned char null_bit,
1872
enum_field_types field_type,
1873
const CHARSET_INFO * field_charset,
1874
Field::utype unireg_check,
1876
const char *field_name)
1878
return make_field(pfield,
1890
pfield.constraints().is_unsigned());
1893
Field *TableShare::make_field(const message::Table::Field &,
1895
uint32_t field_length,
1897
unsigned char *null_pos,
1898
unsigned char null_bit,
1900
enum_field_types field_type,
1901
const CHARSET_INFO * field_charset,
1902
Field::utype unireg_check,
1904
const char *field_name,
1914
null_bit= ((unsigned char) 1) << null_bit;
1919
case DRIZZLE_TYPE_ENUM:
1920
return new (&mem_root) Field_enum(ptr,
1927
case DRIZZLE_TYPE_VARCHAR:
1929
return new (&mem_root) Field_varstring(ptr,field_length,
1930
ha_varchar_packlength(field_length),
1934
case DRIZZLE_TYPE_BLOB:
1935
return new (&mem_root) Field_blob(ptr,
1941
case DRIZZLE_TYPE_DECIMAL:
1942
return new (&mem_root) Field_decimal(ptr,
1949
case DRIZZLE_TYPE_DOUBLE:
1950
return new (&mem_root) Field_double(ptr,
1958
false /* is_unsigned */);
1959
case DRIZZLE_TYPE_UUID:
1960
return new (&mem_root) field::Uuid(ptr,
1965
case DRIZZLE_TYPE_BOOLEAN:
1966
return new (&mem_root) field::Boolean(ptr,
1972
case DRIZZLE_TYPE_LONG:
1973
return new (&mem_root) field::Int32(ptr,
1979
case DRIZZLE_TYPE_LONGLONG:
1983
return new (&mem_root) field::Size(ptr,
1991
return new (&mem_root) field::Int64(ptr,
1998
case DRIZZLE_TYPE_MICROTIME:
1999
return new (&mem_root) field::Microtime(ptr,
2005
case DRIZZLE_TYPE_TIMESTAMP:
2006
return new (&mem_root) field::Epoch(ptr,
2012
case DRIZZLE_TYPE_TIME:
2013
return new (&mem_root) field::Time(ptr,
2018
case DRIZZLE_TYPE_DATE:
2019
return new (&mem_root) Field_date(ptr,
2023
case DRIZZLE_TYPE_DATETIME:
2024
return new (&mem_root) Field_datetime(ptr,
2028
case DRIZZLE_TYPE_NULL:
2029
return new (&mem_root) Field_null(ptr,
2037
void TableShare::refreshVersion()
2039
version= refresh_version;
2043
} /* namespace drizzled */