~drizzle-developers/ubuntu/natty/drizzle/natty

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-07-29 18:35:48 UTC
  • mfrom: (1101.1.12 merge)
  • Revision ID: brian@gaz-20090729183548-yp36iwoaemfc76z0
Merging Monty (which includes new replication)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
*/
28
28
#define YYPARSE_PARAM yysession
29
29
#define YYLEX_PARAM yysession
30
 
#define YYSession ((Session *)yysession)
 
30
#define YYSession (static_cast<Session *>(yysession))
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
38
#define Lex (YYSession->lex)
39
 
#define Select Lex->current_select
40
39
#include <drizzled/server_includes.h>
41
40
#include <drizzled/lex_symbol.h>
42
41
#include <drizzled/function/locate.h>
88
87
#include <drizzled/function/get_system_var.h>
89
88
#include <mysys/thr_lock.h>
90
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/command.h>
 
91
#include <drizzled/command/show_status.h>
 
92
#include <drizzled/command/select.h>
 
93
 
 
94
using namespace drizzled;
91
95
 
92
96
class Table_ident;
93
97
class Item;
1214
1218
          field_list ')' opt_create_table_options
1215
1219
          create3 {}
1216
1220
        |  create_select ')'
1217
 
           { Select->set_braces(1);}
 
1221
           { Lex->current_select->set_braces(1);}
1218
1222
           union_opt {}
1219
1223
        ;
1220
1224
 
1221
1225
create3:
1222
1226
          /* empty */ {}
1223
1227
        | opt_duplicate opt_as create_select
1224
 
          { Select->set_braces(0);}
 
1228
          { Lex->current_select->set_braces(0);}
1225
1229
          union_clause {}
1226
1230
        | opt_duplicate opt_as '(' create_select ')'
1227
 
          { Select->set_braces(1);}
 
1231
          { Lex->current_select->set_braces(1);}
1228
1232
          union_opt {}
1229
1233
        ;
1230
1234
 
1247
1251
          }
1248
1252
          select_options select_item_list
1249
1253
          {
1250
 
            Select->parsing_place= NO_MATTER;
 
1254
            Lex->current_select->parsing_place= NO_MATTER;
1251
1255
          }
1252
1256
          opt_select_from
1253
1257
          {
2467
2471
assign_to_keycache:
2468
2472
          table_ident cache_keys_spec
2469
2473
          {
2470
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2471
 
                                           Select->pop_index_hints()))
 
2474
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
 
2475
                   0, TL_READ, Lex->current_select->pop_index_hints()))
2472
2476
              DRIZZLE_YYABORT;
2473
2477
          }
2474
2478
        ;
2481
2485
cache_keys_spec:
2482
2486
          {
2483
2487
            Lex->select_lex.alloc_index_hints(YYSession);
2484
 
            Select->set_index_hint_type(INDEX_HINT_USE, INDEX_HINT_MASK_ALL);
 
2488
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE,
 
2489
                                                     INDEX_HINT_MASK_ALL);
2485
2490
          }
2486
2491
          cache_key_list_or_empty
2487
2492
        ;
2501
2506
          {
2502
2507
            LEX *lex= Lex;
2503
2508
            lex->sql_command= SQLCOM_SELECT;
 
2509
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
2510
                                                            YYSession);
 
2511
            if (lex->command == NULL)
 
2512
              DRIZZLE_YYABORT;
2504
2513
          }
2505
2514
        ;
2506
2515
 
2559
2568
          }
2560
2569
          select_options select_item_list
2561
2570
          {
2562
 
            Select->parsing_place= NO_MATTER;
 
2571
            Lex->current_select->parsing_place= NO_MATTER;
2563
2572
          }
2564
2573
          select_into select_lock_type
2565
2574
        ;
2576
2585
          FROM join_table_list where_clause group_clause having_clause
2577
2586
          opt_order_clause opt_limit_clause
2578
2587
          {
2579
 
            Select->context.table_list=
2580
 
              Select->context.first_name_resolution_table= 
2581
 
                (TableList *) Select->table_list.first;
 
2588
            Lex->current_select->context.table_list=
 
2589
              Lex->current_select->context.first_name_resolution_table= 
 
2590
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2582
2591
          }
2583
2592
        ;
2584
2593
 
2586
2595
          /* empty*/
