~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
** The type will be void*, so it must be  cast to (Session*) when used.
26
26
** Use the YYSession macro for this.
27
27
*/
28
 
 
29
 
#define YYSession (session)
 
28
#define YYPARSE_PARAM yysession
 
29
#define YYLEX_PARAM yysession
 
30
#define YYSession (static_cast<Session *>(yysession))
30
31
 
31
32
#define YYENABLE_NLS 0
32
33
#define YYLTYPE_IS_TRIVIAL 0
33
34
 
 
35
#define DRIZZLE_YACC
34
36
#define YYINITDEPTH 100
35
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
36
 
#define Lex (session->getLex())
 
38
#define Lex (YYSession->lex)
37
39
 
38
 
#include <config.h>
 
40
#include "config.h"
39
41
#include <cstdio>
40
 
#include <drizzled/parser.h>
 
42
#include "drizzled/parser.h"
41
43
 
42
 
int yylex(union ParserType *yylval, drizzled::Session *session);
 
44
int yylex(void *yylval, void *yysession);
43
45
 
44
46
#define yyoverflow(A,B,C,D,E,F)               \
45
47
  {                                           \
46
 
    unsigned long val= *(F);                          \
 
48
    ulong val= *(F);                          \
47
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
48
50
    {                                         \
49
 
      yyerror(NULL, (char*) (A));                   \
 
51
      yyerror((char*) (A));                   \
50
52
      return 2;                               \
51
53
    }                                         \
52
54
    else                                      \
58
60
#define DRIZZLE_YYABORT                         \
59
61
  do                                          \
60
62
  {                                           \
 
63
    LEX::cleanup_lex_after_parse_error(YYSession);\
61
64
    YYABORT;                                  \
62
65
  } while (0)
63
66
 
64
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
65
68
  if (!(A))                             \
66
69
  {                                     \
67
 
    parser::my_parse_error(YYSession->m_lip);\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
68
72
    DRIZZLE_YYABORT;                      \
69
73
  }
70
74
 
 
75
 
 
76
#define YYDEBUG 0
 
77
 
71
78
namespace drizzled
72
79
{
73
80
 
83
90
}
84
91
 
85
92
 
 
93
static bool check_reserved_words(LEX_STRING *name)
 
94
{
 
95
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
 
96
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
 
97
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
 
98
    return true;
 
99
  return false;
 
100
}
 
101
 
 
102
/**
 
103
  @brief Push an error message into MySQL error stack with line
 
104
  and position information.
 
105
 
 
106
  This function provides semantic action implementers with a way
 
107
  to push the famous "You have a syntax error near..." error
 
108
  message into the error stack, which is normally produced only if
 
109
  a parse error is discovered internally by the Bison generated
 
110
  parser.
 
111
*/
 
112
 
 
113
struct my_parse_error_st {
 
114
  const char *s;
 
115
  Session *session;
 
116
};
 
117
 
 
118
static void my_parse_error(void *arg)
 
119
{
 
120
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
 
121
 
 
122
  const char *s= ptr->s;
 
123
  Session *session= ptr->session;
 
124
 
 
125
  Lex_input_stream *lip= session->m_lip;
 
126
 
 
127
  const char *yytext= lip->get_tok_start();
 
128
  /* Push an error into the error stack */
 
129
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
130
                  (yytext ? yytext : ""),
 
131
                  lip->yylineno);
 
132
}
 
133
 
86
134
/**
87
135
  @brief Bison callback to report a syntax/OOM error
88
136
 
98
146
 
99
147
  This function is not for use in semantic actions and is internal to
100
148
  the parser, as it performs some pre-return cleanup.
101
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
149
  In semantic actions, please use my_parse_error or my_error to
102
150
  push an error into the error stack and DRIZZLE_YYABORT
103
151
  to abort from the parser.
104
152
*/
105
153
 
106
 
static void base_sql_error(drizzled::Session *session, const char *s)
107
 
{
108
 
  parser::errorOn(session, s);
 
154
static void DRIZZLEerror(const char *s)
 
155
{
 
156
  Session *session= current_session;
 
157
 
 
158
  /*
 
159
    Restore the original LEX if it was replaced when parsing
 
160
    a stored procedure. We must ensure that a parsing error
 
161
    does not leave any side effects in the Session.
 
162
  */
 
163
  LEX::cleanup_lex_after_parse_error(session);
 
164
 
 
165
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
166
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
167
    s= ER(ER_SYNTAX_ERROR);
 
168
 
 
169
  struct my_parse_error_st pass= { s, session };
 
170
  my_parse_error(&pass);
 
171
}
 
172
 
 
173
/**
 
174
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
175
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
176
  This function returns the proper item for the SQL expression
 
177
  <code>left [NOT] IN ( expr )</code>
 
178
  @param session the current thread
 
179
  @param left the in predicand
 
180
  @param equal true for IN predicates, false for NOT IN predicates
 
181
  @param expr first and only expression of the in value list
 
182
  @return an expression representing the IN predicate.
 
183
*/
 
184
static Item* handle_sql2003_note184_exception(Session *session,
 
185
                                              Item* left, bool equal,
 
186
                                              Item *expr)
 
187
{
 
188
  /*
 
189
    Relevant references for this issue:
 
190
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
191
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
192
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
193
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
194
    - SQL:2003 Feature F561, "Full value expressions".
 
195
 
 
196
    The exception in SQL:2003 Note 184 means:
 
197
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
198
    should be re-interpreted as an Item_in_subselect, which corresponds
 
199
    to a <table subquery> when used inside an <in predicate>.
 
200
 
 
201
    Our reading of Note 184 is reccursive, so that all:
 
202
    - IN (( <subquery> ))
 
203
    - IN ((( <subquery> )))
 
204
    - IN '('^N <subquery> ')'^N
 
205
    - etc
 
206
    should be interpreted as a <table subquery>, no matter how deep in the
 
207
    expression the <subquery> is.
 
208
  */
 
209
 
 
210
  Item *result;
 
211
 
 
212
  if (expr->type() == Item::SUBSELECT_ITEM)
 
213
  {
 
214
    Item_subselect *expr2 = (Item_subselect*) expr;
 
215
 
 
216
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
217
    {
 
218
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
219
      Select_Lex *subselect;
 
220
 
 
221
      /*
 
222
        Implement the mandated change, by altering the semantic tree:
 
223
          left IN Item_singlerow_subselect(subselect)
 
224
        is modified to
 
225
          left IN (subselect)
 
226
        which is represented as
 
227
          Item_in_subselect(left, subselect)
 
228
      */
 
229
      subselect= expr3->invalidate_and_restore_select_lex();
 
230
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
231
 
 
232
      if (! equal)
 
233
        result = negate_expression(session, result);
 
234
 
 
235
      return(result);
 
236
    }
 
237
  }
 
238
 
 
239
  if (equal)
 
240
    result= new (session->mem_root) Item_func_eq(left, expr);
 
241
  else
 
242
    result= new (session->mem_root) Item_func_ne(left, expr);
 
243
 
 
244
  return(result);
 
245
}
 
246
 
 
247
/**
 
248
   @brief Creates a new Select_Lex for a UNION branch.
 
249
 
 
250
   Sets up and initializes a Select_Lex structure for a query once the parser
 
251
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
252
   the new Select_Lex becomes the current one..=
 
253
 
 
254
   @lex The parser state.
 
255
 
 
256
   @is_union_distinct True if the union preceding the new select statement
 
257
   uses UNION DISTINCT.
 
258
 
 
259
   @return <code>false</code> if successful, <code>true</code> if an error was
 
260
   reported. In the latter case parsing should stop.
 
261
 */
 
262
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
 
263
{
 
264
  if (lex->result)
 
265
  {
 
266
    /* Only the last SELECT can have  INTO...... */
 
267
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
268
    return true;
 
269
  }
 
270
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
271
  {
 
272
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
273
    my_parse_error(&pass);
 
274
    return true;
 
275
  }
 
276
  /* This counter shouldn't be incremented for UNION parts */
 
277
  lex->nest_level--;
 
278
  if (new_select(lex, 0))
 
279
    return true;
 
280
  init_select(lex);
 
281
  lex->current_select->linkage=UNION_TYPE;
 
282
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
283
    lex->current_select->master_unit()->union_distinct=
 
284
      lex->current_select;
 
285
  return false;
 
286
}
 
287
 
 
288
/**
 
289
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
290
   braces).
 
291
 
 
292
   @return false if successful, true if an error was reported. In the latter
 
293
   case parsing should stop.
 
294
 */
 
295
static bool setup_select_in_parentheses(Session *session, LEX *lex)
 
296
{
 
297
  Select_Lex * sel= lex->current_select;
 
298
  if (sel->set_braces(1))
 
299
  {
 
300
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
301
    my_parse_error(&pass);
 
302
    return true;
 
303
  }
 
304
  if (sel->linkage == UNION_TYPE &&
 
305
      !sel->master_unit()->first_select()->braces &&
 
306
      sel->master_unit()->first_select()->linkage ==
 
307
      UNION_TYPE)
 
308
  {
 
309
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
310
    my_parse_error(&pass);
 
311
    return true;
 
312
  }
 
313
  if (sel->linkage == UNION_TYPE &&
 
314
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
315
      sel->master_unit()->fake_select_lex)
 
316
  {
 
317
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
318
    return true;
 
319
  }
 
320
  /* select in braces, can't contain global parameters */
 
321
  if (sel->master_unit()->fake_select_lex)
 
322
    sel->master_unit()->global_parameters=
 
323
      sel->master_unit()->fake_select_lex;
 
324
  return false;
 
325
}
 
326
 
 
327
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
 
328
{
 
329
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
330
  Item *item= NULL;
 
331
 
 
332
  if (udf)
 
333
  {
 
334
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
 
335
  } else {
 
336
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
337
  }
 
338
 
 
339
  return item;
109
340
}
110
341
 
111
342
} /* namespace drizzled; */
112
343
 
113
344
using namespace drizzled;
114
345
%}
115
 
