~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Lee Bieber
  • Date: 2011-02-10 01:09:23 UTC
  • mfrom: (2152.2.1 alter-table)
  • Revision ID: kalebral@gmail.com-20110210010923-mbwuwow0nudk7ryh
Merge Brian - more parser rework

Show diffs side-by-side

added added

removed removed

Lines of Context:
852
852
          }
853
853
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
854
          {
855
 
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
856
 
 
857
855
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
858
856
                                                            NULL,
859
857
                                                            TL_OPTION_UPDATING))
860
858
              DRIZZLE_YYABORT;
861
 
            Key *key;
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();
 
859
 
 
860
            parser::buildKey(Lex, $4, $6);
865
861
          }
866
862
        | CREATE DATABASE opt_if_not_exists schema_name
867
863
          {
1048
1044
default_collation:
1049
1045
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1050
1046
          {
1051
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1052
 
 
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))
1057
 
              {
1058
 
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1059
 
                         $4->name, cinfo->default_table_charset->csname);
1060
 
                DRIZZLE_YYABORT;
1061
 
              }
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))
 
1048
            {
 
1049
              DRIZZLE_YYABORT;
 
1050
            }
1064
1051
          }
1065
1052
        ;
1066
1053
 
1067
1054
default_collation_schema:
1068
1055
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1069
1056
          {
1070
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1071
 
 
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);
1074
1058
          }
1075
1059
        ;
1076
1060
 
1117
1101
key_def:
1118
1102
          key_type opt_ident key_alg '(' key_list ')' key_options
1119
1103
          {
1120
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1121
 
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1122
 
                              Lex->col_list);
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);
1125
1105
          }
1126
1106
        | opt_constraint constraint_key_type opt_ident key_alg
1127
1107
          '(' key_list ')' key_options
1128
1108
          {
1129
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1130
 
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1131
 
                              Lex->col_list);
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);
1134
1110
          }
1135
1111
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1136
1112
          {
1137
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1138
 
            Key *key= new Foreign_key($1.str ? $1 : $4, Lex->col_list,
1139
 
                                      $8,
1140
 
                                      Lex->ref_list,
1141
 
                                      statement->fk_delete_opt,
1142
 
                                      statement->fk_update_opt,
1143
 
                                      statement->fk_match_option);
1144
 
 
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,
1148
 
                         Lex->col_list);
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);
1153
1114
          }
1154
1115
        | constraint opt_check_constraint
