~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

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
 
#include <storage/myisam/myisam.h>
43
 
#include <drizzled/drizzled_error_messages.h>
 
42
#include <drizzled/functions/locate.h>
 
43
#include <drizzled/error.h>
 
44
#include <drizzled/nested_join.h>
 
45
#include <drizzled/sql_parse.h>
44
46
 
45
 
int yylex(void *yylval, void *yythd);
 
47
int yylex(void *yylval, void *yysession);
46
48
 
47
49
#define yyoverflow(A,B,C,D,E,F)               \
48
50
  {                                           \
61
63
#define DRIZZLE_YYABORT                         \
62
64
  do                                          \
63
65
  {                                           \
64
 
    LEX::cleanup_lex_after_parse_error(YYTHD);\
 
66
    LEX::cleanup_lex_after_parse_error(YYSession);\
65
67
    YYABORT;                                  \
66
68
  } while (0)
67
69
 
109
111
 
110
112
void my_parse_error(const char *s)
111
113
{
112
 
  THD *thd= current_thd;
113
 
  Lex_input_stream *lip= thd->m_lip;
 
114
  Session *session= current_session;
 
115
  Lex_input_stream *lip= session->m_lip;
114
116
 
115
117
  const char *yytext= lip->get_tok_start();
116
118
  /* Push an error into the error stack */
139
141
  to abort from the parser.
140
142
*/
141
143
 
142
 
void MYSQLerror(const char *s)
 
144
void DRIZZLEerror(const char *s)
143
145
{
144
 
  THD *thd= current_thd;
 
146
  Session *session= current_session;
145
147
 
146
148
  /*
147
149
    Restore the original LEX if it was replaced when parsing
148
150
    a stored procedure. We must ensure that a parsing error
149
 
    does not leave any side effects in the THD.
 
151
    does not leave any side effects in the Session.
150
152
  */
151
 
  LEX::cleanup_lex_after_parse_error(thd);
 
153
  LEX::cleanup_lex_after_parse_error(session);
152
154
 
153
155
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
154
156
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
161
163
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
162
164
  This function returns the proper item for the SQL expression
163
165
  <code>left [NOT] IN ( expr )</code>
164
 
  @param thd the current thread
 
166
  @param session the current thread
165
167
  @param left the in predicand
166
168
  @param equal true for IN predicates, false for NOT IN predicates
167
169
  @param expr first and only expression of the in value list
168
170
  @return an expression representing the IN predicate.
169
171
*/
170
 
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
 
172
Item* handle_sql2003_note184_exception(Session *session, Item* left, bool equal,
171
173
                                       Item *expr)
172
174
{
173
175
  /*
212
214
          Item_in_subselect(left, subselect)
213
215
      */
214
216
      subselect= expr3->invalidate_and_restore_select_lex();
215
 
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
 
217
      result= new (session->mem_root) Item_in_subselect(left, subselect);
216
218
 
217
219
      if (! equal)
218
 
        result = negate_expression(thd, result);
 
220
        result = negate_expression(session, result);
219
221
 
220
222
      return(result);
221
223
    }
222
224
  }
223
225
 
224
226
  if (equal)
225
 
    result= new (thd->mem_root) Item_func_eq(left, expr);
 
227
    result= new (session->mem_root) Item_func_eq(left, expr);
226
228
  else
227
 
    result= new (thd->mem_root) Item_func_ne(left, expr);
 
229
    result= new (session->mem_root) Item_func_ne(left, expr);
228
230
 
229
231
  return(result);
230
232
}
341
343
  thr_lock_type lock_type;
342
344
  struct st_table_lock_info table_lock_info;
343
345
  interval_type interval, interval_time_st;
344
 
  timestamp_type date_time_type;
 
346
  enum enum_drizzle_timestamp_type date_time_type;
345
347
  st_select_lex *select_lex;
346
348
  chooser_compare_func_creator boolfunc2creator;
347
349
  struct sp_cond_type *spcondtype;
513
515
%token  ERRORS
514
516
%token  ESCAPED
515
517
%token  ESCAPE_SYM                    /* SQL-2003-R */
516
 
%token  EVENTS_SYM
517
518
%token  EXCLUSIVE_SYM
518
519
%token  EXISTS                        /* SQL-2003-R */
519
520
%token  EXIT_SYM
679
680
%token  PAGE_SYM
680
681
%token  PAGE_CHECKSUM_SYM
681
682
%token  PARAM_MARKER
 
683
%token  PARSE_VCOL_EXPR_SYM
682
684
%token  PARTIAL                       /* SQL-2003-N */
683
685
%token  PHASE_SYM
684
686
%token  PLUGINS_SYM
753
755
%token  SHARE_SYM
754
756
%token  SHOW
755
757
%token  SHUTDOWN
756
 
%token  SIGNED_SYM
757
758
%token  SIMPLE_SYM                    /* SQL-2003-N */
758
759
%token  SLAVE
759
 
%token  SMALLINT                      /* SQL-2003-R */
760
760
%token  SNAPSHOT_SYM
761
761
%token  SOCKET_SYM
762
762
%token  SONAME_SYM
779
779
%token  STD_SYM
780
780
%token  STOP_SYM
781
781
%token  STORAGE_SYM
 
782
%token  STORED_SYM
782
783
%token  STRAIGHT_JOIN
783
784
%token  STRING_SYM
784
785
%token  SUBDATE_SYM
806
807
%token  TIMESTAMP_ADD
807
808
%token  TIMESTAMP_DIFF
808
809
%token  TIME_SYM                      /* SQL-2003-R */
809
 
%token  TINYINT
810
810
%token  TO_SYM                        /* SQL-2003-R */
811
811
%token  TRAILING                      /* SQL-2003-R */
812
812
%token  TRANSACTION_SYM
826
826
%token  UNIQUE_SYM
827
827
%token  UNKNOWN_SYM                   /* SQL-2003-R */
828
828
%token  UNLOCK_SYM
829
 
%token  UNSIGNED
830
829
%token  UNTIL_SYM
831
830
%token  UPDATE_SYM                    /* SQL-2003-R */
832
831
%token  UPGRADE_SYM
846
845
%token  VARIANCE_SYM
847
846
%token  VARYING                       /* SQL-2003-R */
848
847
%token  VAR_SAMP_SYM
 
848
%token  VIRTUAL_SYM
849
849
%token  WAIT_SYM
850
850
%token  WARNINGS
851
851
%token  WEEK_SYM
853
853
%token  WHEN_SYM                      /* SQL-2003-R */
854
854
%token  WHERE                         /* SQL-2003-R */
855
855
%token  WITH                          /* SQL-2003-R */
856
 
%token  WITH_CUBE_SYM                 /* INTERNAL */
857
856
%token  WITH_ROLLUP_SYM               /* INTERNAL */
858
857
%token  WORK_SYM                      /* SQL-2003-N */
859
858
%token  WRITE_SYM                     /* SQL-2003-N */
898
897
        text_string opt_gconcat_separator
899
898
 
900
899
%type <num>
901
 
        type int_type real_type order_dir
 
900
        type int_type real_type order_dir field_def
902
901
        if_exists opt_local opt_table_options table_options
903
902
        table_option opt_if_not_exists
904
903
        opt_temporary all_or_any opt_distinct
1018
1017
        select_item_list select_item values_list no_braces
1019
1018
        opt_limit_clause delete_limit_clause fields opt_values values
1020
1019
        opt_precision opt_ignore opt_column
1021
 
        set lock unlock string_list field_options field_option
1022
 
        field_opt_list opt_binary table_lock_list table_lock
 
1020
        set lock unlock string_list
 
1021
        opt_binary table_lock_list table_lock
1023
1022
        ref_list opt_match_clause opt_on_update_delete use
1024
1023
        opt_delete_options opt_delete_option varchar
1025
1024
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
1031
1030
        table_to_table_list table_to_table opt_table_list opt_as
1032
1031
        single_multi table_wild_list table_wild_one opt_wild
1033
1032
        union_clause union_list
1034
 
        precision subselect_start charset
 
1033
        precision subselect_start
1035
1034
        subselect_end select_var_list select_var_list_init opt_len
1036
1035
        opt_extended_describe
1037
1036
        statement
1038
1037
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1039
1038
        binlog_base64_event
1040
1039
        init_key_options key_options key_opts key_opt key_using_alg
 
1040
        parse_vcol_expr vcol_opt_attribute vcol_opt_attribute_list
 
1041
        vcol_attribute
1041
1042
END_OF_INPUT
1042
1043
 
1043
1044
%type <index_hint> index_hint_type
1074
1075
query:
1075
1076
          END_OF_INPUT
1076
1077
          {
1077
 
            THD *thd= YYTHD;
1078
 
            if (!thd->bootstrap &&
1079
 
              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
 
1078
            Session *session= YYSession;
 
1079
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
1080
1080
            {
1081
1081
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1082
1082
              DRIZZLE_YYABORT;
1083
1083
            }
1084
1084
            else
1085
1085
            {
1086
 
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1086
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
1087
1087
            }
1088
1088
          }
1089
1089
        | verb_clause END_OF_INPUT {}
1114
1114
        | lock
1115
1115
        | optimize
1116
1116
        | keycache
 
1117
        | parse_vcol_expr
1117
1118
        | purge
1118
1119
        | release
1119
1120
        | rename
1189
1190
            }
1190
1191
            if (Lex->mi.heartbeat_period > slave_net_timeout)
1191
1192
            {
1192
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1193
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1193
1194
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1194
1195
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1195
1196
                                  " exceeds the value of `slave_net_timeout' sec.",
1200
1201
            {
1201
1202
              if (Lex->mi.heartbeat_period != 0.0)
1202
1203
              {
1203
 
                push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1204
                push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1204
1205
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1205
1206
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1206
1207
                                    " is less than 1 msec.",
1235
1236
               from 0" (4 in fact), unspecified means "don't change the position
1236
1237
               (keep the preceding value)").
1237
1238
            */
1238
 
            Lex->mi.pos = max((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
 
1239
            Lex->mi.pos = cmax((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1239
1240
          }
1240
1241
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1241
1242
          {
1245
1246
          {
1246
1247
            Lex->mi.relay_log_pos = $3;
1247
1248
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1248
 
            Lex->mi.relay_log_pos = max((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
 
1249
            Lex->mi.relay_log_pos = cmax((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1249
1250
          }
1250
1251
        ;
1251
1252
 
1254
1255
create:
1255
1256
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1256
1257
          {
1257
 
            THD *thd= YYTHD;
1258
 
            LEX *lex= thd->lex;
 
1258
            Session *session= YYSession;
 
1259
            LEX *lex= session->lex;
1259
1260
            lex->sql_command= SQLCOM_CREATE_TABLE;
1260
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
1261
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1261
1262
                                                   TL_OPTION_UPDATING,
1262
1263
                                                   TL_WRITE))
1263
1264
              DRIZZLE_YYABORT;
1264
1265
            lex->alter_info.reset();
1265
1266
            lex->col_list.empty();
1266
 
            lex->change=NullS;
 
1267
            lex->change=NULL;
1267
1268
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1268
1269
            lex->create_info.options=$2 | $4;
1269
 
            lex->create_info.db_type= ha_default_handlerton(thd);
 
1270
            lex->create_info.db_type= ha_default_handlerton(session);
1270
1271
            lex->create_info.default_table_charset= NULL;
1271
1272
            lex->name.str= 0;
1272
1273
            lex->name.length= 0;
1273
1274
          }
1274
1275
          create2
1275
1276
          {
1276
 
            LEX *lex= YYTHD->lex;
 
1277
            LEX *lex= YYSession->lex;
1277
1278
            lex->current_select= &lex->select_lex; 
1278
1279
            if (!lex->create_info.db_type)
1279
1280
            {
1280
 
              lex->create_info.db_type= ha_default_handlerton(YYTHD);
1281
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1281
              lex->create_info.db_type= ha_default_handlerton(YYSession);
 
1282
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1282
1283
                                  ER_WARN_USING_OTHER_HANDLER,
1283
1284
                                  ER(ER_WARN_USING_OTHER_HANDLER),
1284
1285
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
1290
1291
          {
1291
1292
            LEX *lex=Lex;
1292
1293
            lex->sql_command= SQLCOM_CREATE_INDEX;
1293
 
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
 
1294
            if (!lex->current_select->add_table_to_list(lex->session, $8,
1294
1295
                                                        NULL,
1295
1296
                                                        TL_OPTION_UPDATING))
1296
1297
              DRIZZLE_YYABORT;
1298
1299
            lex->alter_info.flags= ALTER_ADD_INDEX;
1299
1300
            lex->alter_info.build_method= $2;
1300
1301
            lex->col_list.empty();
1301
 
            lex->change=NullS;
 
1302
            lex->change=NULL;
1302
1303
          }
1303
1304
          '(' key_list ')' key_options
1304
1305
          {
1329
1330
          create3 {}
1330
1331
        | LIKE table_ident
1331
1332
          {
1332
 
            THD *thd= YYTHD;
1333
 
            LEX *lex= thd->lex;
 
1333
            Session *session= YYSession;
 
1334
            LEX *lex= session->lex;
1334
1335
 
1335
1336
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1336
 
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
 
1337
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1337
1338
              DRIZZLE_YYABORT;
1338
1339
          }
1339
1340
        | '(' LIKE table_ident ')'
1340
1341
          {
1341
 
            THD *thd= YYTHD;
1342
 
            LEX *lex= thd->lex;
 
1342
            Session *session= YYSession;
 
1343
            LEX *lex= session->lex;
1343
1344
 
1344
1345
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1345
 
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
 
1346
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1346
1347
              DRIZZLE_YYABORT;
1347
1348
          }
1348
1349
        ;
1555
1556
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1556
1557
            Lex->create_info.key_block_size= $3;
1557
1558
          }
1558
 
        | TRANSACTIONAL_SYM opt_equal choice
1559
 
          {
1560
 
            Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
1561
 
            Lex->create_info.transactional= $3;
1562
 
          }
1563
1559
        ;
1564
1560
 
1565
1561
default_collation:
1582
1578
storage_engines:
1583
1579
          ident_or_text
1584
1580
          {
1585
 
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
 
1581
            plugin_ref plugin= ha_resolve_by_name(YYSession, &$1);
1586
1582
 
1587
1583
            if (plugin)
1588
1584
              $$= plugin_data(plugin, handlerton*);
1598
1594
          ident_or_text
1599
1595
          {
1600
1596
            plugin_ref plugin;
1601
 
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
 
1597
            if ((plugin= ha_resolve_by_name(YYSession, &$1)))
1602
1598
              $$= plugin_data(plugin, handlerton*);
1603
1599
            else
1604
1600
            {
1720
1716
            lex->comment=null_lex_str;
1721
1717
            lex->charset=NULL;
1722
1718
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1719
            lex->vcol_info= NULL;
1723
1720
          }
1724
 
          type opt_attribute
 
1721
          field_def
1725
1722
          {
1726
1723
            LEX *lex=Lex;
1727
 
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
 
1724
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1728
1725
                                  lex->length,lex->dec,lex->type,
1729
1726
                                  lex->column_format,
1730
1727
                                  lex->default_value, lex->on_update_value, 
1731
1728
                                  &lex->comment,
1732
 
                                  lex->change,&lex->interval_list,lex->charset))
1733
 
              DRIZZLE_YYABORT;
 
1729
                                  lex->change,&lex->interval_list,lex->charset,
 
1730
                                  lex->vcol_info))
 
1731
              DRIZZLE_YYABORT;
 
1732
          }
 
1733
        ;
 
1734
field_def:
 
1735
          type opt_attribute {}
 
1736
        | VIRTUAL_SYM type AS '(' virtual_column_func ')' vcol_opt_attribute
 
1737
          {
 
1738
            $$=DRIZZLE_TYPE_VIRTUAL;
 
1739
            Lex->vcol_info->set_field_type((enum enum_field_types) $2);
 
1740
          }
 
1741
        ;
 
1742
 
 
1743
vcol_opt_attribute:
 
1744
          /* empty */ {}
 
1745
        | vcol_opt_attribute_list {}
 
1746
        ;
 
1747
 
 
1748
vcol_opt_attribute_list:
 
1749
          vcol_opt_attribute_list vcol_attribute {}
 
1750
        | vcol_attribute
 
1751
        ;
 
1752
 
 
1753
vcol_attribute:
 
1754
          UNIQUE_SYM
 
1755
          {
 
1756
            LEX *lex=Lex;
 
1757
            lex->type|= UNIQUE_FLAG; 
 
1758
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1759
          }
 
1760
        | UNIQUE_SYM KEY_SYM
 
1761
          {
 
1762
            LEX *lex=Lex;
 
1763
            lex->type|= UNIQUE_KEY_FLAG; 
 
1764
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
1765
          }
 
1766
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
 
1767
        | STORED_SYM
 
1768
          {
 
1769
            Lex->vcol_info->set_field_stored(true);
 
1770
          }
 
1771
        ;
 
1772
 
 
1773
parse_vcol_expr:
 
1774
          PARSE_VCOL_EXPR_SYM '(' virtual_column_func ')'
 
1775
          {
 
1776
            /* 
 
1777
              "PARSE_VCOL_EXPR" can only be used by the SQL server
 
1778
              when reading a '*.frm' file.
 
1779
              Prevent the end user from invoking this command.
 
1780
            */
 
1781
            if (not Lex->parse_vcol_expr)
 
1782
            {
 
1783
              my_message(ER_SYNTAX_ERROR, ER(ER_SYNTAX_ERROR), MYF(0));
 
1784
              DRIZZLE_YYABORT;
 
1785
            }
 
1786
          }
 
1787
        ;
 
1788
 
 
1789
virtual_column_func:
 
1790
          remember_name expr remember_end
 
1791
          {
 
1792
            Lex->vcol_info= new virtual_column_info();
 
1793
            if (not Lex->vcol_info)
 
1794
            {
 
1795
              my_error(ER_OUTOFMEMORY, MYF(0), sizeof(virtual_column_info));
 
1796
              DRIZZLE_YYABORT;
 
1797
            }
 
1798
            uint expr_len= (uint)($3 - $1) - 1;
 
1799
            Lex->vcol_info->expr_str.str= (char* ) sql_memdup($1 + 1, expr_len);
 
1800
            Lex->vcol_info->expr_str.length= expr_len;
 
1801
            Lex->vcol_info->expr_item= $2;
1734
1802
          }
1735
1803
        ;
1736
1804
 
1737
1805
type:
1738
 
        int_type field_options 
 
1806
        int_type
1739
1807
        { 
1740
1808
          $$=$1; 
1741
1809
          Lex->length=(char*) 0; /* use default length */
1742
1810
        }
1743
 
        | real_type opt_precision field_options { $$=$1; }
1744
 
        | BIT_SYM
1745
 
          {
1746
 
            Lex->length= (char*) "1";
1747
 
            $$=DRIZZLE_TYPE_TINY;
1748
 
          }
1749
 
        | BOOL_SYM
1750
 
          {
1751
 
            Lex->length=(char*) "1";
1752
 
            $$=DRIZZLE_TYPE_TINY;
1753
 
          }
1754
 
        | BOOLEAN_SYM
1755
 
          {
1756
 
            Lex->length=(char*) "1";
1757
 
            $$=DRIZZLE_TYPE_TINY;
1758
 
          }
 
1811
        | real_type opt_precision { $$=$1; }
1759
1812
        | char '(' NUM ')' opt_binary
1760
1813
          {
1761
1814
            Lex->length=$3.str;
1800
1853
            $$=DRIZZLE_TYPE_BLOB; 
1801
1854
            Lex->length=(char*) 0; /* use default length */
1802
1855
          }
1803
 
        | DECIMAL_SYM float_options field_options
1804
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1805
 
        | NUMERIC_SYM float_options field_options
1806
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1807
 
        | FIXED_SYM float_options field_options
 
1856
        | DECIMAL_SYM float_options
 
1857
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1858
        | NUMERIC_SYM float_options
 
1859
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1860
        | FIXED_SYM float_options
1808
1861
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1809
1862
        | ENUM
1810
1863
          {Lex->interval_list.empty();}
1813
1866
        | SERIAL_SYM
1814
1867
          {
1815
1868
            $$=DRIZZLE_TYPE_LONGLONG;
1816
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
1817
 
              UNIQUE_FLAG);
 
1869
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1818
1870
          }
1819
1871
        ;
1820
1872
 
1829
1881
 
1830
1882
int_type:
1831
1883
          INT_SYM   { $$=DRIZZLE_TYPE_LONG; }
1832
 
        | TINYINT   { $$=DRIZZLE_TYPE_TINY; }
1833
 
        | SMALLINT  { $$=DRIZZLE_TYPE_SHORT; }
1834
1884
        | BIGINT    { $$=DRIZZLE_TYPE_LONGLONG; }
1835
1885
        ;
1836
1886
 
1863
1913
          }
1864
1914
        ;
1865
1915
 
1866
 
field_options:
1867
 
          /* empty */ {}
1868
 
        | field_opt_list {}
1869
 
        ;
1870
 
 
1871
 
field_opt_list:
1872
 
          field_opt_list field_option {}
1873
 
        | field_option {}
1874
 
        ;
1875
 
 
1876
 
field_option:
1877
 
          SIGNED_SYM {}
1878
 
        | UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
1879
 
        ;
1880
 
 
1881
1916
opt_len:
1882
1917
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1883
1918
        | '(' NUM ')' { Lex->length= $2.str; }
1961
1996
          { $$=$1; }
1962
1997
        ;
1963
1998
 
1964
 
charset:
1965
 
          CHAR_SYM SET {}
1966
 
        | CHARSET {}
1967
 
        ;
1968
 
 
1969
1999
collation_name:
1970
2000
          ident_or_text
1971
2001
          {
2044
2074
ws_level_range:
2045
2075
        ws_level_number '-' ws_level_number
2046
2076
        {
2047
 
          uint start= $1;
2048
 
          uint end= $3;
 
2077
          uint32_t start= $1;
 
2078
          uint32_t end= $3;
2049
2079
          for ($$= 0; start <= end; start++)
2050
2080
            $$|= (1 << start);
2051
2081
        }
2262
2292
alter:
2263
2293
          ALTER build_method opt_ignore TABLE_SYM table_ident
2264
2294
          {
2265
 
            THD *thd= YYTHD;
2266
 
            LEX *lex= thd->lex;
 
2295
            Session *session= YYSession;
 
2296
            LEX *lex= session->lex;
2267
2297
            lex->name.str= 0;
2268
2298
            lex->name.length= 0;
2269
2299
            lex->sql_command= SQLCOM_ALTER_TABLE;
2270
2300
            lex->duplicates= DUP_ERROR; 
2271
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
2301
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2272
2302
                                                   TL_OPTION_UPDATING))
2273
2303
              DRIZZLE_YYABORT;
2274
2304
            lex->alter_info.reset();
2368
2398
            lex->charset= NULL;
2369
2399
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2370
2400
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2401
            lex->vcol_info= NULL;
2371
2402
          }
2372
 
          type opt_attribute
 
2403
          field_def
2373
2404
          {
2374
2405
            LEX *lex=Lex;
2375
 
            if (add_field_to_list(lex->thd,&$3,
 
2406
            if (add_field_to_list(lex->session,&$3,
2376
2407
                                  (enum enum_field_types) $5,
2377
2408
                                  lex->length,lex->dec,lex->type,
2378
2409
                                  lex->column_format,
2379
2410
                                  lex->default_value, lex->on_update_value,
2380
2411
                                  &lex->comment,
2381
 
                                  $3.str, &lex->interval_list, lex->charset))
 
2412
                                  $3.str, &lex->interval_list, lex->charset,
 
2413
                                  lex->vcol_info))
2382
2414
              DRIZZLE_YYABORT;
2383
2415
          }
2384
2416
          opt_place
2454
2486
          {
2455
2487
            if (!$3)
2456
2488
            {
2457
 
              THD *thd= YYTHD;
2458
 
              $3= thd->variables.collation_database;
 
2489
              Session *session= YYSession;
 
2490
              $3= session->variables.collation_database;
2459
2491
            }
2460
2492
            LEX *lex= Lex;
2461
2493
            lex->create_info.table_charset=
2570
2602
        ;
2571
2603
 
2572
2604
slave_thread_opts:
2573
 
          { Lex->slave_thd_opt= 0; }
 
2605
          { Lex->slave_session_opt= 0; }
2574
2606
          slave_thread_opt_list
2575
2607
          {}
2576
2608
        ;
2582
2614
 
2583
2615
slave_thread_opt:
2584
2616
          /*empty*/ {}
2585
 
        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
2586
 
        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
 
2617
        | SQL_THREAD   { Lex->slave_session_opt|=SLAVE_SQL; }
 
2618
        | RELAY_THREAD { Lex->slave_session_opt|=SLAVE_IO; }
2587
2619
        ;
2588
2620
 
2589
2621
slave_until:
2730
2762
          {
2731
2763
            LEX *lex=Lex;
2732
2764
            SELECT_LEX *sl= lex->current_select;
2733
 
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
 
2765
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
2734
2766
                                       TL_IGNORE) ||
2735
 
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 
2767
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
2736
2768
                                       TL_IGNORE))
2737
2769
              DRIZZLE_YYABORT;
2738
2770
          }
2755
2787
assign_to_keycache:
2756
2788
          table_ident cache_keys_spec
2757
2789
          {
2758
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
 
2790
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2759
2791
                                           Select->pop_index_hints()))
2760
2792
              DRIZZLE_YYABORT;
2761
2793
          }
2768
2800
 
2769
2801
cache_keys_spec:
2770
2802
          {
2771
 
            Lex->select_lex.alloc_index_hints(YYTHD);
 
2803
            Lex->select_lex.alloc_index_hints(YYSession);
2772
2804
            Select->set_index_hint_type(INDEX_HINT_USE, 
2773
2805
                                        global_system_variables.old_mode ? 
2774
2806
                                        INDEX_HINT_MASK_JOIN : 
2936
2968
        | select_item
2937
2969
        | '*'
2938
2970
          {
2939
 
            THD *thd= YYTHD;
2940
 
            if (add_item_to_list(thd,
2941
 
                                 new Item_field(&thd->lex->current_select->
 
2971
            Session *session= YYSession;
 
2972
            if (add_item_to_list(session,
 
2973
                                 new Item_field(&session->lex->current_select->
2942
2974
                                                context,
2943
2975
                                                NULL, NULL, "*")))
2944
2976
              DRIZZLE_YYABORT;
2945
 
            (thd->lex->current_select->with_wild)++;
 
2977
            (session->lex->current_select->with_wild)++;
2946
2978
          }
2947
2979
        ;
2948
2980
 
2949
2981
select_item:
2950
2982
          remember_name table_wild remember_end
2951
2983
          {
2952
 
            THD *thd= YYTHD;
 
2984
            Session *session= YYSession;
2953
2985
 
2954
 
            if (add_item_to_list(thd, $2))
 
2986
            if (add_item_to_list(session, $2))
2955
2987
              DRIZZLE_YYABORT;
2956
2988
          }
2957
2989
        | remember_name expr remember_end select_alias
2958
2990
          {
2959
 
            THD *thd= YYTHD;
 
2991
            Session *session= YYSession;
2960
2992
            assert($1 < $3);
2961
2993
 
2962
 
            if (add_item_to_list(thd, $2))
 
2994
            if (add_item_to_list(session, $2))
2963
2995
              DRIZZLE_YYABORT;
2964
2996
            if ($4.str)
2965
2997
            {
2968
3000
            }
2969
3001
            else if (!$2->name)
2970
3002
            {
2971
 
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
 
3003
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2972
3004
            }
2973
3005
          }
2974
3006
        ;
2975
3007
 
2976
3008
remember_name:
2977
3009
          {
2978
 
            THD *thd= YYTHD;
2979
 
            Lex_input_stream *lip= thd->m_lip;
 
3010
            Session *session= YYSession;
 
3011
            Lex_input_stream *lip= session->m_lip;
2980
3012
            $$= (char*) lip->get_cpp_tok_start();
2981
3013
          }
2982
3014
        ;
2983
3015
 
2984
3016
remember_end:
2985
3017
          {
2986
 
            THD *thd= YYTHD;
2987
 
            Lex_input_stream *lip= thd->m_lip;
 
3018
            Session *session= YYSession;
 
3019
            Lex_input_stream *lip= session->m_lip;
2988
3020
            $$= (char*) lip->get_cpp_tok_end();
2989
3021
          }
2990
3022
        ;
3008
3040
          {
3009
3041
            /*
3010
3042
              Design notes:
3011
 
              Do not use a manually maintained stack like thd->lex->xxx_list,
 
3043
              Do not use a manually maintained stack like session->lex->xxx_list,
3012
3044
              but use the internal bison stack ($$, $1 and $3) instead.
3013
3045
              Using the bison stack is:
3014
3046
              - more robust to changes in the grammar,
3050
3082
            else
3051
3083
            {
3052
3084
              /* X OR Y */
3053
 
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
 
3085
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
3054
3086
            }
3055
3087
          }
3056
3088
        | expr XOR expr %prec XOR
3057
3089
          {
3058
3090
            /* XOR is a proprietary extension */
3059
 
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
 
3091
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
3060
3092
          }
3061
3093
        | expr and expr %prec AND_SYM
3062
3094
          {
3096
3128
            else
3097
3129
            {
3098
3130
              /* X AND Y */
3099
 
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
 
3131
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
3100
3132
            }
3101
3133
          }
3102
3134
        | NOT_SYM expr %prec NOT_SYM
3103
 
          { $$= negate_expression(YYTHD, $2); }
 
3135
          { $$= negate_expression(YYSession, $2); }
3104
3136
        | bool_pri IS TRUE_SYM %prec IS
3105
 
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
 
3137
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
3106
3138
        | bool_pri IS not TRUE_SYM %prec IS
3107
 
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
 
3139
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
3108
3140
        | bool_pri IS FALSE_SYM %prec IS
3109
 
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
 
3141
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
3110
3142
        | bool_pri IS not FALSE_SYM %prec IS
3111
 
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
 
3143
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
3112
3144
        | bool_pri IS UNKNOWN_SYM %prec IS
3113
3145
          { $$= new Item_func_isnull($1); }
3114
3146
        | bool_pri IS not UNKNOWN_SYM %prec IS
3133
3165
predicate:
3134
3166
          bit_expr IN_SYM '(' subselect ')'
3135
3167
          {
3136
 
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
 
3168
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
3137
3169
          }
3138
3170
        | bit_expr not IN_SYM '(' subselect ')'
3139
3171
          {
3140
 
            THD *thd= YYTHD;
3141
 
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
3142
 
            $$= negate_expression(thd, item);
 
3172
            Session *session= YYSession;
 
3173
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
3174
            $$= negate_expression(session, item);
3143
3175
          }
3144
3176
        | bit_expr IN_SYM '(' expr ')'
3145
3177
          {
3146
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
 
3178
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
3147
3179
          }
3148
3180
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
3149
3181
          { 
3150
3182
            $6->push_front($4);
3151
3183
            $6->push_front($1);
3152
 
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
 
3184
            $$= new (YYSession->mem_root) Item_func_in(*$6);
3153
3185
          }
3154
3186
        | bit_expr not IN_SYM '(' expr ')'
3155
3187
          {
3156
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
 
3188
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
3157
3189
          }
3158
3190
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
3159
3191
          {
3160
3192
            $7->push_front($5);
3161
3193
            $7->push_front($1);
3162
 
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
 
3194
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
3163
3195
            item->negate();
3164
3196
            $$= item;
3165
3197
          }
3234
3266
        | function_call_conflict
3235
3267
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3236
3268
          {
3237
 
            THD *thd= YYTHD;
3238
 
            Item *i1= new (thd->mem_root) Item_string($3.str,
 
3269
            Session *session= YYSession;
 
3270
            Item *i1= new (session->mem_root) Item_string($3.str,
3239
3271
                                                      $3.length,
3240
 
                                                      thd->charset());
3241
 
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
 
3272
                                                      session->charset());
 
3273
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
3242
3274
          }
3243
3275
        | literal
3244
3276
        | variable
3245
3277
        | sum_expr
3246
3278
        | '+' simple_expr %prec NEG { $$= $2; }
3247
3279
        | '-' simple_expr %prec NEG
3248
 
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
 
3280
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
3249
3281
        | '(' subselect ')'
3250
3282
          { 
3251
 
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
 
3283
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
3252
3284
          }
3253
3285
        | '(' expr ')' { $$= $2; }
3254
3286
        | '(' expr ',' expr_list ')'
3255
3287
          {
3256
3288
            $4->push_front($2);
3257
 
            $$= new (YYTHD->mem_root) Item_row(*$4);
 
3289
            $$= new (YYSession->mem_root) Item_row(*$4);
3258
3290
          }
3259
3291
        | ROW_SYM '(' expr ',' expr_list ')'
3260
3292
          {
3261
3293
            $5->push_front($3);
3262
 
            $$= new (YYTHD->mem_root) Item_row(*$5);
 
3294
            $$= new (YYSession->mem_root) Item_row(*$5);
3263
3295
          }
3264
3296
        | EXISTS '(' subselect ')'
3265
3297
          {
3266
 
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
 
3298
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
3267
3299
          }
3268
3300
        | '{' ident expr '}' { $$= $3; }
3269
3301
        | BINARY simple_expr %prec NEG
3270
3302
          {
3271
 
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
 
3303
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
3272
3304
                                 &my_charset_bin);
3273
3305
          }
3274
3306
        | CAST_SYM '(' expr AS cast_type ')'
3275
3307
          {
3276
3308
            LEX *lex= Lex;
3277
 
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
 
3309
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
3278
3310
                                 lex->charset);
3279
3311
            if (!$$)
3280
3312
              DRIZZLE_YYABORT;
3281
3313
          }
3282
3314
        | CASE_SYM opt_expr when_list opt_else END
3283
 
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
 
3315
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
3284
3316
        | CONVERT_SYM '(' expr ',' cast_type ')'
3285
3317
          {
3286
 
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
 
3318
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
3287
3319
                                 Lex->charset);
3288
3320
            if (!$$)
3289
3321
              DRIZZLE_YYABORT;
3290
3322
          }
3291
3323
        | DEFAULT '(' simple_ident ')'
3292
3324
          {
3293
 
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
 
3325
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
3294
3326
                                                         $3);
3295
3327
          }
3296
3328
        | VALUES '(' simple_ident_nospvar ')'
3297
3329
          {
3298
 
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
 
3330
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
3299
3331
                                                        $3);
3300
3332
          }
3301
3333
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3302
3334
          /* we cannot put interval before - */
3303
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3335
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
3304
3336
        ;
3305
3337
 
3306
3338
/*
3311
3343
*/
3312
3344
function_call_keyword:
3313
3345
          CHAR_SYM '(' expr_list ')'
3314
 
          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
 
3346
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
3315
3347
        | CURRENT_USER optional_braces
3316
3348
          {
3317
 
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
 
3349
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
3318
3350
            Lex->set_stmt_unsafe();
3319
3351
          }
3320
3352
        | DATE_SYM '(' expr ')'
3321
 
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
 
3353
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3322
3354
        | DAY_SYM '(' expr ')'
3323
 
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
 
3355
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
3324
3356
        | HOUR_SYM '(' expr ')'
3325
 
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
 
3357
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3326
3358
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3327
 
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3359
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
3328
3360
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3329
3361
          {
3330
 
            THD *thd= YYTHD;
3331
 
            List<Item> *list= new (thd->mem_root) List<Item>;
 
3362
            Session *session= YYSession;
 
3363
            List<Item> *list= new (session->mem_root) List<Item>;
3332
3364
            list->push_front($5);
3333
3365
            list->push_front($3);
3334
 
            Item_row *item= new (thd->mem_root) Item_row(*list);
3335
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3366
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3367
            $$= new (session->mem_root) Item_func_interval(item);
3336
3368
          }
3337
3369
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3338
3370
          {
3339
 
            THD *thd= YYTHD;
 
3371
            Session *session= YYSession;
3340
3372
            $7->push_front($5);
3341
3373
            $7->push_front($3);
3342
 
            Item_row *item= new (thd->mem_root) Item_row(*$7);
3343
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3374
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3375
            $$= new (session->mem_root) Item_func_interval(item);
3344
3376
          }
3345
3377
        | LEFT '(' expr ',' expr ')'
3346
 
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
 
3378
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3347
3379
        | MINUTE_SYM '(' expr ')'
3348
 
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
 
3380
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
3349
3381
        | MONTH_SYM '(' expr ')'
3350
 
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
 
3382
          { $$= new (YYSession->mem_root) Item_func_month($3); }
3351
3383
        | RIGHT '(' expr ',' expr ')'
3352
 
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
 
3384
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
3353
3385
        | SECOND_SYM '(' expr ')'
3354
 
          { $$= new (YYTHD->mem_root) Item_func_second($3); }
 
3386
          { $$= new (YYSession->mem_root) Item_func_second($3); }
3355
3387
        | TIME_SYM '(' expr ')'
3356
 
          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
 
3388
          { $$= new (YYSession->mem_root) Item_time_typecast($3); }
3357
3389
        | TIMESTAMP '(' expr ')'
3358
 
          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
 
3390
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
3359
3391
        | TIMESTAMP '(' expr ',' expr ')'
3360
 
          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
 
3392
          { $$= new (YYSession->mem_root) Item_func_add_time($3, $5, 1, 0); }
3361
3393
        | TRIM '(' expr ')'
3362
 
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
 
3394
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
3363
3395
        | TRIM '(' LEADING expr FROM expr ')'
3364
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
 
3396
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
3365
3397
        | TRIM '(' TRAILING expr FROM expr ')'
3366
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
 
3398
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
3367
3399
        | TRIM '(' BOTH expr FROM expr ')'
3368
 
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
 
3400
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
3369
3401
        | TRIM '(' LEADING FROM expr ')'
3370
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
 
3402
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
3371
3403
        | TRIM '(' TRAILING FROM expr ')'
3372
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
 
3404
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
3373
3405
        | TRIM '(' BOTH FROM expr ')'
3374
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
 
3406
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
3375
3407
        | TRIM '(' expr FROM expr ')'
3376
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
 
3408
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3377
3409
        | USER '(' ')'
3378
3410
          {
3379
 
            $$= new (YYTHD->mem_root) Item_func_user();
 
3411
            $$= new (YYSession->mem_root) Item_func_user();
3380
3412
            Lex->set_stmt_unsafe();
3381
3413
          }
3382
3414
        | YEAR_SYM '(' expr ')'
3383
 
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
 
3415
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3384
3416
        ;
3385
3417
 
3386
3418
/*
3398
3430
function_call_nonkeyword:
3399
3431
          ADDDATE_SYM '(' expr ',' expr ')'
3400
3432
          {
3401
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3433
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3402
3434
                                                             INTERVAL_DAY, 0);
3403
3435
          }
3404
3436
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3405
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3437
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3406
3438
        | CURDATE optional_braces
3407
3439
          {
3408
 
            $$= new (YYTHD->mem_root) Item_func_curdate_local();
 
3440
            $$= new (YYSession->mem_root) Item_func_curdate_local();
3409
3441
          }
3410
3442
        | CURTIME optional_braces
3411
3443
          {
3412
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local();
 
3444
            $$= new (YYSession->mem_root) Item_func_curtime_local();
3413
3445
          }
3414
3446
        | CURTIME '(' expr ')'
3415
3447
          {
3416
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
 
3448
            $$= new (YYSession->mem_root) Item_func_curtime_local($3);
3417
3449
          }
3418
3450
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3419
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3451
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3420
3452
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3421
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3453
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
3422
3454
        | EXTRACT_SYM '(' interval FROM expr ')'
3423
 
          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
 
3455
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
3424
3456
        | GET_FORMAT '(' date_time_type  ',' expr ')'
3425
 
          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
 
3457
          { $$= new (YYSession->mem_root) Item_func_get_format($3, $5); }
3426
3458
        | NOW_SYM optional_braces
3427
3459
          {
3428
 
            $$= new (YYTHD->mem_root) Item_func_now_local();
 
3460
            $$= new (YYSession->mem_root) Item_func_now_local();
3429
3461
          }
3430
3462
        | NOW_SYM '(' expr ')'
3431
3463
          {
3432
 
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3464
            $$= new (YYSession->mem_root) Item_func_now_local($3);
3433
3465
          }
3434
3466
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3435
 
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
 
3467
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3436
3468
        | SUBDATE_SYM '(' expr ',' expr ')'
3437
3469
          {
3438
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3470
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3439
3471
                                                             INTERVAL_DAY, 1);
3440
3472
          }
3441
3473
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3442
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
 
3474
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3443
3475
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3444
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3476
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3445
3477
        | SUBSTRING '(' expr ',' expr ')'
3446
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3478
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3447
3479
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3448
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3480
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3449
3481
        | SUBSTRING '(' expr FROM expr ')'
3450
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3482
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3451
3483
        | SYSDATE optional_braces
3452
3484
          {
3453
3485
            if (global_system_variables.sysdate_is_now == 0)
3454
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local();
 
3486
              $$= new (YYSession->mem_root) Item_func_sysdate_local();
3455
3487
            else
3456
 
              $$= new (YYTHD->mem_root) Item_func_now_local();
 
3488
              $$= new (YYSession->mem_root) Item_func_now_local();
3457
3489
          }
3458
3490
        | SYSDATE '(' expr ')'
3459
3491
          {
3460
3492
            if (global_system_variables.sysdate_is_now == 0)
3461
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
 
3493
              $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
3462
3494
            else
3463
 
              $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3495
              $$= new (YYSession->mem_root) Item_func_now_local($3);
3464
3496
          }
3465
3497
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3466
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3498
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3467
3499
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3468
 
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3500
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3469
3501
        | UTC_DATE_SYM optional_braces
3470
3502
          {
3471
 
            $$= new (YYTHD->mem_root) Item_func_curdate_utc();
 
3503
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
3472
3504
          }
3473
3505
        | UTC_TIME_SYM optional_braces
3474
3506
          {
3475
 
            $$= new (YYTHD->mem_root) Item_func_curtime_utc();
 
3507
            $$= new (YYSession->mem_root) Item_func_curtime_utc();
3476
3508
          }
3477
3509
        | UTC_TIMESTAMP_SYM optional_braces
3478
3510
          {
3479
 
            $$= new (YYTHD->mem_root) Item_func_now_utc();
 
3511
            $$= new (YYSession->mem_root) Item_func_now_utc();
3480
3512
          }
3481
3513
        ;
3482
3514
 
3487
3519
*/
3488
3520
function_call_conflict:
3489
3521
          ASCII_SYM '(' expr ')'
3490
 
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
 
3522
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
3491
3523
        | COALESCE '(' expr_list ')'
3492
 
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
 
3524
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
3493
3525
        | COLLATION_SYM '(' expr ')'
3494
 
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
 
3526
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3495
3527
        | DATABASE '(' ')'
3496
3528
          {
3497
 
            $$= new (YYTHD->mem_root) Item_func_database();
 
3529
            $$= new (YYSession->mem_root) Item_func_database();
3498
3530
          }
3499
3531
        | IF '(' expr ',' expr ',' expr ')'
3500
 
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
 
3532
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3501
3533
        | MICROSECOND_SYM '(' expr ')'
3502
 
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
 
3534
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3503
3535
        | MOD_SYM '(' expr ',' expr ')'
3504
 
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
 
3536
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
3505
3537
        | QUARTER_SYM '(' expr ')'
3506
 
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
 
3538
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3507
3539
        | REPEAT_SYM '(' expr ',' expr ')'
3508
 
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 
3540
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
3509
3541
        | REPLACE '(' expr ',' expr ',' expr ')'
3510
 
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
 
3542
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3511
3543
        | REVERSE_SYM '(' expr ')'
3512
 
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 
3544
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
3513
3545
        | TRUNCATE_SYM '(' expr ',' expr ')'
3514
 
          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
 
3546
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3515
3547
        | WEEK_SYM '(' expr ')'
3516
3548
          {
3517
 
            THD *thd= YYTHD;
3518
 
            Item *i1= new (thd->mem_root) Item_int((char*) "0",
3519
 
                                           thd->variables.default_week_format,
 
3549
            Session *session= YYSession;
 
3550
            Item *i1= new (session->mem_root) Item_int((char*) "0",
 
3551
                                           session->variables.default_week_format,
3520
3552
                                                   1);
3521
3553
 
3522
 
            $$= new (thd->mem_root) Item_func_week($3, i1);
 
3554
            $$= new (session->mem_root) Item_func_week($3, i1);
3523
3555
          }
3524
3556
        | WEEK_SYM '(' expr ',' expr ')'
3525
 
          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
 
3557
          { $$= new (YYSession->mem_root) Item_func_week($3,$5); }
3526
3558
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3527
 
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
 
3559
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
3528
3560
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3529
3561
          {
3530
 
            $$= new (YYTHD->mem_root)
 
3562
            $$= new (YYSession->mem_root)
3531
3563
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3532
3564
          }
3533
3565
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3534
3566
          {
3535
 
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
3536
 
            $$= new (YYTHD->mem_root)
 
3567
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3568
            $$= new (YYSession->mem_root)
3537
3569
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3538
3570
          }
3539
3571
        ;
3551
3583
          IDENT_sys '('
3552
3584
          {
3553
3585
            udf_func *udf= 0;
3554
 
            LEX *lex= Lex;
3555
 
            if (using_udf_functions &&
3556
 
                (udf= find_udf($1.str, $1.length)) &&
3557
 
                udf->type == UDFTYPE_AGGREGATE)
3558
 
            {
3559
 
              if (lex->current_select->inc_in_sum_expr())
3560
 
              {
3561
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
3562
 
                DRIZZLE_YYABORT;
3563
 
              }
3564
 
            }
 
3586
            udf= find_udf($1.str, $1.length);
 
3587
 
3565
3588
            /* Temporary placing the result of find_udf in $3 */
3566
3589
            $<udf>$= udf;
3567
3590
          }
3568
3591
          opt_udf_expr_list ')'
3569
3592
          {
3570
 
            THD *thd= YYTHD;
 
3593
            Session *session= YYSession;
3571
3594
            Create_func *builder;
3572
3595
            Item *item= NULL;
3573
3596
 
3580
3603
 
3581
3604
              This will be revised with WL#2128 (SQL PATH)
3582
3605
            */
3583
 
            builder= find_native_function_builder(thd, $1);
 
3606
            builder= find_native_function_builder(session, $1);
3584
3607
            if (builder)
3585
3608
            {
3586
 
              item= builder->create(thd, $1, $4);
 
3609
              item= builder->create(session, $1, $4);
3587
3610
            }
3588
3611
            else
3589
3612
            {
3591
3614
              udf_func *udf= $<udf>3;
3592
3615
              if (udf)
3593
3616
              {
3594
 
                if (udf->type == UDFTYPE_AGGREGATE)
3595
 
                {
3596
 
                  Select->in_sum_expr--;
3597
 
                }
3598
 
 
3599
 
                item= Create_udf_func::s_singleton.create(thd, udf, $4);
 
3617
                item= Create_udf_func::s_singleton.create(session, udf, $4);
3600
3618
              } else {
3601
3619
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3602
3620
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3618
3636
udf_expr_list:
3619
3637
          udf_expr
3620
3638
          {
3621
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3639
            $$= new (YYSession->mem_root) List<Item>;
3622
3640
            $$->push_back($1);
3623
3641
          }
3624
3642
        | udf_expr_list ',' udf_expr
3643
3661
              $2->set_name($4.str, $4.length, system_charset_info);
3644
3662
            }
3645
3663
            else
3646
 
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
 
3664
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
3647
3665
            $$= $2;
3648
3666
          }
3649
3667
        ;
3734
3752
              my_parse_error(ER(ER_SYNTAX_ERROR));
3735
3753
              DRIZZLE_YYABORT;
3736
3754
            }
3737
 
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
 
3755
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3738
3756
              DRIZZLE_YYABORT;
3739
3757
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
3740
3758
              Lex->set_stmt_unsafe();
3749
3767
opt_gconcat_separator:
3750
3768
          /* empty */
3751
3769
            {
3752
 
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_utf8_general_ci);
 
3770
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
3753
3771
            }
3754
3772
        | SEPARATOR_SYM text_string { $$ = $2; }
3755
3773
        ;
3791
3809
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3792
3810
        | CHAR_SYM opt_len opt_binary
3793
3811
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3794
 
        | SIGNED_SYM
3795
 
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3796
 
        | SIGNED_SYM INT_SYM
3797
 
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3798
 
        | UNSIGNED
3799
 
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3800
 
        | UNSIGNED INT_SYM
3801
 
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3802
3812
        | DATE_SYM
3803
3813
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3804
3814
        | TIME_SYM
3812
3822
expr_list:
3813
3823
          expr
3814
3824
          {
3815
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3825
            $$= new (YYSession->mem_root) List<Item>;
3816
3826
            $$->push_back($1);
3817
3827
          }
3818
3828
        | expr_list ',' expr
3854
3864
        | join_table
3855
3865
          {
3856
3866
            LEX *lex= Lex;
3857
 
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
 
3867
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3858
3868
              DRIZZLE_YYABORT;
3859
3869
          }
3860
3870
        ;
3908
3918
          {
3909
3919
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3910
3920
            /* Change the current name resolution context to a local context. */
3911
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3921
            if (push_new_name_resolution_context(YYSession, $1, $3))
3912
3922
              DRIZZLE_YYABORT;
3913
3923
            Select->parsing_place= IN_ON;
3914
3924
          }
3923
3933
          {
3924
3934
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3925
3935
            /* Change the current name resolution context to a local context. */
3926
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3936
            if (push_new_name_resolution_context(YYSession, $1, $3))
3927
3937
              DRIZZLE_YYABORT;
3928
3938
            Select->parsing_place= IN_ON;
3929
3939
          }
3953
3963
          {
3954
3964
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3955
3965
            /* Change the current name resolution context to a local context. */
3956
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3966
            if (push_new_name_resolution_context(YYSession, $1, $5))
3957
3967
              DRIZZLE_YYABORT;
3958
3968
            Select->parsing_place= IN_ON;
3959
3969
          }
3989
3999
          {
3990
4000
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3991
4001
            /* Change the current name resolution context to a local context. */
3992
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
4002
            if (push_new_name_resolution_context(YYSession, $1, $5))
3993
4003
              DRIZZLE_YYABORT;
3994
4004
            Select->parsing_place= IN_ON;
3995
4005
          }
4044
4054
          }
4045
4055
          table_ident opt_table_alias opt_key_definition
4046
4056
          {
4047
 
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
 
4057
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
4048
4058
                                                Select->get_table_join_options(),
4049
4059
                                                Lex->lock_option,
4050
4060
                                                Select->pop_index_hints())))