%union ParserType {
 
346
%union {
116
347
  bool boolean;
117
348
  int  num;
118
 
  unsigned long ulong_num;
 
349
  ulong ulong_num;
119
350
  uint64_t ulonglong_number;
120
351
  int64_t longlong_number;
121
352
  drizzled::LEX_STRING lex_str;
131
362
  drizzled::Key_part_spec *key_part;
132
363
  const drizzled::plugin::Function *udf;
133
364
  drizzled::TableList *table_list;
134
 
  drizzled::enum_field_types field_val;
135
 
  drizzled::sys_var_with_base variable;
136
 
  drizzled::sql_var_t var_type;
 
365
  enum drizzled::enum_field_types field_val;
 
366
  struct drizzled::sys_var_with_base variable;
 
367
  enum drizzled::sql_var_t var_type;
137
368
  drizzled::Key::Keytype key_type;
138
 
  drizzled::ha_key_alg key_alg;
139
 
  drizzled::ha_rkey_function ha_rkey_mode;
140
 
  drizzled::enum_tx_isolation tx_isolation;
141
 
  drizzled::Cast_target cast_type;
 
369
  enum drizzled::ha_key_alg key_alg;
 
370
  enum drizzled::ha_rkey_function ha_rkey_mode;
 
371
  enum drizzled::enum_tx_isolation tx_isolation;
 
372
  enum drizzled::Cast_target cast_type;
142
373
  const drizzled::CHARSET_INFO *charset;
143
374
  drizzled::thr_lock_type lock_type;
144
375
  drizzled::interval_type interval, interval_time_st;
145
 
  drizzled::type::timestamp_t date_time_type;
 
376
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
146
377
  drizzled::Select_Lex *select_lex;
147
378
  drizzled::chooser_compare_func_creator boolfunc2creator;
148
 
  drizzled::st_lex *lex;
149
 
  drizzled::index_hint_type index_hint;
150
 
  drizzled::enum_filetype filetype;
151
 
  drizzled::ha_build_method build_method;
 
379
  struct drizzled::st_lex *lex;
 
380
  enum drizzled::index_hint_type index_hint;
 
381
  enum drizzled::enum_filetype filetype;
 
382
  enum drizzled::ha_build_method build_method;
152
383
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
153
384
  drizzled::execute_string_t execute_string;
154
385
}
156
387
%{
157
388
namespace drizzled
158
389
{
159
 
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
 
390
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
160
391
}
161
392
%}
162
393
 
163
394
%debug
164
 
%require "2.2"
165
 
%pure-parser
166
 
%name-prefix="base_sql_"
167
 
%parse-param { drizzled::Session *session }
168
 
%lex-param { drizzled::Session *session }
169
 
%verbose
170
 
 
 
395
%pure_parser                                    /* We have threads */
171
396
 
172
397
/*
173
398
  Currently there are 70 shift/reduce conflicts.
298
523
%token  END_OF_INPUT                  /* INTERNAL */
299
524
%token  ENGINE_SYM
300
525
%token  ENUM_SYM
 
526
%token  EQ                            /* OPERATOR */
301
527
%token  EQUAL_SYM                     /* OPERATOR */
302
528
%token  ERRORS
303
529
%token  ESCAPED
324
550
%token  GLOBAL_SYM                    /* SQL-2003-R */
325
551
%token  GROUP_SYM                     /* SQL-2003-R */
326
552
%token  GROUP_CONCAT_SYM
 
553
%token  GT_SYM                        /* OPERATOR */
327
554
%token  HASH_SYM
328
555
%token  HAVING                        /* SQL-2003-R */
329
556
%token  HEX_NUM
373
600
%token  LOGS_SYM
374
601
%token  LONG_NUM
375
602
%token  LONG_SYM
 
603
%token  LT                            /* OPERATOR */
376
604
%token  MATCH                         /* SQL-2003-R */
377
605
%token  MAX_SYM                       /* SQL-2003-N */
378
606
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
393
621
%token  NATIONAL_SYM                  /* SQL-2003-R */
394
622
%token  NATURAL                       /* SQL-2003-R */
395
623
%token  NE                            /* OPERATOR */
 
624
%token  NEG
396
625
%token  NEW_SYM                       /* SQL-2003-R */
397
626
%token  NEXT_SYM                      /* SQL-2003-N */
398
627
%token  NONE_SYM                      /* SQL-2003-R */
439
668
%token  REPEATABLE_SYM                /* SQL-2003-N */
440
669
%token  REPEAT_SYM                    /* MYSQL-FUNC */
441
670
%token  REPLACE                       /* MYSQL-FUNC */
442
 
%token  REPLICATION
443
671
%token  RESTRICT
444
672
%token  RETURNS_SYM                   /* SQL-2003-R */
445
673
%token  RETURN_SYM                    /* SQL-2003-R */
552
780
%token  YEAR_SYM                      /* SQL-2003-R */
553
781
%token  ZEROFILL_SYM
554
782
 
555
 
/* Lowest to highest */
556
783
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
557
784
/* A dummy token to force the priority of table_ref production in a join. */
558
 
%left  TABLE_REF_PRIORITY
559
 
%left  SET_VAR
560
 
%left  OR_SYM
561
 
%left  XOR
562
 
%left  AND_SYM
563
 
%right NOT_SYM
564
 
%right '='
565
 
%nonassoc EQUAL_SYM GE '>' LE '<' NE
566
 
%nonassoc LIKE REGEXP_SYM
567
 
%nonassoc BETWEEN_SYM
568
 
%nonassoc IN_SYM
569
 
%nonassoc IS NULL_SYM TRUE_SYM FALSE_SYM
 
785
%left   TABLE_REF_PRIORITY
 
786
%left   SET_VAR
 
787
%left   OR_SYM
 
788
%left   XOR
 
789
%left   AND_SYM
 
790
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
791
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP_SYM IN_SYM
570
792
%left   '-' '+'
571
793
%left   '*' '/' '%' DIV_SYM MOD_SYM
 
794
%left   NEG
 
795
%right  NOT_SYM
572
796
%right  BINARY COLLATE_SYM
573
797
%left  INTERVAL_SYM
574
 
%right UMINUS
575
 
%left  '(' ')'
576
 
%left  '{' '}'
577
798
 
578
799
%type <lex_str>
579
800
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
652
873
        table_wild simple_expr udf_expr
653
874
        expr_or_default set_expr_or_default
654
875
        signed_literal now_or_signed_literal opt_escape
655
 
        simple_ident_q
 
876
        simple_ident_nospvar simple_ident_q
656
877
        field_or_var limit_option
657
878
        function_call_keyword
658
879
        function_call_nonkeyword
728
949
        opt_precision opt_ignore opt_column
729
950
        set unlock string_list
730
951
        ref_list opt_match_clause opt_on_update_delete use
731
 
        opt_delete_option varchar
 
952
        opt_delete_options opt_delete_option varchar
732
953
        opt_outer table_list table_name
733
954
        opt_option opt_place
734
955
        opt_attribute opt_attribute_list attribute
736
957
        equal optional_braces
737
958
        normal_join
738
959
        table_to_table_list table_to_table opt_table_list
 
960
        single_multi
739
961
        union_clause union_list
740
962
        precision subselect_start
741
963
        subselect_end select_var_list select_var_list_init opt_len
750
972
%type <num> index_hint_clause
751
973
%type <filetype> data_file
752
974
 
 
975
%type <NONE>
 
976
        '-' '+' '*' '/' '%' '(' ')'
 
977
        ',' '!' '{' '}' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
 
978
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM DELETE_SYM
753
979
%%
754
980
 
755
981
/*
776
1002
query:
777
1003
          END_OF_INPUT
778
1004
          {
779
 
            if (!(YYSession->getLex()->select_lex.options & OPTION_FOUND_COMMENT))
 
1005
            Session *session= YYSession;
 
1006
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
780
1007
            {
781
1008
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
782
1009
              DRIZZLE_YYABORT;
783
1010
            }
784
1011
            else
785
1012
            {
786
 
              YYSession->getLex()->statement= new statement::EmptyQuery(YYSession);
 
1013
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1014
              session->lex->statement= new statement::EmptyQuery(YYSession);
787
1015
            }
788
1016
          }
789
1017
        | verb_clause END_OF_INPUT {}
833
1061
          }
834
1062
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
835
1063
          {
836
 
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
 
1064
            Lex->sql_command= SQLCOM_CREATE_TABLE;
 
1065
            Lex->statement= new statement::CreateTable(YYSession);
837
1066
 
838
1067
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
839
1068
                                                     TL_OPTION_UPDATING,
840
1069
                                                     TL_WRITE))
841
1070
              DRIZZLE_YYABORT;
842
 
            Lex->col_list.clear();
 
1071
            Lex->col_list.empty();
 
1072
 
 
1073
            Lex->table()->set_name($5->table.str);
 
1074
            if ($2)
 
1075
              Lex->table()->set_type(message::Table::TEMPORARY);
 
1076
            else
 
1077
              Lex->table()->set_type(message::Table::STANDARD);
843
1078
          }
844
1079
          create_table_definition
845
1080
          {
847
1082
          }
848
1083
        | CREATE build_method
849
1084
          {
850
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1085
            Lex->sql_command= SQLCOM_CREATE_INDEX;
 
1086
            statement::CreateIndex *statement= new statement::CreateIndex(YYSession);
 
1087
            Lex->statement= statement;
 
1088
 
 
1089
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1090
            statement->alter_info.build_method= $2;
 
1091
            Lex->col_list.empty();
 
1092
            statement->change=NULL;
851
1093
          }
852
1094
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
853
1095
          {
 
1096
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1097
 
854
1098
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
855
1099
                                                            NULL,
856
1100
                                                            TL_OPTION_UPDATING))
857
1101
              DRIZZLE_YYABORT;
858
 
 
859
 
            parser::buildKey(Lex, $4, $6);
 
1102
            Key *key;
 
1103
            key= new Key($4, $6, &statement->key_create_info, 0, Lex->col_list);
 
1104
            statement->alter_info.key_list.push_back(key);
 
1105
            Lex->col_list.empty();
860
1106
          }
861
1107
        | CREATE DATABASE opt_if_not_exists schema_name
862
1108
          {
 
1109
            Lex->sql_command=SQLCOM_CREATE_DB;
863
1110
            Lex->statement= new statement::CreateSchema(YYSession);
864
1111
          }
865
1112
          opt_create_database_options
923
1170
            Lex->lock_option= TL_READ;
924
1171
            if (Lex->sql_command == SQLCOM_INSERT)
925
1172
            {
 
1173
              Lex->sql_command= SQLCOM_INSERT_SELECT;
926
1174
              delete Lex->statement;
927
1175
              Lex->statement= new statement::InsertSelect(YYSession);
928
1176
            }
929
1177
            else if (Lex->sql_command == SQLCOM_REPLACE)
930
1178
            {
 
1179
              Lex->sql_command= SQLCOM_REPLACE_SELECT;
931
1180
              delete Lex->statement;
932
1181
              Lex->statement= new statement::ReplaceSelect(YYSession);
933
1182
            }
966
1215
 
967
1216
custom_database_option:
968
1217
          ident_or_text
969
 
          {
970
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
971
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
972
 
          }
973
 
        | REPLICATION opt_equal TRUE_SYM
974
 
          {
975
 
            parser::buildReplicationOption(Lex, true);
976
 
          }
977
 
        | REPLICATION opt_equal FALSE_SYM
978
 
          {
979
 
            parser::buildReplicationOption(Lex, false);
980
 
          }
 
1218
        {
 
1219
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1220
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1221
 
 
1222
          opt->set_name($1.str);
 
1223
        }
981
1224
        | ident_or_text equal ident_or_text
982
 
          {
983
 
            parser::buildSchemaOption(Lex, $1.str, $3);
984
 
          }
 
1225
        {
 
1226
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1227
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1228
 
 
1229
          opt->set_name($1.str);
 
1230
          opt->set_state($3.str);
 
1231
        }
985
1232
        | ident_or_text equal ulonglong_num
986
 
          {
987
 
            parser::buildSchemaOption(Lex, $1.str, $3);
988
 
          }
 
1233
        {
 
1234
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1235
          char number_as_string[22];
 
1236
 
 
1237
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1238
 
 
1239
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1240
 
 
1241
          opt->set_name($1.str);
 
1242
          opt->set_state(number_as_string);
 
1243
        }
989
1244
        ;
990
1245
 
991
1246
opt_table_options:
1029
1284
          {
1030
1285
            Lex->table()->mutable_options()->set_auto_increment_value($3);
1031
1286
          }
1032
 
        | REPLICATION opt_equal TRUE_SYM
1033
 
          {
1034
 
            Lex->table()->mutable_options()->set_dont_replicate(false);
1035
 
          }
1036
 
        | REPLICATION opt_equal FALSE_SYM
1037
 
          {
1038
 
            Lex->table()->mutable_options()->set_dont_replicate(true);
1039
 
          }
1040
1287
        |  ROW_FORMAT_SYM equal row_format_or_text
1041
1288
          {
1042
 
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
 
1289
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1290
 
 
1291
            opt->set_name("ROW_FORMAT");
 
1292
            opt->set_state($3.str);
1043
1293
          }
1044
1294
        |  FILE_SYM equal TEXT_STRING_sys
1045
1295
          {
1046
 
            parser::buildEngineOption(Lex, "FILE", $3);
 
1296
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1297
 
 
1298
            opt->set_name("FILE");
 
1299
            opt->set_state($3.str);
1047
1300
          }
1048
1301
        |  ident_or_text equal engine_option_value
1049
1302
          {
1050
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1303
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1304
 
 
1305
            opt->set_name($1.str);
 
1306
            opt->set_state($3.str);
1051
1307
          }
1052
1308
        | ident_or_text equal ulonglong_num
1053
1309
          {
1054
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1310
            char number_as_string[22];
 
1311
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1312
 
 
1313
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1314
            opt->set_name($1.str);
 
1315
            opt->set_state(number_as_string);
1055
1316
          }
1056
1317
        | default_collation
1057
1318
        ;
1059
1320
default_collation:
1060
1321
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1061
1322
          {
1062
 
            if (not parser::buildCollation(Lex, $4))
1063
 
            {
1064
 
              DRIZZLE_YYABORT;
1065
 
            }
 
1323
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1324
 
 
1325
            HA_CREATE_INFO *cinfo= &statement->create_info();
 
1326
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1327
                 cinfo->default_table_charset && $4 &&
 
1328
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1329
              {
 
1330
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1331
                         $4->name, cinfo->default_table_charset->csname);
 
1332
                DRIZZLE_YYABORT;
 
1333
              }
 
1334
              statement->create_info().default_table_charset= $4;
 
1335
              statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1066
1336
          }
1067
1337
        ;
1068
1338
 
1069
1339
default_collation_schema:
1070
1340
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1071
1341
          {
1072
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
 
1342
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1343
 
 
1344
            message::Schema &schema_message= statement->schema_message;
 
1345
            schema_message.set_collation($4->name);
1073
1346
          }
1074
1347
        ;
1075
1348
 
1109
1382
          field_spec opt_check_constraint
1110
1383
        | field_spec references
1111
1384
          {
1112
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1385
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1113
1386
          }
1114
1387
        ;
1115
1388
 
1116
1389
key_def:
1117
1390
          key_type opt_ident key_alg '(' key_list ')' key_options
1118
1391
          {
1119
 
            parser::buildKey(Lex, $1, $2);
 
1392
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1393
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1394
                              Lex->col_list);
 
1395
            statement->alter_info.key_list.push_back(key);
 
1396
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1120
1397
          }
1121
1398
        | opt_constraint constraint_key_type opt_ident key_alg
1122
1399
          '(' key_list ')' key_options
1123
1400
          {
1124
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1401
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1402
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1403
                              Lex->col_list);
 
1404
            statement->alter_info.key_list.push_back(key);
 
1405
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1125
1406
          }
1126
1407
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1127
1408
          {
1128
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1409
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1410
            Key *key= new Foreign_key($1.str ? $1 : $4, Lex->col_list,
 
1411
                                      $8,
 
1412
                                      Lex->ref_list,
 
1413
                                      statement->fk_delete_opt,
 
1414
                                      statement->fk_update_opt,
 
1415
                                      statement->fk_match_option);
 
1416
 
 
1417
            statement->alter_info.key_list.push_back(key);
 
1418
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1419
                         &default_key_create_info, 1,
 
1420
                         Lex->col_list);
 
1421
            statement->alter_info.key_list.push_back(key);
 
1422
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1423
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1424
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1129
1425
          }
1130
1426
        | constraint opt_check_constraint
1131
1427
          {
1132
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1428
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1133
1429
          }
1134
1430
        | opt_constraint check_constraint
1135
1431
          {
1136
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1432
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1137
1433
          }
1138
1434
        ;
1139
1435
 
1158
1454
field_spec:
1159
1455
          field_ident
1160
1456
          {
1161
 
            parser::buildCreateFieldIdent(Lex);
 
1457
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1458
            Lex->length= Lex->dec=0;
 
1459
            Lex->type=0;
 
1460
            statement->default_value= statement->on_update_value= 0;
 
1461
            statement->comment= null_lex_str;
 
1462
            Lex->charset= NULL;
 
1463
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1464
 
 
1465
            message::AlterTable &alter_proto= ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1466
            Lex->setField(alter_proto.add_added_field());
1162
1467
          }
1163
1468
          field_def
1164
1469
          {
1180
1485
            Lex->setField(NULL);
1181
1486
          }
1182
1487
        ;
1183
 
 
1184
1488
field_def:
1185
1489
          field_definition opt_attribute {}
1186
1490
        ;
1188
1492
field_definition:
1189
1493
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1190
1494
          { 
1191
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1495
            $$= $1;
 
1496
            Lex->length=(char*) 0; /* use default length */
 
1497
 
 
1498
            if ($3 or $4)
 
1499
            {
 
1500
              $1= DRIZZLE_TYPE_LONGLONG;
 
1501
            }
 
1502
 
 
1503
            if (Lex->field())
 
1504
            {
 
1505
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
 
1506
              // We update the type for unsigned types
 
1507
              if ($3 or $4)
 
1508
              {
 
1509
                Lex->field()->set_type(message::Table::Field::BIGINT);
 
1510
                Lex->field()->mutable_constraints()->set_is_unsigned(true);
 
1511
              }
 
1512
              if ($1 == DRIZZLE_TYPE_LONG)
 
1513
              {
 
1514
                Lex->field()->set_type(message::Table::Field::INTEGER);
 
1515
              }
 
1516
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1517
              {
 
1518
                Lex->field()->set_type(message::Table::Field::BIGINT);
 
1519
              }
 
1520
            }
1192
1521
          }
