~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

update to latest from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
%{
24
 
/* thd is passed as an argument to yyparse(), and subsequently to yylex().
25
 
** The type will be void*, so it must be  cast to (THD*) when used.
26
 
** Use the YYTHD macro for this.
 
24
/* session is passed as an argument to yyparse(), and subsequently to yylex().
 
25
** The type will be void*, so it must be  cast to (Session*) when used.
 
26
** Use the YYSession macro for this.
27
27
*/
28
 
#define YYPARSE_PARAM yythd
29
 
#define YYLEX_PARAM yythd
30
 
#define YYTHD ((THD *)yythd)
 
28
#define YYPARSE_PARAM yysession
 
29
#define YYLEX_PARAM yysession
 
30
#define YYSession ((Session *)yysession)
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
35
35
#define DRIZZLE_YACC
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
 
#define Lex (YYTHD->lex)
 
38
#define Lex (YYSession->lex)
39
39
#define Select Lex->current_select
40
40
#include <drizzled/server_includes.h>
41
41
#include "lex_symbol.h"
43
43
#include <drizzled/drizzled_error_messages.h>
44
44
#include <drizzled/functions/locate.h>
45
45
 
46
 
int yylex(void *yylval, void *yythd);
 
46
int yylex(void *yylval, void *yysession);
47
47
 
48
48
#define yyoverflow(A,B,C,D,E,F)               \
49
49
  {                                           \
62
62
#define DRIZZLE_YYABORT                         \
63
63
  do                                          \
64
64
  {                                           \
65
 
    LEX::cleanup_lex_after_parse_error(YYTHD);\
 
65
    LEX::cleanup_lex_after_parse_error(YYSession);\
66
66
    YYABORT;                                  \
67
67
  } while (0)
68
68
 
110
110
 
111
111
void my_parse_error(const char *s)
112
112
{
113
 
  THD *thd= current_thd;
114
 
  Lex_input_stream *lip= thd->m_lip;
 
113
  Session *session= current_session;
 
114
  Lex_input_stream *lip= session->m_lip;
115
115
 
116
116
  const char *yytext= lip->get_tok_start();
117
117
  /* Push an error into the error stack */
142
142
 
143
143
void MYSQLerror(const char *s)
144
144
{
145
 
  THD *thd= current_thd;
 
145
  Session *session= current_session;
146
146
 
147
147
  /*
148
148
    Restore the original LEX if it was replaced when parsing
149
149
    a stored procedure. We must ensure that a parsing error
150
 
    does not leave any side effects in the THD.
 
150
    does not leave any side effects in the Session.
151
151
  */
152
 
  LEX::cleanup_lex_after_parse_error(thd);
 
152
  LEX::cleanup_lex_after_parse_error(session);
153
153
 
154
154
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
155
155
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
162
162
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
163
163
  This function returns the proper item for the SQL expression
164
164
  <code>left [NOT] IN ( expr )</code>
165
 
  @param thd the current thread
 
165
  @param session the current thread
166
166
  @param left the in predicand
167
167
  @param equal true for IN predicates, false for NOT IN predicates
168
168
  @param expr first and only expression of the in value list
169
169
  @return an expression representing the IN predicate.
170
170
*/
171
 
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
 
171
Item* handle_sql2003_note184_exception(Session *session, Item* left, bool equal,
172
172
                                       Item *expr)
173
173
{
174
174
  /*
213
213
          Item_in_subselect(left, subselect)
214
214
      */
215
215
      subselect= expr3->invalidate_and_restore_select_lex();
216
 
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
 
216
      result= new (session->mem_root) Item_in_subselect(left, subselect);
217
217
 
218
218
      if (! equal)
219
 
        result = negate_expression(thd, result);
 
219
        result = negate_expression(session, result);
220
220
 
221
221
      return(result);
222
222
    }
223
223
  }
224
224
 
225
225
  if (equal)
226
 
    result= new (thd->mem_root) Item_func_eq(left, expr);
 
226
    result= new (session->mem_root) Item_func_eq(left, expr);
227
227
  else
228
 
    result= new (thd->mem_root) Item_func_ne(left, expr);
 
228
    result= new (session->mem_root) Item_func_ne(left, expr);
229
229
 
230
230
  return(result);
231
231
}
1074
1074
query:
1075
1075
          END_OF_INPUT
1076
1076
          {
1077
 
            THD *thd= YYTHD;
1078
 
            if (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT))
 
1077
            Session *session= YYSession;
 
1078
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
1079
1079
            {
1080
1080
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1081
1081
              DRIZZLE_YYABORT;
1082
1082
            }
1083
1083
            else
1084
1084
            {
1085
 
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1085
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
1086
1086
            }
1087
1087
          }
1088
1088
        | verb_clause END_OF_INPUT {}
1189
1189
            }
1190
1190
            if (Lex->mi.heartbeat_period > slave_net_timeout)