4067
4077
                sel->master_unit()->global_parameters=
4068
4078
                   sel->master_unit()->fake_select_lex;
4069
4079
            }
4070
 
            if ($2->init_nested_join(lex->thd))
 
4080
            if ($2->init_nested_join(lex->session))
4071
4081
              DRIZZLE_YYABORT;
4072
4082
            $$= 0;
4073
4083
            /* incomplete derived tables return NULL, we must be
4113
4123
              SELECT_LEX *sel= lex->current_select;
4114
4124
              SELECT_LEX_UNIT *unit= sel->master_unit();
4115
4125
              lex->current_select= sel= unit->outer_select();
4116
 
              if (!($$= sel->add_table_to_list(lex->thd,
 
4126
              if (!($$= sel->add_table_to_list(lex->session,
4117
4127
                                               new Table_ident(unit), $5, 0,
4118
4128
                                               TL_READ)))
4119
4129
 
4193
4203
          get_select_lex
4194
4204
          {
4195
4205
            LEX *lex= Lex;
4196
 
            if ($1->init_nested_join(lex->thd))
 
4206
            if ($1->init_nested_join(lex->session))
4197
4207
              DRIZZLE_YYABORT;
4198
4208
          }
4199
4209
          derived_table_list
4202
4212
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4203
4213
               for derived tables, both must equal NULL */