1193
1522
        | real_type opt_precision
1194
1523
          {
1195
 
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
1196
 
            $$= parser::buildDoubleColumn(Lex);
1197
 
          }
1198
 
        | char '(' NUM ')'
1199
 
          {
1200
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1201
 
          }
1202
 
        | char
1203
 
          {
1204
 
            $$= parser::buildVarcharColumn(Lex, "1");
1205
 
          }
1206
 
        | varchar '(' NUM ')'
1207
 
          {
1208
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1209
 
          }
1210
 
        | VARBINARY '(' NUM ')'
1211
 
          {
1212
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
1213
 
          }
1214
 
        | DATE_SYM
1215
 
          {
1216
 
            $$=DRIZZLE_TYPE_DATE;
1217
 
 
1218
 
            if (Lex->field())
1219
 
              Lex->field()->set_type(message::Table::Field::DATE);
1220
 
          }
1221
 
        | TIME_SYM
1222
 
          {
1223
 
            $$=DRIZZLE_TYPE_TIME;
1224
 
 
1225
 
            if (Lex->field())
1226
 
              Lex->field()->set_type(message::Table::Field::TIME);
1227
 
          }
1228
 
        | TIMESTAMP_SYM
1229
 
          {
1230
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1231
 
          }
1232
 
        | TIMESTAMP_SYM '(' NUM ')'
1233
 
          {
1234
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1235
 
          }
1236
 
        | DATETIME_SYM
1237
 
          {
1238
 
            $$=DRIZZLE_TYPE_DATETIME;
1239
 
 
1240
 
            if (Lex->field())
1241
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1242
 
          }
1243
 
        | BLOB_SYM
1244
 
          {
1245
 
            $$= parser::buildBlobColumn(Lex);
1246
 
          }
1247
 
        | TEXT_SYM
1248
 
          {
1249
 
            $$=DRIZZLE_TYPE_BLOB;
1250
 
            Lex->length=(char*) 0; /* use default length */
1251
 
 
1252
 
          if (Lex->field())
1253
 
            Lex->field()->set_type(message::Table::Field::BLOB);
1254
 
          }
1255
 
        | DECIMAL_SYM float_options
1256
 
          {
1257
 
            $$= parser::buildDecimalColumn(Lex);
1258
 
          }
1259
 
        | NUMERIC_SYM float_options
1260
 
          {
1261
 
            $$= parser::buildDecimalColumn(Lex);
1262
 
          }
1263
 
        | FIXED_SYM float_options
1264
 
          {
1265
 
            $$= parser::buildDecimalColumn(Lex);
1266
 
          }
1267
 
        | ENUM_SYM
1268
 
          {
1269
 
            Lex->interval_list.clear();
1270
 
          }
1271
 
          '(' string_list ')'
 
1524
            $$=$1;
 
1525
 
 
1526
            if (Lex->field())
 
1527
            {
 
1528
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1529
              Lex->field()->set_type(message::Table::Field::DOUBLE);
 
1530
            }
 
1531
          }
 
1532
          | char '(' NUM ')'
 
1533
            {
 
1534
              Lex->length=$3.str;
 
1535
              $$=DRIZZLE_TYPE_VARCHAR;
 
1536
 
 
1537
            if (Lex->field())
 
1538
            {
 
1539
              Lex->field()->set_type(message::Table::Field::VARCHAR);
 
1540
              message::Table::Field::StringFieldOptions *string_field_options;
 
1541
 
 
1542
              string_field_options= Lex->field()->mutable_string_options();
 
1543
 
 
1544
              string_field_options->set_length(atoi($3.str));
 
1545
            }
 
1546
            }
 
1547
          | char
 
1548
            {
 
1549
              Lex->length=(char*) "1";
 
1550
              $$=DRIZZLE_TYPE_VARCHAR;
 
1551
 
 
1552
            if (Lex->field())
 
1553
              Lex->field()->set_type(message::Table::Field::VARCHAR);
 
1554
            }
 
1555
          | varchar '(' NUM ')'
 
1556
            {
 
1557
              Lex->length=$3.str;
 
1558
              $$= DRIZZLE_TYPE_VARCHAR;
 
1559
 
 
1560
            if (Lex->field())
 
1561
            {
 
1562
              Lex->field()->set_type(message::Table::Field::VARCHAR);
 
1563
 
 
1564
              message::Table::Field::StringFieldOptions *string_field_options;
 
1565
 
 
1566
              string_field_options= Lex->field()->mutable_string_options();
 
1567
 
 
1568
              string_field_options->set_length(atoi($3.str));
 
1569
            }
 
1570
            }
 
1571
          | VARBINARY '(' NUM ')'
 
1572
            {
 
1573
              Lex->length=$3.str;
 
1574
              Lex->charset=&my_charset_bin;
 
1575
              $$= DRIZZLE_TYPE_VARCHAR;
 
1576
 
 
1577
            if (Lex->field())
 
1578
            {
 
1579
              Lex->field()->set_type(message::Table::Field::VARCHAR);
 
1580
              message::Table::Field::StringFieldOptions *string_field_options;
 
1581
 
 
1582
              string_field_options= Lex->field()->mutable_string_options();
 
1583
 
 
1584
              string_field_options->set_length(atoi($3.str));
 
1585
              string_field_options->set_collation_id(my_charset_bin.number);
 
1586
              string_field_options->set_collation(my_charset_bin.name);
 
1587
            }
 
1588
            }
 
1589
          | DATE_SYM
 
1590
            {
 
1591
              $$=DRIZZLE_TYPE_DATE;
 
1592
 
 
1593
              if (Lex->field())
 
1594
                Lex->field()->set_type(message::Table::Field::DATE);
 
1595
            }
 
1596
          | TIME_SYM
 
1597
            {
 
1598
              $$=DRIZZLE_TYPE_TIME;
 
1599
 
 
1600
              if (Lex->field())
 
1601
                Lex->field()->set_type(message::Table::Field::TIME);
 
1602
            }
 
1603
          | TIMESTAMP_SYM
 
1604
            {
 
1605
              $$=DRIZZLE_TYPE_TIMESTAMP;
 
1606
              Lex->length= 0;
 
1607
 
 
1608
              if (Lex->field())
 
1609
                Lex->field()->set_type(message::Table::Field::EPOCH);
 
1610
            }
 
1611
          | TIMESTAMP_SYM '(' NUM ')'
 
1612
            {
 
1613
              $$=DRIZZLE_TYPE_MICROTIME;
 
1614
              Lex->length= $3.str;
 
1615
 
 
1616
              if (Lex->field())
 
1617
                Lex->field()->set_type(message::Table::Field::EPOCH);
 
1618
            }
 
1619
          | DATETIME_SYM
 
1620
            {
 
1621
              $$=DRIZZLE_TYPE_DATETIME;
 
1622
 
 
1623
              if (Lex->field())
 
1624
                Lex->field()->set_type(message::Table::Field::DATETIME);
 
1625
            }
 
1626
          | BLOB_SYM
 
1627
            {
 
1628
              Lex->charset=&my_charset_bin;
 
1629
              $$=DRIZZLE_TYPE_BLOB;
 
1630
              Lex->length=(char*) 0; /* use default length */
 
1631
 
 
1632
              if (Lex->field())
 
1633
              {
 
1634
                Lex->field()->set_type(message::Table::Field::BLOB);
 
1635
                message::Table::Field::StringFieldOptions *string_field_options;
 
1636
 
 
1637
                string_field_options= Lex->field()->mutable_string_options();
 
1638
                string_field_options->set_collation_id(my_charset_bin.number);
 
1639
                string_field_options->set_collation(my_charset_bin.name);
 
1640
              }
 
1641
            }
 
1642
          | TEXT_SYM
 
1643
            {
 
1644
              $$=DRIZZLE_TYPE_BLOB;
 
1645
              Lex->length=(char*) 0; /* use default length */
 
1646
 
 
1647
            if (Lex->field())
 
1648
              Lex->field()->set_type(message::Table::Field::BLOB);
 
1649
            }
 
1650
          | DECIMAL_SYM float_options
 
1651
          {
 
1652
            $$=DRIZZLE_TYPE_DECIMAL;
 
1653
 
 
1654
            if (Lex->field())
 
1655
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1656
          }
 
1657
          | NUMERIC_SYM float_options
 
1658
          {
 
1659
            $$=DRIZZLE_TYPE_DECIMAL;
 
1660
 
 
1661
            if (Lex->field())
 
1662
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1663
          }
 
1664
          | FIXED_SYM float_options
 
1665
          {
 
1666
            $$=DRIZZLE_TYPE_DECIMAL;
 
1667
 
 
1668
            if (Lex->field())
 
1669
              Lex->field()->set_type(message::Table::Field::DECIMAL);
 
1670
          }
 
1671
          | ENUM_SYM
 
1672
            {Lex->interval_list.empty();}
 
1673
            '(' string_list ')'
1272
1674
          {
1273
1675
            $$=DRIZZLE_TYPE_ENUM;
1274
1676
 
1277
1679
          }
1278
1680
        | UUID_SYM
1279
1681
          {
1280
 
            $$= parser::buildUuidColumn(Lex);
 
1682
            $$=DRIZZLE_TYPE_UUID;
 
1683
 
 
1684
            if (Lex->field())
 
1685
              Lex->field()->set_type(message::Table::Field::UUID);
1281
1686
          }
1282
1687
        | BOOLEAN_SYM
1283
1688
          {
1284
 
            $$= parser::buildBooleanColumn(Lex);
 
1689
            $$=DRIZZLE_TYPE_BOOLEAN;
 
1690
 
 
1691
            if (Lex->field())
 
1692
              Lex->field()->set_type(message::Table::Field::BOOLEAN);
1285
1693
          }
1286
1694
        | SERIAL_SYM
1287
1695
          {
1288
 
            $$= parser::buildSerialColumn(Lex);
 
1696
            $$=DRIZZLE_TYPE_LONGLONG;
 
1697
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1698
 
 
1699
            if (Lex->field())
 
1700
            {
 
1701
              message::Table::Field::FieldConstraints *constraints;
 
1702
              constraints= Lex->field()->mutable_constraints();
 
1703
              constraints->set_is_notnull(true);
 
1704
 
 
1705
              Lex->field()->set_type(message::Table::Field::BIGINT);
 
1706
            }
1289
1707
          }
1290
1708
        ;
1291
1709
 
