~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-09-22 16:51:28 UTC
  • mto: This revision was merged to the branch mainline in revision 1135.
  • Revision ID: brian@gaz-20090922165128-ojtj01my5m4wkqic
AlterInfo refactor back to class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1144
1144
                                                   TL_OPTION_UPDATING,
1145
1145
                                                   TL_WRITE))
1146
1146
              DRIZZLE_YYABORT;
1147
 
            lex->alter_info.reset();
1148
1147
            lex->col_list.empty();
1149
1148
            lex->change=NULL;
1150
1149
            statement->create_info.options=$2 | $4;
1180
1179
          {
1181
1180
            LEX *lex=Lex;
1182
1181
            lex->sql_command= SQLCOM_CREATE_INDEX;
1183
 
            lex->statement= new(std::nothrow) 
1184
 
              statement::CreateIndex(YYSession);
 
1182
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1183
            lex->statement= statement;
1185
1184
            if (lex->statement == NULL)
1186
1185
              DRIZZLE_YYABORT;
1187
1186
            if (!lex->current_select->add_table_to_list(lex->session, $8,
1188
1187
                                                        NULL,
1189
1188
                                                        TL_OPTION_UPDATING))
1190
1189
              DRIZZLE_YYABORT;
1191
 
            lex->alter_info.reset();
1192
 
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1193
 
            lex->alter_info.build_method= $2;
 
1190
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1191
            statement->alter_info.build_method= $2;
1194
1192
            lex->col_list.empty();
1195
1193
            lex->change=NULL;
1196
1194
          }
1197
1195
          '(' key_list ')' key_options
1198
1196
          {
1199
1197
            LEX *lex=Lex;
 
1198
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1200
1199
            Key *key;
1201
1200
            key= new Key($3, $5, &lex->key_create_info, 0,
1202
1201
                         lex->col_list);
1203
 
            lex->alter_info.key_list.push_back(key);
 
1202
            statement->alter_info.key_list.push_back(key);
1204
1203
            lex->col_list.empty();
1205
1204
          }
1206
1205
        | CREATE DATABASE opt_if_not_exists ident
1405
1404
 
1406
1405
            statement->create_info.row_type= $3;
1407
1406
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1408
 
            Lex->alter_info.flags.set(ALTER_ROW_FORMAT);
 
1407
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1409
1408
          }
1410
1409
        | default_collation
1411
1410
        | KEY_BLOCK_SIZE opt_equal ulong_num
1529
1528
          key_type opt_ident key_alg '(' key_list ')' key_options
1530
1529
          {
1531
1530
            LEX *lex=Lex;
 
1531
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1532
1532
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
1533
1533
                              lex->col_list);
1534
 
            lex->alter_info.key_list.push_back(key);
 
1534
            statement->alter_info.key_list.push_back(key);
1535
1535
            lex->col_list.empty(); /* Alloced by sql_alloc */
1536
1536
          }
1537
1537
        | opt_constraint constraint_key_type opt_ident key_alg
1538
1538
          '(' key_list ')' key_options
1539
1539
          {
1540
1540
            LEX *lex=Lex;
 
1541
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1541
1542
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
1542
1543
                              lex->col_list);
1543
 
            lex->alter_info.key_list.push_back(key);
 
1544
            statement->alter_info.key_list.push_back(key);
1544
1545
            lex->col_list.empty(); /* Alloced by sql_alloc */
1545
1546
          }
1546
1547
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1547
1548
          {
1548
1549
            LEX *lex=Lex;
 
1550
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1549
1551
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1550
1552
                                      $8,
1551
1553
                                      lex->ref_list,
1552
1554
                                      lex->fk_delete_opt,
1553
1555
                                      lex->fk_update_opt,
1554
1556
                                      lex->fk_match_option);
1555
 
            lex->alter_info.key_list.push_back(key);
 
1557
            statement->alter_info.key_list.push_back(key);
1556
1558
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1557
1559
                         &default_key_create_info, 1,
1558
1560
                         lex->col_list);
1559
 
            lex->alter_info.key_list.push_back(key);
 
1561
            statement->alter_info.key_list.push_back(key);
1560
1562
            lex->col_list.empty(); /* Alloced by sql_alloc */
1561
1563
            /* Only used for ALTER TABLE. Ignored otherwise. */
1562
 
            lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
1564
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1563
1565
          }
1564
1566
        | constraint opt_check_constraint
