12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
#include "config.h"
17
17
#include <drizzled/error.h>
46
44
namespace drizzled {
48
bool fill_table_proto(message::Table &table_proto,
49
List<CreateField> &create_fields,
50
HA_CREATE_INFO *create_info,
46
static int fill_table_proto(message::Table &table_proto,
47
List<CreateField> &create_fields,
48
HA_CREATE_INFO *create_info,
54
52
CreateField *field_arg;
55
53
List_iterator<CreateField> it(create_fields);
58
56
if (create_fields.elements > MAX_FIELDS)
60
58
my_error(ER_TOO_MANY_FIELDS, MYF(0), ER(ER_TOO_MANY_FIELDS));
64
62
assert(strcmp(table_proto.engine().name().c_str(),
86
82
if (field_arg->flags & NOT_NULL_FLAG)
88
attribute->mutable_constraints()->set_is_notnull(true);
84
message::Table::Field::FieldConstraints *constraints;
91
if (field_arg->flags & UNSIGNED_FLAG and
92
(field_arg->sql_type == DRIZZLE_TYPE_LONGLONG or field_arg->sql_type == DRIZZLE_TYPE_LONG))
94
field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
95
attribute->mutable_constraints()->set_is_unsigned(true);
86
constraints= attribute->mutable_constraints();
87
constraints->set_is_nullable(false);
98
90
attribute->set_name(field_arg->field_name);
101
assert(((field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_notnull());
93
assert((!(field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_nullable());
102
94
assert(strcmp(attribute->name().c_str(), field_arg->field_name)==0);
105
97
message::Table::Field::FieldType parser_type= attribute->type();
107
if (field_arg->sql_type == DRIZZLE_TYPE_NULL)
109
my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), table_proto.name().c_str(), -1);
113
if (field_arg->flags & UNSIGNED_FLAG and
114
(field_arg->sql_type == DRIZZLE_TYPE_LONGLONG or field_arg->sql_type == DRIZZLE_TYPE_LONG))
116
message::Table::Field::FieldConstraints *constraints= attribute->mutable_constraints();
118
field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
119
constraints->set_is_unsigned(true);
122
99
attribute->set_type(message::internalFieldTypeToFieldProtoType(field_arg->sql_type));
124
101
switch (attribute->type()) {
125
case message::Table::Field::BIGINT:
126
case message::Table::Field::INTEGER:
127
case message::Table::Field::DATE:
128
case message::Table::Field::DATETIME:
129
case message::Table::Field::UUID:
130
case message::Table::Field::TIME:
131
case message::Table::Field::BOOLEAN:
102
default: /* Only deal with types that need extra information */
133
104
case message::Table::Field::DOUBLE:
209
case message::Table::Field::EPOCH:
211
if (field_arg->sql_type == DRIZZLE_TYPE_MICROTIME)
212
attribute->mutable_time_options()->set_microseconds(true);
218
180
assert (!use_existing_fields || parser_type == attribute->type());
236
198
my_error(ER_WRONG_STRING_LENGTH, MYF(0),
237
199
field_arg->comment.str,"COLUMN COMMENT",
238
200
(uint32_t) COLUMN_COMMENT_MAXLEN);
242
204
if (! use_existing_fields)
268
230
field_options->set_update_expression("CURRENT_TIMESTAMP");
271
if (field_arg->def == NULL && not attribute->constraints().is_notnull())
233
if (field_arg->def == NULL && attribute->constraints().is_nullable())
273
235
message::Table::Field::FieldOptions *field_options;
274
236
field_options= attribute->mutable_options();
297
259
< default_value->length()))
299
261
my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name);
303
265
if (field_arg->sql_type == DRIZZLE_TYPE_DATE
304
|| field_arg->sql_type == DRIZZLE_TYPE_TIME
305
266
|| field_arg->sql_type == DRIZZLE_TYPE_DATETIME
306
|| field_arg->sql_type == DRIZZLE_TYPE_MICROTIME
307
267
|| field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
311
if (field_arg->def->get_date(ltime, TIME_FUZZY_DATE))
271
if (field_arg->def->get_date(<ime, TIME_FUZZY_DATE))
313
273
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
314
274
default_value->c_str());
318
278
/* We now do the casting down to the appropriate type.
386
346
my_error(ER_WRONG_STRING_LENGTH, MYF(0),
387
347
table_options->comment().c_str(),"Table COMMENT",
388
348
(uint32_t) TABLE_COMMENT_MAXLEN);
393
353
if (create_info->default_table_charset)
395
table_options->set_collation_id(create_info->default_table_charset->number);
355
table_options->set_collation_id(
356
create_info->default_table_charset->number);
396
357
table_options->set_collation(create_info->default_table_charset->name);
482
443
my_error(ER_WRONG_STRING_LENGTH, MYF(0),
483
444
key_info[i].comment.str,"Index COMMENT",
484
445
(uint32_t) TABLE_COMMENT_MAXLEN);
488
449
idx->set_comment(key_info[i].comment.str);
490
static const uint64_t unknown_index_flag= (HA_NOSAME | HA_PACK_KEY |
495
HA_KEY_HAS_PART_KEY_SEG |
498
if (key_info[i].flags & ~unknown_index_flag)
451
if (key_info[i].flags &
452
~(HA_NOSAME | HA_PACK_KEY | HA_USES_BLOCK_SIZE |
453
HA_BINARY_PACK_KEY | HA_VAR_LENGTH_PART | HA_NULL_PART_KEY |
454
HA_KEY_HAS_PART_KEY_SEG | HA_GENERATED_KEY | HA_USES_COMMENT))
499
455
abort(); // Invalid (unknown) index flag.
501
457
for(unsigned int j=0; j< key_info[i].key_parts; j++)
530
486
if (not table_proto.IsInitialized())
532
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
533
table_proto.name().c_str(),
534
table_proto.InitializationErrorString().c_str());
488
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table_proto.InitializationErrorString().c_str());
552
505
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
553
table_proto.name().c_str(),
554
table_proto.InitializationErrorString().c_str());
506
table_proto.InitializationErrorString().empty() ? "": table_proto.InitializationErrorString().c_str());
582
534
bool rea_create_table(Session *session,
583
const identifier::Table &identifier,
535
TableIdentifier &identifier,
584
536
message::Table &table_proto,
585
537
HA_CREATE_INFO *create_info,
586
538
List<CreateField> &create_fields,
589
541
assert(table_proto.has_name());
590
542
if (fill_table_proto(table_proto, create_fields, create_info,
596
546
assert(table_proto.name() == identifier.getTableName());
598
if (not plugin::StorageEngine::createTable(*session,
548
if (plugin::StorageEngine::createTable(*session,