1299
1717
        ;
1300
1718
 
1301
1719
int_type:
1302
 
          INT_SYM 
1303
 
          {
1304
 
            $$= DRIZZLE_TYPE_LONG;
1305
 
          }
1306
 
        | BOOL_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_LONG;
1309
 
          }
1310
 
        | BIGINT_SYM
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_LONGLONG;
1313
 
          }
 
1720
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1721
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1314
1722
        ;
1315
1723
 
1316
1724
real_type:
1319
1727
            $$= DRIZZLE_TYPE_DOUBLE;
1320
1728
          }
1321
1729
        | DOUBLE_SYM
1322
 
          {
1323
 
            $$= DRIZZLE_TYPE_DOUBLE;
1324
 
          }
 
1730
          { $$=DRIZZLE_TYPE_DOUBLE; }
1325
1731
        | DOUBLE_SYM PRECISION
1326
 
          {
1327
 
            $$= DRIZZLE_TYPE_DOUBLE;
1328
 
          }
 
1732
          { $$=DRIZZLE_TYPE_DOUBLE; }
1329
1733
        ;
1330
1734
 
1331
1735
float_options:
1367
1771
        ;
1368
1772
 
1369
1773
opt_precision:
1370
 
          /* empty */
1371
 
          { Lex->dec=Lex->length= (char*)0; }
1372
 
        | '(' NUM ')'
1373
 
          { Lex->length=Lex->dec= (char*)0; }
1374
 
        | precision
1375
 
          {}
 
1774
          /* empty */ {}
 
1775
        | precision {}
1376
1776
        ;
1377
1777
 
1378
1778
opt_attribute:
1389
1789
          NULL_SYM
1390
1790
          {
1391
1791
            Lex->type&= ~ NOT_NULL_FLAG;
 
1792
 
 
1793
            if (Lex->field())
 
1794
            {
 
1795
              message::Table::Field::FieldConstraints *constraints;
 
1796
              constraints= Lex->field()->mutable_constraints();
 
1797
              constraints->set_is_notnull(false);
 
1798
            }
1392
1799
          }
1393
1800
        | not NULL_SYM
1394
1801
          {
1396
1803
 
1397
1804
            if (Lex->field())
1398
1805
            {
1399
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1806
              message::Table::Field::FieldConstraints *constraints;
 
1807
              constraints= Lex->field()->mutable_constraints();
 
1808
              constraints->set_is_notnull(true);
1400
1809
            }
1401
1810
          }
1402
1811
        | DEFAULT now_or_signed_literal
1412
1821
          }
1413
1822
        | AUTO_INC
1414
1823
          {
1415
 
            parser::buildAutoOnColumn(Lex);
 
1824
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1825
 
 
1826
            if (Lex->field())
 
1827
            {
 
1828
              message::Table::Field::FieldConstraints *constraints;
 
1829
 
 
1830
              constraints= Lex->field()->mutable_constraints();
 
1831
              constraints->set_is_notnull(true);
 
1832
            }
1416
1833
          }
1417
1834
        | SERIAL_SYM DEFAULT VALUE_SYM
1418
1835
          {
1419
 
            (void)parser::buildSerialColumn(Lex);
 
1836
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1837
 
 
1838
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1839
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1840
 
 
1841
            if (Lex->field())
 
1842
            {
 
1843
              message::Table::Field::FieldConstraints *constraints;
 
1844
              constraints= Lex->field()->mutable_constraints();
 
1845
              constraints->set_is_notnull(true);
 
1846
            }
1420
1847
          }
1421
1848
        | opt_primary KEY_SYM
1422
1849
          {
1423
 
            parser::buildPrimaryOnColumn(Lex);
 
1850
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1851
 
 
1852
            Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1853
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1854
 
 
1855
            if (Lex->field())
 
1856
            {
 
1857
              message::Table::Field::FieldConstraints *constraints;
 
1858
              constraints= Lex->field()->mutable_constraints();
 
1859
              constraints->set_is_notnull(true);
 
1860
            }
1424
1861
          }
1425
1862
        | UNIQUE_SYM
1426
1863
          {
1427
 
            parser::buildKeyOnColumn(Lex);
 
1864
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1865
 
 
1866
            Lex->type|= UNIQUE_FLAG;
 
1867
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1428
1868
          }
1429
1869
        | UNIQUE_SYM KEY_SYM
1430
1870
          {
1431
 
            parser::buildKeyOnColumn(Lex);
 
1871
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1872
 
 
1873
            Lex->type|= UNIQUE_KEY_FLAG;
 
1874
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1432
1875
          }
1433
1876
        | COMMENT_SYM TEXT_STRING_sys
1434
1877
          {
1487
1930
        ;
1488
1931
 
1489
1932
references:
1490
 
          REFERENCES table_ident opt_ref_list opt_match_clause opt_on_update_delete
 
1933
          REFERENCES
 
1934
          table_ident
 
1935
          opt_ref_list
 
1936
          opt_match_clause
 
1937
          opt_on_update_delete
1491
1938
          {
1492
1939
            $$=$2;
1493
1940
          }
1495
1942
 
1496
1943
opt_ref_list:
1497
1944
          /* empty */
1498
 
          { Lex->ref_list.clear(); }
 
1945
          { Lex->ref_list.empty(); }
1499
1946
        | '(' ref_list ')'
1500
1947
        ;
1501
1948
 
1504
1951
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1505
1952
        | ident
1506
1953
          {
1507
 
            Lex->ref_list.clear();
 
1954
            Lex->ref_list.empty();
1508
1955
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
1509
1956
          }
1510
1957
        ;
1671
2118
alter:
1672
2119
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
1673
2120
          {
1674
 
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
 
2121
            Lex->sql_command= SQLCOM_ALTER_TABLE;
 
2122
            statement::AlterTable *statement= new statement::AlterTable(YYSession);
1675
2123
            Lex->statement= statement;
1676
2124
            Lex->duplicates= DUP_ERROR;
1677
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
1678
 
            {
 
2125
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
 
2126
                                                     TL_OPTION_UPDATING))
1679
2127
              DRIZZLE_YYABORT;
1680
 
            }
1681
2128
 
1682
 
            Lex->col_list.clear();
 
2129
            Lex->col_list.empty();
1683
2130
            Lex->select_lex.init_order();
1684
2131
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
 
2132
            statement->alter_info.build_method= $2;
1685
2133
          }
1686
2134
          alter_commands
1687
2135
          {}
1688
2136
        | ALTER_SYM DATABASE schema_name
1689
2137
          {
 
2138
            Lex->sql_command=SQLCOM_ALTER_DB;
1690
2139
            Lex->statement= new statement::AlterSchema(YYSession);
1691
2140
          }
1692
2141
          default_collation_schema
1801
2250
          }
1802
2251
        | DROP FOREIGN KEY_SYM opt_ident
1803
2252
          {
1804
 
            parser::buildAddAlterDropIndex(Lex, $4.str, true);
 
2253
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2254
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
 
2255
                                                                    $4.str));
 
2256
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2257
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1805
2258
          }
1806
2259
        | DROP PRIMARY_SYM KEY_SYM
1807
2260
          {
1808
 
            parser::buildAddAlterDropIndex(Lex, "PRIMARY");
 
2261
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2262
 
 
2263
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2264
                                                               "PRIMARY"));
 
2265
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1809
2266
          }
1810
2267
        | DROP key_or_index field_ident
1811
2268
          {
1812
 
            parser::buildAddAlterDropIndex(Lex, $3.str);
 
2269
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2270
 
 
2271
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2272
                                                                    $3.str));
 
2273
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1813
2274
          }
1814
2275
        | DISABLE_SYM KEYS
1815
2276
          {
1904
2365
          /* empty */ {}
1905
2366
        | AFTER_SYM ident
1906
2367
          {
1907
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2368
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2369
 
 
2370
            store_position_for_column($2.str);
 
2371
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1908
2372
          }
1909
2373
        | FIRST_SYM
1910
2374
          {
1911
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2375
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2376
 
 
2377
            store_position_for_column(first_keyword);
 
2378
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1912
2379
          }
1913
2380
        ;
1914
2381
 
1915
2382
opt_to:
1916
2383
          /* empty */ {}
1917
2384
        | TO_SYM {}
 
2385
        | EQ {}
1918
2386
        | AS {}
1919
2387
        ;
1920
2388
 
1921
2389
start:
1922
2390
          START_SYM TRANSACTION_SYM start_transaction_opts
1923
2391
          {
 
2392
            Lex->sql_command= SQLCOM_BEGIN;
1924
2393
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
1925
2394
          }
1926
2395
        ;
1936
2405
analyze:
1937
2406
          ANALYZE_SYM table_or_tables
1938
2407
          {
 
2408
            Lex->sql_command = SQLCOM_ANALYZE;
1939
2409
            Lex->statement= new statement::Analyze(YYSession);
1940
2410
          }
1941
2411
          table_list
1945
2415
check:
1946
2416
          CHECK_SYM table_or_tables
1947
2417
          {
 
2418
            Lex->sql_command = SQLCOM_CHECK;
1948
2419
            Lex->statement= new statement::Check(YYSession);
1949
2420
          }
1950
2421
          table_list
1954
2425
rename:
1955
2426
          RENAME table_or_tables
1956
2427
          {
 
2428
            Lex->sql_command= SQLCOM_RENAME_TABLE;
1957
2429
            Lex->statement= new statement::RenameTable(YYSession);
1958
2430
          }
1959
2431
          table_to_table_list
1985
2457
select:
1986
2458
          select_init
1987
2459
          {
 
2460
            Lex->sql_command= SQLCOM_SELECT;
1988
2461
            Lex->statement= new statement::Select(YYSession);
1989
2462
          }
1990
2463
        ;
1998
2471
select_paren:
1999
2472
          SELECT_SYM select_part2
2000
2473
          {
2001
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2474
            if (setup_select_in_parentheses(YYSession, Lex))
2002
2475
              DRIZZLE_YYABORT;
2003
2476
          }
2004
2477
        | '(' select_paren ')'
2008
2481
select_paren_derived:
2009
2482
          SELECT_SYM select_part2_derived
2010
2483
          {
2011
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2484
            if (setup_select_in_parentheses(YYSession, Lex))
2012
2485
              DRIZZLE_YYABORT;
2013
2486
          }
2014
2487
        | '(' select_paren_derived ')'
2020
2493
            Select_Lex * sel= Lex->current_select;
2021
2494
            if (Lex->current_select->set_braces(0))
2022
2495
            {
2023
 
              parser::my_parse_error(YYSession->m_lip);
 
2496
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2497
              my_parse_error(&pass);
2024
2498
              DRIZZLE_YYABORT;
2025
2499
            }
2026
2500
            if (sel->linkage == UNION_TYPE &&
2027
2501
                sel->master_unit()->first_select()->braces)
2028
2502
            {
2029
 
              parser::my_parse_error(YYSession->m_lip);
 
2503
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2504
              my_parse_error(&pass);
2030
2505
              DRIZZLE_YYABORT;
2031
2506
            }
2032
2507
          }
2161
2636
        | select_item
2162
2637
        | '*'
2163
2638
          {
2164
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->getLex()->current_select->context, NULL, NULL, "*")))
 
2639
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2640
                                                          context,
 
2641
                                                          NULL, NULL, "*")))
2165
2642
              DRIZZLE_YYABORT;
2166
 
 
2167
 
            (YYSession->getLex()->current_select->with_wild)++;
 
2643
            (YYSession->lex->current_select->with_wild)++;
2168
2644
          }
2169
2645
        ;
2170
2646
 
2341
2817
          { $$= new Item_func_isnotnull($1); }
2342
2818
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2343
2819
          { $$= new Item_func_equal($1,$3); }
2344
 
        | bool_pri comp_op predicate %prec '='
 
2820
        | bool_pri comp_op predicate %prec EQ
2345
2821
          { $$= (*$2)(0)->create($1,$3); }
2346
 
        | bool_pri comp_op all_or_any '(' subselect ')' %prec '='
 
2822
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
2347
2823
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
2348
2824
        | predicate
2349
2825
        ;
2360
2836
          }
2361
2837
        | bit_expr IN_SYM '(' expr ')'
2362
2838
          {
2363
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2839
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2364
2840
          }
2365
2841
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2366
2842
          {
2370
2846
          }
2371
2847
        | bit_expr not IN_SYM '(' expr ')'
2372
2848
          {
2373
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2849
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2374
2850
          }