1565
1567
          {
1745
1747
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
1746
1748
        | COLUMN_FORMAT_SYM column_format_types
1747
1749
          {
 
1750
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1751
 
1748
1752
            Lex->column_format= $2;
1749
 
            Lex->alter_info.flags.set(ALTER_COLUMN_FORMAT);
 
1753
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1750
1754
          }
1751
1755
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
1752
1756
        | DEFAULT now_or_signed_literal 
1753
1757
          { 
 
1758
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1759
 
1754
1760
            Lex->default_value=$2; 
1755
 
            Lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
1761
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1756
1762
          }
1757
1763
        | ON UPDATE_SYM NOW_SYM optional_braces 
1758
1764
          { Lex->on_update_value= new Item_func_now_local(); }
1760
1766
        | SERIAL_SYM DEFAULT VALUE_SYM
1761
1767
          { 
1762
1768
            LEX *lex=Lex;
 
1769
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1770
 
1763
1771
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1764
 
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1772
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1765
1773
          }
1766
1774
        | opt_primary KEY_SYM
1767
1775
          {
1768
1776
            LEX *lex=Lex;
 
1777
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1778
 
1769
1779
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1770
 
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1780
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1771
1781
          }
1772
1782
        | UNIQUE_SYM
1773
1783
          {
1774
1784
            LEX *lex=Lex;
 
1785
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1786
 
1775
1787
            lex->type|= UNIQUE_FLAG; 
1776
 
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1788
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1777
1789
          }
1778
1790
        | UNIQUE_SYM KEY_SYM
1779
1791
          {
1780
1792
            LEX *lex=Lex;
 
1793
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1794
 
1781
1795
            lex->type|= UNIQUE_KEY_FLAG; 
1782
 
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1796
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1783
1797
          }
1784
1798
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
1785
1799
        | COLLATE_SYM collation_name
2113
2127
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2114
2128
                                                   TL_OPTION_UPDATING))
2115
2129
              DRIZZLE_YYABORT;
2116
 
            lex->alter_info.reset();
2117
2130
            lex->col_list.empty();
2118
2131
            lex->select_lex.init_order();
2119
2132
            lex->select_lex.db=
2121
2134
            statement->create_info.db_type= 0;
2122
2135
            statement->create_info.default_table_charset= NULL;
2123
2136
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
2124
 
            lex->alter_info.reset();
2125
 
            lex->alter_info.build_method= $2;
 
2137
            statement->alter_info.build_method= $2;
2126
2138
          }
2127
2139
          alter_commands
2128
2140
          {}
2151
2163
 
2152
2164
alter_commands:
2153
2165
          /* empty */
2154
 
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
2155
 
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
 
2166
        | DISCARD TABLESPACE 
 
2167
          { 
 
2168
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2169
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE; 
 
2170
          }
 
2171
        | IMPORT TABLESPACE 
 
2172
          { 
 
2173
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2174
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE; 
 
2175
          }
2156
2176
        | alter_list
2157
2177
        ;
2158
2178
 
2180
2200
          ADD opt_column
2181
2201
          {
2182
2202
            LEX *lex=Lex;
 
2203
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2183
2204
            lex->change=0;
2184
 
            lex->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2205
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2185
2206
          }
2186
2207
        ;
2187
2208
 
2189
2210
          add_column column_def opt_place { }
2190
2211
        | ADD key_def
2191
2212
          {
2192
 
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
2213
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2214
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2193
2215
          }
2194
2216
        | add_column '(' field_list ')'
2195
2217
          {
2196
 
            Lex->alter_info.flags.set(ALTER_ADD_COLUMN);
2197
 
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
2218
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2219
 
 
2220
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2221
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2198
2222
          }
2199
2223
        | CHANGE opt_column field_ident
2200
2224
          {
2201
2225
            LEX *lex=Lex;
 
2226
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2202
2227
            lex->change= $3.str;
2203
 
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2228
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2204
2229
          }
2205
2230
          field_spec opt_place
2206
2231
        | MODIFY_SYM opt_column field_ident
2207
2232
          {
2208
2233
            LEX *lex=Lex;
 
2234
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2209
2235
            lex->length=lex->dec=0; lex->type=0;
2210
2236
            lex->default_value= lex->on_update_value= 0;
2211
2237
            lex->comment=null_lex_str;
2212
2238
            lex->charset= NULL;
2213
 
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2239
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2214
2240
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2215
2241
          }
2216
2242
          field_def
2228
2254
          opt_place
2229
2255
        | DROP opt_column field_ident
2230
2256
          {
2231
 
            LEX *lex=Lex;
2232
 
            lex->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN,
2233
 
                                                               $3.str));
2234
 
            lex->alter_info.flags.set(ALTER_DROP_COLUMN);
 
2257
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2258
 
 
2259
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN,
 
2260
                                                                    $3.str));
 
2261
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
2235
2262
          }
2236
2263
        | DROP FOREIGN KEY_SYM opt_ident
2237
2264
          {
2238
 
            Lex->alter_info.flags.set(ALTER_DROP_INDEX);
2239
 
            Lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
2265
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2266
 
 
2267
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2268
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
2240
2269
          }
2241
2270
        | DROP PRIMARY_SYM KEY_SYM
2242
2271
          {
2243
 
            LEX *lex=Lex;
2244
 
            lex->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2272
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2273
 
 
2274
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
2245
2275
                                                               "PRIMARY"));
2246
 
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
2276
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2247
2277
          }
2248
2278
        | DROP key_or_index field_ident
