~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
%{
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.
 
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.
27
27
*/
28
 
#define YYPARSE_PARAM yysession
29
 
#define YYLEX_PARAM yysession
30
 
#define YYSession ((Session *)yysession)
 
28
#define YYPARSE_PARAM yythd
 
29
#define YYLEX_PARAM yythd
 
30
#define YYTHD ((THD *)yythd)
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 (YYSession->lex)
 
38
#define Lex (YYTHD->lex)
39
39
#define Select Lex->current_select
40
40
#include <drizzled/server_includes.h>
41
41
#include "lex_symbol.h"
42
 
#include <drizzled/functions/locate.h>
43
 
#include <drizzled/error.h>
44
 
#include <drizzled/nested_join.h>
45
 
#include <drizzled/sql_parse.h>
 
42
#include <storage/myisam/myisam.h>
 
43
#include <drizzled/drizzled_error_messages.h>
46
44
 
47
 
int yylex(void *yylval, void *yysession);
 
45
int yylex(void *yylval, void *yythd);
48
46
 
49
47
#define yyoverflow(A,B,C,D,E,F)               \
50
48
  {                                           \
63
61
#define DRIZZLE_YYABORT                         \
64
62
  do                                          \
65
63
  {                                           \
66
 
    LEX::cleanup_lex_after_parse_error(YYSession);\
 
64
    LEX::cleanup_lex_after_parse_error(YYTHD);\
67
65
    YYABORT;                                  \
68
66
  } while (0)
69
67
 
111
109
 
112
110
void my_parse_error(const char *s)
113
111
{
114
 
  Session *session= current_session;
115
 
  Lex_input_stream *lip= session->m_lip;
 
112
  THD *thd= current_thd;
 
113
  Lex_input_stream *lip= thd->m_lip;
116
114
 
117
115
  const char *yytext= lip->get_tok_start();
118
116
  /* Push an error into the error stack */
141
139
  to abort from the parser.
142
140
*/
143
141
 
144
 
void DRIZZLEerror(const char *s)
 
142
void MYSQLerror(const char *s)
145
143
{
146
 
  Session *session= current_session;
 
144
  THD *thd= current_thd;
147
145
 
148
146
  /*
149
147
    Restore the original LEX if it was replaced when parsing
150
148
    a stored procedure. We must ensure that a parsing error
151
 
    does not leave any side effects in the Session.
 
149
    does not leave any side effects in the THD.
152
150
  */
153
 
  LEX::cleanup_lex_after_parse_error(session);
 
151
  LEX::cleanup_lex_after_parse_error(thd);
154
152
 
155
153
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
156
154
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
163
161
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
164
162
  This function returns the proper item for the SQL expression
165
163
  <code>left [NOT] IN ( expr )</code>
166
 
  @param session the current thread
 
164
  @param thd the current thread
167
165
  @param left the in predicand
168
166
  @param equal true for IN predicates, false for NOT IN predicates
169
167
  @param expr first and only expression of the in value list
170
168
  @return an expression representing the IN predicate.
171
169
*/
172
 
Item* handle_sql2003_note184_exception(Session *session, Item* left, bool equal,
 
170
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
173
171
                                       Item *expr)
174
172
{
175
173
  /*
214
212
          Item_in_subselect(left, subselect)
215
213
      */
216
214
      subselect= expr3->invalidate_and_restore_select_lex();
217
 
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
215
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
218
216
 
219
217
      if (! equal)
220
 
        result = negate_expression(session, result);
 
218
        result = negate_expression(thd, result);
221
219
 
222
220
      return(result);
223
221
    }
224
222
  }
225
223
 
226
224
  if (equal)
227
 
    result= new (session->mem_root) Item_func_eq(left, expr);
 
225
    result= new (thd->mem_root) Item_func_eq(left, expr);
228
226
  else
229
 
    result= new (session->mem_root) Item_func_ne(left, expr);
 
227
    result= new (thd->mem_root) Item_func_ne(left, expr);
230
228
 
231
229
  return(result);
232
230
}
343
341
  thr_lock_type lock_type;
344
342
  struct st_table_lock_info table_lock_info;
345
343
  interval_type interval, interval_time_st;
346
 
  enum enum_drizzle_timestamp_type date_time_type;
 
344
  timestamp_type date_time_type;
347
345
  st_select_lex *select_lex;
348
346
  chooser_compare_func_creator boolfunc2creator;
349
347
  struct sp_cond_type *spcondtype;
362
360
 
363
361
%pure_parser                                    /* We have threads */
364
362
/*
365
 
  Currently there are 93 shift/reduce conflicts.
 
363
  Currently there are 100 shift/reduce conflicts.
366
364
  We should not introduce new conflicts any more.
367
365
*/
368
 
%expect 93
 
366
%expect 95
369
367
 
370
368
/*
371
369
   Comments for TOKENS.
515
513
%token  ERRORS
516
514
%token  ESCAPED
517
515
%token  ESCAPE_SYM                    /* SQL-2003-R */
 
516
%token  EVENTS_SYM
518
517
%token  EXCLUSIVE_SYM
519
518
%token  EXISTS                        /* SQL-2003-R */
520
519
%token  EXIT_SYM
680
679
%token  PAGE_SYM
681
680
%token  PAGE_CHECKSUM_SYM
682
681
%token  PARAM_MARKER
683
 
%token  PARSE_VCOL_EXPR_SYM
684
682
%token  PARTIAL                       /* SQL-2003-N */
685
683
%token  PHASE_SYM
686
684
%token  PLUGINS_SYM
755
753
%token  SHARE_SYM
756
754
%token  SHOW
757
755
%token  SHUTDOWN
 
756
%token  SIGNED_SYM
758
757
%token  SIMPLE_SYM                    /* SQL-2003-N */
759
758
%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
783
782
%token  STRAIGHT_JOIN
784
783
%token  STRING_SYM
785
784
%token  SUBDATE_SYM
807
806
%token  TIMESTAMP_ADD
808
807
%token  TIMESTAMP_DIFF
809
808
%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
822
822
%token  UNDERSCORE_CHARSET
823
823
%token  UNDOFILE_SYM
824
824
%token  UNDO_SYM                      /* FUTURE-USE */
 
825
%token  UNICODE_SYM
 
826
%token  UNINSTALL_SYM
825
827
%token  UNION_SYM                     /* SQL-2003-R */
826
828
%token  UNIQUE_SYM
827
829
%token  UNKNOWN_SYM                   /* SQL-2003-R */
828
830
%token  UNLOCK_SYM
 
831
%token  UNSIGNED
829
832
%token  UNTIL_SYM
830
833
%token  UPDATE_SYM                    /* SQL-2003-R */
831
834
%token  UPGRADE_SYM
845
848
%token  VARIANCE_SYM
846
849
%token  VARYING                       /* SQL-2003-R */
847
850
%token  VAR_SAMP_SYM
848
 
%token  VIRTUAL_SYM
849
851
%token  WAIT_SYM
850
852
%token  WARNINGS
851
853
%token  WEEK_SYM
853
855
%token  WHEN_SYM                      /* SQL-2003-R */
854
856
%token  WHERE                         /* SQL-2003-R */
855
857
%token  WITH                          /* SQL-2003-R */
 
858
%token  WITH_CUBE_SYM                 /* INTERNAL */
856
859
%token  WITH_ROLLUP_SYM               /* INTERNAL */
857
860
%token  WORK_SYM                      /* SQL-2003-N */
 
861
%token  WRAPPER_SYM
858
862
%token  WRITE_SYM                     /* SQL-2003-N */
859
863
%token  XOR
860
864
%token  YEAR_MONTH_SYM
897
901
        text_string opt_gconcat_separator
898
902
 
899
903
%type <num>
900
 
        type int_type real_type order_dir field_def
 
904
        type int_type real_type order_dir
901
905
        if_exists opt_local opt_table_options table_options
902
 
        table_option opt_if_not_exists
 
906
        table_option opt_if_not_exists opt_no_write_to_binlog
903
907
        opt_temporary all_or_any opt_distinct
904
908
        union_option
905
909
        start_transaction_opts opt_chain opt_release
991
995
%type <symbol> keyword keyword_sp
992
996
 
993
997
%type <charset>
 
998
        opt_collate
 
999
        charset_name
 
1000
        charset_name_or_default
 
1001
        old_or_new_charset_name
 
1002
        old_or_new_charset_name_or_default
994
1003
        collation_name
995
1004
        collation_name_or_default
 
1005
        opt_load_data_charset
996
1006
        UNDERSCORE_CHARSET
997
1007
 
998
1008
%type <variable> internal_variable_name
1017
1027
        select_item_list select_item values_list no_braces
1018
1028
        opt_limit_clause delete_limit_clause fields opt_values values
1019
1029
        opt_precision opt_ignore opt_column
1020
 
        set lock unlock string_list
1021
 
        opt_binary table_lock_list table_lock
 
1030
        set lock unlock string_list field_options field_option
 
1031
        field_opt_list opt_binary table_lock_list table_lock
1022
1032
        ref_list opt_match_clause opt_on_update_delete use
1023
1033
        opt_delete_options opt_delete_option varchar
1024
1034
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
1030
1040
        table_to_table_list table_to_table opt_table_list opt_as
1031
1041
        single_multi table_wild_list table_wild_one opt_wild
1032
1042
        union_clause union_list
1033
 
        precision subselect_start
 
1043
        precision subselect_start charset
1034
1044
        subselect_end select_var_list select_var_list_init opt_len
1035
1045
        opt_extended_describe
1036
1046
        statement
1037
1047
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1038
1048
        binlog_base64_event
1039
1049
        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
1042
1050
END_OF_INPUT
1043
1051
 
1044
1052
%type <index_hint> index_hint_type
1075
1083
query:
1076
1084
          END_OF_INPUT
1077
1085
          {
1078
 
            Session *session= YYSession;
1079
 
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
 
1086
            THD *thd= YYTHD;
 
1087
            if (!thd->bootstrap &&
 
1088
              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
1080
1089
            {
1081
1090
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1082
1091
              DRIZZLE_YYABORT;
1083
1092
            }
1084
1093
            else
1085
1094
            {
1086
 
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1095
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
1087
1096
            }
1088
1097
          }
1089
1098
        | verb_clause END_OF_INPUT {}
1114
1123
        | lock
1115
1124
        | optimize
1116
1125
        | keycache
1117
 
        | parse_vcol_expr
1118
1126
        | purge
1119
1127
        | release
1120
1128
        | rename
1190
1198
            }
1191
1199
            if (Lex->mi.heartbeat_period > slave_net_timeout)
1192
1200
            {
1193
 
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1201
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1194
1202
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1195
1203
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1196
1204
                                  " exceeds the value of `slave_net_timeout' sec.",
1201
1209
            {
1202
1210
              if (Lex->mi.heartbeat_period != 0.0)
1203
1211
              {
1204
 
                push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1212
                push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1205
1213
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1206
1214
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1207
1215
                                    " is less than 1 msec.",
1236
1244
               from 0" (4 in fact), unspecified means "don't change the position
1237
1245
               (keep the preceding value)").
1238
1246
            */
1239
 
            Lex->mi.pos = cmax((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
 
1247
            Lex->mi.pos = max((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1240
1248
          }
1241
1249
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1242
1250
          {
1246
1254
          {
1247
1255
            Lex->mi.relay_log_pos = $3;
1248
1256
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1249
 
            Lex->mi.relay_log_pos = cmax((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
 
1257
            Lex->mi.relay_log_pos = max((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1250
1258
          }
1251
1259
        ;
1252
1260
 
1255
1263
create:
1256
1264
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1257
1265
          {
1258
 
            Session *session= YYSession;
1259
 
            LEX *lex= session->lex;
 
1266
            THD *thd= YYTHD;
 
1267
            LEX *lex= thd->lex;
1260
1268
            lex->sql_command= SQLCOM_CREATE_TABLE;
1261
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1269
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
1262
1270
                                                   TL_OPTION_UPDATING,
1263
1271
                                                   TL_WRITE))
1264
1272
              DRIZZLE_YYABORT;
1265
1273
            lex->alter_info.reset();
1266
1274
            lex->col_list.empty();
1267
 
            lex->change=NULL;
 
1275
            lex->change=NullS;
1268
1276
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1269
1277
            lex->create_info.options=$2 | $4;
1270
 
            lex->create_info.db_type= ha_default_handlerton(session);
 
1278
            lex->create_info.db_type= ha_default_handlerton(thd);
1271
1279
            lex->create_info.default_table_charset= NULL;
1272
1280
            lex->name.str= 0;
1273
1281
            lex->name.length= 0;
1274
1282
          }
1275
1283
          create2
1276
1284
          {
1277
 
            LEX *lex= YYSession->lex;
 
1285
            LEX *lex= YYTHD->lex;
1278
1286
            lex->current_select= &lex->select_lex; 
1279
1287
            if (!lex->create_info.db_type)
1280
1288
            {
1281
 
              lex->create_info.db_type= ha_default_handlerton(YYSession);
1282
 
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1289
              lex->create_info.db_type= ha_default_handlerton(YYTHD);
 
1290
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1283
1291
                                  ER_WARN_USING_OTHER_HANDLER,
1284
1292
                                  ER(ER_WARN_USING_OTHER_HANDLER),
1285
1293
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
1291
1299
          {
1292
1300
            LEX *lex=Lex;
1293
1301
            lex->sql_command= SQLCOM_CREATE_INDEX;
1294
 
            if (!lex->current_select->add_table_to_list(lex->session, $8,
 
1302
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
1295
1303
                                                        NULL,
1296
1304
                                                        TL_OPTION_UPDATING))
1297
1305
              DRIZZLE_YYABORT;
1299
1307
            lex->alter_info.flags= ALTER_ADD_INDEX;
1300
1308
            lex->alter_info.build_method= $2;
1301
1309
            lex->col_list.empty();
1302
 
            lex->change=NULL;
 
1310
            lex->change=NullS;
1303
1311
          }
1304
1312
          '(' key_list ')' key_options
1305
1313
          {
1330
1338
          create3 {}
1331
1339
        | LIKE table_ident
1332
1340
          {
1333
 
            Session *session= YYSession;
1334
 
            LEX *lex= session->lex;
 
1341
            THD *thd= YYTHD;
 
1342
            LEX *lex= thd->lex;
1335
1343
 
1336
1344
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1337
 
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1345
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
1338
1346
              DRIZZLE_YYABORT;
1339
1347
          }
1340
1348
        | '(' LIKE table_ident ')'
1341
1349
          {
1342
 
            Session *session= YYSession;
1343
 
            LEX *lex= session->lex;
 
1350
            THD *thd= YYTHD;
 
1351
            LEX *lex= thd->lex;
1344
1352
 
1345
1353
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1346
 
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1354
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
1347
1355
              DRIZZLE_YYABORT;
1348
1356
          }
1349
1357
        ;
1414
1422
 
1415
1423
create_database_option:
1416
1424
          default_collation {}
 
1425
        | default_charset {}
1417
1426
        ;
1418
1427
 
1419
1428
opt_table_options:
1534
1543
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1535
1544
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
1536
1545
          }
 
1546
        | default_charset
1537
1547
        | default_collation
1538
1548
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1539
1549
          {
1556
1566
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1557
1567
            Lex->create_info.key_block_size= $3;
1558
1568
          }
 
1569
        | TRANSACTIONAL_SYM opt_equal choice
 
1570
          {
 
1571
            Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
 
1572
            Lex->create_info.transactional= $3;
 
1573
          }
 
1574
        ;
 
1575
 
 
1576
default_charset:
 
1577
          opt_default charset opt_equal charset_name_or_default
 
1578
          {
 
1579
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1580
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1581
                 cinfo->default_table_charset && $4 &&
 
1582
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1583
            {
 
1584
              my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
 
1585
                       "CHARACTER SET ", cinfo->default_table_charset->csname,
 
1586
                       "CHARACTER SET ", $4->csname);
 
1587
              DRIZZLE_YYABORT;
 
1588
            }
 
1589
            Lex->create_info.default_table_charset= $4;
 
1590
            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1591
          }
1559
1592
        ;
1560
1593
 
1561
1594
default_collation:
1578
1611
storage_engines:
1579
1612
          ident_or_text
1580
1613
          {
1581
 
            plugin_ref plugin= ha_resolve_by_name(YYSession, &$1);
 
1614
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
1582
1615
 
1583
1616
            if (plugin)
1584
1617
              $$= plugin_data(plugin, handlerton*);
1594
1627
          ident_or_text
1595
1628
          {
1596
1629
            plugin_ref plugin;
1597
 
            if ((plugin= ha_resolve_by_name(YYSession, &$1)))
 
1630
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
1598
1631
              $$= plugin_data(plugin, handlerton*);
1599
1632
            else
1600
1633
            {
1716
1749
            lex->comment=null_lex_str;
1717
1750
            lex->charset=NULL;
1718
1751
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1719
 
            lex->vcol_info= NULL;
1720
1752
          }
1721
 
          field_def
 
1753
          type opt_attribute
1722
1754
          {
1723
1755
            LEX *lex=Lex;
1724
 
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1756
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
1725
1757
                                  lex->length,lex->dec,lex->type,
1726
1758
                                  lex->column_format,
1727
1759
                                  lex->default_value, lex->on_update_value, 
1728
1760
                                  &lex->comment,
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;
 
1761
                                  lex->change,&lex->interval_list,lex->charset))
 
1762
              DRIZZLE_YYABORT;
1802
1763
          }
1803
1764
        ;
1804
1765
 
1805
1766
type:
1806
 
        int_type
 
1767
        int_type field_options 
1807
1768
        { 
1808
1769
          $$=$1; 
1809
1770
          Lex->length=(char*) 0; /* use default length */
1810
1771
        }
1811
 
        | real_type opt_precision { $$=$1; }
 
1772
        | real_type opt_precision field_options { $$=$1; }
 
1773
        | BIT_SYM
 
1774
          {
 
1775
            Lex->length= (char*) "1";
 
1776
            $$=DRIZZLE_TYPE_TINY;
 
1777
          }
 
1778
        | BOOL_SYM
 
1779
          {
 
1780
            Lex->length=(char*) "1";
 
1781
            $$=DRIZZLE_TYPE_TINY;
 
1782
          }
 
1783
        | BOOLEAN_SYM
 
1784
          {
 
1785
            Lex->length=(char*) "1";
 
1786
            $$=DRIZZLE_TYPE_TINY;
 
1787
          }
1812
1788
        | char '(' NUM ')' opt_binary
1813
1789
          {
1814
1790
            Lex->length=$3.str;
1853
1829
            $$=DRIZZLE_TYPE_BLOB; 
1854
1830
            Lex->length=(char*) 0; /* use default length */
1855
1831
          }
1856
 
        | DECIMAL_SYM float_options
1857
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1858
 
        | NUMERIC_SYM float_options
1859
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1860
 
        | FIXED_SYM float_options
 
1832
        | DECIMAL_SYM float_options field_options
 
1833
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1834
        | NUMERIC_SYM float_options field_options
 
1835
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1836
        | FIXED_SYM float_options field_options
1861
1837
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1862
1838
        | ENUM
1863
1839
          {Lex->interval_list.empty();}
1866
1842
        | SERIAL_SYM
1867
1843
          {
1868
1844
            $$=DRIZZLE_TYPE_LONGLONG;
1869
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1845
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
 
1846
              UNIQUE_FLAG);
1870
1847
          }
1871
1848
        ;
1872
1849
 
1881
1858
 
1882
1859
int_type:
1883
1860
          INT_SYM   { $$=DRIZZLE_TYPE_LONG; }
 
1861
        | TINYINT   { $$=DRIZZLE_TYPE_TINY; }
 
1862
        | SMALLINT  { $$=DRIZZLE_TYPE_SHORT; }
1884
1863
        | BIGINT    { $$=DRIZZLE_TYPE_LONGLONG; }
1885
1864
        ;
1886
1865
 
1913
1892
          }
1914
1893
        ;
1915
1894
 
 
1895
field_options:
 
1896
          /* empty */ {}
 
1897
        | field_opt_list {}
 
1898
        ;
 
1899
 
 
1900
field_opt_list:
 
1901
          field_opt_list field_option {}
 
1902
        | field_option {}
 
1903
        ;
 
1904
 
 
1905
field_option:
 
1906
          SIGNED_SYM {}
 
1907
        | UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
 
1908
        ;
 
1909
 
1916
1910
opt_len:
1917
1911
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1918
1912
        | '(' NUM ')' { Lex->length= $2.str; }
1996
1990
          { $$=$1; }
1997
1991
        ;
1998
1992
 
 
1993
charset:
 
1994
          CHAR_SYM SET {}
 
1995
        | CHARSET {}
 
1996
        ;
 
1997
 
 
1998
charset_name:
 
1999
          ident_or_text
 
2000
          {
 
2001
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
 
2002
            {
 
2003
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
 
2004
              DRIZZLE_YYABORT;
 
2005
            }
 
2006
          }
 
2007
        | BINARY { $$= &my_charset_bin; }
 
2008
        ;
 
2009
 
 
2010
charset_name_or_default:
 
2011
          charset_name { $$=$1;   }
 
2012
        | DEFAULT    { $$=NULL; }
 
2013
        ;
 
2014
 
 
2015
opt_load_data_charset:
 
2016
          /* Empty */ { $$= NULL; }
 
2017
        | charset charset_name_or_default { $$= $2; }
 
2018
        ;
 
2019
 
 
2020
old_or_new_charset_name:
 
2021
          ident_or_text
 
2022
          {
 
2023
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
 
2024
                !($$=get_old_charset_by_name($1.str)))
 
2025
            {
 
2026
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
 
2027
              DRIZZLE_YYABORT;
 
2028
            }
 
2029
          }
 
2030
        | BINARY { $$= &my_charset_bin; }
 
2031
        ;
 
2032
 
 
2033
old_or_new_charset_name_or_default:
 
2034
          old_or_new_charset_name { $$=$1;   }
 
2035
        | DEFAULT    { $$=NULL; }
 
2036
        ;
 
2037
 
1999
2038
collation_name:
2000
2039
          ident_or_text
2001
2040
          {
2007
2046
          }
2008
2047
        ;
2009
2048
 
 
2049
opt_collate:
 
2050
          /* empty */ { $$=NULL; }
 
2051
        | COLLATE_SYM collation_name_or_default { $$=$2; }
 
2052
        ;
 
2053
 
2010
2054
collation_name_or_default:
2011
2055
          collation_name { $$=$1; }
2012
2056
        | DEFAULT    { $$=NULL; }
2019
2063
 
2020
2064
opt_binary:
2021
2065
          /* empty */ { Lex->charset=NULL; }
 
2066
        | ASCII_SYM opt_bin_mod { Lex->charset=&my_charset_latin1; }
2022
2067
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
 
2068
        | UNICODE_SYM opt_bin_mod
 
2069
          {
 
2070
            if (!(Lex->charset=get_charset_by_csname("ucs2",
 
2071
                                                     MY_CS_PRIMARY,MYF(0))))
 
2072
            {
 
2073
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
 
2074
              DRIZZLE_YYABORT;
 
2075
            }
 
2076
          }
 
2077
        | charset charset_name opt_bin_mod { Lex->charset=$2; }
 
2078
        | BINARY opt_bin_charset { Lex->type|= BINCMP_FLAG; }
 
2079
        ;
 
2080
 
 
2081
opt_bin_mod:
 
2082
          /* empty */ { }
2023
2083
        | BINARY { Lex->type|= BINCMP_FLAG; }
2024
2084
        ;
2025
2085
 
 
2086
opt_bin_charset:
 
2087
          /* empty */ { Lex->charset= NULL; }
 
2088
        | ASCII_SYM { Lex->charset=&my_charset_latin1; }
 
2089
        | UNICODE_SYM
 
2090
          {
 
2091
            if (!(Lex->charset=get_charset_by_csname("ucs2",
 
2092
                                                     MY_CS_PRIMARY,MYF(0))))
 
2093
            {
 
2094
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
 
2095
              DRIZZLE_YYABORT;
 
2096
            }
 
2097
          }
 
2098
        | charset charset_name { Lex->charset=$2; }
 
2099
        ;
 
2100
 
2026
2101
ws_nweights:
2027
2102
        '(' real_ulong_num
2028
2103
        {
2074
2149
ws_level_range:
2075
2150
        ws_level_number '-' ws_level_number
2076
2151
        {
2077
 
          uint32_t start= $1;
2078
 
          uint32_t end= $3;
 
2152
          uint start= $1;
 
2153
          uint end= $3;
2079
2154
          for ($$= 0; start <= end; start++)
2080
2155
            $$|= (1 << start);
2081
2156
        }
2292
2367
alter:
2293
2368
          ALTER build_method opt_ignore TABLE_SYM table_ident
2294
2369
          {
2295
 
            Session *session= YYSession;
2296
 
            LEX *lex= session->lex;
 
2370
            THD *thd= YYTHD;
 
2371
            LEX *lex= thd->lex;
2297
2372
            lex->name.str= 0;
2298
2373
            lex->name.length= 0;
2299
2374
            lex->sql_command= SQLCOM_ALTER_TABLE;
2300
2375
            lex->duplicates= DUP_ERROR; 
2301
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2376
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
2302
2377
                                                   TL_OPTION_UPDATING))
2303
2378
              DRIZZLE_YYABORT;
2304
2379
            lex->alter_info.reset();
2311
2386
            lex->create_info.default_table_charset= NULL;
2312
2387
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
2313
2388
            lex->alter_info.reset();
 
2389
            lex->no_write_to_binlog= 0;
2314
2390
            lex->alter_info.build_method= $2;
2315
2391
          }
2316
2392
          alter_commands
2398
2474
            lex->charset= NULL;
2399
2475
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2400
2476
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2401
 
            lex->vcol_info= NULL;
2402
2477
          }
2403
 
          field_def
 
2478
          type opt_attribute
2404
2479
          {
2405
2480
            LEX *lex=Lex;
2406
 
            if (add_field_to_list(lex->session,&$3,
 
2481
            if (add_field_to_list(lex->thd,&$3,
2407
2482
                                  (enum enum_field_types) $5,
2408
2483
                                  lex->length,lex->dec,lex->type,
2409
2484
                                  lex->column_format,
2410
2485
                                  lex->default_value, lex->on_update_value,
2411
2486
                                  &lex->comment,
2412
 
                                  $3.str, &lex->interval_list, lex->charset,
2413
 
                                  lex->vcol_info))
 
2487
                                  $3.str, &lex->interval_list, lex->charset))
2414
2488
              DRIZZLE_YYABORT;
2415
2489
          }
2416
2490
          opt_place
2482
2556
            lex->name= $3->table;
2483
2557
            lex->alter_info.flags|= ALTER_RENAME;
2484
2558
          }
2485
 
        | CONVERT_SYM TO_SYM collation_name_or_default
 
2559
        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
2486
2560
          {
2487
 
            if (!$3)
2488
 
            {
2489
 
              Session *session= YYSession;
2490
 
              $3= session->variables.collation_database;
 
2561
            if (!$4)
 
2562
            {
 
2563
              THD *thd= YYTHD;
 
2564
              $4= thd->variables.collation_database;
 
2565
            }
 
2566
            $5= $5 ? $5 : $4;
 
2567
            if (!my_charset_same($4,$5))
 
2568
            {
 
2569
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
2570
                       $5->name, $4->csname);
 
2571
              DRIZZLE_YYABORT;
2491
2572
            }
2492
2573
            LEX *lex= Lex;
2493
2574
            lex->create_info.table_charset=
2494
 
            lex->create_info.default_table_charset= $3;
 
2575
            lex->create_info.default_table_charset= $5;
2495
2576
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2496
2577
              HA_CREATE_USED_DEFAULT_CHARSET);
2497
2578
            lex->alter_info.flags|= ALTER_CONVERT;
2602
2683
        ;
2603
2684
 
2604
2685
slave_thread_opts:
2605
 
          { Lex->slave_session_opt= 0; }
 
2686
          { Lex->slave_thd_opt= 0; }
2606
2687
          slave_thread_opt_list
2607
2688
          {}
2608
2689
        ;
2614
2695
 
2615
2696
slave_thread_opt:
2616
2697
          /*empty*/ {}
2617
 
        | SQL_THREAD   { Lex->slave_session_opt|=SLAVE_SQL; }
2618
 
        | RELAY_THREAD { Lex->slave_session_opt|=SLAVE_IO; }
 
2698
        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
 
2699
        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
2619
2700
        ;
2620
2701
 
2621
2702
slave_until:
2656
2737
        ;
2657
2738
 
2658
2739
repair:
2659
 
          REPAIR table_or_tables
 
2740
          REPAIR opt_no_write_to_binlog table_or_tables
2660
2741
          {
2661
2742
            LEX *lex=Lex;
2662
2743
            lex->sql_command = SQLCOM_REPAIR;
 
2744
            lex->no_write_to_binlog= $2;
2663
2745
            lex->check_opt.init();
2664
2746
          }
2665
2747
          table_list opt_mi_repair_type
2683
2765
        ;
2684
2766
 
2685
2767
analyze:
2686
 
          ANALYZE_SYM table_or_tables
 
2768
          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
2687
2769
          {
2688
2770
            LEX *lex=Lex;
2689
2771
            lex->sql_command = SQLCOM_ANALYZE;
 
2772
            lex->no_write_to_binlog= $2;
2690
2773
            lex->check_opt.init();
2691
2774
          }
2692
2775
          table_list
2733
2816
        ;
2734
2817
 
2735
2818
optimize:
2736
 
          OPTIMIZE table_or_tables
 
2819
          OPTIMIZE opt_no_write_to_binlog table_or_tables
2737
2820
          {
2738
2821
            LEX *lex=Lex;
2739
2822
            lex->sql_command = SQLCOM_OPTIMIZE;
 
2823
            lex->no_write_to_binlog= $2;
2740
2824
            lex->check_opt.init();
2741
2825
          }
2742
2826
          table_list
2743
2827
          {}
2744
2828
        ;
2745
2829
 
 
2830
opt_no_write_to_binlog:
 
2831
          /* empty */ { $$= 0; }
 
2832
        | NO_WRITE_TO_BINLOG { $$= 1; }
 
2833
        | LOCAL_SYM { $$= 1; }
 
2834
        ;
 
2835
 
2746
2836
rename:
2747
2837
          RENAME table_or_tables
2748
2838
          {
2762
2852
          {
2763
2853
            LEX *lex=Lex;
2764
2854
            SELECT_LEX *sl= lex->current_select;
2765
 
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2855
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
2766
2856
                                       TL_IGNORE) ||
2767
 
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2857
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
2768
2858
                                       TL_IGNORE))
2769
2859
              DRIZZLE_YYABORT;
2770
2860
          }
2787
2877
assign_to_keycache:
2788
2878
          table_ident cache_keys_spec
2789
2879
          {
2790
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
 
2880
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
2791
2881
                                           Select->pop_index_hints()))
2792
2882
              DRIZZLE_YYABORT;
2793
2883
          }
2800
2890
 
2801
2891
cache_keys_spec:
2802
2892
          {
2803
 
            Lex->select_lex.alloc_index_hints(YYSession);
 
2893
            Lex->select_lex.alloc_index_hints(YYTHD);
2804
2894
            Select->set_index_hint_type(INDEX_HINT_USE, 
2805
2895
                                        global_system_variables.old_mode ? 
2806
2896
                                        INDEX_HINT_MASK_JOIN : 
2968
3058
        | select_item
2969
3059
        | '*'
2970
3060
          {
2971
 
            Session *session= YYSession;
2972
 
            if (add_item_to_list(session,
2973
 
                                 new Item_field(&session->lex->current_select->
 
3061
            THD *thd= YYTHD;
 
3062
            if (add_item_to_list(thd,
 
3063
                                 new Item_field(&thd->lex->current_select->
2974
3064
                                                context,
2975
3065
                                                NULL, NULL, "*")))
2976
3066
              DRIZZLE_YYABORT;
2977
 
            (session->lex->current_select->with_wild)++;
 
3067
            (thd->lex->current_select->with_wild)++;
2978
3068
          }
2979
3069
        ;
2980
3070
 
2981
3071
select_item:
2982
3072
          remember_name table_wild remember_end
2983
3073
          {
2984
 
            Session *session= YYSession;
 
3074
            THD *thd= YYTHD;
2985
3075
 
2986
 
            if (add_item_to_list(session, $2))
 
3076
            if (add_item_to_list(thd, $2))
2987
3077
              DRIZZLE_YYABORT;
2988
3078
          }
2989
3079
        | remember_name expr remember_end select_alias
2990
3080
          {
2991
 
            Session *session= YYSession;
 
3081
            THD *thd= YYTHD;
2992
3082
            assert($1 < $3);
2993
3083
 
2994
 
            if (add_item_to_list(session, $2))
 
3084
            if (add_item_to_list(thd, $2))
2995
3085
              DRIZZLE_YYABORT;
2996
3086
            if ($4.str)
2997
3087
            {
3000
3090
            }
3001
3091
            else if (!$2->name)
3002
3092
            {
3003
 
              $2->set_name($1, (uint) ($3 - $1), session->charset());
 
3093
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
3004
3094
            }
3005
3095
          }
3006
3096
        ;
3007
3097
 
3008
3098
remember_name:
3009
3099
          {
3010
 
            Session *session= YYSession;
3011
 
            Lex_input_stream *lip= session->m_lip;
 
3100
            THD *thd= YYTHD;
 
3101
            Lex_input_stream *lip= thd->m_lip;
3012
3102
            $$= (char*) lip->get_cpp_tok_start();
3013
3103
          }
3014
3104
        ;
3015
3105
 
3016
3106
remember_end:
3017
3107
          {
3018
 
            Session *session= YYSession;
3019
 
            Lex_input_stream *lip= session->m_lip;
 
3108
            THD *thd= YYTHD;
 
3109
            Lex_input_stream *lip= thd->m_lip;
3020
3110
            $$= (char*) lip->get_cpp_tok_end();
3021
3111
          }
3022
3112
        ;
3040
3130
          {
3041
3131
            /*
3042
3132
              Design notes:
3043
 
              Do not use a manually maintained stack like session->lex->xxx_list,
 
3133
              Do not use a manually maintained stack like thd->lex->xxx_list,
3044
3134
              but use the internal bison stack ($$, $1 and $3) instead.
3045
3135
              Using the bison stack is:
3046
3136
              - more robust to changes in the grammar,
3082
3172
            else
3083
3173
            {
3084
3174
              /* X OR Y */
3085
 
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
 
3175
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
3086
3176
            }
3087
3177
          }
3088
3178
        | expr XOR expr %prec XOR
3089
3179
          {
3090
3180
            /* XOR is a proprietary extension */
3091
 
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
 
3181
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
3092
3182
          }
3093
3183
        | expr and expr %prec AND_SYM
3094
3184
          {
3128
3218
            else
3129
3219
            {
3130
3220
              /* X AND Y */
3131
 
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
 
3221
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
3132
3222
            }
3133
3223
          }
3134
3224
        | NOT_SYM expr %prec NOT_SYM
3135
 
          { $$= negate_expression(YYSession, $2); }
 
3225
          { $$= negate_expression(YYTHD, $2); }
3136
3226
        | bool_pri IS TRUE_SYM %prec IS
3137
 
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
 
3227
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
3138
3228
        | bool_pri IS not TRUE_SYM %prec IS
3139
 
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
 
3229
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
3140
3230
        | bool_pri IS FALSE_SYM %prec IS
3141
 
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
 
3231
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
3142
3232
        | bool_pri IS not FALSE_SYM %prec IS
3143
 
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
 
3233
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
3144
3234
        | bool_pri IS UNKNOWN_SYM %prec IS
3145
3235
          { $$= new Item_func_isnull($1); }
3146
3236
        | bool_pri IS not UNKNOWN_SYM %prec IS
3165
3255
predicate:
3166
3256
          bit_expr IN_SYM '(' subselect ')'
3167
3257
          {
3168
 
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
 
3258
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
3169
3259
          }
3170
3260
        | bit_expr not IN_SYM '(' subselect ')'
3171
3261
          {
3172
 
            Session *session= YYSession;
3173
 
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
3174
 
            $$= negate_expression(session, item);
 
3262
            THD *thd= YYTHD;
 
3263
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
 
3264
            $$= negate_expression(thd, item);
3175
3265
          }
3176
3266
        | bit_expr IN_SYM '(' expr ')'
3177
3267
          {
3178
 
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
3268
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
3179
3269
          }
3180
3270
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
3181
3271
          { 
3182
3272
            $6->push_front($4);
3183
3273
            $6->push_front($1);
3184
 
            $$= new (YYSession->mem_root) Item_func_in(*$6);
 
3274
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
3185
3275
          }
3186
3276
        | bit_expr not IN_SYM '(' expr ')'
3187
3277
          {
3188
 
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
3278
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
3189
3279
          }
3190
3280
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
3191
3281
          {
3192
3282
            $7->push_front($5);
3193
3283
            $7->push_front($1);
3194
 
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
 
3284
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
3195
3285
            item->negate();
3196
3286
            $$= item;
3197
3287
          }
3266
3356
        | function_call_conflict
3267
3357
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3268
3358
          {
3269
 
            Session *session= YYSession;
3270
 
            Item *i1= new (session->mem_root) Item_string($3.str,
 
3359
            THD *thd= YYTHD;
 
3360
            Item *i1= new (thd->mem_root) Item_string($3.str,
3271
3361
                                                      $3.length,
3272
 
                                                      session->charset());
3273
 
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
 
3362
                                                      thd->charset());
 
3363
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
3274
3364
          }
3275
3365
        | literal
3276
3366
        | variable
3277
3367
        | sum_expr
3278
3368
        | '+' simple_expr %prec NEG { $$= $2; }
3279
3369
        | '-' simple_expr %prec NEG
3280
 
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
 
3370
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
3281
3371
        | '(' subselect ')'
3282
3372
          { 
3283
 
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
 
3373
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
3284
3374
          }
3285
3375
        | '(' expr ')' { $$= $2; }
3286
3376
        | '(' expr ',' expr_list ')'
3287
3377
          {
3288
3378
            $4->push_front($2);
3289
 
            $$= new (YYSession->mem_root) Item_row(*$4);
 
3379
            $$= new (YYTHD->mem_root) Item_row(*$4);
3290
3380
          }
3291
3381
        | ROW_SYM '(' expr ',' expr_list ')'
3292
3382
          {
3293
3383
            $5->push_front($3);
3294
 
            $$= new (YYSession->mem_root) Item_row(*$5);
 
3384
            $$= new (YYTHD->mem_root) Item_row(*$5);
3295
3385
          }
3296
3386
        | EXISTS '(' subselect ')'
3297
3387
          {
3298
 
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
 
3388
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
3299
3389
          }
3300
3390
        | '{' ident expr '}' { $$= $3; }
3301
3391
        | BINARY simple_expr %prec NEG
3302
3392
          {
3303
 
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
 
3393
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
3304
3394
                                 &my_charset_bin);
3305
3395
          }
3306
3396
        | CAST_SYM '(' expr AS cast_type ')'
3307
3397
          {
3308
3398
            LEX *lex= Lex;
3309
 
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
3399
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
3310
3400
                                 lex->charset);
3311
3401
            if (!$$)
3312
3402
              DRIZZLE_YYABORT;
3313
3403
          }
3314
3404
        | CASE_SYM opt_expr when_list opt_else END
3315
 
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
 
3405
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
3316
3406
        | CONVERT_SYM '(' expr ',' cast_type ')'
3317
3407
          {
3318
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
 
3408
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
3319
3409
                                 Lex->charset);
3320
3410
            if (!$$)
3321
3411
              DRIZZLE_YYABORT;
3322
3412
          }
 
3413
        | CONVERT_SYM '(' expr USING charset_name ')'
 
3414
          { $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
3323
3415
        | DEFAULT '(' simple_ident ')'
3324
3416
          {
3325
 
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
 
3417
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
3326
3418
                                                         $3);
3327
3419
          }
3328
3420
        | VALUES '(' simple_ident_nospvar ')'
3329
3421
          {
3330
 
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
 
3422
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
3331
3423
                                                        $3);
3332
3424
          }
3333
3425
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3334
3426
          /* we cannot put interval before - */
3335
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3427
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
3336
3428
        ;
3337
3429
 
3338
3430
/*
3343
3435
*/
3344
3436
function_call_keyword:
3345
3437
          CHAR_SYM '(' expr_list ')'
3346
 
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
 
3438
          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
 
3439
        | CHAR_SYM '(' expr_list USING charset_name ')'
 
3440
          { $$= new (YYTHD->mem_root) Item_func_char(*$3, $5); }
3347
3441
        | CURRENT_USER optional_braces
3348
3442
          {
3349
 
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
 
3443
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
3350
3444
            Lex->set_stmt_unsafe();
3351
3445
          }
3352
3446
        | DATE_SYM '(' expr ')'
3353
 
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
 
3447
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
3354
3448
        | DAY_SYM '(' expr ')'
3355
 
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
 
3449
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
3356
3450
        | HOUR_SYM '(' expr ')'
3357
 
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
 
3451
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
3358
3452
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3359
 
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3453
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
3360
3454
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3361
3455
          {
3362
 
            Session *session= YYSession;
3363
 
            List<Item> *list= new (session->mem_root) List<Item>;
 
3456
            THD *thd= YYTHD;
 
3457
            List<Item> *list= new (thd->mem_root) List<Item>;
3364
3458
            list->push_front($5);
3365
3459
            list->push_front($3);
3366
 
            Item_row *item= new (session->mem_root) Item_row(*list);
3367
 
            $$= new (session->mem_root) Item_func_interval(item);
 
3460
            Item_row *item= new (thd->mem_root) Item_row(*list);
 
3461
            $$= new (thd->mem_root) Item_func_interval(item);
3368
3462
          }
3369
3463
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3370
3464
          {
3371
 
            Session *session= YYSession;
 
3465
            THD *thd= YYTHD;
3372
3466
            $7->push_front($5);
3373
3467
            $7->push_front($3);
3374
 
            Item_row *item= new (session->mem_root) Item_row(*$7);
3375
 
            $$= new (session->mem_root) Item_func_interval(item);
 
3468
            Item_row *item= new (thd->mem_root) Item_row(*$7);
 
3469
            $$= new (thd->mem_root) Item_func_interval(item);
3376
3470
          }
3377
3471
        | LEFT '(' expr ',' expr ')'
3378
 
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
 
3472
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
3379
3473
        | MINUTE_SYM '(' expr ')'
3380
 
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
 
3474
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
3381
3475
        | MONTH_SYM '(' expr ')'
3382
 
          { $$= new (YYSession->mem_root) Item_func_month($3); }
 
3476
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
3383
3477
        | RIGHT '(' expr ',' expr ')'
3384
 
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
 
3478
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
3385
3479
        | SECOND_SYM '(' expr ')'
3386
 
          { $$= new (YYSession->mem_root) Item_func_second($3); }
 
3480
          { $$= new (YYTHD->mem_root) Item_func_second($3); }
3387
3481
        | TIME_SYM '(' expr ')'
3388
 
          { $$= new (YYSession->mem_root) Item_time_typecast($3); }
 
3482
          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
3389
3483
        | TIMESTAMP '(' expr ')'
3390
 
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
 
3484
          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
3391
3485
        | TIMESTAMP '(' expr ',' expr ')'
3392
 
          { $$= new (YYSession->mem_root) Item_func_add_time($3, $5, 1, 0); }
 
3486
          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
3393
3487
        | TRIM '(' expr ')'
3394
 
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
 
3488
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
3395
3489
        | TRIM '(' LEADING expr FROM expr ')'
3396
 
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
 
3490
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
3397
3491
        | TRIM '(' TRAILING expr FROM expr ')'
3398
 
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
 
3492
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
3399
3493
        | TRIM '(' BOTH expr FROM expr ')'
3400
 
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
 
3494
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
3401
3495
        | TRIM '(' LEADING FROM expr ')'
3402
 
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
 
3496
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
3403
3497
        | TRIM '(' TRAILING FROM expr ')'
3404
 
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
 
3498
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
3405
3499
        | TRIM '(' BOTH FROM expr ')'
3406
 
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
 
3500
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
3407
3501
        | TRIM '(' expr FROM expr ')'
3408
 
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
 
3502
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
3409
3503
        | USER '(' ')'
3410
3504
          {
3411
 
            $$= new (YYSession->mem_root) Item_func_user();
 
3505
            $$= new (YYTHD->mem_root) Item_func_user();
3412
3506
            Lex->set_stmt_unsafe();
3413
3507
          }
3414
3508
        | YEAR_SYM '(' expr ')'
3415
 
          { $$= new (YYSession->mem_root) Item_func_year($3); }
 
3509
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
3416
3510
        ;
3417
3511
 
3418
3512
/*
3430
3524
function_call_nonkeyword:
3431
3525
          ADDDATE_SYM '(' expr ',' expr ')'
3432
3526
          {
3433
 
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
 
3527
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
3434
3528
                                                             INTERVAL_DAY, 0);
3435
3529
          }
3436
3530
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3437
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3531
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3438
3532
        | CURDATE optional_braces
3439
3533
          {
3440
 
            $$= new (YYSession->mem_root) Item_func_curdate_local();
 
3534
            $$= new (YYTHD->mem_root) Item_func_curdate_local();
3441
3535
          }
3442
3536
        | CURTIME optional_braces
3443
3537
          {
3444
 
            $$= new (YYSession->mem_root) Item_func_curtime_local();
 
3538
            $$= new (YYTHD->mem_root) Item_func_curtime_local();
3445
3539
          }
3446
3540
        | CURTIME '(' expr ')'
3447
3541
          {
3448
 
            $$= new (YYSession->mem_root) Item_func_curtime_local($3);
 
3542
            $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
3449
3543
          }
3450
3544
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3451
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3545
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
3452
3546
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3453
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3547
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
3454
3548
        | EXTRACT_SYM '(' interval FROM expr ')'
3455
 
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
 
3549
          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
3456
3550
        | GET_FORMAT '(' date_time_type  ',' expr ')'
3457
 
          { $$= new (YYSession->mem_root) Item_func_get_format($3, $5); }
 
3551
          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
3458
3552
        | NOW_SYM optional_braces
3459
3553
          {
3460
 
            $$= new (YYSession->mem_root) Item_func_now_local();
 
3554
            $$= new (YYTHD->mem_root) Item_func_now_local();
3461
3555
          }
3462
3556
        | NOW_SYM '(' expr ')'
3463
3557
          {
3464
 
            $$= new (YYSession->mem_root) Item_func_now_local($3);
 
3558
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
3465
3559
          }
3466
3560
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3467
 
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
 
3561
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
3468
3562
        | SUBDATE_SYM '(' expr ',' expr ')'
3469
3563
          {
3470
 
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
 
3564
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
3471
3565
                                                             INTERVAL_DAY, 1);
3472
3566
          }
3473
3567
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3474
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
 
3568
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3475
3569
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3476
 
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
 
3570
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
3477
3571
        | SUBSTRING '(' expr ',' expr ')'
3478
 
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
 
3572
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
3479
3573
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3480
 
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
 
3574
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
3481
3575
        | SUBSTRING '(' expr FROM expr ')'
3482
 
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
 
3576
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
3483
3577
        | SYSDATE optional_braces
3484
3578
          {
3485
3579
            if (global_system_variables.sysdate_is_now == 0)
3486
 
              $$= new (YYSession->mem_root) Item_func_sysdate_local();
 
3580
              $$= new (YYTHD->mem_root) Item_func_sysdate_local();
3487
3581
            else
3488
 
              $$= new (YYSession->mem_root) Item_func_now_local();
 
3582
              $$= new (YYTHD->mem_root) Item_func_now_local();
3489
3583
          }
3490
3584
        | SYSDATE '(' expr ')'
3491
3585
          {
3492
3586
            if (global_system_variables.sysdate_is_now == 0)
3493
 
              $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
 
3587
              $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
3494
3588
            else
3495
 
              $$= new (YYSession->mem_root) Item_func_now_local($3);
 
3589
              $$= new (YYTHD->mem_root) Item_func_now_local($3);
3496
3590
          }
3497
3591
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3498
 
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3592
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
3499
3593
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3500
 
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3594
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3501
3595
        | UTC_DATE_SYM optional_braces
3502
3596
          {
3503
 
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
 
3597
            $$= new (YYTHD->mem_root) Item_func_curdate_utc();
3504
3598
          }
3505
3599
        | UTC_TIME_SYM optional_braces
3506
3600
          {
3507
 
            $$= new (YYSession->mem_root) Item_func_curtime_utc();
 
3601
            $$= new (YYTHD->mem_root) Item_func_curtime_utc();
3508
3602
          }
3509
3603
        | UTC_TIMESTAMP_SYM optional_braces
3510
3604
          {
3511
 
            $$= new (YYSession->mem_root) Item_func_now_utc();
 
3605
            $$= new (YYTHD->mem_root) Item_func_now_utc();
3512
3606
          }
3513
3607
        ;
3514
3608
 
3519
3613
*/
3520
3614
function_call_conflict:
3521
3615
          ASCII_SYM '(' expr ')'
3522
 
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
 
3616
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
 
3617
        | CHARSET '(' expr ')'
 
3618
          { $$= new (YYTHD->mem_root) Item_func_charset($3); }
3523
3619
        | COALESCE '(' expr_list ')'
3524
 
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
 
3620
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
3525
3621
        | COLLATION_SYM '(' expr ')'
3526
 
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
 
3622
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
3527
3623
        | DATABASE '(' ')'
3528
3624
          {
3529
 
            $$= new (YYSession->mem_root) Item_func_database();
 
3625
            $$= new (YYTHD->mem_root) Item_func_database();
3530
3626
          }
3531
3627
        | IF '(' expr ',' expr ',' expr ')'
3532
 
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
 
3628
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
3533
3629
        | MICROSECOND_SYM '(' expr ')'
3534
 
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
 
3630
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
3535
3631
        | MOD_SYM '(' expr ',' expr ')'
3536
 
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
 
3632
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
3537
3633
        | QUARTER_SYM '(' expr ')'
3538
 
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
 
3634
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
3539
3635
        | REPEAT_SYM '(' expr ',' expr ')'
3540
 
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
 
3636
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
3541
3637
        | REPLACE '(' expr ',' expr ',' expr ')'
3542
 
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
 
3638
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
3543
3639
        | REVERSE_SYM '(' expr ')'
3544
 
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
 
3640
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
3545
3641
        | TRUNCATE_SYM '(' expr ',' expr ')'
3546
 
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
 
3642
          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
3547
3643
        | WEEK_SYM '(' expr ')'
3548
3644
          {
3549
 
            Session *session= YYSession;
3550
 
            Item *i1= new (session->mem_root) Item_int((char*) "0",
3551
 
                                           session->variables.default_week_format,
 
3645
            THD *thd= YYTHD;
 
3646
            Item *i1= new (thd->mem_root) Item_int((char*) "0",
 
3647
                                           thd->variables.default_week_format,
3552
3648
                                                   1);
3553
3649
 
3554
 
            $$= new (session->mem_root) Item_func_week($3, i1);
 
3650
            $$= new (thd->mem_root) Item_func_week($3, i1);
3555
3651
          }
3556
3652
        | WEEK_SYM '(' expr ',' expr ')'
3557
 
          { $$= new (YYSession->mem_root) Item_func_week($3,$5); }
 
3653
          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
3558
3654
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3559
 
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
 
3655
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
3560
3656
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3561
3657
          {
3562
 
            $$= new (YYSession->mem_root)
 
3658
            $$= new (YYTHD->mem_root)
3563
3659
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3564
3660
          }
3565
3661
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3566
3662
          {
3567
 
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
3568
 
            $$= new (YYSession->mem_root)
 
3663
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
 
3664
            $$= new (YYTHD->mem_root)
3569
3665
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3570
3666
          }
3571
3667
        ;
3583
3679
          IDENT_sys '('
3584
3680
          {
3585
3681
            udf_func *udf= 0;
3586
 
            udf= find_udf($1.str, $1.length);
3587
 
 
 
3682
            LEX *lex= Lex;
 
3683
            if (using_udf_functions &&
 
3684
                (udf= find_udf($1.str, $1.length)) &&
 
3685
                udf->type == UDFTYPE_AGGREGATE)
 
3686
            {
 
3687
              if (lex->current_select->inc_in_sum_expr())
 
3688
              {
 
3689
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
3690
                DRIZZLE_YYABORT;
 
3691
              }
 
3692
            }
3588
3693
            /* Temporary placing the result of find_udf in $3 */
3589
3694
            $<udf>$= udf;
3590
3695
          }
3591
3696
          opt_udf_expr_list ')'
3592
3697
          {
3593
 
            Session *session= YYSession;
 
3698
            THD *thd= YYTHD;
3594
3699
            Create_func *builder;
3595
3700
            Item *item= NULL;
3596
3701
 
3603
3708
 
3604
3709
              This will be revised with WL#2128 (SQL PATH)
3605
3710
            */
3606
 
            builder= find_native_function_builder(session, $1);
 
3711
            builder= find_native_function_builder(thd, $1);
3607
3712
            if (builder)
3608
3713
            {
3609
 
              item= builder->create(session, $1, $4);
 
3714
              item= builder->create(thd, $1, $4);
3610
3715
            }
3611
3716
            else
3612
3717
            {
3614
3719
              udf_func *udf= $<udf>3;
3615
3720
              if (udf)
3616
3721
              {
3617
 
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
3722
                if (udf->type == UDFTYPE_AGGREGATE)
 
3723
                {
 
3724
                  Select->in_sum_expr--;
 
3725
                }
 
3726
 
 
3727
                item= Create_udf_func::s_singleton.create(thd, udf, $4);
3618
3728
              } else {
3619
3729
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3620
3730
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3636
3746
udf_expr_list:
3637
3747
          udf_expr
3638
3748
          {
3639
 
            $$= new (YYSession->mem_root) List<Item>;
 
3749
            $$= new (YYTHD->mem_root) List<Item>;
3640
3750
            $$->push_back($1);
3641
3751
          }
3642
3752
        | udf_expr_list ',' udf_expr
3661
3771
              $2->set_name($4.str, $4.length, system_charset_info);
3662
3772
            }
3663
3773
            else
3664
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
3774
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
3665
3775
            $$= $2;
3666
3776
          }
3667
3777
        ;
3752
3862
              my_parse_error(ER(ER_SYNTAX_ERROR));
3753
3863
              DRIZZLE_YYABORT;
3754
3864
            }
3755
 
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
 
3865
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
3756
3866
              DRIZZLE_YYABORT;
3757
3867
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
3758
3868
              Lex->set_stmt_unsafe();
3767
3877
opt_gconcat_separator:
3768
3878
          /* empty */
3769
3879
            {
3770
 
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
 
3880
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
3771
3881
            }
3772
3882
        | SEPARATOR_SYM text_string { $$ = $2; }
3773
3883
        ;
3809
3919
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3810
3920
        | CHAR_SYM opt_len opt_binary
3811
3921
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
 
3922
        | SIGNED_SYM
 
3923
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3924
        | SIGNED_SYM INT_SYM
 
3925
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3926
        | UNSIGNED
 
3927
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3928
        | UNSIGNED INT_SYM
 
3929
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3812
3930
        | DATE_SYM
3813
3931
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3814
3932
        | TIME_SYM
3822
3940
expr_list:
3823
3941
          expr
3824
3942
          {
3825
 
            $$= new (YYSession->mem_root) List<Item>;
 
3943
            $$= new (YYTHD->mem_root) List<Item>;
3826
3944
            $$->push_back($1);
3827
3945
          }
3828
3946
        | expr_list ',' expr
3864
3982
        | join_table
3865
3983
          {
3866
3984
            LEX *lex= Lex;
3867
 
            if (!($$= lex->current_select->nest_last_join(lex->session)))
 
3985
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
3868
3986
              DRIZZLE_YYABORT;
3869
3987
          }
3870
3988
        ;
3918
4036
          {
3919
4037
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3920
4038
            /* Change the current name resolution context to a local context. */
3921
 
            if (push_new_name_resolution_context(YYSession, $1, $3))
 
4039
            if (push_new_name_resolution_context(YYTHD, $1, $3))
3922
4040
              DRIZZLE_YYABORT;
3923
4041
            Select->parsing_place= IN_ON;
3924
4042
          }
3933
4051
          {
3934
4052
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3935
4053
            /* Change the current name resolution context to a local context. */
3936
 
            if (push_new_name_resolution_context(YYSession, $1, $3))
 
4054
            if (push_new_name_resolution_context(YYTHD, $1, $3))
3937
4055
              DRIZZLE_YYABORT;
3938
4056
            Select->parsing_place= IN_ON;
3939
4057
          }
3963
4081
          {
3964
4082
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3965
4083
            /* Change the current name resolution context to a local context. */
3966
 
            if (push_new_name_resolution_context(YYSession, $1, $5))
 
4084
            if (push_new_name_resolution_context(YYTHD, $1, $5))
3967
4085
              DRIZZLE_YYABORT;
3968
4086
            Select->parsing_place= IN_ON;
3969
4087
          }
3999
4117
          {
4000
4118
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4001
4119
            /* Change the current name resolution context to a local context. */
4002
 
            if (push_new_name_resolution_context(YYSession, $1, $5))
 
4120
            if (push_new_name_resolution_context(YYTHD, $1, $5))
4003
4121
              DRIZZLE_YYABORT;
4004
4122
            Select->parsing_place= IN_ON;
4005
4123
          }
4054
4172
          }
4055
4173
          table_ident opt_table_alias opt_key_definition
4056
4174
          {
4057
 
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
 
4175
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
4058
4176
                                                Select->get_table_join_options(),
4059
4177
                                                Lex->lock_option,
4060
4178
                                                Select->pop_index_hints())))