2375
2851
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2376
2852
          {
2403
2879
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2404
2880
            args->push_back($1);
2405
2881
            args->push_back($3);
2406
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2882
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2407
2883
            {
2408
2884
              DRIZZLE_YYABORT;
2409
2885
            }
2414
2890
            args->push_back($1);
2415
2891
            args->push_back($4);
2416
2892
            args->push_back(new (YYSession->mem_root) Item_int(1));
2417
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2893
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2418
2894
            {
2419
2895
              DRIZZLE_YYABORT;
2420
2896
            }
2457
2933
        ;
2458
2934
 
2459
2935
comp_op:
2460
 
          '='     { $$ = &comp_eq_creator; }
 
2936
          EQ     { $$ = &comp_eq_creator; }
2461
2937
        | GE     { $$ = &comp_ge_creator; }
2462
 
        | '>' { $$ = &comp_gt_creator; }
 
2938
        | GT_SYM { $$ = &comp_gt_creator; }
2463
2939
        | LE     { $$ = &comp_le_creator; }
2464
 
        | '<'     { $$ = &comp_lt_creator; }
 
2940
        | LT     { $$ = &comp_lt_creator; }
2465
2941
        | NE     { $$ = &comp_ne_creator; }
2466
2942
        ;
2467
2943
 
2476
2952
        | function_call_nonkeyword
2477
2953
        | function_call_generic
2478
2954
        | function_call_conflict
2479
 
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
 
2955
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2480
2956
          {
2481
2957
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
2482
2958
                                                      $3.length,
2489
2965
          {
2490
2966
            Lex->setSumExprUsed();
2491
2967
          }
2492
 
        | '+' simple_expr %prec UMINUS { $$= $2; }
2493
 
        | '-' simple_expr %prec UMINUS
 
2968
        | '+' simple_expr %prec NEG { $$= $2; }
 
2969
        | '-' simple_expr %prec NEG
2494
2970
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2495
2971
        | '(' subselect ')'
2496
2972
          {
2512
2988
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
2513
2989
          }
2514
2990
        | '{' ident expr '}' { $$= $3; }
2515
 
        | BINARY simple_expr %prec UMINUS
 
2991
        | BINARY simple_expr %prec NEG
2516
2992
          {
2517
2993
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
2518
2994
                                 &my_charset_bin);
2538
3014
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2539
3015
                                                         $3);
2540
3016
          }
2541
 
        | VALUES '(' simple_ident ')'
 
3017
        | VALUES '(' simple_ident_nospvar ')'
2542
3018
          {
2543
3019
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2544
3020
                                                        $3);
2559
3035
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2560
3036
        | CURRENT_USER optional_braces
2561
3037
          {
2562
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3038
            std::string user_str("user");
 
3039
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2563
3040
            {
2564
3041
              DRIZZLE_YYABORT;
2565
3042
            }
2618
3095
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2619
3096
        | USER '(' ')'
2620
3097
          {
2621
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3098
            if (! ($$= reserved_keyword_function(YYSession, "user", NULL)))
2622
3099
            {
2623
3100
              DRIZZLE_YYABORT;
2624
3101
            }
2679
3156
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2680
3157
        | SUBSTRING '(' expr ',' expr ',' expr ')'
2681
3158
          {
 
3159
            std::string reverse_str("substr");
2682
3160
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2683
3161
            args->push_back($3);
2684
3162
            args->push_back($5);
2685
3163
            args->push_back($7);
2686
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3164
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2687
3165
            {
2688
3166
              DRIZZLE_YYABORT;
2689
3167
            }
2690
3168
          }
2691
3169
        | SUBSTRING '(' expr ',' expr ')'
2692
3170
          {
 
3171
            std::string reverse_str("substr");
2693
3172
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2694
3173
            args->push_back($3);
2695
3174
            args->push_back($5);
2696
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3175
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2697
3176
            {
2698
3177
              DRIZZLE_YYABORT;
2699
3178
            }
2700
3179
          }
2701
3180
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
2702
3181
          {
 
3182
            std::string reverse_str("substr");
2703
3183
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2704
3184
            args->push_back($3);
2705
3185
            args->push_back($5);
2706
3186
            args->push_back($7);
2707
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3187
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2708
3188
            {
2709
3189
              DRIZZLE_YYABORT;
2710
3190
            }
2711
3191
          }
2712
3192
        | SUBSTRING '(' expr FROM expr ')'
2713
3193
          {
 
3194
            std::string reverse_str("substr");
2714
3195
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2715
3196
            args->push_back($3);
2716
3197
            args->push_back($5);
2717
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3198
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2718
3199
            {
2719
3200
              DRIZZLE_YYABORT;
2720
3201
            }
2757
3238
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2758
3239
        | DATABASE '(' ')'
2759
3240
          {
2760
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
 
3241
            if (! ($$= reserved_keyword_function(YYSession, "database", NULL)))
2761
3242
            {
2762
3243
              DRIZZLE_YYABORT;
2763
3244
            }
2765
3246
          }
2766
3247
        | CATALOG_SYM '(' ')'
2767
3248
          {
2768
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
 
3249
            if (! ($$= reserved_keyword_function(YYSession, "catalog", NULL)))
2769
3250
            {
2770
3251
              DRIZZLE_YYABORT;
2771
3252
            }
2781
3262
              args->push_back(new (YYSession->mem_root) Item_int(1));
2782
3263
            }
2783
3264
 
2784
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
 
3265
            if (! ($$= reserved_keyword_function(YYSession, "execute", args)))
2785
3266
            {
2786
3267
              DRIZZLE_YYABORT;
2787
3268
            }
2790
3271
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
2791
3272
        | KILL_SYM kill_option '(' expr ')'
2792
3273
          {
 
3274
            std::string kill_str("kill");
2793
3275
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2794
3276
            args->push_back($4);
2795
3277
 
2798
3280
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2799
3281
            }
2800
3282
 
2801
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "kill", args)))
 
3283
            if (! ($$= reserved_keyword_function(YYSession, kill_str, args)))
2802
3284
            {
2803
3285
              DRIZZLE_YYABORT;
2804
3286
            }
2817
3299
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2818
3300
        | WAIT_SYM '(' expr ')'
2819
3301
          {
 
3302
            std::string wait_str("wait");
2820
3303
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2821
3304
            args->push_back($3);
2822
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
 
3305
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2823
3306
            {
2824
3307
              DRIZZLE_YYABORT;
2825
3308
            }
2826
3309
          }
2827
3310
        | UUID_SYM '(' ')'
2828
3311
          {
2829
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
 
3312
            if (! ($$= reserved_keyword_function(YYSession, "uuid", NULL)))
2830
3313
            {
2831
3314
              DRIZZLE_YYABORT;
2832
3315
            }
2834
3317
          }
2835
3318
        | WAIT_SYM '(' expr ',' expr ')'
2836
3319
          {
 
3320
            std::string wait_str("wait");
2837
3321
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2838
3322
            args->push_back($3);
2839
3323
            args->push_back($5);
2840
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
 
3324
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2841
3325
            {
2842
3326
              DRIZZLE_YYABORT;
2843
3327
            }
2988
3472
            sel->in_sum_expr--;
2989
3473
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
2990
3474
                                          sel->gorder_list, $7);
2991
 
            $5->clear();
 
3475
            $5->empty();
2992
3476
          }
2993
3477
        ;
2994
3478
 
3015
3499
        | '@' opt_var_ident_type user_variable_ident opt_component
3016
3500
          {
3017
3501
            /* disallow "SELECT @@global.global.variable" */
3018
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3502
            if ($3.str && $4.str && check_reserved_words(&$3))
3019
3503
            {
3020
 
              parser::my_parse_error(YYSession->m_lip);
 
3504
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3505
              my_parse_error(&pass);
3021
3506
              DRIZZLE_YYABORT;
3022
3507
            }
3023
3508
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3049
3534
            select->gorder_list=
3050
3535
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
3051
3536
                                     sizeof(st_sql_list));
3052
 
            select->order_list.clear();
 
3537
            select->order_list.empty();
3053
3538
          }
3054
3539
        ;
3055
3540
 
3058
3543
          {
3059
3544
            if (Lex->current_select->inc_in_sum_expr())
3060
3545
            {
3061
 
              parser::my_parse_error(YYSession->m_lip);
 
3546
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3547
              my_parse_error(&pass);
3062
3548
              DRIZZLE_YYABORT;
3063
3549
            }
3064
3550
          }
3315
3801
normal_join:
3316
3802
          JOIN_SYM {}
3317
3803
        | INNER_SYM JOIN_SYM {}
3318
 
        | CROSS JOIN_SYM
3319
 
          {
3320
 
            Lex->is_cross= true;
3321
 
            Lex->current_select->is_cross= true;
3322
 
          }
 
3804
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3323
3805
        ;
3324
3806
 
3325
3807
/*
3349
3831
            {
3350
3832
              if (sel->set_braces(1))
3351
3833
              {
3352
 
                parser::my_parse_error(YYSession->m_lip);
 
3834
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3835
                my_parse_error(&pass);
3353
3836
                DRIZZLE_YYABORT;
3354
3837
              }
3355
3838
              /* select in braces, can't contain global parameters */
3413
3896
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3414
3897
            {
3415
3898
              /* simple nested joins cannot have aliases or unions */
3416
 
              parser::my_parse_error(YYSession->m_lip);
 
3899
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3900
              my_parse_error(&pass);
3417
3901
              DRIZZLE_YYABORT;
3418
3902
            }
3419
3903
            else
3427
3911
          UNION_SYM
3428
3912
          union_option
3429
3913
          {
3430
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3914
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3431
3915
              DRIZZLE_YYABORT;
3432
3916
          }
3433
3917
          query_specification
3448
3932
            Select_Lex * sel= Lex->current_select;
3449
3933
            if (Lex->current_select->set_braces(0))
3450
3934
            {
3451
 
              parser::my_parse_error(YYSession->m_lip);
 
3935
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3936
              my_parse_error(&pass);
3452
3937
              DRIZZLE_YYABORT;
3453
3938
            }
3454
3939
            if (sel->linkage == UNION_TYPE &&
3455
3940
                sel->master_unit()->first_select()->braces)
3456
3941
            {
3457
 
              parser::my_parse_error(YYSession->m_lip);
 
3942
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3943
              my_parse_error(&pass);
3458
3944
              DRIZZLE_YYABORT;
3459
3945
            }
3460
3946
          }
3489
3975
 
3490
3976
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
3491
3977
              DRIZZLE_YYABORT;
3492
 
 
3493
3978
            if (!$3 && $$)
3494
3979
            {
3495
 
              parser::my_parse_error(YYSession->m_lip);
 
3980
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3981
              my_parse_error(&pass);
3496
3982
              DRIZZLE_YYABORT;
3497
3983
            }
3498
3984
          }
3503
3989
            Lex->derived_tables|= DERIVED_SUBQUERY;
3504
3990
            if (not Lex->expr_allows_subselect)
3505
3991
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3992
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3993
              my_parse_error(&pass);
3507
3994
              DRIZZLE_YYABORT;
3508
3995
            }
3509
3996
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
3531
4018
            if (!sel->embedding || sel->end_nested_join(Lex->session))
3532
4019
            {
3533
4020
              /* we are not in parentheses */
3534
 
              parser::my_parse_error(YYSession->m_lip);
 
4021
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4022
              my_parse_error(&pass);
3535
4023
              DRIZZLE_YYABORT;
3536
4024
            }
3537
4025
            embedding= Lex->current_select->embedding;
3673
4161
table_alias:
3674
4162
          /* empty */
3675
4163
        | AS
 
4164
        | EQ
3676
4165
        ;
3677
4166
 
3678
4167
opt_table_alias:
3679
4168
          /* empty */ { $$=0; }
3680
4169
        | table_alias ident
3681
 
          {
3682
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3683
 
          }
 
4170
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3684
4171
        ;
3685
4172
 
3686
4173
opt_all:
3784
4271
        ;
3785
4272
 
3786
4273
alter_order_item:
3787
 
          simple_ident order_dir
 
4274
          simple_ident_nospvar order_dir
3788
4275
          {
3789
4276
            bool ascending= ($2 == 1) ? true : false;
3790
4277
            if (YYSession->add_order_to_list($1, ascending))
3804
4291
order_clause:
3805
4292
          ORDER_SYM BY
3806
4293
          {
3807
 
            if (not parser::buildOrderBy(Lex))
 
4294
            Select_Lex *sel= Lex->current_select;
 
4295
            Select_Lex_Unit *unit= sel-> master_unit();
 
4296
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4297
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4298
                (sel->linkage != UNION_TYPE || sel->braces))
 
4299
            {
 
4300
              my_error(ER_WRONG_USAGE, MYF(0),
 
4301
                       "CUBE/ROLLUP", "ORDER BY");
3808
4302
              DRIZZLE_YYABORT;
 
4303
            }
 
4304
            if (Lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4305
            {
 
4306
              /*
 
4307
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4308
                executed in the same way as the query
 
4309
                SELECT ... ORDER BY order_list
 
4310
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4311
                Otherwise we create a fake Select_Lex if it has not been created
 
4312
                yet.
 
4313
              */
 
4314
              Select_Lex *first_sl= unit->first_select();
 
4315
              if (!unit->is_union() &&
 
4316
                  (first_sl->order_list.elements ||
 
4317
                   first_sl->select_limit) &&           
 
4318
                  unit->add_fake_select_lex(Lex->session))
 
4319
                DRIZZLE_YYABORT;
 
4320
            }
3809
4321
          }
3810
4322
          order_list
3811
4323
        ;
3812
4324
 
3813
4325
order_list:
3814
4326
          order_list ',' order_ident order_dir
3815
 
          {
3816
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3817
 
              DRIZZLE_YYABORT;
3818
 
          }
 
4327
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3819
4328
        | order_ident order_dir
3820
 
          {
3821
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3822
 
              DRIZZLE_YYABORT;
3823
 
          }
 
4329
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3824
4330
        ;
3825
4331
 
3826
4332
order_dir:
3892
4398
        ;
3893
4399
 
3894
4400
ulong_num:
3895
 
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3896
 
        | HEX_NUM       { $$= (unsigned long) strtol($1.str, (char**) 0, 16); }
3897
 
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3898
 
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3899
 
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3900
 
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4401
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4402
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4403
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4404
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4405
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4406
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3901
4407
        ;
3902
4408
 
3903
4409
ulonglong_num:
3981
4487
          }