2249
2279
          {
2250
 
            LEX *lex=Lex;
2251
 
            lex->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
2252
 
                                                               $3.str));
2253
 
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
2280
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2281
 
 
2282
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2283
                                                                    $3.str));
 
2284
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2254
2285
          }
2255
2286
        | DISABLE_SYM KEYS
2256
2287
          {
2257
 
            LEX *lex=Lex;
2258
 
            lex->alter_info.keys_onoff= DISABLE;
2259
 
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2288
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2289
 
 
2290
            statement->alter_info.keys_onoff= DISABLE;
 
2291
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2260
2292
          }
2261
2293
        | ENABLE_SYM KEYS
2262
2294
          {
2263
 
            LEX *lex=Lex;
2264
 
            lex->alter_info.keys_onoff= ENABLE;
2265
 
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2295
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2296
 
 
2297
            statement->alter_info.keys_onoff= ENABLE;
 
2298
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2266
2299
          }
2267
2300
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2268
2301
          {
2269
 
            LEX *lex=Lex;
2270
 
            lex->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
2271
 
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2302
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2303
 
 
2304
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
 
2305
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2272
2306
          }
2273
2307
        | ALTER opt_column field_ident DROP DEFAULT
2274
2308
          {
2275
 
            LEX *lex=Lex;
2276
 
            lex->alter_info.alter_list.push_back(new AlterColumn($3.str,
2277
 
                                                                  (Item*) 0));
2278
 
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2309
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2310
 
 
2311
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
 
2312
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2279
2313
          }
2280
2314
        | RENAME opt_to table_ident
2281
2315
          {
2282
2316
            LEX *lex=Lex;
 
2317
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2283
2318
            size_t dummy;
 
2319
 
2284
2320
            lex->select_lex.db=$3->db.str;
2285
2321
            if (lex->select_lex.db == NULL &&
2286
2322
                lex->copy_db_to(&lex->select_lex.db, &dummy))
2293
2329
              DRIZZLE_YYABORT;
2294
2330
            }
2295
2331
            lex->name= $3->table;
2296
 
            lex->alter_info.flags.set(ALTER_RENAME);
 
2332
            statement->alter_info.flags.set(ALTER_RENAME);
2297
2333
          }
2298
2334
        | CONVERT_SYM TO_SYM collation_name_or_default
2299
2335
          {
2300
 
            LEX *lex= Lex;
2301
2336
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2302
2337
 
2303
2338
            statement->create_info.table_charset=
2304
2339
            statement->create_info.default_table_charset= $3;
2305
2340
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2306
2341
              HA_CREATE_USED_DEFAULT_CHARSET);
2307
 
            lex->alter_info.flags.set(ALTER_CONVERT);
 
2342
            statement->alter_info.flags.set(ALTER_CONVERT);
2308
2343
          }
2309
2344
        | create_table_options_space_separated
2310
2345
          {
2311
 
            LEX *lex=Lex;
2312
 
            lex->alter_info.flags.set(ALTER_OPTIONS);
 
2346
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2347
 
 
2348
            statement->alter_info.flags.set(ALTER_OPTIONS);
2313
2349
          }
2314
2350
        | FORCE_SYM
2315
2351
          {
2316
 
            Lex->alter_info.flags.set(ALTER_FORCE);
 
2352
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2353
 
 
2354
            statement->alter_info.flags.set(ALTER_FORCE);
2317
2355
          }
2318
2356
        | alter_order_clause
2319
2357
          {
2320
 
            LEX *lex=Lex;
2321
 
            lex->alter_info.flags.set(ALTER_ORDER);
 
2358
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2359
 
 
2360
            statement->alter_info.flags.set(ALTER_ORDER);
2322
2361
          }
2323
2362
        ;
2324
2363
 
2336
2375
          /* empty */ {}
2337
2376
        | AFTER_SYM ident
2338
2377
          {
 
2378
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2379
 
2339
2380
            store_position_for_column($2.str);
2340
 
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
2381
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2341
2382
          }
2342
2383
        | FIRST_SYM
2343
2384
          {
 
2385
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2386
 
2344
2387
            store_position_for_column(first_keyword);
2345
 
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
2388
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2346
2389
          }
2347
2390
        ;
2348
2391
 
4368
4411
          {
4369
4412
            LEX *lex=Lex;
4370
4413
            lex->sql_command= SQLCOM_DROP_INDEX;
4371
 
            lex->statement= new(std::nothrow) 
4372
 
              statement::DropIndex(YYSession);
 
4414
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4415
            lex->statement= statement;
4373
4416
            if (lex->statement == NULL)
4374
4417
              DRIZZLE_YYABORT;
4375
 
            lex->alter_info.reset();
4376
 
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
4377
 
            lex->alter_info.build_method= $2;
4378
 
            lex->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
4379
 
                                                               $4.str));
 
4418
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
4419
            statement->alter_info.build_method= $2;
 
4420
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4380
4421
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4381
4422
                                                        TL_OPTION_UPDATING))
4382
4423
              DRIZZLE_YYABORT;