853
853
opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
855
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
857
855
if (not Lex->current_select->add_table_to_list(Lex->session, $9,
859
857
TL_OPTION_UPDATING))
862
key= new Key($4, $6, &statement->key_create_info, 0, Lex->col_list);
863
statement->alter_info.key_list.push_back(key);
864
Lex->col_list.empty();
860
parser::buildKey(Lex, $4, $6);
866
862
| CREATE DATABASE opt_if_not_exists schema_name
1048
1044
default_collation:
1049
1045
opt_default COLLATE_SYM opt_equal collation_name_or_default
1051
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1053
HA_CREATE_INFO *cinfo= &statement->create_info();
1054
if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1055
cinfo->default_table_charset && $4 &&
1056
!my_charset_same(cinfo->default_table_charset,$4))
1058
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1059
$4->name, cinfo->default_table_charset->csname);
1062
statement->create_info().default_table_charset= $4;
1063
statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1047
if (not parser::buildCollation(Lex, $4))
1067
1054
default_collation_schema:
1068
1055
opt_default COLLATE_SYM opt_equal collation_name_or_default
1070
statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1072
message::Schema &schema_message= statement->schema_message;
1073
schema_message.set_collation($4->name);
1057
((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
1118
1102
key_type opt_ident key_alg '(' key_list ')' key_options
1120
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1121
Key *key= new Key($1, $2, &statement->key_create_info, 0,
1123
statement->alter_info.key_list.push_back(key);
1124
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1104
parser::buildKey(Lex, $1, $2);
1126
1106
| opt_constraint constraint_key_type opt_ident key_alg
1127
1107
'(' key_list ')' key_options
1129
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1130
Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1132
statement->alter_info.key_list.push_back(key);
1133
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1109
parser::buildKey(Lex, $2, $3.str ? $3 : $1);
1135
1111
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1137
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1138
Key *key= new Foreign_key($1.str ? $1 : $4, Lex->col_list,
1141
statement->fk_delete_opt,
1142
statement->fk_update_opt,
1143
statement->fk_match_option);
1145
statement->alter_info.key_list.push_back(key);
1146
key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1147
&default_key_create_info, 1,
1149
statement->alter_info.key_list.push_back(key);
1150
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1151
/* Only used for ALTER TABLE. Ignored otherwise. */
1152
statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1113
parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
1154
1115
| constraint opt_check_constraint
1212
1173
field_definition:
1213
1174
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1216
Lex->length=(char*) 0; /* use default length */
1220
$1= DRIZZLE_TYPE_LONGLONG;
1225
assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
1226
// We update the type for unsigned types
1229
Lex->field()->set_type(message::Table::Field::BIGINT);
1230
Lex->field()->mutable_constraints()->set_is_unsigned(true);
1232
if ($1 == DRIZZLE_TYPE_LONG)
1234
Lex->field()->set_type(message::Table::Field::INTEGER);
1236
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1238
Lex->field()->set_type(message::Table::Field::BIGINT);
1176
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1242
1178
| real_type opt_precision
1248
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1249
Lex->field()->set_type(message::Table::Field::DOUBLE);
1180
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1181
$$= parser::buildDoubleColumn(Lex);
1252
1183
| char '(' NUM ')'
1255
$$=DRIZZLE_TYPE_VARCHAR;
1259
Lex->field()->set_type(message::Table::Field::VARCHAR);
1260
message::Table::Field::StringFieldOptions *string_field_options;
1262
string_field_options= Lex->field()->mutable_string_options();
1264
string_field_options->set_length(atoi($3.str));
1185
$$= parser::buildVarcharColumn(Lex, $3.str);
1269
Lex->length=(char*) "1";
1270
$$=DRIZZLE_TYPE_VARCHAR;
1273
Lex->field()->set_type(message::Table::Field::VARCHAR);
1189
$$= parser::buildVarcharColumn(Lex, "1");
1275
1191
| varchar '(' NUM ')'
1278
$$= DRIZZLE_TYPE_VARCHAR;
1282
Lex->field()->set_type(message::Table::Field::VARCHAR);
1284
message::Table::Field::StringFieldOptions *string_field_options;
1286
string_field_options= Lex->field()->mutable_string_options();
1288
string_field_options->set_length(atoi($3.str));
1193
$$= parser::buildVarcharColumn(Lex, $3.str);
1291
1195
| VARBINARY '(' NUM ')'
1294
Lex->charset=&my_charset_bin;
1295
$$= DRIZZLE_TYPE_VARCHAR;
1299
Lex->field()->set_type(message::Table::Field::VARCHAR);
1300
message::Table::Field::StringFieldOptions *string_field_options;
1302
string_field_options= Lex->field()->mutable_string_options();
1304
string_field_options->set_length(atoi($3.str));
1305
string_field_options->set_collation_id(my_charset_bin.number);
1306
string_field_options->set_collation(my_charset_bin.name);
1197
$$= parser::buildVarbinaryColumn(Lex, $3.str);
1323
1213
| TIMESTAMP_SYM
1325
$$=DRIZZLE_TYPE_TIMESTAMP;
1329
Lex->field()->set_type(message::Table::Field::EPOCH);
1215
$$=parser::buildTimestampColumn(Lex, NULL);
1331
1217
| TIMESTAMP_SYM '(' NUM ')'
1333
$$=DRIZZLE_TYPE_MICROTIME;
1334
Lex->length= $3.str;
1337
Lex->field()->set_type(message::Table::Field::EPOCH);
1219
$$=parser::buildTimestampColumn(Lex, $3.str);
1348
Lex->charset=&my_charset_bin;
1349
$$=DRIZZLE_TYPE_BLOB;
1350
Lex->length=(char*) 0; /* use default length */
1354
Lex->field()->set_type(message::Table::Field::BLOB);
1355
message::Table::Field::StringFieldOptions *string_field_options;
1357
string_field_options= Lex->field()->mutable_string_options();
1358
string_field_options->set_collation_id(my_charset_bin.number);
1359
string_field_options->set_collation(my_charset_bin.name);
1230
$$= parser::buildBlobColumn(Lex);
1370
1240
| DECIMAL_SYM float_options
1372
$$=DRIZZLE_TYPE_DECIMAL;
1375
Lex->field()->set_type(message::Table::Field::DECIMAL);
1242
$$= parser::buildDecimalColumn(Lex);
1377
1244
| NUMERIC_SYM float_options
1379
$$=DRIZZLE_TYPE_DECIMAL;
1382
Lex->field()->set_type(message::Table::Field::DECIMAL);
1246
$$= parser::buildDecimalColumn(Lex);
1384
1248
| FIXED_SYM float_options
1386
$$=DRIZZLE_TYPE_DECIMAL;
1389
Lex->field()->set_type(message::Table::Field::DECIMAL);
1250
$$= parser::buildDecimalColumn(Lex);
1404
$$=DRIZZLE_TYPE_UUID;
1407
Lex->field()->set_type(message::Table::Field::UUID);
1265
$$= parser::buildUuidColumn(Lex);
1411
$$=DRIZZLE_TYPE_BOOLEAN;
1414
Lex->field()->set_type(message::Table::Field::BOOLEAN);
1269
$$= parser::buildBooleanColumn(Lex);
1418
$$=DRIZZLE_TYPE_LONGLONG;
1419
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
1423
Lex->field()->mutable_constraints()->set_is_notnull(true);
1424
Lex->field()->mutable_constraints()->set_is_unsigned(true);
1426
Lex->field()->set_type(message::Table::Field::BIGINT);
1273
$$= parser::buildSerialColumn(Lex);
1554
Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1558
Lex->field()->mutable_constraints()->set_is_notnull(true);
1400
parser::buildAutoOnColumn(Lex);
1561
1402
| SERIAL_SYM DEFAULT VALUE_SYM
1563
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1565
Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG;
1566
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1570
Lex->field()->mutable_constraints()->set_is_notnull(true);
1571
Lex->field()->mutable_constraints()->set_is_unsigned(true);
1404
(void)parser::buildSerialColumn(Lex);
1574
1406
| opt_primary KEY_SYM
1576
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1578
Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1579
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1583
Lex->field()->mutable_constraints()->set_is_notnull(true);
1408
parser::buildPrimaryOnColumn(Lex);
1588
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1590
Lex->type|= UNIQUE_FLAG;
1591
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1595
Lex->field()->mutable_constraints()->set_is_unique(true);
1412
parser::buildKeyOnColumn(Lex);
1598
1414
| UNIQUE_SYM KEY_SYM
1600
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1602
Lex->type|= UNIQUE_KEY_FLAG;
1603
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1607
Lex->field()->mutable_constraints()->set_is_unique(true);
1416
parser::buildKeyOnColumn(Lex);
1610
1418
| COMMENT_SYM TEXT_STRING_sys