1191
1191
            {
1192
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1192
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1193
1193
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1194
1194
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1195
1195
                                  " exceeds the value of `slave_net_timeout' sec.",
1200
1200
            {
1201
1201
              if (Lex->mi.heartbeat_period != 0.0)
1202
1202
              {
1203
 
                push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1203
                push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1204
1204
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1205
1205
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1206
1206
                                    " is less than 1 msec.",
1254
1254
create:
1255
1255
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1256
1256
          {
1257
 
            THD *thd= YYTHD;
1258
 
            LEX *lex= thd->lex;
 
1257
            Session *session= YYSession;
 
1258
            LEX *lex= session->lex;
1259
1259
            lex->sql_command= SQLCOM_CREATE_TABLE;
1260
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
1260
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1261
1261
                                                   TL_OPTION_UPDATING,
1262
1262
                                                   TL_WRITE))
1263
1263
              DRIZZLE_YYABORT;
1266
1266
            lex->change=NULL;
1267
1267
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1268
1268
            lex->create_info.options=$2 | $4;
1269
 
            lex->create_info.db_type= ha_default_handlerton(thd);
 
1269
            lex->create_info.db_type= ha_default_handlerton(session);
1270
1270
            lex->create_info.default_table_charset= NULL;
1271
1271
            lex->name.str= 0;
1272
1272
            lex->name.length= 0;
1273
1273
          }
1274
1274
          create2
1275
1275
          {
1276
 
            LEX *lex= YYTHD->lex;
 
1276
            LEX *lex= YYSession->lex;
1277
1277
            lex->current_select= &lex->select_lex; 
1278
1278
            if (!lex->create_info.db_type)
1279
1279
            {
1280
 
              lex->create_info.db_type= ha_default_handlerton(YYTHD);
1281
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1280
              lex->create_info.db_type= ha_default_handlerton(YYSession);
 
1281
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1282
1282
                                  ER_WARN_USING_OTHER_HANDLER,
1283
1283
                                  ER(ER_WARN_USING_OTHER_HANDLER),
1284
1284
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
1290
1290
          {
1291
1291
            LEX *lex=Lex;
1292
1292
            lex->sql_command= SQLCOM_CREATE_INDEX;
1293
 
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
 
1293
            if (!lex->current_select->add_table_to_list(lex->session, $8,
1294
1294
                                                        NULL,
1295
1295
                                                        TL_OPTION_UPDATING))
1296
1296
              DRIZZLE_YYABORT;
1329
1329
          create3 {}
1330
1330
        | LIKE table_ident
1331
1331
          {
1332
 
            THD *thd= YYTHD;
1333
 
            LEX *lex= thd->lex;
 
1332
            Session *session= YYSession;
 
1333
            LEX *lex= session->lex;
1334
1334
 
1335
1335
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1336
 
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
 
1336
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1337
1337
              DRIZZLE_YYABORT;
1338
1338
          }
1339
1339
        | '(' LIKE table_ident ')'
1340
1340
          {
1341
 
            THD *thd= YYTHD;
1342
 
            LEX *lex= thd->lex;
 
1341
            Session *session= YYSession;
 
1342
            LEX *lex= session->lex;
1343
1343
 
1344
1344
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1345
 
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
 
1345
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1346
1346
              DRIZZLE_YYABORT;
1347
1347
          }
1348
1348
        ;
1577
1577
storage_engines:
1578
1578
          ident_or_text
1579
1579
          {
1580
 
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
 
1580
            plugin_ref plugin= ha_resolve_by_name(YYSession, &$1);
1581
1581
 
1582
1582
            if (plugin)
1583
1583
              $$= plugin_data(plugin, handlerton*);
1593
1593
          ident_or_text
1594
1594
          {
1595
1595
            plugin_ref plugin;
1596
 
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
 
1596
            if ((plugin= ha_resolve_by_name(YYSession, &$1)))
1597
1597
              $$= plugin_data(plugin, handlerton*);
1598
1598
            else
1599
1599
            {
1720
1720
          field_def
1721
1721
          {
1722
1722
            LEX *lex=Lex;
1723
 
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
 
1723
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1724
1724
                                  lex->length,lex->dec,lex->type,
1725
1725
                                  lex->column_format,
1726
1726
                                  lex->default_value, lex->on_update_value, 
2291
2291
alter:
2292
2292
          ALTER build_method opt_ignore TABLE_SYM table_ident
2293
2293
          {
2294
 
            THD *thd= YYTHD;
2295
 
            LEX *lex= thd->lex;
 
2294
            Session *session= YYSession;
 
2295
            LEX *lex= session->lex;
2296
2296
            lex->name.str= 0;
2297
2297
            lex->name.length= 0;
2298
2298
            lex->sql_command= SQLCOM_ALTER_TABLE;
2299
2299
            lex->duplicates= DUP_ERROR; 
2300
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
2300
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2301
2301
                                                   TL_OPTION_UPDATING))
2302
2302
              DRIZZLE_YYABORT;
2303
2303
            lex->alter_info.reset();
2402
2402
          field_def
2403
2403
          {
2404
2404
            LEX *lex=Lex;
2405
 
            if (add_field_to_list(lex->thd,&$3,
 
2405
            if (add_field_to_list(lex->session,&$3,
2406
2406
                                  (enum enum_field_types) $5,
2407
2407
                                  lex->length,lex->dec,lex->type,
2408
2408
                                  lex->column_format,
2485
2485
          {
2486
2486
            if (!$3)
2487
2487
            {
2488
 
              THD *thd= YYTHD;
2489
 
              $3= thd->variables.collation_database;
 
2488
              Session *session= YYSession;
 
2489
              $3= session->variables.collation_database;
2490
2490
            }
2491
2491
            LEX *lex= Lex;
2492
2492
            lex->create_info.table_charset=
2601
2601
        ;
2602
2602
 
2603
2603
slave_thread_opts:
2604
 
          { Lex->slave_thd_opt= 0; }
 
2604
          { Lex->slave_session_opt= 0; }
2605
2605
          slave_thread_opt_list
2606
2606
          {}
2607
2607
        ;
2613
2613
 
2614
2614
slave_thread_opt:
2615
2615
          /*empty*/ {}
2616
 
        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
2617
 
        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
 
2616
        | SQL_THREAD   { Lex->slave_session_opt|=SLAVE_SQL; }
 
2617
        | RELAY_THREAD { Lex->slave_session_opt|=SLAVE_IO; }
2618
2618
        ;
2619
2619
 
2620
2620
slave_until:
2761
2761
          {
2762
2762
            LEX *lex=Lex;
2763
2763
            SELECT_LEX *sl= lex->current_select;
2764
 
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
 
2764
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
2765
2765
                                       TL_IGNORE) ||
2766
 
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 
2766
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
2767
2767
                                       TL_IGNORE))
2768
2768
              DRIZZLE_YYABORT;
2769
2769
          }
2786
2786
assign_to_keycache:
2787
2787
          table_ident cache_keys_spec
2788
2788
          {
2789
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
 
2789
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2790
2790
                                           Select->pop_index_hints()))
2791
2791
              DRIZZLE_YYABORT;
2792
2792
          }
2799
2799
 
2800
2800
cache_keys_spec:
2801
2801
          {
2802
 
            Lex->select_lex.alloc_index_hints(YYTHD);
 
2802
            Lex->select_lex.alloc_index_hints(YYSession);
2803
2803
            Select->set_index_hint_type(INDEX_HINT_USE, 
2804
2804
                                        global_system_variables.old_mode ? 
2805
2805
                                        INDEX_HINT_MASK_JOIN : 
2967
2967
        | select_item
2968
2968
        | '*'
2969
2969
          {
2970
 
            THD *thd= YYTHD;
2971
 
            if (add_item_to_list(thd,
2972
 
                                 new Item_field(&thd->lex->current_select->
 
2970
            Session *session= YYSession;
 
2971
            if (add_item_to_list(session,
 
2972
                                 new Item_field(&session->lex->current_select->
2973
2973
                                                context,
2974
2974
                                                NULL, NULL, "*")))
2975
2975
              DRIZZLE_YYABORT;
2976
 
            (thd->lex->current_select->with_wild)++;
 
2976
            (session->lex->current_select->with_wild)++;
2977
2977
          }
2978
2978
        ;
2979
2979
 
2980
2980
select_item:
2981
2981
          remember_name table_wild remember_end
2982
2982
          {
2983
 
            THD *thd= YYTHD;
 
2983
            Session *session= YYSession;
2984
2984
 
2985
 
            if (add_item_to_list(thd, $2))
 
2985
            if (add_item_to_list(session, $2))
2986
2986
              DRIZZLE_YYABORT;
2987
2987
          }
2988
2988
        | remember_name expr remember_end select_alias
2989
2989
          {
2990
 
            THD *thd= YYTHD;
 
2990
            Session *session= YYSession;
2991
2991
            assert($1 < $3);
2992
2992
 
2993
 
            if (add_item_to_list(thd, $2))
 
2993
            if (add_item_to_list(session, $2))
2994
2994
              DRIZZLE_YYABORT;
2995
2995
            if ($4.str)
2996
2996
            {
2999
2999
            }
3000
3000
            else if (!$2->name)
3001
3001
            {
3002
 
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
 
3002
              $2->set_name($1, (uint) ($3 - $1), session->charset());
3003
3003
            }
3004
3004
          }
3005
3005
        ;
3006
3006
 
3007
3007
remember_name:
3008
3008
          {
3009
 
            THD *thd= YYTHD;
3010
 
            Lex_input_stream *lip= thd->m_lip;
 
3009
            Session *session= YYSession;
 
3010
            Lex_input_stream *lip= session->m_lip;
3011
3011
            $$= (char*) lip->get_cpp_tok_start();
3012
3012
          }
3013
3013
        ;
3014
3014
 
3015
3015
remember_end:
3016
3016
          {
3017
 
            THD *thd= YYTHD;
3018
 
            Lex_input_stream *lip= thd->m_lip;
 
3017
            Session *session= YYSession;
 
3018
            Lex_input_stream *lip= session->m_lip;
3019
3019
            $$= (char*) lip->get_cpp_tok_end();
3020
3020
          }
3021
3021
        ;
3039
3039
          {
3040
3040
            /*
3041
3041
              Design notes:
3042
 
              Do not use a manually maintained stack like thd->lex->xxx_list,
 
3042
              Do not use a manually maintained stack like session->lex->xxx_list,
3043
3043
              but use the internal bison stack ($$, $1 and $3) instead.
3044
3044
              Using the bison stack is:
3045
3045
              - more robust to changes in the grammar,
3081
3081
            else
3082
3082
            {
3083
3083
              /* X OR Y */
3084
 
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
 
3084
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
3085
3085
            }
3086
3086
          }
3087
3087
        | expr XOR expr %prec XOR
3088
3088
          {
3089
3089
            /* XOR is a proprietary extension */
3090
 
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
 
3090
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
3091
3091
          }
3092
3092
        | expr and expr %prec AND_SYM
3093
3093
          {
3127
3127
            else
3128
3128
            {
3129
3129
              /* X AND Y */
3130
 
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
 
3130
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
3131
3131
            }
3132
3132
          }
3133
3133
        | NOT_SYM expr %prec NOT_SYM
3134
 
          { $$= negate_expression(YYTHD, $2); }
 
3134
          { $$= negate_expression(YYSession, $2); }
3135
3135
        | bool_pri IS TRUE_SYM %prec IS
3136
 
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
 
3136
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
3137
3137
        | bool_pri IS not TRUE_SYM %prec IS
3138
 
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
 
3138
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
3139
3139
        | bool_pri IS FALSE_SYM %prec IS
3140
 
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
 
3140
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
3141
3141
        | bool_pri IS not FALSE_SYM %prec IS
3142
 
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
 
3142
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
3143
3143
        | bool_pri IS UNKNOWN_SYM %prec IS
3144
3144
          { $$= new Item_func_isnull($1); }
3145
3145
        | bool_pri IS not UNKNOWN_SYM %prec IS
3164
3164
predicate:
3165
3165
          bit_expr IN_SYM '(' subselect ')'
3166
3166
          {
3167
 
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
 
3167
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
3168
3168
          }
3169
3169
        | bit_expr not IN_SYM '(' subselect ')'
3170
3170
          {
3171
 
            THD *thd= YYTHD;
3172
 
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
3173
 
            $$= negate_expression(thd, item);
 
3171
            Session *session= YYSession;
 
3172
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
3173
            $$= negate_expression(session, item);
3174
3174
          }
3175
3175
        | bit_expr IN_SYM '(' expr ')'
3176
3176
          {
3177
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
 
3177
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
3178
3178
          }
3179
3179
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
3180
3180
          { 
3181
3181
            $6->push_front($4);
3182
3182
            $6->push_front($1);
3183
 
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
 
3183
            $$= new (YYSession->mem_root) Item_func_in(*$6);
3184
3184
          }
3185
3185
        | bit_expr not IN_SYM '(' expr ')'
3186
3186
          {
3187
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
 
3187
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
3188
3188
          }
3189
3189
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
3190
3190
          {
3191
3191
            $7->push_front($5);
3192
3192
            $7->push_front($1);
3193
 
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
 
3193
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
3194
3194
            item->negate();
3195
3195
            $$= item;
3196
3196
          }
3265
3265
        | function_call_conflict
3266
3266
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3267
3267
          {
3268
 
            THD *thd= YYTHD;
3269
 
            Item *i1= new (thd->mem_root) Item_string($3.str,
 
3268
            Session *session= YYSession;
 
3269
            Item *i1= new (session->mem_root) Item_string($3.str,
3270
3270
                                                      $3.length,
3271
 
                                                      thd->charset());
3272
 
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
 
3271
                                                      session->charset());
 
3272
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
3273
3273
          }
3274
3274
        | literal
3275
3275
        | variable
3276
3276
        | sum_expr
3277
3277
        | '+' simple_expr %prec NEG { $$= $2; }
3278
3278
        | '-' simple_expr %prec NEG
3279
 
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
 
3279
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
3280
3280
        | '(' subselect ')'
3281
3281
          { 
3282
 
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
 
3282
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
3283
3283
          }
3284
3284
        | '(' expr ')' { $$= $2; }
3285
3285
        | '(' expr ',' expr_list ')'
3286
3286
          {
3287
3287
            $4->push_front($2);
3288
 
            $$= new (YYTHD->mem_root) Item_row(*$4);
 
3288
            $$= new (YYSession->mem_root) Item_row(*$4);
3289
3289
          }
3290
3290
        | ROW_SYM '(' expr ',' expr_list ')'
3291
3291
          {
3292
3292
            $5->push_front($3);
3293
 
            $$= new (YYTHD->mem_root) Item_row(*$5);
 
3293
            $$= new (YYSession->mem_root) Item_row(*$5);
3294
3294
          }
3295
3295
        | EXISTS '(' subselect ')'
3296
3296
          {
3297
 
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
 
3297
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
3298
3298
          }
3299
3299
        | '{' ident expr '}' { $$= $3; }
3300
3300
        | BINARY simple_expr %prec NEG
3301
3301
          {
3302
 
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
 
3302
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
3303
3303
                                 &my_charset_bin);
3304
3304
          }
3305
3305
        | CAST_SYM '(' expr AS cast_type ')'
3306
3306
          {
3307
3307
            LEX *lex= Lex;
3308
 
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
 
3308
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
3309
3309
                                 lex->charset);
3310
3310
            if (!$$)
3311
3311
              DRIZZLE_YYABORT;
3312
3312
          }
3313
3313
        | CASE_SYM opt_expr when_list opt_else END
3314
 
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
 
3314
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
3315
3315
        | CONVERT_SYM '(' expr ',' cast_type ')'
3316
3316
          {
3317
 
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
 
3317
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
3318
3318
                                 Lex->charset);
3319
3319
            if (!$$)
3320
3320
              DRIZZLE_YYABORT;
3321
3321
          }
3322
3322
        | DEFAULT '(' simple_ident ')'
3323
3323
          {
3324
 
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
 
3324
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
3325
3325
                                                         $3);
3326
3326
          }
3327
3327
        | VALUES '(' simple_ident_nospvar ')'
3328
3328
          {
3329
 
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
 
3329
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
3330
3330
                                                        $3);
3331
3331
          }
3332
3332
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3333
3333
          /* we cannot put interval before - */
3334
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3334
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
3335
3335
        ;
3336
3336
 
3337
3337
/*
3342
3342
*/
3343
3343
function_call_keyword:
3344
3344
          CHAR_SYM '(' expr_list ')'
3345
 
          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
 
3345
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
3346
3346
        | CURRENT_USER optional_braces
3347
3347
          {
3348
 
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
 
3348
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
3349
3349
            Lex->set_stmt_unsafe();
3350
3350
          }
3351
3351
        | DATE_SYM '(' expr ')'
3352
 
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
 
3352
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3353
3353
        | DAY_SYM '(' expr ')'
3354
 
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
 
3354
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
3355
3355
        | HOUR_SYM '(' expr ')'
3356
 
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
 
3356
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3357
3357
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3358
 
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3358
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
3359
3359
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3360
3360
          {
3361
 
            THD *thd= YYTHD;
3362
 
            List<Item> *list= new (thd->mem_root) List<Item>;
 
3361
            Session *session= YYSession;
 
3362
            List<Item> *list= new (session->mem_root) List<Item>;
3363
3363
            list->push_front($5);
3364
3364
            list->push_front($3);
3365
 
            Item_row *item= new (thd->mem_root) Item_row(*list);
3366
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3365
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3366
            $$= new (session->mem_root) Item_func_interval(item);
3367
3367
          }
3368
3368
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3369
3369
          {
3370
 
            THD *thd= YYTHD;
 
3370
            Session *session= YYSession;
3371
3371
            $7->push_front($5);
3372
3372
            $7->push_front($3);
3373
 
            Item_row *item= new (thd->mem_root) Item_row(*$7);
3374
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3373
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3374
            $$= new (session->mem_root) Item_func_interval(item);
3375
3375
          }
3376
3376
        | LEFT '(' expr ',' expr ')'
3377
 
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
 
3377
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3378
3378
        | MINUTE_SYM '(' expr ')'
3379
 
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
 
3379
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
3380
3380
        | MONTH_SYM '(' expr ')'
3381
 
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
 
3381
          { $$= new (YYSession->mem_root) Item_func_month($3); }
3382
3382
        | RIGHT '(' expr ',' expr ')'
3383
 
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
 
3383
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
3384
3384
        | SECOND_SYM '(' expr ')'
3385
 
          { $$= new (YYTHD->mem_root) Item_func_second($3); }
 
3385
          { $$= new (YYSession->mem_root) Item_func_second($3); }
3386
3386
        | TIME_SYM '(' expr ')'
3387
 
          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
 
3387
          { $$= new (YYSession->mem_root) Item_time_typecast($3); }
3388
3388
        | TIMESTAMP '(' expr ')'
3389
 
          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
 
3389
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
3390
3390
        | TIMESTAMP '(' expr ',' expr ')'
3391
 
          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
 
3391
          { $$= new (YYSession->mem_root) Item_func_add_time($3, $5, 1, 0); }
3392
3392
        | TRIM '(' expr ')'
3393
 
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
 
3393
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
3394
3394
        | TRIM '(' LEADING expr FROM expr ')'
3395
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
 
3395
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
3396
3396
        | TRIM '(' TRAILING expr FROM expr ')'
3397
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
 
3397
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
3398
3398
        | TRIM '(' BOTH expr FROM expr ')'
3399
 
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
 
3399
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
3400
3400
        | TRIM '(' LEADING FROM expr ')'
3401
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
 
3401
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
3402
3402
        | TRIM '(' TRAILING FROM expr ')'
3403
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
 
3403
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
3404
3404
        | TRIM '(' BOTH FROM expr ')'
3405
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
 
3405
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
3406
3406
        | TRIM '(' expr FROM expr ')'
3407
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
 
3407
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3408
3408
        | USER '(' ')'
3409
3409
          {
3410
 
            $$= new (YYTHD->mem_root) Item_func_user();
 
3410
            $$= new (YYSession->mem_root) Item_func_user();
3411
3411
            Lex->set_stmt_unsafe();
3412
3412
          }
3413
3413
        | YEAR_SYM '(' expr ')'
3414
 
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
 
3414
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3415
3415
        ;
3416
3416
 
3417
3417
/*
3429
3429
function_call_nonkeyword:
3430
3430
          ADDDATE_SYM '(' expr ',' expr ')'
3431
3431
          {
3432
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3432
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3433
3433
                                                             INTERVAL_DAY, 0);
3434
3434
          }
3435
3435
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3436
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3436
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3437
3437
        | CURDATE optional_braces
3438
3438
          {
3439
 
            $$= new (YYTHD->mem_root) Item_func_curdate_local();
 
3439
            $$= new (YYSession->mem_root) Item_func_curdate_local();
3440
3440
          }
3441
3441
        | CURTIME optional_braces
3442
3442
          {
3443
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local();
 
3443
            $$= new (YYSession->mem_root) Item_func_curtime_local();
3444
3444
          }
3445
3445
        | CURTIME '(' expr ')'
3446
3446
          {
3447
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
 
3447
            $$= new (YYSession->mem_root) Item_func_curtime_local($3);
3448
3448
          }
3449
3449
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3450
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3450
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3451
3451
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3452
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3452
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
3453
3453
        | EXTRACT_SYM '(' interval FROM expr ')'
3454
 
          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
 
3454
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
3455
3455
        | GET_FORMAT '(' date_time_type  ',' expr ')'
3456
 
          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
 
3456
          { $$= new (YYSession->mem_root) Item_func_get_format($3, $5); }
3457
3457
        | NOW_SYM optional_braces
3458
3458
          {
3459
 
            $$= new (YYTHD->mem_root) Item_func_now_local();
 
3459
            $$= new (YYSession->mem_root) Item_func_now_local();
3460
3460
          }
3461
3461
        | NOW_SYM '(' expr ')'
3462
3462
          {
3463
 
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3463
            $$= new (YYSession->mem_root) Item_func_now_local($3);
3464
3464
          }
3465
3465
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3466
 
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
 
3466
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3467
3467
        | SUBDATE_SYM '(' expr ',' expr ')'
3468
3468
          {
3469
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3469
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3470
3470
                                                             INTERVAL_DAY, 1);
3471
3471
          }
3472
3472
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3473
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
 
3473
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3474
3474
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3475
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3475
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3476
3476
        | SUBSTRING '(' expr ',' expr ')'
3477
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3477
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3478
3478
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3479
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3479
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3480
3480
        | SUBSTRING '(' expr FROM expr ')'
3481
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3481
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3482
3482
        | SYSDATE optional_braces
3483
3483
          {
3484
3484
            if (global_system_variables.sysdate_is_now == 0)
3485
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local();
 
3485
              $$= new (YYSession->mem_root) Item_func_sysdate_local();
3486
3486
            else
3487
 
              $$= new (YYTHD->mem_root) Item_func_now_local();
 
3487
              $$= new (YYSession->mem_root) Item_func_now_local();
3488
3488
          }
3489
3489
        | SYSDATE '(' expr ')'
3490
3490
          {
3491
3491
            if (global_system_variables.sysdate_is_now == 0)
3492
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
 
3492
              $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
3493
3493
            else
3494
 
              $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3494
              $$= new (YYSession->mem_root) Item_func_now_local($3);
3495
3495
          }
3496
3496
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3497
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3497
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3498
3498
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3499
 
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3499
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3500
3500
        | UTC_DATE_SYM optional_braces
3501
3501
          {
3502
 
            $$= new (YYTHD->mem_root) Item_func_curdate_utc();
 
3502
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
3503
3503
          }
3504
3504
        | UTC_TIME_SYM optional_braces
3505
3505
          {
3506
 
            $$= new (YYTHD->mem_root) Item_func_curtime_utc();
 
3506
            $$= new (YYSession->mem_root) Item_func_curtime_utc();
3507
3507
          }
3508
3508
        | UTC_TIMESTAMP_SYM optional_braces
3509
3509
          {
3510
 
            $$= new (YYTHD->mem_root) Item_func_now_utc();
 
3510
            $$= new (YYSession->mem_root) Item_func_now_utc();
3511
3511
          }
3512
3512
        ;
3513
3513
 
3518
3518
*/
3519
3519
function_call_conflict:
3520
3520
          ASCII_SYM '(' expr ')'
3521
 
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
 
3521
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
3522
3522
        | COALESCE '(' expr_list ')'
3523
 
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
 
3523
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
3524
3524
        | COLLATION_SYM '(' expr ')'
3525
 
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
 
3525
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3526
3526
        | DATABASE '(' ')'
3527
3527
          {
3528
 
            $$= new (YYTHD->mem_root) Item_func_database();
 
3528
            $$= new (YYSession->mem_root) Item_func_database();
3529
3529
          }
3530
3530
        | IF '(' expr ',' expr ',' expr ')'
3531
 
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
 
3531
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3532
3532
        | MICROSECOND_SYM '(' expr ')'
3533
 
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
 
3533
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3534
3534
        | MOD_SYM '(' expr ',' expr ')'
3535
 
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
 
3535
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
3536
3536
        | QUARTER_SYM '(' expr ')'
3537
 
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
 
3537
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3538
3538
        | REPEAT_SYM '(' expr ',' expr ')'
3539
 
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 
3539
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
3540
3540
        | REPLACE '(' expr ',' expr ',' expr ')'
3541
 
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
 
3541
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3542
3542
        | REVERSE_SYM '(' expr ')'
3543
 
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 
3543
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
3544
3544
        | TRUNCATE_SYM '(' expr ',' expr ')'
3545
 
          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
 
3545
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3546
3546
        | WEEK_SYM '(' expr ')'
3547
3547
          {
3548
 
            THD *thd= YYTHD;
3549
 
            Item *i1= new (thd->mem_root) Item_int((char*) "0",
3550
 
                                           thd->variables.default_week_format,
 
3548
            Session *session= YYSession;
 
3549
            Item *i1= new (session->mem_root) Item_int((char*) "0",
 
3550
                                           session->variables.default_week_format,
3551
3551
                                                   1);
3552
3552
 
3553
 
            $$= new (thd->mem_root) Item_func_week($3, i1);
 
3553
            $$= new (session->mem_root) Item_func_week($3, i1);
3554
3554
          }
3555
3555
        | WEEK_SYM '(' expr ',' expr ')'
3556
 
          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
 
3556
          { $$= new (YYSession->mem_root) Item_func_week($3,$5); }
3557
3557
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3558
 
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
 
3558
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
3559
3559
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3560
3560
          {
3561
 
            $$= new (YYTHD->mem_root)
 
3561
            $$= new (YYSession->mem_root)
3562
3562
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3563
3563
          }
3564
3564
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3565
3565
          {
3566
 
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
3567
 
            $$= new (YYTHD->mem_root)
 
3566
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3567
            $$= new (YYSession->mem_root)
3568
3568
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3569
3569
          }
3570
3570
        ;
3589
3589
          }
3590
3590
          opt_udf_expr_list ')'
3591
3591
          {
3592
 
            THD *thd= YYTHD;
 
3592
            Session *session= YYSession;
3593
3593
            Create_func *builder;
3594
3594
            Item *item= NULL;
3595
3595
 
3602
3602
 
3603
3603
              This will be revised with WL#2128 (SQL PATH)
3604
3604
            */
3605
 
            builder= find_native_function_builder(thd, $1);
 
3605
            builder= find_native_function_builder(session, $1);
3606
3606
            if (builder)
3607
3607
            {
3608
 
              item= builder->create(thd, $1, $4);
 
3608
              item= builder->create(session, $1, $4);
3609
3609
            }
3610
3610
            else
3611
3611
            {
3613
3613
              udf_func *udf= $<udf>3;
3614
3614
              if (udf)
3615
3615
              {
3616
 
                item= Create_udf_func::s_singleton.create(thd, udf, $4);
 
3616
                item= Create_udf_func::s_singleton.create(session, udf, $4);
3617
3617
              } else {
3618
3618
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3619
3619
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3635
3635
udf_expr_list:
3636
3636
          udf_expr
3637
3637
          {
3638
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3638
            $$= new (YYSession->mem_root) List<Item>;
3639
3639
            $$->push_back($1);
3640
3640
          }
3641
3641
        | udf_expr_list ',' udf_expr
3660
3660
              $2->set_name($4.str, $4.length, system_charset_info);
3661
3661
            }
3662
3662
            else
3663
 
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
 
3663
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
3664
3664
            $$= $2;
3665
3665
          }
3666
3666
        ;
3751
3751
              my_parse_error(ER(ER_SYNTAX_ERROR));
3752
3752
              DRIZZLE_YYABORT;
3753
3753
            }
3754
 
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
 
3754
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3755
3755
              DRIZZLE_YYABORT;
3756
3756
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
3757
3757
              Lex->set_stmt_unsafe();
3766
3766
opt_gconcat_separator:
3767
3767
          /* empty */
3768
3768
            {
3769
 
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_utf8_general_ci);
 
3769
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
3770
3770
            }
3771
3771
        | SEPARATOR_SYM text_string { $$ = $2; }
3772
3772
        ;
3821
3821
expr_list:
3822
3822
          expr
3823
3823
          {
3824
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3824
            $$= new (YYSession->mem_root) List<Item>;
3825
3825
            $$->push_back($1);
3826
3826
          }
3827
3827
        | expr_list ',' expr
3863
3863
        | join_table
3864
3864
          {
3865
3865
            LEX *lex= Lex;
3866
 
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
 
3866
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3867
3867
              DRIZZLE_YYABORT;
3868
3868
          }
3869
3869
        ;
3917
3917
          {
3918
3918
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3919
3919
            /* Change the current name resolution context to a local context. */
3920
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3920
            if (push_new_name_resolution_context(YYSession, $1, $3))
3921
3921
              DRIZZLE_YYABORT;
3922
3922
            Select->parsing_place= IN_ON;
3923
3923
          }
3932
3932
          {
3933
3933
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3934
3934
            /* Change the current name resolution context to a local context. */
3935
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3935
            if (push_new_name_resolution_context(YYSession, $1, $3))
3936
3936
              DRIZZLE_YYABORT;
3937
3937
            Select->parsing_place= IN_ON;
3938
3938
          }
3962
3962
          {
3963
3963
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3964
3964
            /* Change the current name resolution context to a local context. */
3965
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3965
            if (push_new_name_resolution_context(YYSession, $1, $5))
3966
3966
              DRIZZLE_YYABORT;
3967
3967
            Select->parsing_place= IN_ON;
3968
3968
          }
3998
3998
          {
3999
3999
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4000
4000
            /* Change the current name resolution context to a local context. */
4001
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
4001
            if (push_new_name_resolution_context(YYSession, $1, $5))
4002
4002
              DRIZZLE_YYABORT;
4003
4003
            Select->parsing_place= IN_ON;
4004
4004
          }
4053
4053
          }
4054
4054
          table_ident opt_table_alias opt_key_definition
4055
4055
          {
4056
 
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
 
4056
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
4057
4057
                                                Select->get_table_join_options(),
4058
4058
                                                Lex->lock_option,
4059
4059
                                                Select->pop_index_hints())))
4076
4076
                sel->master_unit()->global_parameters=
4077
4077
                   sel->master_unit()->fake_select_lex;
4078
4078
            }
4079
 
            if ($2->init_nested_join(lex->thd))
 
4079
            if ($2->init_nested_join(lex->session))
4080
4080
              DRIZZLE_YYABORT;
4081
4081
            $$= 0;
4082
4082
            /* incomplete derived tables return NULL, we must be
4122
4122
              SELECT_LEX *sel= lex->current_select;
4123
4123
              SELECT_LEX_UNIT *unit= sel->master_unit();
4124
4124
              lex->current_select= sel= unit->outer_select();
4125
 
              if (!($$= sel->add_table_to_list(lex->thd,
 
4125
              if (!($$= sel->add_table_to_list(lex->session,
4126
4126
                                               new Table_ident(unit), $5, 0,
4127
4127
                                               TL_READ)))
4128
4128
 
4202
4202
          get_select_lex
4203
4203
          {
4204
4204
            LEX *lex= Lex;
4205
 
            if ($1->init_nested_join(lex->thd))
 
4205
            if ($1->init_nested_join(lex->session))
4206
4206
              DRIZZLE_YYABORT;
4207
4207
          }
4208
4208
          derived_table_list
4211
4211
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4212
4212
               for derived tables, both must equal NULL */
4213
4213
 
4214
 
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
 
4214
            if (!($$= $1->end_nested_join(lex->session)) && $3)
4215
4215
              DRIZZLE_YYABORT;
4216
4216
            if (!$3 && $$)
4217
4217
            {
4262
4262
 
4263
4263
            SELECT_LEX *sel= lex->current_select;
4264
4264
            TableList *embedding;
4265
 
            if (!sel->embedding || sel->end_nested_join(lex->thd))
 
4265
            if (!sel->embedding || sel->end_nested_join(lex->session))
4266
4266
            {
4267
4267
              /* we are not in parentheses */
4268
4268
              my_parse_error(ER(ER_SYNTAX_ERROR));
4316
4316
 
4317
4317
opt_index_hints_list:
4318
4318
          /* empty */
4319
 
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
 
4319
        | { Select->alloc_index_hints(YYSession); } index_hints_list
4320
4320
        ;
4321
4321
 
4322
4322
opt_key_definition:
4325
4325
        ;
4326
4326
 
4327
4327
opt_key_usage_list:
4328
 
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
 
4328
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
4329
4329
        | key_usage_list {}
4330
4330
        ;
4331
4331
 
4332
4332
key_usage_element:
4333
4333
          ident
4334
 
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
 
4334
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
4335
4335
        | PRIMARY_SYM
4336
 
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
 
4336
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
4337
4337
        ;
4338
4338
 
4339
4339
key_usage_list:
4346
4346
          {
4347
4347
            if (!($$= new List<String>))
4348
4348
              DRIZZLE_YYABORT;
4349
 
            $$->push_back(new (YYTHD->mem_root)
 
4349
            $$->push_back(new (YYSession->mem_root)
4350
4350
                              String((const char *) $1.str, $1.length,
4351
4351
                                      system_charset_info));
4352
4352
          }
4353
4353
        | using_list ',' ident
4354
4354
          {
4355
 
            $1->push_back(new (YYTHD->mem_root)
 
4355
            $1->push_back(new (YYSession->mem_root)
4356
4356
                              String((const char *) $3.str, $3.length,
4357
4357
                                      system_charset_info));
4358
4358
            $$= $1;
4485
4485
 
4486
4486
group_list:
4487
4487
          group_list ',' order_ident order_dir
4488
 
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4488
          { if (add_group_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
4489
4489
        | order_ident order_dir
4490
 
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4490
          { if (add_group_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
4491
4491
        ;
4492
4492
 
4493
4493
olap_opt:
4528
4528
alter_order_item:
4529
4529
          simple_ident_nospvar order_dir
4530
4530
          {
4531
 
            THD *thd= YYTHD;
 
4531
            Session *session= YYSession;
4532
4532
            bool ascending= ($2 == 1) ? true : false;
4533
 
            if (add_order_to_list(thd, $1, ascending))
 
4533
            if (add_order_to_list(session, $1, ascending))
4534
4534
              DRIZZLE_YYABORT;
4535
4535
          }
4536
4536
        ;
4572
4572
              if (!unit->is_union() &&
4573
4573
                  (first_sl->order_list.elements || 
4574
4574
                   first_sl->select_limit) &&            
4575
 
                  unit->add_fake_select_lex(lex->thd))
 
4575
                  unit->add_fake_select_lex(lex->session))
4576
4576
                DRIZZLE_YYABORT;
4577
4577
            }
4578
4578
          }
4581
4581
 
4582
4582
order_list:
4583
4583
          order_list ',' order_ident order_dir
4584
 
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4584
          { if (add_order_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
4585
4585
        | order_ident order_dir
4586
 
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4586
          { if (add_order_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
4587
4587
        ;
4588
4588
 
4589
4589
order_dir:
4783
4783
            lex->alter_info.build_method= $2;
4784
4784
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4785
4785
                                                               $4.str));
4786
 
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
 
4786
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4787
4787
                                                        TL_OPTION_UPDATING))
4788
4788
              DRIZZLE_YYABORT;
4789
4789
          }
4802
4802
table_name:
4803
4803
          table_ident
4804
4804
          {
4805
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
 
4805
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4806
4806
              DRIZZLE_YYABORT;
4807
4807
          }
4808
4808
        ;
4815
4815
table_alias_ref:
4816
4816
          table_ident
4817
4817
          {
4818
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
 
4818
            if (!Select->add_table_to_list(YYSession, $1, NULL,
4819
4819
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4820
4820
                                           Lex->lock_option ))
4821
4821
              DRIZZLE_YYABORT;
5046
5046
update_elem:
5047
5047
          simple_ident_nospvar equal expr_or_default
5048
5048
          {
5049
 
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
 
5049
            if (add_item_to_list(YYSession, $1) || add_value_to_list(YYSession, $3))
5050
5050
              DRIZZLE_YYABORT;
5051
5051
          }
5052
5052
        ;
5089
5089
single_multi:
5090
5090
          FROM table_ident
5091
5091
          {
5092
 
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 
5092
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
5093
5093
                                           Lex->lock_option))
5094
5094
              DRIZZLE_YYABORT;
5095
5095
          }
5119
5119
table_wild_one:
5120
5120
          ident opt_wild
5121
5121
          {
5122
 
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
 
5122
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
5123
5123
                                           NULL,
5124
5124
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5125
5125
                                           Lex->lock_option))
5127
5127
          }
5128
5128
        | ident '.' ident opt_wild
5129
5129
          {
5130
 
            if (!Select->add_table_to_list(YYTHD,
5131
 
                                           new Table_ident(YYTHD, $1, $3, 0),
 
5130
            if (!Select->add_table_to_list(YYSession,
 
5131
                                           new Table_ident(YYSession, $1, $3, 0),
5132
5132
                                           NULL,
5133
5133
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5134
5134
                                           Lex->lock_option))
5188
5188
           {
5189
5189
             LEX *lex= Lex;
5190
5190
             lex->sql_command= SQLCOM_SHOW_DATABASES;
5191
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
 
5191
             if (prepare_schema_table(YYSession, lex, 0, SCH_SCHEMATA))
5192
5192
               DRIZZLE_YYABORT;
5193
5193
           }
5194
5194
         | opt_full TABLES opt_db show_wild
5196
5196
             LEX *lex= Lex;
5197
5197
             lex->sql_command= SQLCOM_SHOW_TABLES;
5198
5198
             lex->select_lex.db= $3;
5199
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
 
5199
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLE_NAMES))
5200
5200
               DRIZZLE_YYABORT;
5201
5201
           }
5202
5202
         | TABLE_SYM STATUS_SYM opt_db show_wild
5204
5204
             LEX *lex= Lex;
5205
5205
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
5206
5206
             lex->select_lex.db= $3;
5207
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
 
5207
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLES))
5208
5208
               DRIZZLE_YYABORT;
5209
5209
           }
5210
5210
        | OPEN_SYM TABLES opt_db show_wild
5212
5212
            LEX *lex= Lex;
5213
5213
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5214
5214
            lex->select_lex.db= $3;
5215
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
 
5215
            if (prepare_schema_table(YYSession, lex, 0, SCH_OPEN_TABLES))
5216
5216
              DRIZZLE_YYABORT;
5217
5217
          }