2587
2596
        | select_option_list
2588
2597
          {
2589
 
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
2598
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2599
                Lex->current_select->options & SELECT_ALL)
2590
2600
            {
2591
2601
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2592
2602
              DRIZZLE_YYABORT;
2600
2610
        ;
2601
2611
 
2602
2612
select_option:
2603
 
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2604
 
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
2605
 
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
2606
 
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
 
2613
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2614
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2615
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2616
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2607
2617
        | SQL_BUFFER_RESULT
2608
2618
          {
2609
2619
            if (check_simple_select())
2610
2620
              DRIZZLE_YYABORT;
2611
 
            Select->options|= OPTION_BUFFER_RESULT;
 
2621
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2612
2622
          }
2613
2623
        | SQL_CALC_FOUND_ROWS
2614
2624
          {
2615
2625
            if (check_simple_select())
2616
2626
              DRIZZLE_YYABORT;
2617
 
            Select->options|= OPTION_FOUND_ROWS;
 
2627
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2618
2628
          }
2619
 
        | ALL { Select->options|= SELECT_ALL; }
 
2629
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2620
2630
        ;
2621
2631
 
2622
2632
select_lock_type:
3301
3311
        | COUNT_SYM '(' in_sum_expr ')'
3302
3312
          { $$=new Item_sum_count($3); }
3303
3313
        | COUNT_SYM '(' DISTINCT
3304
 
          { Select->in_sum_expr++; }
 
3314
          { Lex->current_select->in_sum_expr++; }
3305
3315
          expr_list
3306
 
          { Select->in_sum_expr--; }
 
3316
          { Lex->current_select->in_sum_expr--; }
3307
3317
          ')'
3308
3318
          { $$=new Item_sum_count_distinct(* $5); }
3309
3319
        | MIN_SYM '(' in_sum_expr ')'
3332
3342
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3333
3343
          { $$=new Item_sum_sum_distinct($4); }
3334
3344
        | GROUP_CONCAT_SYM '(' opt_distinct
3335
 
          { Select->in_sum_expr++; }
 
3345
          { Lex->current_select->in_sum_expr++; }
3336
3346
          expr_list opt_gorder_clause
3337
3347
          opt_gconcat_separator
3338
3348
          ')'
3339
3349
          {
3340
 
            Select_Lex *sel= Select;
 
3350
            Select_Lex *sel= Lex->current_select;
3341
3351
            sel->in_sum_expr--;
3342
3352
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3343
3353
                                          sel->gorder_list, $7);
3392
3402
opt_gorder_clause:
3393
3403
          /* empty */
3394
3404
          {
3395
 
            Select->gorder_list = NULL;
 
3405
            Lex->current_select->gorder_list = NULL;
3396
3406
          }
3397
3407
        | order_clause
3398
3408
          {
3399
 
            Select_Lex *select= Select;
 
3409
            Select_Lex *select= Lex->current_select;
3400
3410
            select->gorder_list=
3401
3411
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3402
3412
                                     sizeof(st_sql_list));
3416
3426
          }
3417
3427
          expr
3418
3428
          {
3419
 
            Select->in_sum_expr--;
 
3429
            Lex->current_select->in_sum_expr--;
3420
3430
            $$= $3;
3421
3431
          }
3422
3432
        ;
3535
3545
            /* Change the current name resolution context to a local context. */
3536
3546
            if (push_new_name_resolution_context(YYSession, $1, $3))
3537
3547
              DRIZZLE_YYABORT;
3538
 
            Select->parsing_place= IN_ON;
 
3548
            Lex->current_select->parsing_place= IN_ON;
3539
3549
          }
3540
3550
          expr
3541
3551
          {
3542
3552
            add_join_on($3,$6);
3543
3553
            Lex->pop_context();
3544
 
            Select->parsing_place= NO_MATTER;
 
3554
            Lex->current_select->parsing_place= NO_MATTER;
3545
3555
          }
3546
3556
        | table_ref STRAIGHT_JOIN table_factor
3547
3557
          ON
3550
3560
            /* Change the current name resolution context to a local context. */
3551
3561
            if (push_new_name_resolution_context(YYSession, $1, $3))
3552
3562
              DRIZZLE_YYABORT;
3553
 
            Select->parsing_place= IN_ON;
 
