796
bool add_field_to_list(Session *session, lex_string_t *field_name, enum_field_types type,
796
bool add_field_to_list(Session *session, str_ref field_name, enum_field_types type,
797
797
const char *length, const char *decimals,
798
798
uint32_t type_modifier, column_format_type column_format,
799
799
Item *default_value, Item *on_update_value, str_ref comment,
802
802
LEX *lex= &session->lex();
803
803
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
805
if (check_identifier_name(*field_name, ER_TOO_LONG_IDENT))
805
if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
808
808
if (type_modifier & PRI_KEY_FLAG)
810
lex->col_list.push_back(new Key_part_spec(*field_name, 0));
810
lex->col_list.push_back(new Key_part_spec(field_name, 0));
811
811
statement->alter_info.key_list.push_back(new Key(Key::PRIMARY, null_lex_string(), &default_key_create_info, 0, lex->col_list));
812
812
lex->col_list.clear();
814
814
if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
816
lex->col_list.push_back(new Key_part_spec(*field_name, 0));
816
lex->col_list.push_back(new Key_part_spec(field_name, 0));
817
817
statement->alter_info.key_list.push_back(new Key(Key::UNIQUE, null_lex_string(), &default_key_create_info, 0, lex->col_list));
818
818
lex->col_list.clear();
831
831
!(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
832
832
(type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
834
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->data());
834
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
837
837
else if (default_value->type() == Item::NULL_ITEM)
839
839
default_value= 0;
840
840
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
842
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->data());
842
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
846
846
else if (type_modifier & AUTO_INCREMENT_FLAG)
848
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->data());
848
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
853
853
if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
855
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->data());
855
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name.data());
859
859
CreateField* new_field= new CreateField;
860
if (new_field->init(session, field_name->data(), type, length, decimals, type_modifier, comment, change, interval_list, cs, 0, column_format)
860
if (new_field->init(session, field_name.data(), type, length, decimals, type_modifier, comment, change, interval_list, cs, 0, column_format)
861
861
|| new_field->setDefaultValue(default_value, on_update_value))