5218
5218
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
5226
5226
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5227
5227
            if ($5)
5228
5228
              $4->change_db($5);
5229
 
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
 
5229
            if (prepare_schema_table(YYSession, lex, $4, SCH_COLUMNS))
5230
5230
              DRIZZLE_YYABORT;
5231
5231
          }
5232
5232
        | master_or_binary LOGS_SYM
5239
5239
            lex->sql_command= SQLCOM_SHOW_KEYS;
5240
5240
            if ($4)
5241
5241
              $3->change_db($4);
5242
 
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
 
5242
            if (prepare_schema_table(YYSession, lex, $3, SCH_STATISTICS))
5243
5243
              DRIZZLE_YYABORT;
5244
5244
          }
5245
5245
        | COUNT_SYM '(' '*' ')' WARNINGS
5255
5255
            LEX *lex= Lex;
5256
5256
            lex->sql_command= SQLCOM_SHOW_STATUS;
5257
5257
            lex->option_type= $1;
5258
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
 
5258
            if (prepare_schema_table(YYSession, lex, 0, SCH_STATUS))
5259
5259
              DRIZZLE_YYABORT;
5260
5260
          }
5261
5261
        | opt_full PROCESSLIST_SYM
5265
5265
            LEX *lex= Lex;
5266
5266
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
5267
5267
            lex->option_type= $1;