1155
1116
          {
1212
1173
field_definition:
1213
1174
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1214
1175
          { 
1215
 
            $$= $1;
1216
 
            Lex->length=(char*) 0; /* use default length */
1217
 
 
1218
 
            if ($3 or $4)
1219
 
            {
1220
 
              $1= DRIZZLE_TYPE_LONGLONG;
1221
 
            }
1222
 
 
1223
 
            if (Lex->field())
1224
 
            {
1225
 
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
1226
 
              // We update the type for unsigned types
1227
 
              if ($3 or $4)
1228
 
              {
1229
 
                Lex->field()->set_type(message::Table::Field::BIGINT);
1230
 
                Lex->field()->mutable_constraints()->set_is_unsigned(true);
1231
 
              }
1232
 
              if ($1 == DRIZZLE_TYPE_LONG)
1233
 
              {
1234
 
                Lex->field()->set_type(message::Table::Field::INTEGER);
1235
 
              }
1236
 
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
1237
 
              {
1238
 
                Lex->field()->set_type(message::Table::Field::BIGINT);
1239
 
              }
1240
 
            }
 
1176
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1241
1177
          }
1242
1178
        | real_type opt_precision
1243
1179
          {
1244
 
            $$=$1;
1245
 
 
1246
 
            if (Lex->field())
1247
 
            {
1248
 
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1249
 
              Lex->field()->set_type(message::Table::Field::DOUBLE);
1250
 
            }
 
1180
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1181
            $$= parser::buildDoubleColumn(Lex);
1251
1182
          }
1252
1183
        | char '(' NUM ')'
1253
1184
          {
1254
 
            Lex->length=$3.str;
1255
 
            $$=DRIZZLE_TYPE_VARCHAR;
1256
 
 
1257
 
            if (Lex->field())
1258
 
            {
1259
 
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1260
 
              message::Table::Field::StringFieldOptions *string_field_options;
1261
 
 
1262
 
              string_field_options= Lex->field()->mutable_string_options();
1263
 
 
1264
 
              string_field_options->set_length(atoi($3.str));
1265
 
            }
 
1185
            $$= parser::buildVarcharColumn(Lex, $3.str);
1266
1186
          }
1267
1187
        | char
1268
1188
          {
1269
 
            Lex->length=(char*) "1";
1270
 
            $$=DRIZZLE_TYPE_VARCHAR;
1271
 
 
1272
 
            if (Lex->field())
1273
 
              Lex->field()->set_type(message::Table::Field::VARCHAR);
 
1189
            $$= parser::buildVarcharColumn(Lex, "1");
1274
1190
          }
1275
1191
        | varchar '(' NUM ')'
1276
1192
          {
1277
 
            Lex->length=$3.str;
1278
 
            $$= DRIZZLE_TYPE_VARCHAR;
1279
 
 
1280
 
            if (Lex->field())
1281
 
            {
1282
 
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1283
 
 
1284
 
              message::Table::Field::StringFieldOptions *string_field_options;
1285
 
 
1286
 
              string_field_options= Lex->field()->mutable_string_options();
1287
 
 
1288
 
              string_field_options->set_length(atoi($3.str));
1289
 
            }
 
1193
            $$= parser::buildVarcharColumn(Lex, $3.str);
1290
1194
          }
1291
1195
        | VARBINARY '(' NUM ')'
1292
1196
          {
1293
 
            Lex->length=$3.str;
1294
 
            Lex->charset=&my_charset_bin;
1295
 
            $$= DRIZZLE_TYPE_VARCHAR;
1296
 
 
1297
 
            if (Lex->field())
1298
 
            {
1299
 
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1300
 
              message::Table::Field::StringFieldOptions *string_field_options;
1301
 
 
1302
 
              string_field_options= Lex->field()->mutable_string_options();
1303
 
 
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);
1307
 
            }
 
1197
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
1308
1198
          }
1309
1199
        | DATE_SYM
1310
1200
          {
1322
1212
          }
1323
1213
        | TIMESTAMP_SYM
1324
1214
          {
1325
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1326
 
            Lex->length= 0;
1327
 
 
1328
 
            if (Lex->field())
1329
 
              Lex->field()->set_type(message::Table::Field::EPOCH);
 
1215
            $$=parser::buildTimestampColumn(Lex, NULL);
1330
1216
          }
1331
1217
        | TIMESTAMP_SYM '(' NUM ')'
1332
1218
          {
1333
 
            $$=DRIZZLE_TYPE_MICROTIME;
1334
 
            Lex->length= $3.str;
1335
 
 
1336
 
            if (Lex->field())
1337
 
              Lex->field()->set_type(message::Table::Field::EPOCH);
 
1219
            $$=parser::buildTimestampColumn(Lex, $3.str);
1338
1220
          }
1339
1221
        | DATETIME_SYM
1340
1222
          {
1345
1227
          }
1346
1228
        | BLOB_SYM
1347
1229
          {
1348
 
            Lex->charset=&my_charset_bin;
1349
 
            $$=DRIZZLE_TYPE_BLOB;
1350
 
            Lex->length=(char*) 0; /* use default length */
1351
 
 
1352
 
            if (Lex->field())
1353
 
            {
1354
 
              Lex->field()->set_type(message::Table::Field::BLOB);
1355
 
              message::Table::Field::StringFieldOptions *string_field_options;
1356
 
 
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);
1360
 
            }
 
1230
            $$= parser::buildBlobColumn(Lex);
1361
1231
          }
1362
1232
        | TEXT_SYM
1363
1233
          {
1369
1239
          }
1370
1240
        | DECIMAL_SYM float_options
1371
1241
          {
1372
 
            $$=DRIZZLE_TYPE_DECIMAL;
1373
 
 
1374
 
            if (Lex->field())
1375
 
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1242
            $$= parser::buildDecimalColumn(Lex);
1376
1243
          }