3982
4488
        | DROP opt_temporary table_or_tables if_exists table_list
3983
4489
          {
 
4490
            Lex->sql_command = SQLCOM_DROP_TABLE;
3984
4491
            statement::DropTable *statement= new statement::DropTable(YYSession);
3985
4492
            Lex->statement= statement;
3986
4493
            statement->drop_temporary= $2;
3988
4495
          }
3989
4496
        | DROP build_method INDEX_SYM ident ON table_ident {}
3990
4497
          {
 
4498
            Lex->sql_command= SQLCOM_DROP_INDEX;
3991
4499
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
3992
4500
            Lex->statement= statement;
3993
4501
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
3999
4507
          }
4000
4508
        | DROP DATABASE if_exists schema_name
4001
4509
          {
 
4510
            Lex->sql_command= SQLCOM_DROP_DB;
4002
4511
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4003
4512
            Lex->statement= statement;
4004
4513
            statement->drop_if_exists=$3;
4072
4581
insert:
4073
4582
          INSERT
4074
4583
          {
 
4584
            Lex->sql_command= SQLCOM_INSERT;
4075
4585
            Lex->statement= new statement::Insert(YYSession);
4076
4586
            Lex->duplicates= DUP_ERROR;
4077
4587
            init_select(Lex);
4090
4600
replace:
4091
4601
          REPLACE
4092
4602
          {
 
4603
            Lex->sql_command= SQLCOM_REPLACE;
4093
4604
            Lex->statement= new statement::Replace(YYSession);
4094
4605
            Lex->duplicates= DUP_REPLACE;
4095
4606
            init_select(Lex);
4111
4622
insert_table:
4112
4623
          table_name
4113
4624
          {
4114
 
            Lex->field_list.clear();
4115
 
            Lex->many_values.clear();
 
4625
            Lex->field_list.empty();
 
4626
            Lex->many_values.empty();
4116
4627
            Lex->insert_list=0;
4117
4628
          };
4118
4629
 
4160
4671
        ;
4161
4672
 
4162
4673
ident_eq_value:
4163
 
          simple_ident equal expr_or_default
 
4674
          simple_ident_nospvar equal expr_or_default
4164
4675
          {
4165
4676
            if (Lex->field_list.push_back($1) ||
4166
4677
                Lex->insert_list->push_back($3))
4169
4680
        ;
4170
4681
 
4171
4682
equal:
4172
 
          '=' {}
 
4683
          EQ {}
4173
4684
        | SET_VAR {}
4174
4685
        ;
4175
4686
 
4223
4734
/* Update rows in a table */
4224
4735
 
4225
4736
update:
4226
 
          UPDATE_SYM opt_ignore table_ident SET_SYM update_list
 
4737
          UPDATE_SYM opt_ignore table_ident
4227
4738
          {
4228
4739
            init_select(Lex);
 
4740
            Lex->sql_command= SQLCOM_UPDATE;
4229
4741
            Lex->statement= new statement::Update(YYSession);
4230
4742
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
4231
4743
            Lex->duplicates= DUP_ERROR;
4232
4744
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4233
4745
              DRIZZLE_YYABORT;
4234
 
 
 
4746
          }
 
4747
          SET_SYM update_list
 
4748
          {
4235
4749
            if (Lex->select_lex.get_table_list()->derived)
4236
4750
            {
4237
4751
              /* it is single table update and it is update of derived table */
4255
4769
        ;
4256
4770
 
4257
4771
update_elem:
4258
 
          simple_ident equal expr_or_default
 
4772
          simple_ident_nospvar equal expr_or_default
4259
4773
          {
4260
4774
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4261
4775
              DRIZZLE_YYABORT;
4268
4782
        ;
4269
4783
 
4270
4784
insert_update_elem:
4271
 
          simple_ident equal expr_or_default
 
4785
          simple_ident_nospvar equal expr_or_default
4272
4786
          {
4273
4787
          if (Lex->update_list.push_back($1) ||
4274
4788
              Lex->value_list.push_back($3))
4279
4793
/* Delete rows from a table */
4280
4794
 
4281
4795
delete:
4282
 
          DELETE_SYM opt_delete_option FROM table_ident
 
4796
          DELETE_SYM
4283
4797
          {
 
4798
            Lex->sql_command= SQLCOM_DELETE;
4284
4799
            Lex->statement= new statement::Delete(YYSession);
4285
4800
            init_select(Lex);
4286
4801
            Lex->lock_option= TL_WRITE_DEFAULT;
 
4802
            Lex->ignore= 0;
4287
4803
            Lex->select_lex.init_order();
 
4804
          }
 
4805
          opt_delete_options single_multi
 
4806
        ;
4288
4807
 
4289
 
            if (!Lex->current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING,
 
4808
single_multi:
 
4809
          FROM table_ident
 
4810
          {
 
4811
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4290
4812
                                           Lex->lock_option))
4291
4813
              DRIZZLE_YYABORT;
4292
4814
          }
4294
4816
          delete_limit_clause {}
4295
4817
        ;
4296
4818
 
 
4819
opt_delete_options:
 
4820
          /* empty */ {}
 
4821
        | opt_delete_option opt_delete_options {}
 
4822
        ;
 
4823
 
4297
4824
opt_delete_option:
4298
 
           /* empty */ { Lex->ignore= 0; }
4299
 
         | IGNORE_SYM  { Lex->ignore= 1; }
 
4825
         IGNORE_SYM   { Lex->ignore= 1; }
4300
4826
        ;
4301
4827
 
4302
4828
truncate:
4303
4829
          TRUNCATE_SYM opt_table_sym table_name
4304
4830
          {
 
4831
            Lex->sql_command= SQLCOM_TRUNCATE;
4305
4832
            Lex->statement= new statement::Truncate(YYSession);
4306
4833
            Lex->select_lex.options= 0;
4307
4834
            Lex->select_lex.init_order();
4318
4845
show:
4319
4846
          SHOW
4320
4847
          {
 
4848
            Lex->wild=0;
4321
4849
            Lex->lock_option= TL_READ;
4322
4850
            init_select(Lex);
4323
4851
            Lex->current_select->parsing_place= SELECT_LIST;
4330
4858
show_param:
4331
4859
           DATABASES show_wild
4332
4860
           {
4333
 
             if (not show::buildScemas(YYSession))
 
4861
             Lex->sql_command= SQLCOM_SELECT;
 
4862
             Lex->statement= new statement::Show(YYSession);
 
4863
 
 
4864
             std::string column_name= "Database";
 
4865
             if (Lex->wild)
 
4866
             {
 
4867
               column_name.append(" (");
 
4868
               column_name.append(Lex->wild->ptr());
 
4869
               column_name.append(")");
 
4870
             }
 
4871
 
 
4872
             if (Lex->current_select->where)
 
4873
             {
 
4874
               if (prepare_new_schema_table(YYSession, Lex, "SCHEMAS"))
 
4875
                 DRIZZLE_YYABORT;
 
4876
             }
 
4877
             else
 
4878
             {
 
4879
               if (prepare_new_schema_table(YYSession, Lex, "SHOW_SCHEMAS"))
 
4880
                 DRIZZLE_YYABORT;
 
4881
             }
 
4882
 
 
4883
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4884
             my_field->is_autogenerated_name= false;
 
4885
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4886
 
 
4887
             if (YYSession->add_item_to_list(my_field))
4334
4888
               DRIZZLE_YYABORT;
 
4889
 
 
4890
              if (YYSession->add_order_to_list(my_field, true))
 
4891
                DRIZZLE_YYABORT;
4335
4892
           }
4336
4893
           /* SHOW TABLES */
4337
4894
         | TABLES opt_db show_wild
4338
4895
           {
4339
 
             if (not show::buildTables(YYSession, $2))
4340
 
               DRIZZLE_YYABORT;
 
4896
             Lex->sql_command= SQLCOM_SELECT;
 
4897
 
 
4898
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
4899
             Lex->statement= select;
 
4900
 
 
4901
              std::string column_name= "Tables_in_";
 
4902
 
 
4903
              util::string::const_shared_ptr schema(YYSession->schema());
 
4904
              if ($2)
 
4905
              {
 
4906
                identifier::Schema identifier($2);
 
4907
                column_name.append($2);
 
4908
                Lex->select_lex.db= $2;
 
4909
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4910
                {
 
4911
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4912
                }
 
4913
                select->setShowPredicate($2, "");
 
4914
              }
 
4915
              else if (schema and not schema->empty())
 
4916
              {
 
4917
                column_name.append(*schema);
 
4918
                select->setShowPredicate(*schema, "");
 
4919
              }
 
4920
              else
 
4921
              {
 
4922
                my_error(ER_NO_DB_ERROR, MYF(0));
 
4923
                DRIZZLE_YYABORT;
 
4924
              }
 
4925
 
 
4926
 
 
4927
             if (Lex->wild)
 
4928
             {
 
4929
               column_name.append(" (");
 
4930
               column_name.append(Lex->wild->ptr());
 
4931
               column_name.append(")");
 
4932
             }
 
4933
 
 
4934
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLES"))
 
4935
               DRIZZLE_YYABORT;
 
4936
 
 
4937
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4938
             my_field->is_autogenerated_name= false;
 
4939
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4940
 
 
4941
             if (YYSession->add_item_to_list(my_field))
 
4942
               DRIZZLE_YYABORT;
 
4943
 
 
4944
              if (YYSession->add_order_to_list(my_field, true))
 
4945
                DRIZZLE_YYABORT;
4341
4946
           }
4342
4947
           /* SHOW TEMPORARY TABLES */
4343
4948
         | TEMPORARY_SYM TABLES show_wild
4344
4949
           {
4345
 
             if (not show::buildTemporaryTables(YYSession))
4346
 
               DRIZZLE_YYABORT;
 
4950
             Lex->sql_command= SQLCOM_SELECT;
 
4951
 
 
4952
             Lex->statement= new statement::Show(YYSession);
 
4953
 
 
4954
 
 
4955
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TEMPORARY_TABLES"))
 
4956
               DRIZZLE_YYABORT;
 
4957
 
 
4958
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
4959
                                                           context,
 
4960
                                                           NULL, NULL, "*")))
 
4961
               DRIZZLE_YYABORT;
 
4962
             (YYSession->lex->current_select->with_wild)++;
 
4963
 
4347
4964
           }
4348
4965
           /* SHOW TABLE STATUS */
4349
4966
         | TABLE_SYM STATUS_SYM opt_db show_wild
4350
4967
           {
4351
 
             if (not show::buildTableStatus(YYSession, $3))
4352
 
               DRIZZLE_YYABORT;
 
4968
             Lex->sql_command= SQLCOM_SELECT;
 
4969
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
4970
             Lex->statement= select;
 
4971
 
 
4972
             std::string column_name= "Tables_in_";
 
4973
 
 
4974
             util::string::const_shared_ptr schema(YYSession->schema());
 
4975
             if ($3)
 
4976
             {
 
4977
               Lex->select_lex.db= $3;
 
4978
 
 
4979
               identifier::Schema identifier($3);
 
4980
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4981
               {
 
4982
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4983
               }
 
4984
 
 
4985
               select->setShowPredicate($3, "");
 
4986
             }
 
4987
             else if (schema)
 
4988
             {
 
4989
               select->setShowPredicate(*schema, "");
 
4990
             }
 
4991
             else
 
4992
             {
 
4993
               my_error(ER_NO_DB_ERROR, MYF(0));
 
4994
               DRIZZLE_YYABORT;
 
4995
             }
 
4996
 
 
4997
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLE_STATUS"))
 
4998
               DRIZZLE_YYABORT;
 
4999
 
 
5000
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
5001
                                                           context,
 
5002
                                                           NULL, NULL, "*")))
 
5003
               DRIZZLE_YYABORT;
 
5004
             (YYSession->lex->current_select->with_wild)++;
4353
5005
           }
4354
5006
           /* SHOW COLUMNS FROM table_name */
4355
5007
        | COLUMNS from_or_in table_ident opt_db show_wild
4356
 
           {
4357
 
             if (not show::buildColumns(YYSession, $4, $3))
4358
 
               DRIZZLE_YYABORT;
4359
 
           }
 
5008
          {
 
5009
             Lex->sql_command= SQLCOM_SELECT;
 
5010
 
 
5011
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
5012
             Lex->statement= select;
 
5013
 
 
5014
             util::string::const_shared_ptr schema(YYSession->schema());
 
5015
             if ($4)
 
5016
             {
 
5017
              select->setShowPredicate($4, $3->table.str);
 
5018
             }
 
5019
             else if ($3->db.str)
 
5020
             {
 
5021
              select->setShowPredicate($3->db.str, $3->table.str);
 
5022
             }
 
5023
             else if (schema)
 
5024
             {
 
5025
               select->setShowPredicate(*schema, $3->table.str);
 
5026
             }
 
5027
             else
 
5028
             {
 
5029
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5030
               DRIZZLE_YYABORT;
 
5031
             }
 
5032
 
 
5033
             {
 
5034
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
 
5035
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
 
5036
               {
 
5037
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5038
                            select->getShowSchema().c_str(), 
 
5039
                            $3->table.str);
 
5040
               }
 
5041
             }
 
5042
 
 
5043
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
 
5044
               DRIZZLE_YYABORT;
 
5045
 
 
5046
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
5047
                                                           context,
 
5048
                                                           NULL, NULL, "*")))
 