5268
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
 
5268
            if (prepare_schema_table(YYSession, lex, 0, SCH_VARIABLES))
5269
5269
              DRIZZLE_YYABORT;
5270
5270
          }
5271
5271
        | CREATE DATABASE opt_if_not_exists ident
5278
5278
          {
5279
5279
            LEX *lex= Lex;
5280
5280
            lex->sql_command = SQLCOM_SHOW_CREATE;
5281
 
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
 
5281
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
5282
5282
              DRIZZLE_YYABORT;
5283
5283
          }
5284
5284
        | MASTER_SYM STATUS_SYM
5314
5314
          /* empty */
5315
5315
        | LIKE TEXT_STRING_sys
5316
5316
          {
5317
 
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
 
5317
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
5318
5318
                                                    system_charset_info);
5319
5319
          }
5320
5320
        ;
5330
5330
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5331
5331
            lex->select_lex.db= 0;
5332
5332
            lex->verbose= 0;
5333
 
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
 
5333
            if (prepare_schema_table(YYSession, lex, $2, SCH_COLUMNS))
5334
5334
              DRIZZLE_YYABORT;
5335
5335
          }
5336
5336
          opt_describe_column {}
5358
5358
        | text_string { Lex->wild= $1; }
5359
5359
        | ident
5360
5360
          {
5361
 
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
 
5361
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
5362
5362
                                                    $1.length,
5363
5363
                                                    system_charset_info);