3563
            Lex->current_select->parsing_place= IN_ON;
3554
3564
          }
3555
3565
          expr
3556
3566
          {
3557
3567
            $3->straight=1;
3558
3568
            add_join_on($3,$6);
3559
3569
            Lex->pop_context();
3560
 
            Select->parsing_place= NO_MATTER;
 
3570
            Lex->current_select->parsing_place= NO_MATTER;
3561
3571
          }
3562
3572
        | table_ref normal_join table_ref
3563
3573
          USING
3565
3575
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3566
3576
          }
3567
3577
          '(' using_list ')'
3568
 
          { add_join_natural($1,$3,$7,Select); $$=$3; }
 
3578
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
3569
3579
        | table_ref NATURAL JOIN_SYM table_factor
3570
3580
          {
3571
3581
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
3572
 
            add_join_natural($1,$4,NULL,Select);
 
3582
            add_join_natural($1,$4,NULL,Lex->current_select);
3573
3583
          }
3574
3584
 
3575
3585
          /* LEFT JOIN variants */
3580
3590
            /* Change the current name resolution context to a local context. */
3581
3591
            if (push_new_name_resolution_context(YYSession, $1, $5))
3582
3592
              DRIZZLE_YYABORT;
3583
 
            Select->parsing_place= IN_ON;
 
3593
            Lex->current_select->parsing_place= IN_ON;
3584
3594
          }
3585
3595
          expr
3586
3596
          {
3588
3598
            Lex->pop_context();
3589
3599
            $5->outer_join|=JOIN_TYPE_LEFT;
3590
3600
            $$=$5;
3591
 
            Select->parsing_place= NO_MATTER;
 
3601
            Lex->current_select->parsing_place= NO_MATTER;
3592
3602
          }
3593
3603
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3594
3604
          {
3596
3606
          }
3597
3607
          USING '(' using_list ')'
3598
3608
          { 
3599
 
            add_join_natural($1,$5,$9,Select); 
 
3609
            add_join_natural($1,$5,$9,Lex->current_select); 
3600
3610
            $5->outer_join|=JOIN_TYPE_LEFT; 
3601
3611
            $$=$5; 
3602
3612
          }
3603
3613
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3604
3614
          {
3605
3615
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3606
 
            add_join_natural($1,$6,NULL,Select);
 
3616
            add_join_natural($1,$6,NULL,Lex->current_select);
3607
3617
            $6->outer_join|=JOIN_TYPE_LEFT;
3608
3618
            $$=$6;
3609
3619
          }
3616
3626
            /* Change the current name resolution context to a local context. */
3617
3627
            if (push_new_name_resolution_context(YYSession, $1, $5))
3618
3628
              DRIZZLE_YYABORT;
3619
 
            Select->parsing_place= IN_ON;
 
3629
            Lex->current_select->parsing_place= IN_ON;
3620
3630
          }
3621
3631
          expr
3622
3632
          {
3625
3635
              DRIZZLE_YYABORT;
3626
3636
            add_join_on($$, $8);
3627
3637
            Lex->pop_context();
3628
 
            Select->parsing_place= NO_MATTER;
 
3638
            Lex->current_select->parsing_place= NO_MATTER;
3629
3639
          }
3630
3640
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3631
3641
          {
3636
3646
            LEX *lex= Lex;
3637
3647
            if (!($$= lex->current_select->convert_right_join()))
3638
3648
              DRIZZLE_YYABORT;
3639
 
            add_join_natural($$,$5,$9,Select);
 
3649
            add_join_natural($$,$5,$9,Lex->current_select);
3640
3650
          }
3641
3651
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3642
3652
          {
3643
3653
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3644
 
            add_join_natural($6,$1,NULL,Select);
 
3654
            add_join_natural($6,$1,NULL,Lex->current_select);
3645
3655
            LEX *lex= Lex;
3646
3656
            if (!($$= lex->current_select->convert_right_join()))
3647
3657
              DRIZZLE_YYABORT;
3664
3674
/* Warning - may return NULL in case of incomplete SELECT */
3665
3675
table_factor:
3666
3676
          {
3667
 
            Select_Lex *sel= Select;
 
3677
            Select_Lex *sel= Lex->current_select;
3668
3678
            sel->table_join_options= 0;
3669
3679
          }
3670
3680
          table_ident opt_table_alias opt_key_definition
3671
3681
          {
3672
 
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
3673
 
                                                Select->get_table_join_options(),
3674
 
                                                Lex->lock_option,
3675
 
                                                Select->pop_index_hints())))
 