4077
4195
                sel->master_unit()->global_parameters=
4078
4196
                   sel->master_unit()->fake_select_lex;
4079
4197
            }
4080
 
            if ($2->init_nested_join(lex->session))
 
4198
            if ($2->init_nested_join(lex->thd))
4081
4199
              DRIZZLE_YYABORT;
4082
4200
            $$= 0;
4083
4201
            /* incomplete derived tables return NULL, we must be
4123
4241
              SELECT_LEX *sel= lex->current_select;
4124
4242
              SELECT_LEX_UNIT *unit= sel->master_unit();
4125
4243
              lex->current_select= sel= unit->outer_select();
4126
 
              if (!($$= sel->add_table_to_list(lex->session,
 
4244
              if (!($$= sel->add_table_to_list(lex->thd,
4127
4245
                                               new Table_ident(unit), $5, 0,
4128
4246
                                               TL_READ)))
4129
4247
 
4203
4321
          get_select_lex
4204
4322
          {
4205
4323
            LEX *lex= Lex;
4206
 
            if ($1->init_nested_join(lex->session))
 
4324
            if ($1->init_nested_join(lex->thd))
4207
4325
              DRIZZLE_YYABORT;
4208
4326
          }
4209
4327
          derived_table_list
4212
4330
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4213
4331
               for derived tables, both must equal NULL */