5364
5364
          }
5494
5494
load:
5495
5495
          LOAD data_file
5496
5496
          {
5497
 
            THD *thd= YYTHD;
5498
 
            LEX *lex= thd->lex;
5499
 
            Lex_input_stream *lip= thd->m_lip;
 
5497
            Session *session= YYSession;
 
5498
            LEX *lex= session->lex;
 
5499
            Lex_input_stream *lip= session->m_lip;
5500
5500
 
5501
5501
            lex->fname_start= lip->get_ptr();
5502
5502
          }
5513
5513
          }
5514
5514
          opt_duplicate INTO
5515
5515
          {
5516
 
            THD *thd= YYTHD;
5517
 
            LEX *lex= thd->lex;
5518
 
            Lex_input_stream *lip= thd->m_lip;
 
5516
            Session *session= YYSession;
 
5517
            LEX *lex= session->lex;
 
5518
            Lex_input_stream *lip= session->m_lip;
5519
5519
            lex->fname_end= lip->get_ptr();
5520
5520
          }
5521
5521
          TABLE_SYM table_ident
5522
5522
          {
5523
5523
            LEX *lex=Lex;
5524
 
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
 
5524
            if (!Select->add_table_to_list(YYSession, $13, NULL, TL_OPTION_UPDATING,
5525
5525
                                           lex->lock_option))
5526
5526
              DRIZZLE_YYABORT;
5527
5527
            lex->field_list.empty();
5658
5658
          TEXT_STRING
5659
5659
          {
5660
5660
            LEX_STRING tmp;
5661
 
            THD *thd= YYTHD;
5662
 
            const CHARSET_INFO * const cs_con= thd->variables.collation_connection;
5663
 
            const CHARSET_INFO * const cs_cli= thd->variables.character_set_client;
5664
 
            uint32_t repertoire= thd->lex->text_string_is_7bit &&
 
5661
            Session *session= YYSession;
 
5662
            const CHARSET_INFO * const cs_con= session->variables.collation_connection;
 
5663
            const CHARSET_INFO * const cs_cli= session->variables.character_set_client;
 
5664
            uint32_t repertoire= session->lex->text_string_is_7bit &&
5665
5665
                             my_charset_is_ascii_based(cs_cli) ?
5666
5666
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
5667
 
            if (thd->charset_is_collation_connection ||
 
5667
            if (session->charset_is_collation_connection ||
5668
5668
                (repertoire == MY_REPERTOIRE_ASCII &&
5669
5669
                 my_charset_is_ascii_based(cs_con)))
5670
5670
              tmp= $1;
5671
5671
            else
5672
 
              thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
 
5672
              session->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
5673
5673
            $$= new Item_string(tmp.str, tmp.length, cs_con,
5674
5674
                                DERIVATION_COERCIBLE, repertoire);
5675
5675
          }
5691
5691
                 If the string has been pure ASCII so far,
5692
5692
                 check the new part.
5693
5693
              */
5694
 
              const CHARSET_INFO * const cs= YYTHD->variables.collation_connection;
 
5694
              const CHARSET_INFO * const cs= YYSession->variables.collation_connection;
5695
5695
              item->collation.repertoire|= my_string_repertoire(cs,
5696
5696
                                                                $2.str,
5697
5697
                                                                $2.length);
5702
5702
text_string:
5703
5703
          TEXT_STRING_literal
5704
5704
          {
5705
 
            $$= new (YYTHD->mem_root) String($1.str,
 
5705
            $$= new (YYSession->mem_root) String($1.str,
5706
5706
                                             $1.length,
5707
 
                                             YYTHD->variables.collation_connection);
 
5707
                                             YYSession->variables.collation_connection);
5708
5708
          }
5709
5709
        | HEX_NUM
5710
5710
          {
5745
5745
        | NULL_SYM
5746
5746
          {
5747
5747
            $$ = new Item_null();
5748
 
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
5748
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5749
5749
          }
5750
5750
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5751
5751
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5824
5824
          { $$ = new Item_uint($1.str, $1.length); }
5825
5825
        | DECIMAL_NUM
5826
5826
          {
5827
 
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
5828
 
            if (YYTHD->is_error())
 
5827
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
 
5828
            if (YYSession->is_error())
5829
5829
            {
5830
5830
              DRIZZLE_YYABORT;
5831
5831
            }
5833
5833
        | FLOAT_NUM
5834
5834
          {
5835
5835
            $$ = new Item_float($1.str, $1.length);
5836
 
            if (YYTHD->is_error())
 
5836
            if (YYSession->is_error())
5837
5837
            {
5838
5838
              DRIZZLE_YYABORT;
5839
5839
            }
5859
5859
        | ident '.' ident '.' '*'
5860
5860
          {
5861
5861
            SELECT_LEX *sel= Select;
5862
 
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
 
5862
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
5863
5863
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
5864
5864
                                $3.str,"*");
5865
5865
            sel->with_wild++;
5903
5903
simple_ident_q:
5904
5904
          ident '.' ident
5905
5905
          {
5906
 
            THD *thd= YYTHD;
5907
 
            LEX *lex= thd->lex;
 
5906
            Session *session= YYSession;
 
5907
            LEX *lex= session->lex;
5908
5908
 
5909
5909
            {
5910
5910
              SELECT_LEX *sel= lex->current_select;
5911
5911
              if (sel->no_table_names_allowed)
5912
5912
              {
5913
5913
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5914
 
                         MYF(0), $1.str, thd->where);
 
5914
                         MYF(0), $1.str, session->where);
5915
5915
              }
5916
5916
              $$= (sel->parsing_place != IN_HAVING ||
5917
5917
                  sel->get_in_sum_expr() > 0) ?
5923
5923
          }
5924
5924
        | '.' ident '.' ident
5925
5925
          {
5926
 
            THD *thd= YYTHD;
5927
 
            LEX *lex= thd->lex;
 
5926
            Session *session= YYSession;
 
5927
            LEX *lex= session->lex;
5928
5928
            SELECT_LEX *sel= lex->current_select;
5929
5929
            if (sel->no_table_names_allowed)
5930
5930
            {
5931
5931
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5932
 
                       MYF(0), $2.str, thd->where);
 
5932
                       MYF(0), $2.str, session->where);
5933
5933
            }
5934
5934
            $$= (sel->parsing_place != IN_HAVING ||
5935
5935
                sel->get_in_sum_expr() > 0) ?
5939
5939
          }
5940
5940
        | ident '.' ident '.' ident
5941
5941
          {
5942
 
            THD *thd= YYTHD;
5943
 
            LEX *lex= thd->lex;
 
5942
            Session *session= YYSession;
 
5943
            LEX *lex= session->lex;
5944
5944
            SELECT_LEX *sel= lex->current_select;
5945
5945
            if (sel->no_table_names_allowed)
5946
5946
            {
5947
5947
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5948
 
                       MYF(0), $3.str, thd->where);
 
5948
                       MYF(0), $3.str, session->where);
5949
5949
            }
5950
5950
            $$= (sel->parsing_place != IN_HAVING ||
5951
5951
                sel->get_in_sum_expr() > 0) ?
5952
5952
                (Item*) new Item_field(Lex->current_context(),
5953
 
                                       (YYTHD->client_capabilities &
 
5953
                                       (YYSession->client_capabilities &
5954
5954
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
5955
5955
                                       $3.str, $5.str) :
5956
5956
                (Item*) new Item_ref(Lex->current_context(),
5957
 
                                     (YYTHD->client_capabilities &
 
5957
                                     (YYSession->client_capabilities &
5958
5958
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
5959
5959
                                     $3.str, $5.str);
5960
5960
          }
5993
5993
 
5994
5994
table_ident:
5995
5995
          ident { $$=new Table_ident($1); }
5996
 
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
 
5996
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
5997
5997
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
5998
5998
        ;
5999
5999
 
6001
6001
          IDENT { $$= $1; }
6002
6002
        | IDENT_QUOTED
6003
6003
          {
6004
 
            THD *thd= YYTHD;
 
6004
            Session *session= YYSession;
6005
6005
 
6006
 
            if (thd->charset_is_system_charset)
 
6006
            if (session->charset_is_system_charset)
6007
6007
            {
6008
6008
              const CHARSET_INFO * const cs= system_charset_info;
6009
6009
              int dummy_error;
6019
6019
              $$= $1;
6020
6020
            }
6021
6021
            else
6022
 
              thd->convert_string(&$$, system_charset_info,
6023
 
                                  $1.str, $1.length, thd->charset());
 
6022
              session->convert_string(&$$, system_charset_info,
 
6023
                                  $1.str, $1.length, session->charset());
6024
6024
          }
6025
6025
        ;
6026
6026
 
6027
6027
TEXT_STRING_sys:
6028
6028
          TEXT_STRING
6029
6029
          {
6030
 
            THD *thd= YYTHD;
 
6030
            Session *session= YYSession;
6031
6031
 
6032
 
            if (thd->charset_is_system_charset)
 
6032
            if (session->charset_is_system_charset)
6033
6033
              $$= $1;
6034
6034
            else
6035
 
              thd->convert_string(&$$, system_charset_info,
6036
 
                                  $1.str, $1.length, thd->charset());
 
6035
              session->convert_string(&$$, system_charset_info,
 
6036
                                  $1.str, $1.length, session->charset());
6037
6037
          }
6038
6038
        ;
6039
6039
 
6040
6040
TEXT_STRING_literal:
6041
6041
          TEXT_STRING
6042
6042
          {
6043
 
            THD *thd= YYTHD;
 
6043
            Session *session= YYSession;
6044
6044
 
6045
 
            if (thd->charset_is_collation_connection)
 
6045
            if (session->charset_is_collation_connection)
6046
6046
              $$= $1;
6047
6047
            else
6048
 
              thd->convert_string(&$$, thd->variables.collation_connection,
6049
 
                                  $1.str, $1.length, thd->charset());
 
6048
              session->convert_string(&$$, session->variables.collation_connection,
 
6049
                                  $1.str, $1.length, session->charset());
6050
6050
          }
6051
6051
        ;
6052
6052
 
6053
6053
TEXT_STRING_filesystem:
6054
6054
          TEXT_STRING
6055
6055
          {
6056
 
            THD *thd= YYTHD;
 
6056
            Session *session= YYSession;
6057
6057
 
6058
 
            if (thd->charset_is_character_set_filesystem)
 
6058
            if (session->charset_is_character_set_filesystem)
6059
6059
              $$= $1;
6060
6060
            else
6061
 
              thd->convert_string(&$$, thd->variables.character_set_filesystem,
6062
 
                                  $1.str, $1.length, thd->charset());
 
6061
              session->convert_string(&$$, session->variables.character_set_filesystem,
 
6062
                                  $1.str, $1.length, session->charset());
6063
6063
          }
6064
6064
        ;
6065
6065
 
6067
6067
          IDENT_sys    { $$=$1; }
6068
6068
        | keyword
6069
6069
          {
6070
 
            THD *thd= YYTHD;
6071
 
            $$.str= thd->strmake($1.str, $1.length);
 
6070
            Session *session= YYSession;
 
6071
            $$.str= session->strmake($1.str, $1.length);
6072
6072
            $$.length= $1.length;
6073
6073
          }
6074
6074
        ;
6422
6422
            LEX *lex=Lex;
6423
6423
            lex->option_type= $1;
6424
6424
            lex->var_list.push_back(new set_var(lex->option_type,
6425
 
                                                find_sys_var(YYTHD, "tx_isolation"),
 
6425
                                                find_sys_var(YYSession, "tx_isolation"),
6426
6426
                                                &null_lex_str,
6427
6427
                                                new Item_int((int32_t) $5)));
6428
6428
          }
6449
6449
internal_variable_name:
6450
6450
          ident
6451
6451
          {
6452
 
            THD *thd= YYTHD;
 
6452
            Session *session= YYSession;
6453
6453
 
6454
6454
            /* We have to lookup here since local vars can shadow sysvars */
6455
6455
            {
6456
6456
              /* Not an SP local variable */
6457
 
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
 
6457
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
6458
6458
              if (!tmp)
6459
6459
                DRIZZLE_YYABORT;
6460
6460
              $$.var= tmp;
6469
6469
              DRIZZLE_YYABORT;
6470
6470
            }
6471
6471
            {
6472
 
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
6472
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6473
6473
              if (!tmp)
6474
6474
                DRIZZLE_YYABORT;
6475
6475
              if (!tmp->is_struct())
6480
6480
          }
6481
6481
        | DEFAULT '.' ident
6482
6482
          {
6483
 
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
6483
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6484
6484
            if (!tmp)
6485
6485
              DRIZZLE_YYABORT;
6486
6486
            if (!tmp->is_struct())
6544
6544
        table_ident opt_table_alias table_lock_info
6545
6545
        {
6546
6546
          TableList *tlist;
6547
 
          if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
 
6547
          if (!(tlist= Select->add_table_to_list(YYSession, $1, $2, 0,
6548
6548
                                                 $3.lock_type)))
6549
6549
            DRIZZLE_YYABORT; /* purecov: inspected */
6550
6550
          tlist->lock_timeout= $3.lock_timeout;
6636
6636
 
6637
6637
opt_chain:
6638
6638
          /* empty */
6639
 
          { $$= (YYTHD->variables.completion_type == 1); }
 
6639
          { $$= (YYSession->variables.completion_type == 1); }
6640
6640
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6641
6641
        | AND_SYM CHAIN_SYM        { $$=1; }
6642
6642
        ;
6643
6643
 
6644
6644
opt_release:
6645
6645
          /* empty */
6646
 
          { $$= (YYTHD->variables.completion_type == 2); }
 
6646
          { $$= (YYSession->variables.completion_type == 2); }
6647
6647
        | RELEASE_SYM        { $$=1; }
6648
6648
        | NO_SYM RELEASE_SYM { $$=0; }
6649
6649
;
6732
6732
 
6733
6733
union_order_or_limit:
6734
6734
          {
6735
 
            THD *thd= YYTHD;
6736
 
            LEX *lex= thd->lex;
 
6735
            Session *session= YYSession;
 
6736
            LEX *lex= session->lex;
6737
6737
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6738
6738
            SELECT_LEX *sel= lex->current_select;
6739
6739
            SELECT_LEX_UNIT *unit= sel->master_unit();
6744
6744
              fake->no_table_names_allowed= 1;
6745
6745
              lex->current_select= fake;
6746
6746
            }
6747
 
            thd->where= "global ORDER clause";
 
6747
            session->where= "global ORDER clause";
6748
6748
          }
6749
6749
          order_or_limit
6750
6750
          {
6751
 
            THD *thd= YYTHD;
6752
 
            thd->lex->current_select->no_table_names_allowed= 0;
6753
 
            thd->where= "";
 
6751
            Session *session= YYSession;
 
6752
            session->lex->current_select->no_table_names_allowed= 0;
 
6753
            session->where= "";
6754
6754
          }
6755
6755
        ;
6756
6756