3682
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
 
3683
                             Lex->current_select->get_table_join_options(),
 
3684
                             Lex->lock_option,
 
3685
                             Lex->current_select->pop_index_hints())))
3676
3686
              DRIZZLE_YYABORT;
3677
 
            Select->add_joined_table($$);
 
3687
            Lex->current_select->add_joined_table($$);
3678
3688
          }
3679
3689
        | select_derived_init get_select_lex select_derived2
3680
3690
          {
3808
3818
          }
3809
3819
          select_options select_item_list
3810
3820
          {
3811
 
            Select->parsing_place= NO_MATTER;
 
3821
            Lex->current_select->parsing_place= NO_MATTER;
3812
3822
          }
3813
3823
          opt_select_from select_lock_type
3814
3824
        ;
3855
3865
          }
3856
3866
          select_options select_item_list
3857
3867
          {
3858
 
            Select->parsing_place= NO_MATTER;
 
3868
            Lex->current_select->parsing_place= NO_MATTER;
3859
3869
          }
3860
3870
          opt_select_from
3861
3871
        ;
3862
3872
 
3863
3873
get_select_lex:
3864
 
          /* Empty */ { $$= Select; }
 
3874
          /* Empty */ { $$= Lex->current_select; }
3865
3875
        ;
3866
3876
 
3867
3877
select_derived_init:
3877
3887
              my_parse_error(ER(ER_SYNTAX_ERROR));
3878
3888
              DRIZZLE_YYABORT;
3879
3889
            }
3880
 
            embedding= Select->embedding;
 
3890
            embedding= Lex->current_select->embedding;
3881
3891
            $$= embedding &&
3882
3892
                !embedding->nested_join->join_list.elements;
3883
3893
            /* return true if we are deeply nested */
3907
3917
index_hint_definition:
3908
3918
          index_hint_type key_or_index index_hint_clause
3909
3919
          {
3910
 
            Select->set_index_hint_type($1, $3);
 
3920
            Lex->current_select->set_index_hint_type($1, $3);
3911
3921
          }
3912
3922
          '(' key_usage_list ')'
3913
3923
        | USE_SYM key_or_index index_hint_clause
3914
3924
          {
3915
 
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
 
3925
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
3916
3926
          }
3917
3927
          '(' opt_key_usage_list ')'
3918
3928
       ;
3924
3934
 
3925
3935
opt_index_hints_list:
3926
3936
          /* empty */
3927
 
        | { Select->alloc_index_hints(YYSession); } index_hints_list
 
3937
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
3928
3938
        ;
3929
3939
 
3930
3940
opt_key_definition:
3931
 
          {  Select->clear_index_hints(); }
 
3941
          {  Lex->current_select->clear_index_hints(); }
3932
3942
          opt_index_hints_list
3933
3943
        ;
3934
3944
 
3935
3945
opt_key_usage_list:
3936
 
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
 
3946
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
3937
3947
        | key_usage_list {}
3938
3948
        ;
3939
3949
 
3940
3950
key_usage_element:
3941
3951
          ident
3942
 
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
 
3952
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
3943
3953
        | PRIMARY_SYM
3944
 
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
3954
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
3945
3955
        ;
3946
3956
 
3947
3957
key_usage_list:
4031
4041
        ;
4032
4042
 
4033
4043
where_clause:
4034
 
          /* empty */  { Select->where= 0; }
 
4044
          /* empty */  { Lex->current_select->where= 0; }
4035
4045
        | WHERE
4036
4046
          {
4037
 
            Select->parsing_place= IN_WHERE;
 
4047
            Lex->current_select->parsing_place= IN_WHERE;
4038
4048
          }
4039
4049
          expr
