~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

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