405
405
statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
408
bool buildCollation(LEX *lex, const CHARSET_INFO *arg)
410
statement::CreateTable *statement= (statement::CreateTable *)lex->statement;
412
HA_CREATE_INFO *cinfo= &statement->create_info();
413
if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
414
cinfo->default_table_charset && arg &&
415
!my_charset_same(cinfo->default_table_charset, arg))
417
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
418
arg->name, cinfo->default_table_charset->csname);
421
statement->create_info().default_table_charset= arg;
422
statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
427
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
429
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
430
Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0,
432
statement->alter_info.key_list.push_back(key);
433
lex->col_list.empty(); /* Alloced by memory::sql_alloc */
436
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
438
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
439
Key *key= new Foreign_key(name_arg, lex->col_list,
442
statement->fk_delete_opt,
443
statement->fk_update_opt,
444
statement->fk_match_option);
446
statement->alter_info.key_list.push_back(key);
447
key= new Key(Key::MULTIPLE, name_arg,
448
&default_key_create_info, 1,
450
statement->alter_info.key_list.push_back(key);
451
lex->col_list.empty(); /* Alloced by memory::sql_alloc */
452
/* Only used for ALTER TABLE. Ignored otherwise. */
453
statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
456
drizzled::enum_field_types buildIntegerColumn(LEX *lex, drizzled::enum_field_types final_type, const bool is_unsigned)
458
lex->length=(char*) 0; /* use default length */
462
final_type= DRIZZLE_TYPE_LONGLONG;
467
assert (final_type == DRIZZLE_TYPE_LONG or final_type == DRIZZLE_TYPE_LONGLONG);
468
// We update the type for unsigned types
471
lex->field()->set_type(message::Table::Field::BIGINT);
472
lex->field()->mutable_constraints()->set_is_unsigned(true);
474
else if (final_type == DRIZZLE_TYPE_LONG)
476
lex->field()->set_type(message::Table::Field::INTEGER);
478
else if (final_type == DRIZZLE_TYPE_LONGLONG)
480
lex->field()->set_type(message::Table::Field::BIGINT);
487
drizzled::enum_field_types buildSerialColumn(LEX *lex)
489
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
490
statement->alter_info.flags.set(ALTER_ADD_INDEX);
492
lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
496
lex->field()->mutable_constraints()->set_is_notnull(true);
497
lex->field()->mutable_constraints()->set_is_unsigned(true);
499
lex->field()->set_type(message::Table::Field::BIGINT);
502
return DRIZZLE_TYPE_LONGLONG;
505
drizzled::enum_field_types buildVarcharColumn(LEX *lex, const char *length)
507
lex->length= const_cast<char *>(length);
511
lex->field()->set_type(message::Table::Field::VARCHAR);
513
message::Table::Field::StringFieldOptions *string_field_options;
515
string_field_options= lex->field()->mutable_string_options();
517
string_field_options->set_length(atoi(length));
520
return DRIZZLE_TYPE_VARCHAR;
523
drizzled::enum_field_types buildDecimalColumn(LEX *lex)
526
lex->field()->set_type(message::Table::Field::DECIMAL);
528
return DRIZZLE_TYPE_DECIMAL;
531
drizzled::enum_field_types buildVarbinaryColumn(LEX *lex, const char *length)
533
lex->length= const_cast<char *>(length);
534
lex->charset= &my_charset_bin;
538
lex->field()->set_type(message::Table::Field::VARCHAR);
540
message::Table::Field::StringFieldOptions *string_field_options;
542
string_field_options= lex->field()->mutable_string_options();
544
string_field_options->set_length(atoi(length));
545
string_field_options->set_collation_id(my_charset_bin.number);
546
string_field_options->set_collation(my_charset_bin.name);
549
return DRIZZLE_TYPE_VARCHAR;
552
drizzled::enum_field_types buildBlobColumn(LEX *lex)
554
lex->charset=&my_charset_bin;
555
lex->length=(char*) 0; /* use default length */
559
lex->field()->set_type(message::Table::Field::BLOB);
560
message::Table::Field::StringFieldOptions *string_field_options;
562
string_field_options= lex->field()->mutable_string_options();
563
string_field_options->set_collation_id(my_charset_bin.number);
564
string_field_options->set_collation(my_charset_bin.name);
567
return DRIZZLE_TYPE_BLOB;
570
drizzled::enum_field_types buildBooleanColumn(LEX *lex)
573
lex->field()->set_type(message::Table::Field::BOOLEAN);
575
return DRIZZLE_TYPE_BOOLEAN;
578
drizzled::enum_field_types buildUuidColumn(LEX *lex)
581
lex->field()->set_type(message::Table::Field::UUID);
583
return DRIZZLE_TYPE_UUID;
586
drizzled::enum_field_types buildDoubleColumn(LEX *lex)
590
lex->field()->set_type(message::Table::Field::DOUBLE);
593
return DRIZZLE_TYPE_DOUBLE;
596
drizzled::enum_field_types buildTimestampColumn(LEX *lex, const char *length)
600
lex->field()->set_type(message::Table::Field::EPOCH);
605
lex->length= const_cast<char *>(length);
606
return DRIZZLE_TYPE_MICROTIME;
611
return DRIZZLE_TYPE_TIMESTAMP;
614
void buildKeyOnColumn(LEX *lex)
616
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
618
lex->type|= UNIQUE_KEY_FLAG;
619
statement->alter_info.flags.set(ALTER_ADD_INDEX);
623
lex->field()->mutable_constraints()->set_is_unique(true);
627
void buildAutoOnColumn(LEX *lex)
629
lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
633
lex->field()->mutable_constraints()->set_is_notnull(true);
637
void buildPrimaryOnColumn(LEX *lex)
639
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
641
lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
642
statement->alter_info.flags.set(ALTER_ADD_INDEX);
646
lex->field()->mutable_constraints()->set_is_notnull(true);
408
650
} // namespace parser
409
651
} // namespace drizzled