5049
               DRIZZLE_YYABORT;
 
5050
             (YYSession->lex->current_select->with_wild)++;
 
5051
 
 
5052
          }
4360
5053
          /* SHOW INDEXES from table */
4361
5054
        | keys_or_index from_or_in table_ident opt_db where_clause
4362
 
           {
4363
 
             if (not show::buildIndex(YYSession, $4, $3))
4364
 
               DRIZZLE_YYABORT;
4365
 
           }
 
5055
          {
 
5056
             Lex->sql_command= SQLCOM_SELECT;
 
5057
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
5058
             Lex->statement= select;
 
5059
 
 
5060
             util::string::const_shared_ptr schema(YYSession->schema());
 
5061
             if ($4)
 
5062
             {
 
5063
              select->setShowPredicate($4, $3->table.str);
 
5064
             }
 
5065
             else if ($3->db.str)
 
5066
             {
 
5067
              select->setShowPredicate($3->db.str, $3->table.str);
 
5068
             }
 
5069
             else if (schema)
 
5070
             {
 
5071
               select->setShowPredicate(*schema, $3->table.str);
 
5072
             }
 
5073
             else
 
5074
             {
 
5075
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5076
               DRIZZLE_YYABORT;
 
5077
             }
 
5078
 
 
5079
             {
 
5080
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
 
5081
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
 
5082
               {
 
5083
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5084
                            select->getShowSchema().c_str(), 
 
5085
                            $3->table.str);
 
5086
               }
 
5087
             }
 
5088
 
 
5089
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_INDEXES"))
 
5090
               DRIZZLE_YYABORT;
 
5091
 
 
5092
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
5093
                                                           context,
 
5094
                                                           NULL, NULL, "*")))
 
5095
               DRIZZLE_YYABORT;
 
5096
             (YYSession->lex->current_select->with_wild)++;
 
5097
          }
4366
5098
        | COUNT_SYM '(' '*' ')' WARNINGS
4367
5099
          {
4368
 
            show::buildSelectWarning(YYSession);
 
5100
            (void) create_select_for_variable("warning_count");
 
5101
             Lex->statement= new statement::Show(YYSession);
4369
5102
          }
4370
5103
        | COUNT_SYM '(' '*' ')' ERRORS
4371
5104
          {
4372
 
            show::buildSelectError(YYSession);
 
5105
            (void) create_select_for_variable("error_count");
 
5106
             Lex->statement= new statement::Show(YYSession);
4373
5107
          }
4374
5108
        | WARNINGS opt_limit_clause_init
4375
5109
          {
4376
 
            show::buildWarnings(YYSession);
 
5110
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5111
            Lex->statement= new statement::ShowWarnings(YYSession);
4377
5112
          }
4378
5113
        | ERRORS opt_limit_clause_init
4379
5114
          {
4380
 
            show::buildErrors(YYSession);
 
5115
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5116
            Lex->statement= new statement::ShowErrors(YYSession);
4381
5117
          }
4382
5118
        | opt_var_type STATUS_SYM show_wild
4383
 
          {
4384
 
            if (not show::buildStatus(YYSession, $1))
4385
 
              DRIZZLE_YYABORT;
4386
 
          }
4387
 
        | engine_option_value STATUS_SYM
4388
 
          {
4389
 
            if (not show::buildEngineStatus(YYSession, $1))
4390
 
              DRIZZLE_YYABORT;
4391
 
          }
 
5119
           {
 
5120
             Lex->sql_command= SQLCOM_SELECT;
 
5121
             Lex->statement= new statement::Show(YYSession);
 
5122
 
 
5123
             if ($1 == OPT_GLOBAL)
 
5124
             {
 
5125
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_STATUS"))
 
5126
                 DRIZZLE_YYABORT;
 
5127
             }
 
5128
             else
 
5129
             {
 
5130
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_STATUS"))
 
5131
                 DRIZZLE_YYABORT;
 
5132
             }
 
5133
 
 
5134
             std::string key("Variable_name");
 
5135
             std::string value("Value");
 
5136
 
 
5137
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5138
             my_field->is_autogenerated_name= false;
 
5139
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5140
 
 
5141
             if (YYSession->add_item_to_list(my_field))
 
5142
               DRIZZLE_YYABORT;
 
5143
 
 
5144
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5145
             my_field->is_autogenerated_name= false;
 
5146
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5147
 
 
5148
             if (YYSession->add_item_to_list(my_field))
 
5149
               DRIZZLE_YYABORT;
 
5150
           }
4392
5151
        | CREATE TABLE_SYM table_ident
4393
 
          {
4394
 
            if (not show::buildCreateTable(YYSession, $3))
4395
 
              DRIZZLE_YYABORT;
4396
 
          }
 
5152
           {
 
5153
             Lex->sql_command= SQLCOM_SELECT;
 
5154
             statement::Show *select= new statement::Show(YYSession);
 
5155
             Lex->statement= select;
 
5156
 
 
5157
             if (Lex->statement == NULL)
 
5158
               DRIZZLE_YYABORT;
 
5159
 
 
5160
             if (prepare_new_schema_table(YYSession, Lex, "TABLE_SQL_DEFINITION"))
 
5161
               DRIZZLE_YYABORT;
 
5162
 
 
5163
             util::string::const_shared_ptr schema(YYSession->schema());
 
5164
             if ($3->db.str)
 
5165
             {
 
5166
               select->setShowPredicate($3->db.str, $3->table.str);
 
5167
             }
 
5168
             else if (schema)
 
5169
             {
 
5170
               select->setShowPredicate(*schema, $3->table.str);
 
5171
             }
 
5172
             else
 
5173
             {
 
5174
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5175
               DRIZZLE_YYABORT;
 
5176
             }
 
5177
 
 
5178
             std::string key("Table");
 
5179
             std::string value("Create Table");
 
5180
 
 
5181
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5182
             my_field->is_autogenerated_name= false;
 
5183
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5184
 
 
5185
             if (YYSession->add_item_to_list(my_field))
 
5186
               DRIZZLE_YYABORT;
 
5187
 
 
5188
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5189
             my_field->is_autogenerated_name= false;
 
5190
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5191
 
 
5192
             if (YYSession->add_item_to_list(my_field))
 
5193
               DRIZZLE_YYABORT;
 
5194
           }
4397
5195
        | PROCESSLIST_SYM
4398
5196
          {
4399
 
            if (not show::buildProcesslist(YYSession))
4400
 
              DRIZZLE_YYABORT;
 
5197
           {
 
5198
             Lex->sql_command= SQLCOM_SELECT;
 
5199
             Lex->statement= new statement::Show(YYSession);
 
5200
 
 
5201
             if (prepare_new_schema_table(YYSession, Lex, "PROCESSLIST"))
 
5202
               DRIZZLE_YYABORT;
 
5203
 
 
5204
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
5205
                                                           context,
 
5206
                                                           NULL, NULL, "*")))
 
5207
               DRIZZLE_YYABORT;
 
5208
             (YYSession->lex->current_select->with_wild)++;
 
5209
           }
4401
5210
          }
4402
5211
        | opt_var_type  VARIABLES show_wild
4403
 
          {
4404
 
            if (not show::buildVariables(YYSession, $1))
4405
 
              DRIZZLE_YYABORT;
4406
 
          }
 
5212
           {
 
5213
             Lex->sql_command= SQLCOM_SELECT;
 
5214
             Lex->statement= new statement::Show(YYSession);
 
5215
 
 
5216
             if ($1 == OPT_GLOBAL)
 
5217
             {
 
5218
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_VARIABLES"))
 
5219
                 DRIZZLE_YYABORT;
 
5220
             }
 
5221
             else
 
5222
             {
 
5223
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_VARIABLES"))
 
5224
                 DRIZZLE_YYABORT;
 
5225
             }
 
5226
 
 
5227
             std::string key("Variable_name");
 
5228
             std::string value("Value");
 
5229
 
 
5230
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5231
             my_field->is_autogenerated_name= false;
 
5232
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5233
 
 
5234
             if (YYSession->add_item_to_list(my_field))
 
5235
               DRIZZLE_YYABORT;
 
5236
 
 
5237
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5238
             my_field->is_autogenerated_name= false;
 
5239
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5240
 
 
5241
             if (YYSession->add_item_to_list(my_field))
 
5242
               DRIZZLE_YYABORT;
 
5243
           }
4407
5244
        | CREATE DATABASE opt_if_not_exists ident
4408
 
          {
4409
 
            if (not show::buildCreateSchema(YYSession, $4))
4410
 
              DRIZZLE_YYABORT;
4411
 
          }
 
5245
           {
 
5246
             Lex->sql_command= SQLCOM_SELECT;
 
5247
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
5248
             Lex->statement= select;
 
5249
 
 
5250
             if (prepare_new_schema_table(YYSession, Lex, "SCHEMA_SQL_DEFINITION"))
 
5251
               DRIZZLE_YYABORT;
 
5252
 
 
5253
             util::string::const_shared_ptr schema(YYSession->schema());
 
5254
             if ($4.str)
 
5255
             {
 
5256
              select->setShowPredicate($4.str);
 
5257
             }
 
5258
             else if (schema)
 
5259
             {
 
5260
               select->setShowPredicate(*schema);
 
5261
             }
 
5262
             else
 
5263
             {
 
5264
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5265
               DRIZZLE_YYABORT;
 
5266
             }
 
5267
 
 
5268
             std::string key("Database");
 
5269
             std::string value("Create Database");
 
5270
 
 
5271
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5272
             my_field->is_autogenerated_name= false;
 
5273
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5274
 
 
5275
             if (YYSession->add_item_to_list(my_field))
 
5276
               DRIZZLE_YYABORT;
 
5277
 
 
5278
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5279
             my_field->is_autogenerated_name= false;
 
5280
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5281
 
 
5282
             if (YYSession->add_item_to_list(my_field))
 
5283
               DRIZZLE_YYABORT;
 
5284
           }
4412
5285
 
4413
5286
opt_db:
4414
5287
          /* empty */  { $$= 0; }
4441
5314
describe:
4442
5315
          describe_command table_ident
4443
5316
          {
4444
 
            if (not show::buildDescribe(YYSession, $2))
4445
 
            {
4446
 
              DRIZZLE_YYABORT;
4447
 
            }
 
5317
            Lex->lock_option= TL_READ;
 
5318
            init_select(Lex);
 
5319
            Lex->current_select->parsing_place= SELECT_LIST;
 
5320
            Lex->sql_command= SQLCOM_SELECT;
 
5321
            drizzled::statement::Show *select= new statement::Show(YYSession);
 
5322
            Lex->statement= select;
 
5323
            Lex->select_lex.db= 0;
 
5324
 
 
5325
             util::string::const_shared_ptr schema(YYSession->schema());
 
5326
             if ($2->db.str)
 
5327
             {
 
5328
               select->setShowPredicate($2->db.str, $2->table.str);
 
5329
             }
 
5330
             else if (schema)
 
5331
             {
 
5332
               select->setShowPredicate(*schema, $2->table.str);
 
5333
             }
 
5334
             else
 
5335
             {
 
5336
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5337
               DRIZZLE_YYABORT;
 
5338
             }
 
5339
 
 
5340
             {
 
5341
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $2->table.str);
 
5342
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
 
5343
               {
 
5344
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5345
                            select->getShowSchema().c_str(), 
 
5346
                            $2->table.str);
 
5347
               }
 
5348
             }
 
5349
 
 
5350
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
 
5351
               DRIZZLE_YYABORT;
 
5352
 
 
5353
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
5354
                                                           context,
 
5355
                                                           NULL, NULL, "*")))
 
5356
             {
 
5357
               DRIZZLE_YYABORT;
 
5358
             }
 
5359
             (YYSession->lex->current_select->with_wild)++;
 
5360
 
4448
5361
          }
4449
5362
          opt_describe_column {}