4204
4214
 
4205
 
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
 
4215
            if (!($$= $1->end_nested_join(lex->session)) && $3)
4206
4216
              DRIZZLE_YYABORT;
4207
4217
            if (!$3 && $$)
4208
4218
            {
4253
4263
 
4254
4264
            SELECT_LEX *sel= lex->current_select;
4255
4265
            TableList *embedding;
4256
 
            if (!sel->embedding || sel->end_nested_join(lex->thd))
 
4266
            if (!sel->embedding || sel->end_nested_join(lex->session))
4257
4267
            {
4258
4268
              /* we are not in parentheses */
4259
4269
              my_parse_error(ER(ER_SYNTAX_ERROR));
4307
4317
 
4308
4318
opt_index_hints_list:
4309
4319
          /* empty */
4310
 
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
 
4320
        | { Select->alloc_index_hints(YYSession); } index_hints_list
4311
4321
        ;
4312
4322
 
4313
4323
opt_key_definition:
4316
4326
        ;
4317
4327
 
4318
4328
opt_key_usage_list:
4319
 
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
 
4329
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
4320
4330
        | key_usage_list {}
4321
4331
        ;
4322
4332
 
4323
4333
key_usage_element:
4324
4334
          ident
4325
 
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
 
4335
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
4326
4336
        | PRIMARY_SYM
4327
 
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
 
4337
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
4328
4338
        ;
4329
4339
 
4330
4340
key_usage_list:
4337
4347
          {
4338
4348
            if (!($$= new List<String>))
4339
4349
              DRIZZLE_YYABORT;
4340
 
            $$->push_back(new (YYTHD->mem_root)
 
4350
            $$->push_back(new (YYSession->mem_root)
4341
4351
                              String((const char *) $1.str, $1.length,
4342
4352
                                      system_charset_info));
4343
4353
          }
4344
4354
        | using_list ',' ident
4345
4355
          {
4346
 
            $1->push_back(new (YYTHD->mem_root)
 
4356
            $1->push_back(new (YYSession->mem_root)
4347
4357
                              String((const char *) $3.str, $3.length,
4348
4358
                                      system_charset_info));
4349
4359
            $$= $1;
4476
4486
 
4477
4487
group_list:
4478
4488
          group_list ',' order_ident order_dir
4479
 
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4489
          { if (add_group_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
4480
4490
        | order_ident order_dir
4481
 
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4491
          { if (add_group_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
4482
4492
        ;
4483
4493
 
4484
4494
olap_opt:
4485
4495
          /* empty */ {}
4486
 
        | WITH_CUBE_SYM
4487
 
          {
4488
 
            /*
4489
 
              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
4490
 
              and cause LALR(2) conflicts.
4491
 
              This syntax is not standard.
4492
 
              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
4493
 
              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
4494
 
            */
4495
 
            LEX *lex=Lex;
4496
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4497
 
            {
4498
 
              my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
4499
 
                       "global union parameters");
4500
 
              DRIZZLE_YYABORT;
4501
 
            }
4502
 
            lex->current_select->olap= CUBE_TYPE;
4503
 
            my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
4504
 
            DRIZZLE_YYABORT;
4505
 
          }
4506
4496
        | WITH_ROLLUP_SYM
4507
4497
          {
4508
4498
            /*
4539
4529
alter_order_item:
4540
4530
          simple_ident_nospvar order_dir
4541
4531
          {
4542
 
            THD *thd= YYTHD;
 
4532
            Session *session= YYSession;
4543
4533
            bool ascending= ($2 == 1) ? true : false;
4544
 
            if (add_order_to_list(thd, $1, ascending))
 
4534
            if (add_order_to_list(session, $1, ascending))
4545
4535
              DRIZZLE_YYABORT;
4546
4536
          }
4547
4537
        ;
4583
4573
              if (!unit->is_union() &&
4584
4574
                  (first_sl->order_list.elements || 
4585
4575
                   first_sl->select_limit) &&            
4586
 
                  unit->add_fake_select_lex(lex->thd))
 
4576
                  unit->add_fake_select_lex(lex->session))
4587
4577
                DRIZZLE_YYABORT;
4588
4578
            }
4589
4579
          }
4592
4582
 
4593
4583
order_list:
4594
4584
          order_list ',' order_ident order_dir
4595
 
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4585
          { if (add_order_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
4596
4586
        | order_ident order_dir
4597
 
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4587
          { if (add_order_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
4598
4588
        ;
4599
4589
 
4600
4590
order_dir:
4794
4784
            lex->alter_info.build_method= $2;
4795
4785
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4796
4786
                                                               $4.str));
4797
 
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
 
4787
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4798
4788
                                                        TL_OPTION_UPDATING))
4799
4789
              DRIZZLE_YYABORT;
4800
4790
          }
4813
4803
table_name:
4814
4804
          table_ident
4815
4805
          {
4816
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
 
4806
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4817
4807
              DRIZZLE_YYABORT;
4818
4808
          }
4819
4809
        ;
4826
4816
table_alias_ref:
4827
4817
          table_ident
4828
4818
          {
4829
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
 
4819
            if (!Select->add_table_to_list(YYSession, $1, NULL,
4830
4820
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4831
4821
                                           Lex->lock_option ))
4832
4822
              DRIZZLE_YYABORT;
5057
5047
update_elem:
5058
5048
          simple_ident_nospvar equal expr_or_default
5059
5049
          {
5060
 
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
 
5050
            if (add_item_to_list(YYSession, $1) || add_value_to_list(YYSession, $3))
5061
5051
              DRIZZLE_YYABORT;
5062
5052
          }
5063
5053
        ;
5100
5090
single_multi:
5101
5091
          FROM table_ident
5102
5092
          {
5103
 
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 
5093
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
5104
5094
                                           Lex->lock_option))
5105
5095
              DRIZZLE_YYABORT;
5106
5096
          }
5130
5120
table_wild_one:
5131
5121
          ident opt_wild
5132
5122
          {
5133
 
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
 
5123
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
5134
5124
                                           NULL,
5135
5125
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5136
5126
                                           Lex->lock_option))
5138
5128
          }
5139
5129
        | ident '.' ident opt_wild
5140
5130
          {
5141
 
            if (!Select->add_table_to_list(YYTHD,
5142
 
                                           new Table_ident(YYTHD, $1, $3, 0),
 
5131
            if (!Select->add_table_to_list(YYSession,
 
5132
                                           new Table_ident(YYSession, $1, $3, 0),
5143
5133
                                           NULL,
5144
5134
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5145
5135
                                           Lex->lock_option))
5199
5189
           {
5200
5190
             LEX *lex= Lex;
5201
5191
             lex->sql_command= SQLCOM_SHOW_DATABASES;
5202
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
 
5192
             if (prepare_schema_table(YYSession, lex, 0, SCH_SCHEMATA))
5203
5193
               DRIZZLE_YYABORT;
5204
5194
           }
5205
5195
         | opt_full TABLES opt_db show_wild
5207
5197
             LEX *lex= Lex;
5208
5198
             lex->sql_command= SQLCOM_SHOW_TABLES;
5209
5199
             lex->select_lex.db= $3;
5210
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
 
5200
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLE_NAMES))
5211
5201
               DRIZZLE_YYABORT;
5212
5202
           }
5213
5203
         | TABLE_SYM STATUS_SYM opt_db show_wild
5215
5205
             LEX *lex= Lex;
5216
5206
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
5217
5207
             lex->select_lex.db= $3;
5218
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
 
5208
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLES))
5219
5209
               DRIZZLE_YYABORT;
5220
5210
           }
5221
5211
        | OPEN_SYM TABLES opt_db show_wild
5223
5213
            LEX *lex= Lex;
5224
5214
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5225
5215
            lex->select_lex.db= $3;
5226
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
 
5216
            if (prepare_schema_table(YYSession, lex, 0, SCH_OPEN_TABLES))
5227
5217
              DRIZZLE_YYABORT;
5228
5218
          }
5229
5219
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
5237
5227
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5238
5228
            if ($5)
5239
5229
              $4->change_db($5);
5240
 
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
 
5230
            if (prepare_schema_table(YYSession, lex, $4, SCH_COLUMNS))
5241
5231
              DRIZZLE_YYABORT;
5242
5232
          }
5243
5233
        | master_or_binary LOGS_SYM
5244
5234
          {
5245
5235
            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5246
5236
          }
5247
 
        | SLAVE HOSTS_SYM
5248
 
          {
5249
 
            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
5250
 
          }
5251
 
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
5252
 
          {
5253
 
            LEX *lex= Lex;
5254
 
            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
5255
 
          } opt_limit_clause_init
5256
5237
        | keys_or_index from_or_in table_ident opt_db where_clause
5257
5238
          {
5258
5239
            LEX *lex= Lex;
5259
5240
            lex->sql_command= SQLCOM_SHOW_KEYS;
5260
5241
            if ($4)
5261
5242
              $3->change_db($4);
5262
 
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
 
5243
            if (prepare_schema_table(YYSession, lex, $3, SCH_STATISTICS))
5263
5244
              DRIZZLE_YYABORT;
5264
5245
          }
5265
5246
        | COUNT_SYM '(' '*' ')' WARNINGS
5275
5256
            LEX *lex= Lex;
5276
5257
            lex->sql_command= SQLCOM_SHOW_STATUS;
5277
5258
            lex->option_type= $1;
5278
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
 
5259
            if (prepare_schema_table(YYSession, lex, 0, SCH_STATUS))
5279
5260
              DRIZZLE_YYABORT;
5280
5261
          }
5281
5262
        | opt_full PROCESSLIST_SYM
5285
5266
            LEX *lex= Lex;
5286
5267
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
5287
5268
            lex->option_type= $1;
5288
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
5289
 
              DRIZZLE_YYABORT;
5290
 
          }
5291
 
        | charset show_wild
5292
 
          {
5293
 
            LEX *lex= Lex;
5294
 
            lex->sql_command= SQLCOM_SHOW_CHARSETS;
5295
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
5296
 
              DRIZZLE_YYABORT;
5297
 
          }
5298
 
        | COLLATION_SYM show_wild
5299
 
          {
5300
 
            LEX *lex= Lex;
5301
 
            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
5302
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
 
5269
            if (prepare_schema_table(YYSession, lex, 0, SCH_VARIABLES))
5303
5270
              DRIZZLE_YYABORT;
5304
5271
          }
5305
5272
        | CREATE DATABASE opt_if_not_exists ident
5312
5279
          {
5313
5280
            LEX *lex= Lex;
5314
5281
            lex->sql_command = SQLCOM_SHOW_CREATE;
5315
 
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
 
5282
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
5316
5283
              DRIZZLE_YYABORT;
5317
5284
          }
5318
5285
        | MASTER_SYM STATUS_SYM
5344
5311
        | IN_SYM
5345
5312
        ;
5346
5313
 
5347
 
binlog_in:
5348
 
          /* empty */            { Lex->mi.log_file_name = 0; }
5349
 
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
5350
 
        ;
5351
 
 
5352
 
binlog_from:
5353
 
          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
5354
 
        | FROM ulonglong_num { Lex->mi.pos = $2; }
5355
 
        ;
5356
 
 
5357
5314
show_wild:
5358
5315
          /* empty */
5359
5316
        | LIKE TEXT_STRING_sys
5360
5317
          {
5361
 
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
 
5318
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
5362
5319
                                                    system_charset_info);
5363
5320
          }
5364
5321
        ;
5374
5331
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5375
5332
            lex->select_lex.db= 0;
5376
5333
            lex->verbose= 0;
5377
 
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
 
5334
            if (prepare_schema_table(YYSession, lex, $2, SCH_COLUMNS))
5378
5335
              DRIZZLE_YYABORT;
5379
5336
          }
5380
5337
          opt_describe_column {}
5402
5359
        | text_string { Lex->wild= $1; }
5403
5360
        | ident
5404
5361
          {
5405
 
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
 
5362
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
5406
5363
                                                    $1.length,
5407
5364
                                                    system_charset_info);
5408
5365
          }
5538
5495
load:
5539
5496
          LOAD data_file
5540
5497
          {
5541
 
            THD *thd= YYTHD;
5542
 
            LEX *lex= thd->lex;
5543
 
            Lex_input_stream *lip= thd->m_lip;
 
5498
            Session *session= YYSession;
 
5499
            LEX *lex= session->lex;
 
5500
            Lex_input_stream *lip= session->m_lip;
5544
5501
 
5545
5502
            lex->fname_start= lip->get_ptr();
5546
5503
          }
5557
5514
          }
5558
5515
          opt_duplicate INTO
5559
5516
          {
5560
 
            THD *thd= YYTHD;
5561
 
            LEX *lex= thd->lex;
5562
 
            Lex_input_stream *lip= thd->m_lip;
 
5517
            Session *session= YYSession;
 
5518
            LEX *lex= session->lex;
 
5519
            Lex_input_stream *lip= session->m_lip;
5563
5520
            lex->fname_end= lip->get_ptr();
5564
5521
          }
5565
5522
          TABLE_SYM table_ident
5566
5523
          {
5567
5524
            LEX *lex=Lex;
5568
 
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
 
5525
            if (!Select->add_table_to_list(YYSession, $13, NULL, TL_OPTION_UPDATING,
5569
5526
                                           lex->lock_option))
5570
5527
              DRIZZLE_YYABORT;
5571
5528
            lex->field_list.empty();
5702
5659
          TEXT_STRING
5703
5660
          {
5704
5661
            LEX_STRING tmp;
5705
 
            THD *thd= YYTHD;
5706
 
            const CHARSET_INFO * const cs_con= thd->variables.collation_connection;
5707
 
            const CHARSET_INFO * const cs_cli= thd->variables.character_set_client;
5708
 
            uint repertoire= thd->lex->text_string_is_7bit &&
 
5662
            Session *session= YYSession;
 
5663
            const CHARSET_INFO * const cs_con= session->variables.collation_connection;
 
5664
            const CHARSET_INFO * const cs_cli= session->variables.character_set_client;
 
5665
            uint32_t repertoire= session->lex->text_string_is_7bit &&
5709
5666
                             my_charset_is_ascii_based(cs_cli) ?
5710
5667
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
5711
 
            if (thd->charset_is_collation_connection ||
 
5668
            if (session->charset_is_collation_connection ||
5712
5669
                (repertoire == MY_REPERTOIRE_ASCII &&
5713
5670
                 my_charset_is_ascii_based(cs_con)))
5714
5671
              tmp= $1;
5715
5672
            else
5716
 
              thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
 
5673
              session->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
5717
5674
            $$= new Item_string(tmp.str, tmp.length, cs_con,
5718
5675
                                DERIVATION_COERCIBLE, repertoire);
5719
5676
          }
5735
5692
                 If the string has been pure ASCII so far,
5736
5693
                 check the new part.
5737
5694
              */
5738
 
              const CHARSET_INFO * const cs= YYTHD->variables.collation_connection;
 
5695
              const CHARSET_INFO * const cs= YYSession->variables.collation_connection;
5739
5696
              item->collation.repertoire|= my_string_repertoire(cs,
5740
5697
                                                                $2.str,
5741
5698
                                                                $2.length);
5746
5703
text_string:
5747
5704
          TEXT_STRING_literal
5748
5705
          {
5749
 
            $$= new (YYTHD->mem_root) String($1.str,
 
5706
            $$= new (YYSession->mem_root) String($1.str,
5750
5707
                                             $1.length,
5751
 
                                             YYTHD->variables.collation_connection);
 
5708
                                             YYSession->variables.collation_connection);
5752
5709
          }
5753
5710
        | HEX_NUM
5754
5711
          {
5789
5746
        | NULL_SYM
5790
5747
          {
5791
5748
            $$ = new Item_null();
5792
 
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
5749
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5793
5750
          }
5794
5751
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5795
5752
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5868
5825
          { $$ = new Item_uint($1.str, $1.length); }
5869
5826
        | DECIMAL_NUM
5870
5827
          {
5871
 
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
5872
 
            if (YYTHD->is_error())
 
5828
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
 
5829
            if (YYSession->is_error())
5873
5830
            {
5874
5831
              DRIZZLE_YYABORT;
5875
5832
            }
5877
5834
        | FLOAT_NUM
5878
5835
          {
5879
5836
            $$ = new Item_float($1.str, $1.length);
5880
 
            if (YYTHD->is_error())
 
5837
            if (YYSession->is_error())
5881
5838
            {
5882
5839
              DRIZZLE_YYABORT;
5883
5840
            }
5897
5854
          ident '.' '*'
5898
5855
          {
5899
5856
            SELECT_LEX *sel= Select;
5900
 
            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
 
5857
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5901
5858
            sel->with_wild++;
5902
5859
          }
5903
5860
        | ident '.' ident '.' '*'
5904
5861
          {
5905
5862
            SELECT_LEX *sel= Select;
5906
 
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
5907
 
                                CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5863
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
 
5864
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
5908
5865
                                $3.str,"*");
5909
5866
            sel->with_wild++;
5910
5867
          }
5921
5878
              SELECT_LEX *sel=Select;
5922
5879
              $$= (sel->parsing_place != IN_HAVING ||
5923
5880
                  sel->get_in_sum_expr() > 0) ?
5924
 
                  (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
5925
 
                  (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
5881
                  (Item*) new Item_field(Lex->current_context(),
 
5882
                                         (const char *)NULL, NULL, $1.str) :
 
5883
                  (Item*) new Item_ref(Lex->current_context(),
 
5884
                                       (const char *)NULL, NULL, $1.str);
5926
5885
            }
5927
5886
          }
5928
5887
        | simple_ident_q { $$= $1; }
5934
5893
            SELECT_LEX *sel=Select;
5935
5894
            $$= (sel->parsing_place != IN_HAVING ||
5936
5895
                sel->get_in_sum_expr() > 0) ?
5937
 
                (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
5938
 
                (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
5896
                (Item*) new Item_field(Lex->current_context(),
 
5897
                                       (const char *)NULL, NULL, $1.str) :
 
5898
                (Item*) new Item_ref(Lex->current_context(),
 
5899
                                     (const char *)NULL, NULL, $1.str);
5939
5900
          }
5940
5901
        | simple_ident_q { $$= $1; }
5941
5902
        ;
5943
5904
simple_ident_q:
5944
5905
          ident '.' ident
5945
5906
          {
5946
 
            THD *thd= YYTHD;
5947
 
            LEX *lex= thd->lex;
 
5907
            Session *session= YYSession;
 
5908
            LEX *lex= session->lex;
5948
5909
 
5949
5910
            {
5950
5911
              SELECT_LEX *sel= lex->current_select;
5951
5912
              if (sel->no_table_names_allowed)
5952
5913
              {
5953
5914
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5954
 
                         MYF(0), $1.str, thd->where);
 
5915
                         MYF(0), $1.str, session->where);
5955
5916
              }
5956
5917
              $$= (sel->parsing_place != IN_HAVING ||
5957
5918
                  sel->get_in_sum_expr() > 0) ?
5958
 
                  (Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
5959
 
                  (Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
 
5919
                  (Item*) new Item_field(Lex->current_context(),
 
5920
                                         (const char *)NULL, $1.str, $3.str) :
 
5921
                  (Item*) new Item_ref(Lex->current_context(),
 
5922
                                       (const char *)NULL, $1.str, $3.str);
5960
5923
            }
5961
5924
          }
5962
5925
        | '.' ident '.' ident
5963
5926
          {
5964
 
            THD *thd= YYTHD;
5965
 
            LEX *lex= thd->lex;
 
5927
            Session *session= YYSession;
 
5928
            LEX *lex= session->lex;
5966
5929
            SELECT_LEX *sel= lex->current_select;
5967
5930
            if (sel->no_table_names_allowed)
5968
5931
            {
5969
5932
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5970
 
                       MYF(0), $2.str, thd->where);
 
5933
                       MYF(0), $2.str, session->where);
5971
5934
            }
5972
5935
            $$= (sel->parsing_place != IN_HAVING ||
5973
5936
                sel->get_in_sum_expr() > 0) ?
5974
 
                (Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
5975
 
                (Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
 
5937
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5938
                (Item*) new Item_ref(Lex->current_context(),
 
5939
                                     (const char *)NULL, $2.str, $4.str);
5976
5940
          }
5977
5941
        | ident '.' ident '.' ident
5978
5942
          {
5979
 
            THD *thd= YYTHD;
5980
 
            LEX *lex= thd->lex;
 
5943
            Session *session= YYSession;
 
5944
            LEX *lex= session->lex;
5981
5945
            SELECT_LEX *sel= lex->current_select;
5982
5946
            if (sel->no_table_names_allowed)
5983
5947
            {
5984
5948
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5985
 
                       MYF(0), $3.str, thd->where);
 
5949
                       MYF(0), $3.str, session->where);
5986
5950
            }
5987
5951
            $$= (sel->parsing_place != IN_HAVING ||
5988
5952
                sel->get_in_sum_expr() > 0) ?
5989
5953
                (Item*) new Item_field(Lex->current_context(),
5990
 
                                       (YYTHD->client_capabilities &
5991
 
                                       CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5954
                                       (YYSession->client_capabilities &
 
5955
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
5992
5956
                                       $3.str, $5.str) :
5993
5957
                (Item*) new Item_ref(Lex->current_context(),
5994
 
                                     (YYTHD->client_capabilities &
5995
 
                                     CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5958
                                     (YYSession->client_capabilities &
 
5959
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
5996
5960
                                     $3.str, $5.str);
5997
5961
          }
5998
5962
        ;
6030
5994
 
6031
5995
table_ident:
6032
5996
          ident { $$=new Table_ident($1); }
6033
 
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
 
5997
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
6034
5998
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
6035
5999
        ;
6036
6000
 
6038
6002
          IDENT { $$= $1; }
6039
6003
        | IDENT_QUOTED
6040
6004
          {
6041
 
            THD *thd= YYTHD;
 
6005
            Session *session= YYSession;
6042
6006
 
6043
 
            if (thd->charset_is_system_charset)
 
6007
            if (session->charset_is_system_charset)
6044
6008
            {
6045
6009
              const CHARSET_INFO * const cs= system_charset_info;
6046
6010
              int dummy_error;
6047
 
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
 
6011
              uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
6048
6012
                                                   $1.str+$1.length,
6049
6013
                                                   $1.length, &dummy_error);
6050
6014
              if (wlen < $1.length)
6056
6020
              $$= $1;
6057
6021
            }
6058
6022
            else
6059
 
              thd->convert_string(&$$, system_charset_info,
6060
 
                                  $1.str, $1.length, thd->charset());
 
6023
              session->convert_string(&$$, system_charset_info,
 
6024
                                  $1.str, $1.length, session->charset());
6061
6025
          }
6062
6026
        ;
6063
6027
 
6064
6028
TEXT_STRING_sys:
6065
6029
          TEXT_STRING
6066
6030
          {
6067
 
            THD *thd= YYTHD;
 
6031
            Session *session= YYSession;
6068
6032
 
6069
 
            if (thd->charset_is_system_charset)
 
6033
            if (session->charset_is_system_charset)
6070
6034
              $$= $1;
6071
6035
            else
6072
 
              thd->convert_string(&$$, system_charset_info,
6073
 
                                  $1.str, $1.length, thd->charset());
 
6036
              session->convert_string(&$$, system_charset_info,
 
6037
                                  $1.str, $1.length, session->charset());
6074
6038
          }
6075
6039
        ;
6076
6040
 
6077
6041
TEXT_STRING_literal:
6078
6042
          TEXT_STRING
6079
6043
          {
6080
 
            THD *thd= YYTHD;
 
6044
            Session *session= YYSession;
6081
6045
 
6082
 
            if (thd->charset_is_collation_connection)
 
6046
            if (session->charset_is_collation_connection)
6083
6047
              $$= $1;
6084
6048
            else
6085
 
              thd->convert_string(&$$, thd->variables.collation_connection,
6086
 
                                  $1.str, $1.length, thd->charset());
 
6049
              session->convert_string(&$$, session->variables.collation_connection,
 
6050
                                  $1.str, $1.length, session->charset());
6087
6051
          }
6088
6052
        ;
6089
6053
 
6090
6054
TEXT_STRING_filesystem:
6091
6055
          TEXT_STRING
6092
6056
          {
6093
 
            THD *thd= YYTHD;
 
6057
            Session *session= YYSession;
6094
6058
 
6095
 
            if (thd->charset_is_character_set_filesystem)
 
6059
            if (session->charset_is_character_set_filesystem)
6096
6060
              $$= $1;
6097
6061
            else
6098
 
              thd->convert_string(&$$, thd->variables.character_set_filesystem,
6099
 
                                  $1.str, $1.length, thd->charset());
 
6062
              session->convert_string(&$$, session->variables.character_set_filesystem,
 
6063
                                  $1.str, $1.length, session->charset());
6100
6064
          }
6101
6065
        ;
6102
6066
 
6104
6068
          IDENT_sys    { $$=$1; }
6105
6069
        | keyword
6106
6070
          {
6107
 
            THD *thd= YYTHD;
6108
 
            $$.str= thd->strmake($1.str, $1.length);
 
6071
            Session *session= YYSession;
 
6072
            $$.str= session->strmake($1.str, $1.length);
6109
6073
            $$.length= $1.length;
6110
6074
          }
6111
6075
        ;
6146
6110
        | SAVEPOINT_SYM         {}
6147
6111
        | SECURITY_SYM          {}
6148
6112
        | SERVER_SYM            {}
6149
 
        | SIGNED_SYM            {}
6150
6113
        | SOCKET_SYM            {}
6151
6114
        | SLAVE                 {}
6152
6115
        | SONAME_SYM            {}
6215
6178
        | ENGINE_SYM               {}
6216
6179
        | ERRORS                   {}
6217
6180
        | ESCAPE_SYM               {}
6218
 
        | EVENTS_SYM               {}
6219
6181
        | EXCLUSIVE_SYM            {}
6220
6182
        | EXTENDED_SYM             {}
6221
6183
        | EXTENT_SIZE_SYM          {}
6461
6423
            LEX *lex=Lex;
6462
6424
            lex->option_type= $1;
6463
6425
            lex->var_list.push_back(new set_var(lex->option_type,
6464
 
                                                find_sys_var(YYTHD, "tx_isolation"),
 
6426
                                                find_sys_var(YYSession, "tx_isolation"),
6465
6427
                                                &null_lex_str,
6466
6428
                                                new Item_int((int32_t) $5)));
6467
6429
          }
6488
6450
internal_variable_name:
6489
6451
          ident
6490
6452
          {
6491
 
            THD *thd= YYTHD;
 
6453
            Session *session= YYSession;
6492
6454
 
6493
6455
            /* We have to lookup here since local vars can shadow sysvars */
6494
6456
            {
6495
6457
              /* Not an SP local variable */
6496
 
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
 
6458
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
6497
6459
              if (!tmp)
6498
6460
                DRIZZLE_YYABORT;
6499
6461
              $$.var= tmp;
6508
6470
              DRIZZLE_YYABORT;
6509
6471
            }
6510
6472
            {
6511
 
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
6473
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6512
6474
              if (!tmp)
6513
6475
                DRIZZLE_YYABORT;
6514
6476
              if (!tmp->is_struct())
6519
6481
          }
6520
6482
        | DEFAULT '.' ident
6521
6483
          {
6522
 
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
6484
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6523
6485
            if (!tmp)
6524
6486
              DRIZZLE_YYABORT;
6525
6487
            if (!tmp->is_struct())
6583
6545
        table_ident opt_table_alias table_lock_info
6584
6546
        {
6585
6547
          TableList *tlist;
6586
 
          if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
 
6548
          if (!(tlist= Select->add_table_to_list(YYSession, $1, $2, 0,
6587
6549
                                                 $3.lock_type)))
6588
6550
            DRIZZLE_YYABORT; /* purecov: inspected */
6589
6551
          tlist->lock_timeout= $3.lock_timeout;
6675
6637
 
6676
6638
opt_chain:
6677
6639
          /* empty */
6678
 
          { $$= (YYTHD->variables.completion_type == 1); }
 
6640
          { $$= (YYSession->variables.completion_type == 1); }
6679
6641
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6680
6642
        | AND_SYM CHAIN_SYM        { $$=1; }
6681
6643
        ;
6682
6644
 
6683
6645
opt_release:
6684
6646
          /* empty */
6685
 
          { $$= (YYTHD->variables.completion_type == 2); }
 
6647
          { $$= (YYSession->variables.completion_type == 2); }
6686
6648
        | RELEASE_SYM        { $$=1; }
6687
6649
        | NO_SYM RELEASE_SYM { $$=0; }
6688
6650
;
6771
6733
 
6772
6734
union_order_or_limit:
6773
6735
          {
6774
 
            THD *thd= YYTHD;
6775
 
            LEX *lex= thd->lex;
 
6736
            Session *session= YYSession;
 
6737
            LEX *lex= session->lex;
6776
6738
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6777
6739
            SELECT_LEX *sel= lex->current_select;
6778
6740
            SELECT_LEX_UNIT *unit= sel->master_unit();
6783
6745
              fake->no_table_names_allowed= 1;
6784
6746
              lex->current_select= fake;
6785
6747
            }
6786
 
            thd->where= "global ORDER clause";
 
6748
            session->where= "global ORDER clause";
6787
6749
          }
6788
6750
          order_or_limit
6789
6751
          {
6790
 
            THD *thd= YYTHD;
6791
 
            thd->lex->current_select->no_table_names_allowed= 0;
6792
 
            thd->where= "";
 
6752
            Session *session= YYSession;
 
6753
            session->lex->current_select->no_table_names_allowed= 0;
 
6754
            session->where= "";
6793
6755
          }
6794
6756
        ;
6795
6757