4040
4050
          {
4041
 
            Select_Lex *select= Select;
 
4051
            Select_Lex *select= Lex->current_select;
4042
4052
            select->where= $3;
4043
4053
            select->parsing_place= NO_MATTER;
4044
4054
            if ($3)
4050
4060
          /* empty */
4051
4061
        | HAVING
4052
4062
          {
4053
 
            Select->parsing_place= IN_HAVING;
 
4063
            Lex->current_select->parsing_place= IN_HAVING;
4054
4064
          }
4055
4065
          expr
4056
4066
          {
4057
 
            Select_Lex *sel= Select;
 
4067
            Select_Lex *sel= Lex->current_select;
4058
4068
            sel->having= $3;
4059
4069
            sel->parsing_place= NO_MATTER;
4060
4070
            if ($3)
4216
4226
limit_options:
4217
4227
          limit_option
4218
4228
          {
4219
 
            Select_Lex *sel= Select;
 
4229
            Select_Lex *sel= Lex->current_select;
4220
4230
            sel->select_limit= $1;
4221
4231
            sel->offset_limit= 0;
4222
4232
            sel->explicit_limit= 1;
4223
4233
          }
4224
4234
        | limit_option ',' limit_option
4225
4235
          {
4226
 
            Select_Lex *sel= Select;
 
4236
            Select_Lex *sel= Lex->current_select;
4227
4237
            sel->select_limit= $3;
4228
4238
            sel->offset_limit= $1;
4229
4239
            sel->explicit_limit= 1;
4230
4240
          }
4231
4241
        | limit_option OFFSET_SYM limit_option
4232
4242
          {
4233
 
            Select_Lex *sel= Select;
 
4243
            Select_Lex *sel= Lex->current_select;
4234
4244
            sel->select_limit= $1;
4235
4245
            sel->offset_limit= $3;
4236
4246
            sel->explicit_limit= 1;
4251
4261
          }
4252
4262
        | LIMIT limit_option
4253
4263
          {
4254
 
            Select_Lex *sel= Select;
 
4264
            Select_Lex *sel= Lex->current_select;
4255
4265
            sel->select_limit= $2;
4256
4266
            sel->explicit_limit= 1;
4257
4267
          }
4397
4407
table_name:
4398
4408
          table_ident
4399
4409
          {
4400
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4410
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4401
4411
              DRIZZLE_YYABORT;
4402
4412
          }
4403
4413
        ;
4410
4420
table_alias_ref:
4411
4421
          table_ident
4412
4422
          {
4413
 
            if (!Select->add_table_to_list(YYSession, $1, NULL,
 
4423
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
4414
4424
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4415
4425
                                           Lex->lock_option ))
4416
4426
              DRIZZLE_YYABORT;
4442
4452
          }
4443
4453
          opt_ignore insert2
4444
4454
          {
4445
 
            Select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
 
4455
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4446
4456
            Lex->current_select= &Lex->select_lex;
4447
4457
          }
4448
4458
          insert_field_spec opt_insert_update
4459
4469
          }
4460
4470
          insert2
4461
4471
          {
4462
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4472
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4463
4473
            Lex->current_select= &Lex->select_lex;
4464
4474
          }
4465
4475
          insert_field_spec
4503
4513
          VALUES values_list {}
4504
4514
        | VALUE_SYM values_list {}
4505
4515
        | create_select
4506
 
          { Select->set_braces(0);}
 
4516
          { Lex->current_select->set_braces(0);}
4507
4517
          union_clause {}
4508
4518
        | '(' create_select ')'
4509
 
          { Select->set_braces(1);}
 
4519
          { Lex->current_select->set_braces(1);}
4510
4520
          union_opt {}
4511
4521
        ;
4512
4522
 
4612
4622
              be too pessimistic. We will decrease lock level if possible in
4613
4623
              mysql_multi_update().
4614
4624
            */
4615
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4625
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4616
4626
          }
4617
4627
          where_clause opt_order_clause delete_limit_clause {}
4618
4628
        ;
4663
4673
single_multi:
4664
4674
          FROM table_ident
4665
4675
          {
4666
 
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
 
4676
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4667
4677
                                           Lex->lock_option))
4668
4678
              DRIZZLE_YYABORT;
4669
4679
          }
4693
4703
table_wild_one:
4694
4704
          ident opt_wild
4695
4705
          {
4696
 
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
4697
 
                                           NULL,
4698
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4699
 
                                           Lex->lock_option))
 
4706
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4707
                    new Table_ident($1), NULL,
 
4708
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4709
                    Lex->lock_option))
4700
4710
              DRIZZLE_YYABORT;