4450
5363
        | describe_command opt_extended_describe
4482
5395
flush:
4483
5396
          FLUSH_SYM
4484
5397
          {
 
5398
            Lex->sql_command= SQLCOM_FLUSH;
4485
5399
            Lex->statement= new statement::Flush(YYSession);
 
5400
            Lex->type= 0;
4486
5401
          }
4487
5402
          flush_options
4488
5403
          {}
4532
5447
kill:
4533
5448
          KILL_SYM kill_option expr
4534
5449
          {
4535
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5450
            if ($2)
 
5451
            {
 
5452
              Lex->type= ONLY_KILL_QUERY;
 
5453
            }
 
5454
 
 
5455
            Lex->value_list.empty();
 
5456
            Lex->value_list.push_front($3);
 
5457
            Lex->sql_command= SQLCOM_KILL;
 
5458
            Lex->statement= new statement::Kill(YYSession);
4536
5459
          }
4537
5460
        ;
4538
5461
 
4547
5470
use:
4548
5471
          USE_SYM schema_name
4549
5472
          {
 
5473
            Lex->sql_command=SQLCOM_CHANGE_DB;
4550
5474
            Lex->statement= new statement::ChangeSchema(YYSession);
4551
5475
            Lex->select_lex.db= $2.str;
4552
5476
          }
4557
5481
load:
4558
5482
          LOAD data_file
4559
5483
          {
 
5484
            Lex->sql_command= SQLCOM_LOAD;
4560
5485
            statement::Load *statement= new statement::Load(YYSession);
4561
5486
            Lex->statement= statement;
4562
5487
 
4582
5507
                    $12, NULL, TL_OPTION_UPDATING,
4583
5508
                    Lex->lock_option))
4584
5509
              DRIZZLE_YYABORT;
4585
 
            Lex->field_list.clear();
4586
 
            Lex->update_list.clear();
4587
 
            Lex->value_list.clear();
 
5510
            Lex->field_list.empty();
 
5511
            Lex->update_list.empty();
 
5512
            Lex->value_list.empty();
4588
5513
          }
4589
5514
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4590
5515
          opt_load_data_set_spec
4702
5627
        ;
4703
5628
 
4704
5629
field_or_var:
4705
 
          simple_ident {$$= $1;}
 
5630
          simple_ident_nospvar {$$= $1;}
4706
5631
        | '@' user_variable_ident
4707
5632
          { $$= new Item_user_var_as_out_param($2); }
4708
5633
        ;
4817
5742
**********************************************************************/
4818
5743
 
4819
5744
insert_ident:
4820
 
          simple_ident { $$=$1; }
 
5745
          simple_ident_nospvar { $$=$1; }
4821
5746
        | table_wild { $$=$1; }
4822
5747
        ;
4823
5748
 
4824
5749
table_wild:
4825
5750
          ident '.' '*'
4826
5751
          {
4827
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5752
            Select_Lex *sel= Lex->current_select;
 
5753
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5754
            sel->with_wild++;
4828
5755
          }
4829
5756
        | ident '.' ident '.' '*'
4830
5757
          {
4831
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5758
            Select_Lex *sel= Lex->current_select;
 
5759
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5760
            sel->with_wild++;
4832
5761
          }
4833
5762
        ;
4834
5763
 
4839
5768
simple_ident:
4840
5769
          ident
4841
5770
          {
4842
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5771
            {
 
5772
              Select_Lex *sel=Lex->current_select;
 
5773
              $$= (sel->parsing_place != IN_HAVING ||
 
5774
                  sel->get_in_sum_expr() > 0) ?
 
5775
                  (Item*) new Item_field(Lex->current_context(),
 
5776
                                         (const char *)NULL, NULL, $1.str) :
 
5777
                  (Item*) new Item_ref(Lex->current_context(),
 
5778
                                       (const char *)NULL, NULL, $1.str);
 
5779
            }
 
5780
          }
 
5781
        | simple_ident_q { $$= $1; }
 
5782
        ;
 
5783
 
 
5784
simple_ident_nospvar:
 
5785
          ident
 
5786
          {
 
5787
            Select_Lex *sel=Lex->current_select;
 
5788
            $$= (sel->parsing_place != IN_HAVING ||
 
5789
                sel->get_in_sum_expr() > 0) ?
 
5790
                (Item*) new Item_field(Lex->current_context(),
 
5791
                                       (const char *)NULL, NULL, $1.str) :
 
5792
                (Item*) new Item_ref(Lex->current_context(),
 
5793
                                     (const char *)NULL, NULL, $1.str);
4843
5794
          }
4844
5795
        | simple_ident_q { $$= $1; }
4845
5796
        ;
4847
5798
simple_ident_q:
4848
5799
          ident '.' ident
4849
5800
          {
4850
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5801
            {
 
5802
              Select_Lex *sel= Lex->current_select;
 
5803
              if (sel->no_table_names_allowed)
 
5804
              {
 
5805
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5806
                         MYF(0), $1.str, YYSession->where);
 
5807
              }
 
5808
              $$= (sel->parsing_place != IN_HAVING ||
 
5809
                  sel->get_in_sum_expr() > 0) ?
 
5810
                  (Item*) new Item_field(Lex->current_context(),
 
5811
                                         (const char *)NULL, $1.str, $3.str) :
 
5812
                  (Item*) new Item_ref(Lex->current_context(),
 
5813
                                       (const char *)NULL, $1.str, $3.str);
 
5814
            }
4851
5815
          }
4852
5816
        | '.' ident '.' ident
4853
5817
          {
4854
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5818
            Select_Lex *sel= Lex->current_select;
 
5819
            if (sel->no_table_names_allowed)
 
5820
            {
 
5821
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5822
                       MYF(0), $2.str, YYSession->where);
 
5823
            }
 
5824
            $$= (sel->parsing_place != IN_HAVING ||
 
5825
                sel->get_in_sum_expr() > 0) ?
 
5826
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5827
                (Item*) new Item_ref(Lex->current_context(),
 
5828
                                     (const char *)NULL, $2.str, $4.str);
4855
5829
          }
4856
5830
        | ident '.' ident '.' ident
4857
5831
          {
4858
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5832
            Select_Lex *sel= Lex->current_select;
 
5833
            if (sel->no_table_names_allowed)
 
5834
            {
 
5835
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5836
                       MYF(0), $3.str, YYSession->where);
 
5837
            }
 
5838
            $$= (sel->parsing_place != IN_HAVING ||
 
5839
                sel->get_in_sum_expr() > 0) ?
 
5840
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5841
                                       $5.str) :
 
5842
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5843
                                     $5.str);
4859
5844
          }
4860
5845
        ;
4861
5846
 
4862
5847
field_ident:
4863
 
          ident 
4864
 
          {
4865
 
            $$=$1;
4866
 
          }
 
5848
          ident { $$=$1;}
4867
5849
        | ident '.' ident '.' ident
4868
5850
          {
4869
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4870
 
              DRIZZLE_YYABORT;
4871
 
 
 
5851
            TableList *table=
 
5852
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5853
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
 
5854
            {
 
5855
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5856
              DRIZZLE_YYABORT;
 
5857
            }
 
5858
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5859
                              table->getTableName()))
 
5860
            {
 
5861
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5862
              DRIZZLE_YYABORT;
 
5863
            }
4872
5864
            $$=$5;
4873
5865
          }
4874
5866
        | ident '.' ident
4875
5867
          {
4876
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5868
            TableList *table=
 
5869
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5870
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5871
            {
 
5872
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5873
              DRIZZLE_YYABORT;
4878
 
 
 
5874
            }
4879
5875
            $$=$3;
4880
5876
          }
4881
 
        | '.' ident 
4882
 
          { /* For Delphi */
4883
 
            $$=$2;
4884
 
          }
 
5877
        | '.' ident { $$=$2;} /* For Delphi */
4885
5878
        ;
4886
5879
 
4887
5880
table_ident:
4888
 
          ident
4889
 
          {
4890
 
            $$= new Table_ident($1);
4891
 
          }
4892
 
        | schema_name '.' ident
4893
 
          {
4894
 
            $$=new Table_ident($1,$3);
4895
 
          }
4896
 
        | '.' ident
4897
 
        { /* For Delphi */
4898
 
          $$= new Table_ident($2);
4899
 
        }
 
5881
          ident { $$=new Table_ident($1); }
 
5882
        | schema_name '.' ident { $$=new Table_ident($1,$3);}
 
5883
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4900
5884
        ;
4901
5885
 
4902
5886
schema_name:
5140
6124
set:
5141
6125
          SET_SYM opt_option
5142
6126
          {
 
6127
            Lex->sql_command= SQLCOM_SET_OPTION;
5143
6128
            Lex->statement= new statement::SetOption(YYSession);
 
6129
            init_select(Lex);
 
6130
            Lex->option_type=OPT_SESSION;
 
6131
            Lex->var_list.empty();
5144
6132
          }
5145
6133
          option_value_list
5146
6134
          {}
5157
6145
        ;
5158
6146
 
5159
6147
option_type_value:
5160
 
          { }
 
6148
          {
 
6149
          }
5161
6150
          ext_option_value
5162
 
          { }
 
6151
          {
 
6152
          }
5163
6153
        ;
5164
6154
 
5165
6155
option_type:
5280
6270
unlock:
5281
6271
          UNLOCK_SYM
5282
6272
          {
 
6273
            Lex->sql_command= SQLCOM_UNLOCK_TABLES;
5283
6274
            Lex->statement= new statement::UnlockTables(YYSession);
5284
6275
          }
5285
6276
          table_or_tables
5289
6280
begin:
5290
6281
          BEGIN_SYM
5291
6282
          {
 
6283
            Lex->sql_command = SQLCOM_BEGIN;
5292
6284
            Lex->statement= new statement::StartTransaction(YYSession);
5293
6285
          }
5294
6286
          opt_work {}
5321
6313
commit:
5322
6314
          COMMIT_SYM opt_work opt_chain opt_release
5323
6315
          {
5324
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6316
            Lex->sql_command= SQLCOM_COMMIT;
 
6317
            statement::Commit *statement= new statement::Commit(YYSession);
 
6318
            Lex->statement= statement;
 
6319
            statement->tx_chain= $3;
 
6320
            statement->tx_release= $4;
5325
6321
          }
5326
6322
        ;
5327
6323
 
5328
6324
rollback:
5329
6325
          ROLLBACK_SYM opt_work opt_chain opt_release
5330
6326
          {
5331
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6327
            Lex->sql_command= SQLCOM_ROLLBACK;
 
6328
            statement::Rollback *statement= new statement::Rollback(YYSession);
 
6329
            Lex->statement= statement;
 
6330
            statement->tx_chain= $3;
 
6331
            statement->tx_release= $4;
5332
6332
          }
5333
6333
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
5334
6334
          {
5335
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6335
            Lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6336
            Lex->statement= new statement::RollbackToSavepoint(YYSession);
 
6337
            Lex->ident= $5;
5336
6338
          }
5337
6339
        ;
5338
6340
 
5339
6341
savepoint:
5340
6342
          SAVEPOINT_SYM savepoint_ident
5341
6343
          {
5342
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6344
            Lex->sql_command= SQLCOM_SAVEPOINT;
 
6345
            Lex->statement= new statement::Savepoint(YYSession);
 
6346
            Lex->ident= $2;
5343
6347
          }
5344
6348
        ;
5345
6349
 
5346
6350
release:
5347
6351
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
5348
6352
          {
5349
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6353
            Lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6354
            Lex->statement= new statement::ReleaseSavepoint(YYSession);
 
6355
            Lex->ident= $3;
5350
6356
          }
5351
6357
        ;
5352
6358
 
5367
6373
union_list:
5368
6374
          UNION_SYM union_option
5369
6375
          {
5370
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6376
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5371
6377
              DRIZZLE_YYABORT;
5372
6378
          }
5373
6379
          select_init
5398
6404
              fake->no_table_names_allowed= 1;
5399
6405
              Lex->current_select= fake;
5400
6406
            }
5401
 
            YYSession->setWhere("global ORDER clause");
 
6407
            YYSession->where= "global ORDER clause";
5402
6408
          }
5403
6409
          order_or_limit
5404
6410
          {
5405
 
            YYSession->getLex()->current_select->no_table_names_allowed= 0;
5406
 
            YYSession->setWhere("");
 
6411
            YYSession->lex->current_select->no_table_names_allowed= 0;
 
6412
            YYSession->where= "";
5407
6413
          }
5408
6414
        ;
5409
6415
 
5434
6440
        | query_expression_body
5435
6441
          UNION_SYM union_option
5436
6442
          {
5437
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6443
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5438
6444
              DRIZZLE_YYABORT;
5439
6445
          }
5440
6446
          query_specification
5456
6462
          {
5457
6463
            if (not Lex->expr_allows_subselect)
5458
6464
            {
5459
 
              parser::my_parse_error(YYSession->m_lip);
 
6465
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6466
              my_parse_error(&pass);
5460
6467
              DRIZZLE_YYABORT;
5461
6468
            }
5462
6469
            /*