395
397
lex->setField(alter_proto.add_added_field());
398
void storeAlterColumnPosition(LEX *lex, const char *position)
400
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
402
lex->last_field->after=const_cast<char*> (position);
403
statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
406
bool buildCollation(LEX *lex, const CHARSET_INFO *arg)
408
statement::CreateTable *statement= (statement::CreateTable *)lex->statement;
410
HA_CREATE_INFO *cinfo= &statement->create_info();
411
if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
412
cinfo->default_table_charset && arg &&
413
!my_charset_same(cinfo->default_table_charset, arg))
415
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
416
arg->name, cinfo->default_table_charset->csname);
419
statement->create_info().default_table_charset= arg;
420
statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
425
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
427
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
428
Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0,
430
statement->alter_info.key_list.push_back(key);
431
lex->col_list.clear(); /* Alloced by memory::sql_alloc */
434
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
436
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
437
Key *key= new Foreign_key(name_arg, lex->col_list,
440
statement->fk_delete_opt,
441
statement->fk_update_opt,
442
statement->fk_match_option);
444
statement->alter_info.key_list.push_back(key);
445
key= new Key(Key::MULTIPLE, name_arg,
446
&default_key_create_info, 1,
448
statement->alter_info.key_list.push_back(key);
449
lex->col_list.clear(); /* Alloced by memory::sql_alloc */
450
/* Only used for ALTER TABLE. Ignored otherwise. */
451
statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
454
drizzled::enum_field_types buildIntegerColumn(LEX *lex, drizzled::enum_field_types final_type, const bool is_unsigned)
456
lex->length=(char*) 0; /* use default length */
460
final_type= DRIZZLE_TYPE_LONGLONG;
465
assert (final_type == DRIZZLE_TYPE_LONG or final_type == DRIZZLE_TYPE_LONGLONG);
466
// We update the type for unsigned types
469
lex->field()->set_type(message::Table::Field::BIGINT);
470
lex->field()->mutable_constraints()->set_is_unsigned(true);
472
else if (final_type == DRIZZLE_TYPE_LONG)
474
lex->field()->set_type(message::Table::Field::INTEGER);
476
else if (final_type == DRIZZLE_TYPE_LONGLONG)
478
lex->field()->set_type(message::Table::Field::BIGINT);
485
drizzled::enum_field_types buildSerialColumn(LEX *lex)
487
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
488
statement->alter_info.flags.set(ALTER_ADD_INDEX);
490
lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
494
lex->field()->mutable_constraints()->set_is_notnull(true);
495
lex->field()->mutable_constraints()->set_is_unsigned(true);
497
lex->field()->set_type(message::Table::Field::BIGINT);
500
return DRIZZLE_TYPE_LONGLONG;
503
drizzled::enum_field_types buildVarcharColumn(LEX *lex, const char *length)
505
lex->length= const_cast<char *>(length);
509
lex->field()->set_type(message::Table::Field::VARCHAR);
511
message::Table::Field::StringFieldOptions *string_field_options;
513
string_field_options= lex->field()->mutable_string_options();
515
string_field_options->set_length(atoi(length));
518
return DRIZZLE_TYPE_VARCHAR;
521
drizzled::enum_field_types buildDecimalColumn(LEX *lex)
524
lex->field()->set_type(message::Table::Field::DECIMAL);
526
return DRIZZLE_TYPE_DECIMAL;
529
drizzled::enum_field_types buildVarbinaryColumn(LEX *lex, const char *length)
531
lex->length= const_cast<char *>(length);
532
lex->charset= &my_charset_bin;
536
lex->field()->set_type(message::Table::Field::VARCHAR);
538
message::Table::Field::StringFieldOptions *string_field_options;
540
string_field_options= lex->field()->mutable_string_options();
542
string_field_options->set_length(atoi(length));
543
string_field_options->set_collation_id(my_charset_bin.number);
544
string_field_options->set_collation(my_charset_bin.name);
547
return DRIZZLE_TYPE_VARCHAR;
550
drizzled::enum_field_types buildBlobColumn(LEX *lex)
552
lex->charset=&my_charset_bin;
553
lex->length=(char*) 0; /* use default length */
557
lex->field()->set_type(message::Table::Field::BLOB);
558
message::Table::Field::StringFieldOptions *string_field_options;
560
string_field_options= lex->field()->mutable_string_options();
561
string_field_options->set_collation_id(my_charset_bin.number);
562
string_field_options->set_collation(my_charset_bin.name);
565
return DRIZZLE_TYPE_BLOB;
568
drizzled::enum_field_types buildBooleanColumn(LEX *lex)
571
lex->field()->set_type(message::Table::Field::BOOLEAN);
573
return DRIZZLE_TYPE_BOOLEAN;
576
drizzled::enum_field_types buildUuidColumn(LEX *lex)
579
lex->field()->set_type(message::Table::Field::UUID);
581
return DRIZZLE_TYPE_UUID;
584
drizzled::enum_field_types buildDoubleColumn(LEX *lex)
588
lex->field()->set_type(message::Table::Field::DOUBLE);
591
return DRIZZLE_TYPE_DOUBLE;
594
drizzled::enum_field_types buildTimestampColumn(LEX *lex, const char *length)
598
lex->field()->set_type(message::Table::Field::EPOCH);
603
lex->length= const_cast<char *>(length);
604
return DRIZZLE_TYPE_MICROTIME;
609
return DRIZZLE_TYPE_TIMESTAMP;
612
void buildKeyOnColumn(LEX *lex)
614
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
616
lex->type|= UNIQUE_KEY_FLAG;
617
statement->alter_info.flags.set(ALTER_ADD_INDEX);
621
lex->field()->mutable_constraints()->set_is_unique(true);
625
void buildAutoOnColumn(LEX *lex)
627
lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
631
lex->field()->mutable_constraints()->set_is_notnull(true);
635
void buildPrimaryOnColumn(LEX *lex)
637
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
639
lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
640
statement->alter_info.flags.set(ALTER_ADD_INDEX);
644
lex->field()->mutable_constraints()->set_is_notnull(true);
648
void buildReplicationOption(LEX *lex, bool arg)
650
statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
651
message::ReplicationOptions *options= statement->schema_message.mutable_replication_options();
652
options->set_dont_replicate(arg);
655
void buildAddAlterDropIndex(LEX *lex, const char *name, bool is_foreign_key)
657
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
659
statement->alter_info.flags.set(ALTER_DROP_INDEX);
662
statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
663
statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY, name));
667
statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, name));
671
400
} // namespace parser
672
401
} // namespace drizzled