1377
1244
        | NUMERIC_SYM float_options
1378
1245
          {
1379
 
            $$=DRIZZLE_TYPE_DECIMAL;
1380
 
 
1381
 
            if (Lex->field())
1382
 
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1246
            $$= parser::buildDecimalColumn(Lex);
1383
1247
          }
1384
1248
        | FIXED_SYM float_options
1385
1249
          {
1386
 
            $$=DRIZZLE_TYPE_DECIMAL;
1387
 
 
1388
 
            if (Lex->field())
1389
 
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1250
            $$= parser::buildDecimalColumn(Lex);
1390
1251
          }
1391
1252
        | ENUM_SYM
1392
1253
          {
1401
1262
          }
1402
1263
        | UUID_SYM
1403
1264
          {
1404
 
            $$=DRIZZLE_TYPE_UUID;
1405
 
 
1406
 
            if (Lex->field())
1407
 
              Lex->field()->set_type(message::Table::Field::UUID);
 
1265
            $$= parser::buildUuidColumn(Lex);
1408
1266
          }
1409
1267
        | BOOLEAN_SYM
1410
1268
          {
1411
 
            $$=DRIZZLE_TYPE_BOOLEAN;
1412
 
 
1413
 
            if (Lex->field())
1414
 
              Lex->field()->set_type(message::Table::Field::BOOLEAN);
 
1269
            $$= parser::buildBooleanColumn(Lex);
1415
1270
          }
1416
1271
        | SERIAL_SYM
1417
1272
          {
1418
 
            $$=DRIZZLE_TYPE_LONGLONG;
1419
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
1420
 
 
1421
 
            if (Lex->field())
1422
 
            {
1423
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1424
 
              Lex->field()->mutable_constraints()->set_is_unsigned(true);
1425
 
 
1426
 
              Lex->field()->set_type(message::Table::Field::BIGINT);
1427
 
            }
 
1273
            $$= parser::buildSerialColumn(Lex);
1428
1274
          }
1429
1275
        ;
1430
1276
 
1551
1397
          }
1552
1398
        | AUTO_INC
1553
1399
          {
1554
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1555
 
 
1556
 
            if (Lex->field())
1557
 
            {
1558
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1559
 
            }
 
1400
            parser::buildAutoOnColumn(Lex);
1560
1401
          }
1561
1402
        | SERIAL_SYM DEFAULT VALUE_SYM
1562
1403
          {
1563
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1564
 
 
1565
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG;
1566
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1567
 
 
1568
 
            if (Lex->field())
1569
 
            {
1570
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1571
 
              Lex->field()->mutable_constraints()->set_is_unsigned(true);
1572
 
            }
 
1404
            (void)parser::buildSerialColumn(Lex);
1573
1405
          }
1574
1406
        | opt_primary KEY_SYM
1575
1407
          {
1576
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1577
 
 
1578
 
            Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1579
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1580
 
 
1581
 
            if (Lex->field())
1582
 
            {
1583
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1584
 
            }
 
1408
            parser::buildPrimaryOnColumn(Lex);
1585
1409
          }
1586
1410
        | UNIQUE_SYM
1587
1411
          {
1588
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1589
 
 
1590
 
            Lex->type|= UNIQUE_FLAG;
1591
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1592
 
 
1593
 
            if (Lex->field())
1594
 
            {
1595
 
              Lex->field()->mutable_constraints()->set_is_unique(true);
1596
 
            }
 
1412
            parser::buildKeyOnColumn(Lex);
1597
1413
          }
1598
1414
        | UNIQUE_SYM KEY_SYM
1599
1415
          {
1600
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1601
 
 
1602
 
            Lex->type|= UNIQUE_KEY_FLAG;
1603
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1604
 
 
1605
 
            if (Lex->field())
1606
 
            {
1607
 
              Lex->field()->mutable_constraints()->set_is_unique(true);
1608
 
            }
 
1416
            parser::buildKeyOnColumn(Lex);
1609
1417
          }
1610
1418
        | COMMENT_SYM TEXT_STRING_sys
1611
1419
          {