4701
4711
          }
4702
4712
        | ident '.' ident opt_wild
4703
4713
          {
4704
 
            if (!Select->add_table_to_list(YYSession,
4705
 
                                           new Table_ident(YYSession, $1, $3, 0),
4706
 
                                           NULL,
4707
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4708
 
                                           Lex->lock_option))
 
4714
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4715
                    new Table_ident(YYSession, $1, $3, 0), NULL,
 
4716
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4717
                    Lex->lock_option))
4709
4718
              DRIZZLE_YYABORT;
4710
4719
          }
4711
4720
        ;
4721
4730
        ;
4722
4731
 
4723
4732
opt_delete_option:
4724
 
          QUICK        { Select->options|= OPTION_QUICK; }
 
4733
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
4725
4734
        | IGNORE_SYM   { Lex->ignore= 1; }
4726
4735
        ;
4727
4736
 
4761
4770
           {
4762
4771
             LEX *lex= Lex;
4763
4772
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
4773
             lex->command=
 
4774
               new(std::nothrow) command::Select(SQLCOM_SHOW_DATABASES, 
 
4775
                                                 YYSession);
 
4776
             if (lex->command == NULL)
 
4777
               DRIZZLE_YYABORT;
4764
4778
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
4765
4779
               DRIZZLE_YYABORT;
4766
4780
           }