4214
4332
 
4215
 
            if (!($$= $1->end_nested_join(lex->session)) && $3)
 
4333
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
4216
4334
              DRIZZLE_YYABORT;
4217
4335
            if (!$3 && $$)
4218
4336
            {
4263
4381
 
4264
4382
            SELECT_LEX *sel= lex->current_select;
4265
4383
            TableList *embedding;
4266
 
            if (!sel->embedding || sel->end_nested_join(lex->session))
 
4384
            if (!sel->embedding || sel->end_nested_join(lex->thd))
4267
4385
            {
4268
4386
              /* we are not in parentheses */
4269
4387
              my_parse_error(ER(ER_SYNTAX_ERROR));
4317
4435
 
4318
4436
opt_index_hints_list:
4319
4437
          /* empty */
4320
 
        | { Select->alloc_index_hints(YYSession); } index_hints_list
 
4438
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
4321
4439
        ;
4322
4440
 
4323
4441
opt_key_definition:
4326
4444
        ;
4327
4445
 
4328
4446
opt_key_usage_list:
4329
 
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
 
4447
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
4330
4448
        | key_usage_list {}
4331
4449
        ;
4332
4450
 
4333
4451
key_usage_element:
4334
4452
          ident
4335
 
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
 
4453
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
4336
4454
        | PRIMARY_SYM
4337
 
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
4455
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
4338
4456
        ;
4339
4457
 
4340
4458
key_usage_list:
4347
4465
          {
4348
4466
            if (!($$= new List<String>))
4349
4467
              DRIZZLE_YYABORT;
4350
 
            $$->push_back(new (YYSession->mem_root)
 
4468
            $$->push_back(new (YYTHD->mem_root)
4351
4469
                              String((const char *) $1.str, $1.length,
4352
4470
                                      system_charset_info));
4353
4471
          }
4354
4472
        | using_list ',' ident
4355
4473
          {
4356
 
            $1->push_back(new (YYSession->mem_root)
 
4474
            $1->push_back(new (YYTHD->mem_root)
4357
4475
                              String((const char *) $3.str, $3.length,
4358
4476
                                      system_charset_info));
4359
4477
            $$= $1;
4471
4589
        | /* empty */
4472
4590
          {
4473
4591
            Lex->escape_used= false;
4474
 
            $$= new Item_string("\\", 1, &my_charset_utf8_general_ci);
 
4592
            $$= new Item_string("\\", 1, &my_charset_latin1);
4475
4593
          }
4476
4594
        ;
4477
4595
 
4486
4604
 
4487
4605
group_list:
4488
4606
          group_list ',' order_ident order_dir
4489
 
          { if (add_group_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4607
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
4490
4608
        | order_ident order_dir
4491
 
          { if (add_group_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4609
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
4492
4610
        ;
4493
4611
 
4494
4612
olap_opt:
4495
4613
          /* empty */ {}
 
4614
        | WITH_CUBE_SYM
 
4615
          {
 
4616
            /*
 
4617
              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
 
4618
              and cause LALR(2) conflicts.
 
4619
              This syntax is not standard.
 
4620
              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
 
4621
              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
 
4622
            */
 
4623
            LEX *lex=Lex;
 
4624
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4625
            {
 
4626
              my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
 
4627
                       "global union parameters");
 
4628
              DRIZZLE_YYABORT;
 
4629
            }
 
4630
            lex->current_select->olap= CUBE_TYPE;
 
4631
            my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
 
4632
            DRIZZLE_YYABORT;
 
4633
          }
4496
4634
        | WITH_ROLLUP_SYM
4497
4635
          {
4498
4636
            /*
4529
4667
alter_order_item:
4530
4668
          simple_ident_nospvar order_dir
4531
4669
          {
4532
 
            Session *session= YYSession;
 
4670
            THD *thd= YYTHD;
4533
4671
            bool ascending= ($2 == 1) ? true : false;
4534
 
            if (add_order_to_list(session, $1, ascending))
 
4672
            if (add_order_to_list(thd, $1, ascending))
4535
4673
              DRIZZLE_YYABORT;
4536
4674
          }
4537
4675
        ;
4573
4711
              if (!unit->is_union() &&
4574
4712
                  (first_sl->order_list.elements || 
4575
4713
                   first_sl->select_limit) &&            
4576
 
                  unit->add_fake_select_lex(lex->session))
 
4714
                  unit->add_fake_select_lex(lex->thd))
4577
4715
                DRIZZLE_YYABORT;
4578
4716
            }
4579
4717
          }
4582
4720
 
4583
4721
order_list:
4584
4722
          order_list ',' order_ident order_dir
4585
 
          { if (add_order_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4723
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
4586
4724
        | order_ident order_dir
4587
 
          { if (add_order_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4725
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
4588
4726
        ;
4589
4727
 
4590
4728
order_dir:
4784
4922
            lex->alter_info.build_method= $2;
4785
4923
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4786
4924
                                                               $4.str));
4787
 
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4925
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
4788
4926
                                                        TL_OPTION_UPDATING))
4789
4927
              DRIZZLE_YYABORT;
4790
4928
          }
4803
4941
table_name:
4804
4942
          table_ident
4805
4943
          {
4806
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4944
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
4807
4945
              DRIZZLE_YYABORT;
4808
4946
          }
4809
4947
        ;
4816
4954
table_alias_ref:
4817
4955
          table_ident
4818
4956
          {
4819
 
            if (!Select->add_table_to_list(YYSession, $1, NULL,
 
4957
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
4820
4958
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4821
4959
                                           Lex->lock_option ))
4822
4960
              DRIZZLE_YYABORT;
5047
5185
update_elem:
5048
5186
          simple_ident_nospvar equal expr_or_default
5049
5187
          {
5050
 
            if (add_item_to_list(YYSession, $1) || add_value_to_list(YYSession, $3))
 
5188
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
5051
5189
              DRIZZLE_YYABORT;
5052
5190
          }
5053
5191
        ;
5090
5228
single_multi:
5091
5229
          FROM table_ident
5092
5230
          {
5093
 
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
 
5231
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
5094
5232
                                           Lex->lock_option))
5095
5233
              DRIZZLE_YYABORT;
5096
5234
          }
5120
5258
table_wild_one:
5121
5259
          ident opt_wild
5122
5260
          {
5123
 
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
 
5261
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
5124
5262
                                           NULL,
5125
5263
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5126
5264
                                           Lex->lock_option))
5128
5266
          }
5129
5267
        | ident '.' ident opt_wild
5130
5268
          {
5131
 
            if (!Select->add_table_to_list(YYSession,
5132
 
                                           new Table_ident(YYSession, $1, $3, 0),
 
5269
            if (!Select->add_table_to_list(YYTHD,
 
5270
                                           new Table_ident(YYTHD, $1, $3, 0),
5133
5271
                                           NULL,
5134
5272
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5135
5273
                                           Lex->lock_option))
5189
5327
           {
5190
5328
             LEX *lex= Lex;
5191
5329
             lex->sql_command= SQLCOM_SHOW_DATABASES;
5192
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_SCHEMATA))
 
5330
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
5193
5331
               DRIZZLE_YYABORT;
5194
5332
           }
5195
5333
         | opt_full TABLES opt_db show_wild
5197
5335
             LEX *lex= Lex;
5198
5336
             lex->sql_command= SQLCOM_SHOW_TABLES;
5199
5337
             lex->select_lex.db= $3;
5200
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLE_NAMES))
 
5338
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
5201
5339
               DRIZZLE_YYABORT;
5202
5340
           }
5203
5341
         | TABLE_SYM STATUS_SYM opt_db show_wild
5205
5343
             LEX *lex= Lex;
5206
5344
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
5207
5345
             lex->select_lex.db= $3;
5208
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLES))
 
5346
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
5209
5347
               DRIZZLE_YYABORT;
5210
5348
           }
5211
5349
        | OPEN_SYM TABLES opt_db show_wild
5213
5351
            LEX *lex= Lex;
5214
5352
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5215
5353
            lex->select_lex.db= $3;
5216
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_OPEN_TABLES))
 
5354
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
5217
5355
              DRIZZLE_YYABORT;
5218
5356
          }
5219
5357
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
5227
5365
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5228
5366
            if ($5)
5229
5367
              $4->change_db($5);
5230
 
            if (prepare_schema_table(YYSession, lex, $4, SCH_COLUMNS))
 
5368
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
5231
5369
              DRIZZLE_YYABORT;
5232
5370
          }
5233
5371
        | master_or_binary LOGS_SYM
5234
5372
          {
5235
5373
            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5236
5374
          }
 
5375
        | SLAVE HOSTS_SYM
 
5376
          {
 
5377
            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
 
5378
          }
 
5379
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
 
5380
          {
 
5381
            LEX *lex= Lex;
 
5382
            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
 
5383
          } opt_limit_clause_init
5237
5384
        | keys_or_index from_or_in table_ident opt_db where_clause
5238
5385
          {
5239
5386
            LEX *lex= Lex;
5240
5387
            lex->sql_command= SQLCOM_SHOW_KEYS;
5241
5388
            if ($4)
5242
5389
              $3->change_db($4);
5243
 
            if (prepare_schema_table(YYSession, lex, $3, SCH_STATISTICS))
 
5390
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
5244
5391
              DRIZZLE_YYABORT;
5245
5392
          }
5246
5393
        | COUNT_SYM '(' '*' ')' WARNINGS
5256
5403
            LEX *lex= Lex;
5257
5404
            lex->sql_command= SQLCOM_SHOW_STATUS;
5258
5405
            lex->option_type= $1;
5259
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_STATUS))
 
5406
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
5260
5407
              DRIZZLE_YYABORT;
5261
5408
          }
5262
5409
        | opt_full PROCESSLIST_SYM
5266
5413
            LEX *lex= Lex;
5267
5414
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
5268
5415
            lex->option_type= $1;
5269
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_VARIABLES))
 
5416
            if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
 
5417
              DRIZZLE_YYABORT;
 
5418
          }
 
5419
        | charset show_wild
 
5420
          {
 
5421
            LEX *lex= Lex;
 
5422
            lex->sql_command= SQLCOM_SHOW_CHARSETS;
 
5423
            if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
 
5424
              DRIZZLE_YYABORT;
 
5425
          }
 
5426
        | COLLATION_SYM show_wild
 
5427
          {
 
5428
            LEX *lex= Lex;
 
5429
            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
 
5430
            if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
5270
5431
              DRIZZLE_YYABORT;
5271
5432
          }
5272
5433
        | CREATE DATABASE opt_if_not_exists ident
5279
5440
          {
5280
5441
            LEX *lex= Lex;
5281
5442
            lex->sql_command = SQLCOM_SHOW_CREATE;
5282
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
5443
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
5283
5444
              DRIZZLE_YYABORT;
5284
5445
          }
5285
5446
        | MASTER_SYM STATUS_SYM
5311
5472
        | IN_SYM
5312
5473
        ;
5313
5474
 
 
5475
binlog_in:
 
5476
          /* empty */            { Lex->mi.log_file_name = 0; }
 
5477
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
 
5478
        ;
 
5479
 
 
5480
binlog_from:
 
5481
          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
 
5482
        | FROM ulonglong_num { Lex->mi.pos = $2; }
 
5483
        ;
 
5484
 
5314
5485
show_wild:
5315
5486
          /* empty */
5316
5487
        | LIKE TEXT_STRING_sys
5317
5488
          {
5318
 
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
 
5489
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
5319
5490
                                                    system_charset_info);
5320
5491
          }
5321
5492
        ;
5331
5502
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5332
5503
            lex->select_lex.db= 0;
5333
5504
            lex->verbose= 0;
5334
 
            if (prepare_schema_table(YYSession, lex, $2, SCH_COLUMNS))
 
5505
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
5335
5506
              DRIZZLE_YYABORT;
5336
5507
          }
5337
5508
          opt_describe_column {}
5359
5530
        | text_string { Lex->wild= $1; }
5360
5531
        | ident
5361
5532
          {
5362
 
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
 
5533
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
5363
5534
                                                    $1.length,
5364
5535
                                                    system_charset_info);
5365
5536
          }
5369
5540
/* flush things */
5370
5541
 
5371
5542
flush:
5372
 
          FLUSH_SYM
 
5543
          FLUSH_SYM opt_no_write_to_binlog
5373
5544
          {
5374
5545
            LEX *lex=Lex;
5375
5546
            lex->sql_command= SQLCOM_FLUSH;
5376
5547
            lex->type= 0;
 
5548
            lex->no_write_to_binlog= $2;
5377
5549
          }
5378
5550
          flush_options
5379
5551
          {}
5495
5667
load:
5496
5668
          LOAD data_file
5497
5669
          {
5498
 
            Session *session= YYSession;
5499
 
            LEX *lex= session->lex;
5500
 
            Lex_input_stream *lip= session->m_lip;
 
5670
            THD *thd= YYTHD;
 
5671
            LEX *lex= thd->lex;
 
5672
            Lex_input_stream *lip= thd->m_lip;
5501
5673
 
5502
5674
            lex->fname_start= lip->get_ptr();
5503
5675
          }
5514
5686
          }
5515
5687
          opt_duplicate INTO
5516
5688
          {
5517
 
            Session *session= YYSession;
5518
 
            LEX *lex= session->lex;
5519
 
            Lex_input_stream *lip= session->m_lip;
 
5689
            THD *thd= YYTHD;
 
5690
            LEX *lex= thd->lex;
 
5691
            Lex_input_stream *lip= thd->m_lip;
5520
5692
            lex->fname_end= lip->get_ptr();
5521
5693
          }
5522
5694
          TABLE_SYM table_ident
5523
5695
          {
5524
5696
            LEX *lex=Lex;
5525
 
            if (!Select->add_table_to_list(YYSession, $13, NULL, TL_OPTION_UPDATING,
 
5697
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
5526
5698
                                           lex->lock_option))
5527
5699
              DRIZZLE_YYABORT;
5528
5700
            lex->field_list.empty();
5529
5701
            lex->update_list.empty();
5530
5702
            lex->value_list.empty();
5531
5703
          }
 
5704
          opt_load_data_charset
 
5705
          { Lex->exchange->cs= $15; }
5532
5706
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5533
5707
          opt_load_data_set_spec
5534
5708
          {}
5659
5833
          TEXT_STRING
5660
5834
          {
5661
5835
            LEX_STRING tmp;
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 &&
 
5836
            THD *thd= YYTHD;
 
5837
            const CHARSET_INFO * const cs_con= thd->variables.collation_connection;
 
5838
            const CHARSET_INFO * const cs_cli= thd->variables.character_set_client;
 
5839
            uint repertoire= thd->lex->text_string_is_7bit &&
5666
5840
                             my_charset_is_ascii_based(cs_cli) ?
5667
5841
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
5668
 
            if (session->charset_is_collation_connection ||
 
5842
            if (thd->charset_is_collation_connection ||
5669
5843
                (repertoire == MY_REPERTOIRE_ASCII &&
5670
5844
                 my_charset_is_ascii_based(cs_con)))
5671
5845
              tmp= $1;
5672
5846
            else
5673
 
              session->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
 
5847
              thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
5674
5848
            $$= new Item_string(tmp.str, tmp.length, cs_con,
5675
5849
                                DERIVATION_COERCIBLE, repertoire);
5676
5850
          }
5692
5866
                 If the string has been pure ASCII so far,
5693
5867
                 check the new part.
5694
5868
              */
5695
 
              const CHARSET_INFO * const cs= YYSession->variables.collation_connection;
 
5869
              const CHARSET_INFO * const cs= YYTHD->variables.collation_connection;
5696
5870
              item->collation.repertoire|= my_string_repertoire(cs,
5697
5871
                                                                $2.str,
5698
5872
                                                                $2.length);
5703
5877
text_string:
5704
5878
          TEXT_STRING_literal
5705
5879
          {
5706
 
            $$= new (YYSession->mem_root) String($1.str,
 
5880
            $$= new (YYTHD->mem_root) String($1.str,
5707
5881
                                             $1.length,
5708
 
                                             YYSession->variables.collation_connection);
 
5882
                                             YYTHD->variables.collation_connection);
5709
5883
          }
5710
5884
        | HEX_NUM
5711
5885
          {
5746
5920
        | NULL_SYM
5747
5921
          {
5748
5922
            $$ = new Item_null();
5749
 
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
5923
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5750
5924
          }
5751
5925
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5752
5926
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5825
5999
          { $$ = new Item_uint($1.str, $1.length); }
5826
6000
        | DECIMAL_NUM
5827
6001
          {
5828
 
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
5829
 
            if (YYSession->is_error())
 
6002
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
 
6003
            if (YYTHD->is_error())
5830
6004
            {
5831
6005
              DRIZZLE_YYABORT;
5832
6006
            }
5834
6008
        | FLOAT_NUM
5835
6009
          {
5836
6010
            $$ = new Item_float($1.str, $1.length);
5837
 
            if (YYSession->is_error())
 
6011
            if (YYTHD->is_error())
5838
6012
            {
5839
6013
              DRIZZLE_YYABORT;
5840
6014
            }
5854
6028
          ident '.' '*'
5855
6029
          {
5856
6030
            SELECT_LEX *sel= Select;
5857
 
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
6031
            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
5858
6032
            sel->with_wild++;
5859
6033
          }
5860
6034
        | ident '.' ident '.' '*'
5861
6035
          {
5862
6036
            SELECT_LEX *sel= Select;
5863
 
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
5864
 
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
 
6037
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
 
6038
                                CLIENT_NO_SCHEMA ? NullS : $1.str),
5865
6039
                                $3.str,"*");
5866
6040
            sel->with_wild++;
5867
6041
          }
5878
6052
              SELECT_LEX *sel=Select;
5879
6053
              $$= (sel->parsing_place != IN_HAVING ||
5880
6054
                  sel->get_in_sum_expr() > 0) ?
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);
 
6055
                  (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
 
6056
                  (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
5885
6057
            }
5886
6058
          }
5887
6059
        | simple_ident_q { $$= $1; }
5893
6065
            SELECT_LEX *sel=Select;
5894
6066
            $$= (sel->parsing_place != IN_HAVING ||
5895
6067
                sel->get_in_sum_expr() > 0) ?
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);
 
6068
                (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
 
6069
                (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
5900
6070
          }
5901
6071
        | simple_ident_q { $$= $1; }
5902
6072
        ;
5904
6074
simple_ident_q:
5905
6075
          ident '.' ident
5906
6076
          {
5907
 
            Session *session= YYSession;
5908
 
            LEX *lex= session->lex;
 
6077
            THD *thd= YYTHD;
 
6078
            LEX *lex= thd->lex;
5909
6079
 
5910
6080
            {
5911
6081
              SELECT_LEX *sel= lex->current_select;
5912
6082
              if (sel->no_table_names_allowed)
5913
6083
              {
5914
6084
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5915
 
                         MYF(0), $1.str, session->where);
 
6085
                         MYF(0), $1.str, thd->where);
5916
6086
              }
5917
6087
              $$= (sel->parsing_place != IN_HAVING ||
5918
6088
                  sel->get_in_sum_expr() > 0) ?
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);
 
6089
                  (Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
 
6090
                  (Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
5923
6091
            }
5924
6092
          }
5925
6093
        | '.' ident '.' ident
5926
6094
          {
5927
 
            Session *session= YYSession;
5928
 
            LEX *lex= session->lex;
 
6095
            THD *thd= YYTHD;
 
6096
            LEX *lex= thd->lex;
5929
6097
            SELECT_LEX *sel= lex->current_select;
5930
6098
            if (sel->no_table_names_allowed)
5931
6099
            {
5932
6100
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5933
 
                       MYF(0), $2.str, session->where);
 
6101
                       MYF(0), $2.str, thd->where);
5934
6102
            }
5935
6103
            $$= (sel->parsing_place != IN_HAVING ||
5936
6104
                sel->get_in_sum_expr() > 0) ?
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);
 
6105
                (Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
 
6106
                (Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
5940
6107
          }
5941
6108
        | ident '.' ident '.' ident
5942
6109
          {
5943
 
            Session *session= YYSession;
5944
 
            LEX *lex= session->lex;
 
6110
            THD *thd= YYTHD;
 
6111
            LEX *lex= thd->lex;
5945
6112
            SELECT_LEX *sel= lex->current_select;
5946
6113
            if (sel->no_table_names_allowed)
5947
6114
            {
5948
6115
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5949
 
                       MYF(0), $3.str, session->where);
 
6116
                       MYF(0), $3.str, thd->where);
5950
6117
            }
5951
6118
            $$= (sel->parsing_place != IN_HAVING ||
5952
6119
                sel->get_in_sum_expr() > 0) ?
5953
6120
                (Item*) new Item_field(Lex->current_context(),
5954
 
                                       (YYSession->client_capabilities &
5955
 
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
 
6121
                                       (YYTHD->client_capabilities &
 
6122
                                       CLIENT_NO_SCHEMA ? NullS : $1.str),
5956
6123
                                       $3.str, $5.str) :
5957
6124
                (Item*) new Item_ref(Lex->current_context(),
5958
 
                                     (YYSession->client_capabilities &
5959
 
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
 
6125
                                     (YYTHD->client_capabilities &
 
6126
                                     CLIENT_NO_SCHEMA ? NullS : $1.str),
5960
6127
                                     $3.str, $5.str);
5961
6128
          }
5962
6129
        ;
5994
6161
 
5995
6162
table_ident:
5996
6163
          ident { $$=new Table_ident($1); }
5997
 
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
 
6164
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
5998
6165
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
5999
6166
        ;
6000
6167
 
6002
6169
          IDENT { $$= $1; }
6003
6170
        | IDENT_QUOTED
6004
6171
          {
6005
 
            Session *session= YYSession;
 
6172
            THD *thd= YYTHD;
6006
6173
 
6007
 
            if (session->charset_is_system_charset)
 
6174
            if (thd->charset_is_system_charset)
6008
6175
            {
6009
6176
              const CHARSET_INFO * const cs= system_charset_info;
6010
6177
              int dummy_error;
6011
 
              uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
 
6178
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
6012
6179
                                                   $1.str+$1.length,
6013
6180
                                                   $1.length, &dummy_error);
6014
6181
              if (wlen < $1.length)
6020
6187
              $$= $1;
6021
6188
            }
6022
6189
            else
6023
 
              session->convert_string(&$$, system_charset_info,
6024
 
                                  $1.str, $1.length, session->charset());
 
6190
              thd->convert_string(&$$, system_charset_info,
 
6191
                                  $1.str, $1.length, thd->charset());
6025
6192
          }
6026
6193
        ;
6027
6194
 
6028
6195
TEXT_STRING_sys:
6029
6196
          TEXT_STRING
6030
6197
          {
6031
 
            Session *session= YYSession;
 
6198
            THD *thd= YYTHD;
6032
6199
 
6033
 
            if (session->charset_is_system_charset)
 
6200
            if (thd->charset_is_system_charset)
6034
6201
              $$= $1;
6035
6202
            else
6036
 
              session->convert_string(&$$, system_charset_info,
6037
 
                                  $1.str, $1.length, session->charset());
 
6203
              thd->convert_string(&$$, system_charset_info,
 
6204
                                  $1.str, $1.length, thd->charset());
6038
6205
          }
6039
6206
        ;
6040
6207
 
6041
6208
TEXT_STRING_literal:
6042
6209
          TEXT_STRING
6043
6210
          {
6044
 
            Session *session= YYSession;
 
6211
            THD *thd= YYTHD;
6045
6212
 
6046
 
            if (session->charset_is_collation_connection)
 
6213
            if (thd->charset_is_collation_connection)
6047
6214
              $$= $1;
6048
6215
            else
6049
 
              session->convert_string(&$$, session->variables.collation_connection,
6050
 
                                  $1.str, $1.length, session->charset());
 
6216
              thd->convert_string(&$$, thd->variables.collation_connection,
 
6217
                                  $1.str, $1.length, thd->charset());
6051
6218
          }
6052
6219
        ;
6053
6220
 
6054
6221
TEXT_STRING_filesystem:
6055
6222
          TEXT_STRING
6056
6223
          {
6057
 
            Session *session= YYSession;
 
6224
            THD *thd= YYTHD;
6058
6225
 
6059
 
            if (session->charset_is_character_set_filesystem)
 
6226
            if (thd->charset_is_character_set_filesystem)
6060
6227
              $$= $1;
6061
6228
            else
6062
 
              session->convert_string(&$$, session->variables.character_set_filesystem,
6063
 
                                  $1.str, $1.length, session->charset());
 
6229
              thd->convert_string(&$$, thd->variables.character_set_filesystem,
 
6230
                                  $1.str, $1.length, thd->charset());
6064
6231
          }
6065
6232
        ;
6066
6233
 
6068
6235
          IDENT_sys    { $$=$1; }
6069
6236
        | keyword
6070
6237
          {
6071
 
            Session *session= YYSession;
6072
 
            $$.str= session->strmake($1.str, $1.length);
 
6238
            THD *thd= YYTHD;
 
6239
            $$.str= thd->strmake($1.str, $1.length);
6073
6240
            $$.length= $1.length;
6074
6241
          }
6075
6242
        ;
6110
6277
        | SAVEPOINT_SYM         {}
6111
6278
        | SECURITY_SYM          {}
6112
6279
        | SERVER_SYM            {}
 
6280
        | SIGNED_SYM            {}
6113
6281
        | SOCKET_SYM            {}
6114
6282
        | SLAVE                 {}
6115
6283
        | SONAME_SYM            {}
6116
6284
        | START_SYM             {}
6117
6285
        | STOP_SYM              {}
6118
6286
        | TRUNCATE_SYM          {}
 
6287
        | UNICODE_SYM           {}
 
6288
        | UNINSTALL_SYM         {}
 
6289
        | WRAPPER_SYM           {}
6119
6290
        | UPGRADE_SYM           {}
6120
6291
        ;
6121
6292
 
6178
6349
        | ENGINE_SYM               {}
6179
6350
        | ERRORS                   {}
6180
6351
        | ESCAPE_SYM               {}
 
6352
        | EVENTS_SYM               {}
6181
6353
        | EXCLUSIVE_SYM            {}
6182
6354
        | EXTENDED_SYM             {}
6183
6355
        | EXTENT_SIZE_SYM          {}
6423
6595
            LEX *lex=Lex;
6424
6596
            lex->option_type= $1;
6425
6597
            lex->var_list.push_back(new set_var(lex->option_type,
6426
 
                                                find_sys_var(YYSession, "tx_isolation"),
 
6598
                                                find_sys_var(YYTHD, "tx_isolation"),
6427
6599
                                                &null_lex_str,
6428
6600
                                                new Item_int((int32_t) $5)));
6429
6601
          }
6439
6611
            LEX *lex=Lex;
6440
6612
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6441
6613
          }
6442
 
        | NAMES_SYM COLLATE_SYM collation_name_or_default
 
6614
        | charset old_or_new_charset_name_or_default
 
6615
          {
 
6616
            THD *thd= YYTHD;
 
6617
            LEX *lex= thd->lex;
 
6618
            $2= $2 ? $2: global_system_variables.character_set_client;
 
6619
            lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
 
6620
          }
 
6621
        | NAMES_SYM charset_name_or_default opt_collate
6443
6622
          {
6444
6623
            LEX *lex= Lex;
6445
 
            $3= $3 ? $3 : global_system_variables.character_set_client;
 
6624
            $2= $2 ? $2 : global_system_variables.character_set_client;
 
6625
            $3= $3 ? $3 : $2;
 
6626
            if (!my_charset_same($2,$3))
 
6627
            {
 
6628
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
6629
                       $3->name, $2->csname);
 
6630
              DRIZZLE_YYABORT;
 
6631
            }
6446
6632
            lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
6447
6633
          }
6448
6634
        ;
6450
6636
internal_variable_name:
6451
6637
          ident
6452
6638
          {
6453
 
            Session *session= YYSession;
 
6639
            THD *thd= YYTHD;
6454
6640
 
6455
6641
            /* We have to lookup here since local vars can shadow sysvars */
6456
6642
            {
6457
6643
              /* Not an SP local variable */
6458
 
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
 
6644
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
6459
6645
              if (!tmp)
6460
6646
                DRIZZLE_YYABORT;
6461
6647
              $$.var= tmp;
6470
6656
              DRIZZLE_YYABORT;
6471
6657
            }
6472
6658
            {
6473
 
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
6659
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
6474
6660
              if (!tmp)
6475
6661
                DRIZZLE_YYABORT;
6476
6662
              if (!tmp->is_struct())
6481
6667
          }
6482
6668
        | DEFAULT '.' ident
6483
6669
          {
6484
 
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
6670
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
6485
6671
            if (!tmp)
6486
6672
              DRIZZLE_YYABORT;
6487
6673
            if (!tmp->is_struct())
6545
6731
        table_ident opt_table_alias table_lock_info
6546
6732
        {
6547
6733
          TableList *tlist;
6548
 
          if (!(tlist= Select->add_table_to_list(YYSession, $1, $2, 0,
 
6734
          if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
6549
6735
                                                 $3.lock_type)))
6550
6736
            DRIZZLE_YYABORT; /* purecov: inspected */
6551
6737
          tlist->lock_timeout= $3.lock_timeout;
6637
6823
 
6638
6824
opt_chain:
6639
6825
          /* empty */
6640
 
          { $$= (YYSession->variables.completion_type == 1); }
 
6826
          { $$= (YYTHD->variables.completion_type == 1); }
6641
6827
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6642
6828
        | AND_SYM CHAIN_SYM        { $$=1; }
6643
6829
        ;
6644
6830
 
6645
6831
opt_release:
6646
6832
          /* empty */
6647
 
          { $$= (YYSession->variables.completion_type == 2); }
 
6833
          { $$= (YYTHD->variables.completion_type == 2); }
6648
6834
        | RELEASE_SYM        { $$=1; }
6649
6835
        | NO_SYM RELEASE_SYM { $$=0; }
6650
6836
;
6733
6919
 
6734
6920
union_order_or_limit:
6735
6921
          {
6736
 
            Session *session= YYSession;
6737
 
            LEX *lex= session->lex;
 
6922
            THD *thd= YYTHD;
 
6923
            LEX *lex= thd->lex;
6738
6924
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6739
6925
            SELECT_LEX *sel= lex->current_select;
6740
6926
            SELECT_LEX_UNIT *unit= sel->master_unit();
6745
6931
              fake->no_table_names_allowed= 1;
6746
6932
              lex->current_select= fake;
6747
6933
            }
6748
 
            session->where= "global ORDER clause";
 
6934
            thd->where= "global ORDER clause";
6749
6935
          }
6750
6936
          order_or_limit
6751
6937
          {
6752
 
            Session *session= YYSession;
6753
 
            session->lex->current_select->no_table_names_allowed= 0;
6754
 
            session->where= "";
 
6938
            THD *thd= YYTHD;
 
6939
            thd->lex->current_select->no_table_names_allowed= 0;
 
6940
            thd->where= "";
6755
6941
          }
6756
6942
        ;
6757
6943