4768
4782
           {
4769
4783
             LEX *lex= Lex;
4770
4784
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4785
             lex->command=
 
4786
               new(std::nothrow) command::Select(SQLCOM_SHOW_TABLES,
 
4787
                                                 YYSession);
 
4788
             if (lex->command == NULL)
 
4789
               DRIZZLE_YYABORT;
4771
4790
             lex->select_lex.db= $3;
4772
4791
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
4773
4792
               DRIZZLE_YYABORT;
4776
4795
           {
4777
4796
             LEX *lex= Lex;
4778
4797
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4798
             lex->command=
 
4799
               new(std::nothrow) command::Select(SQLCOM_SHOW_TABLE_STATUS,
 
4800
                                                 YYSession);
 
4801
             if (lex->command == NULL)
 
4802
               DRIZZLE_YYABORT;
4779
4803
             lex->select_lex.db= $3;
4780
4804
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
4781
4805
               DRIZZLE_YYABORT;
4784
4808
          {
4785
4809
            LEX *lex= Lex;
4786
4810
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4811
            lex->command=
 
4812
              new(std::nothrow) command::Select(SQLCOM_SHOW_OPEN_TABLES,
 
4813
                                                YYSession);
 
4814
            if (lex->command == NULL)
 
4815
              DRIZZLE_YYABORT;
4787
4816
            lex->select_lex.db= $3;
4788
4817
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
4789
4818
              DRIZZLE_YYABORT;
4797
4826
          {
4798
4827
            LEX *lex= Lex;
4799
4828
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4829
            lex->command=
 
4830
              new(std::nothrow) command::Select(SQLCOM_SHOW_FIELDS, YYSession);
 
4831
            if (lex->command == NULL)
 
4832
              DRIZZLE_YYABORT;
4800
4833
            if ($5)
4801
4834
              $4->change_db($5);
4802
4835
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
4806
4839
          {
4807
4840
            LEX *lex= Lex;
4808
4841
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4842
            lex->command= new(std::nothrow) command::Select(SQLCOM_SHOW_KEYS,
 
4843
                                                            YYSession);
 
4844
            if (lex->command == NULL)
 
4845
              DRIZZLE_YYABORT;
4809
4846
            if ($4)
4810
4847
              $3->change_db($4);
4811
4848
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
4812
4849
              DRIZZLE_YYABORT;
4813
4850
          }
4814
4851
        | COUNT_SYM '(' '*' ')' WARNINGS
4815
 
          { (void) create_select_for_variable("warning_count"); }
 
4852
          { 
 
4853
            (void) create_select_for_variable("warning_count"); 
 
4854
            LEX *lex= Lex;
 
4855
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
4856
                                                            YYSession);
 
4857
            if (lex->command == NULL)
 
4858
              DRIZZLE_YYABORT;
 
4859
          }
4816
4860
        | COUNT_SYM '(' '*' ')' ERRORS
4817
 
          { (void) create_select_for_variable("error_count"); }
 
4861
          { 
 
4862
            (void) create_select_for_variable("error_count"); 
 
4863
            LEX *lex= Lex;
 
4864
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
4865
                                                            YYSession);
 
4866
            if (lex->command == NULL)
 
4867
              DRIZZLE_YYABORT;
 
4868
          }
4818
4869
        | WARNINGS opt_limit_clause_init
4819
4870
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4820
4871
        | ERRORS opt_limit_clause_init
4823
4874
          {
4824
4875
            LEX *lex= Lex;
4825
4876
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4877
            lex->command=
 
4878
              new(std::nothrow) command::ShowStatus(SQLCOM_SHOW_STATUS,
 
4879
                                                    YYSession,
 
4880
                                                    &LOCK_status);
 
4881
            if (lex->command == NULL)
 
4882
              DRIZZLE_YYABORT;
4826
4883
            lex->option_type= $1;
4827
4884
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
4828
4885
              DRIZZLE_YYABORT;
4833
4890
          {
4834
4891
            LEX *lex= Lex;
4835
4892
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4893
            lex->command=
 
4894
              new(std::nothrow) command::Select(SQLCOM_SHOW_VARIABLES, 
 
4895
                                                YYSession);
 
4896
            if (lex->command == NULL)
 
4897
              DRIZZLE_YYABORT;
4836
4898
            lex->option_type= $1;
4837
4899
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
4838
4900
              DRIZZLE_YYABORT;
4877
4939
          }
4878
4940
        | WHERE expr
4879
4941
          {
4880
 
            Select->where= $2;
 
4942
            Lex->current_select->where= $2;
4881
4943
            if ($2)
4882
4944
              $2->top_level_item();
4883
4945
          }
5024
5086
          TABLE_SYM table_ident
5025
5087
          {
5026
5088
            LEX *lex=Lex;
5027
 
            if (!Select->add_table_to_list(YYSession, $12, NULL, TL_OPTION_UPDATING,
5028
 
                                           lex->lock_option))
 
5089
            if (!Lex->current_select->add_table_to_list(YYSession,
 
5090
                    $12, NULL, TL_OPTION_UPDATING,
 
5091
                    lex->lock_option))
5029
5092
              DRIZZLE_YYABORT;
5030
5093
            lex->field_list.empty();
5031
5094
            lex->update_list.empty();
5262
5325
table_wild:
5263
5326
          ident '.' '*'
5264
5327
          {
5265
 
            Select_Lex *sel= Select;
 
5328
            Select_Lex *sel= Lex->current_select;
5266
5329
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5267
5330
            sel->with_wild++;
5268
5331
          }
5269
5332
        | ident '.' ident '.' '*'
5270
5333
          {
5271
 
            Select_Lex *sel= Select;
 
5334
            Select_Lex *sel= Lex->current_select;
5272
5335
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
5273
5336
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
5274
5337
                                $3.str,"*");
5284
5347
          ident
5285
5348
          {
5286
5349
            {
5287
 
              Select_Lex *sel=Select;
 
5350
              Select_Lex *sel=Lex->current_select;
5288
5351
              $$= (sel->parsing_place != IN_HAVING ||
5289
5352
                  sel->get_in_sum_expr() > 0) ?
5290
5353
                  (Item*) new Item_field(Lex->current_context(),
5299
5362
simple_ident_nospvar:
5300
5363
          ident
5301
5364
          {
5302
 
            Select_Lex *sel=Select;
 
5365
            Select_Lex *sel=Lex->current_select;
5303
5366
            $$= (sel->parsing_place != IN_HAVING ||
5304
5367
                sel->get_in_sum_expr() > 0) ?
5305
5368
                (Item*) new Item_field(Lex->current_context(),
5374
5437
          ident { $$=$1;}
5375
5438
        | ident '.' ident '.' ident
5376
5439
          {
5377
 
            TableList *table= (TableList*) Select->table_list.first;
 
5440
            TableList *table=
 
5441
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5378
5442
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5379
5443
            {
5380
5444
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5390
5454
          }
5391
5455
        | ident '.' ident
5392
5456
          {
5393
 
            TableList *table= (TableList*) Select->table_list.first;
 
5457
            TableList *table=
 
5458
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5394
5459
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5395
5460
            {
5396
5461
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);