~drizzle-trunk/drizzle/development

2312.3.1 by Brian Aker
Fix for bug 786509
1
/* 
2
   Copyright (C) 2010-2011 Brian Aker
3
   Copyright (C) 2000-2003 MySQL AB
1 by brian
clean slate
4
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; version 2 of the License.
8
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
16
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
17
18
/* sql_yacc.yy */
19
20
/**
21
  @defgroup Parser Parser
22
  @{
23
*/
24
25
%{
520.1.22 by Brian Aker
Second pass of thd cleanup
26
/* session is passed as an argument to yyparse(), and subsequently to yylex().
27
** The type will be void*, so it must be  cast to (Session*) when used.
28
** Use the YYSession macro for this.
1 by brian
clean slate
29
*/
2172.3.8 by Brian Aker
Modernize our call to the parser, no more casting required.
30
2172.3.9 by Brian Aker
Dead-ish the macro for YYSession since we no longer cast.
31
#define YYSession (session)
1 by brian
clean slate
32
77.1.45 by Monty Taylor
Warning fixes.
33
#define YYENABLE_NLS 0
34
#define YYLTYPE_IS_TRIVIAL 0
35
1 by brian
clean slate
36
#define YYINITDEPTH 100
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
2227.4.10 by Olaf van der Spek
Session::lex()
38
#define Lex (session->lex())
1285 by Brian Aker
Remove giant include header to its own file.
39
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
40
#include <config.h>
1530.5.10 by Monty Taylor
Fixed build errors on FreeBSD.
41
#include <cstdio>
2172.3.6 by Brian Aker
Namespace the parser just a bit, and update our call for the type of parser
42
#include <drizzled/parser.h>
2207.8.4 by Olaf van der Spek
Refactor includes
43
#include <drizzled/session.h>
2198.1.1 by Olaf van der Spek
Remove unnecessary alter* includes
44
#include <drizzled/alter_column.h>
45
#include <drizzled/alter_info.h>
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
46
#include <drizzled/message/alter_table.pb.h>
2198.1.2 by Olaf van der Spek
Refactor includes
47
#include <drizzled/item/subselect.h>
2239.1.9 by Olaf van der Spek
Refactor includes
48
#include <drizzled/table_ident.h>
2241.2.11 by Olaf van der Spek
Refactor
49
#include <drizzled/var.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
50
#include <drizzled/system_variables.h>
2318.8.7 by Olaf van der Spek
Add const
51
#include <drizzled/lex_input_stream.h>
2440.2.4 by Olaf van der Spek
Refactor
52
#include <drizzled/show.h>
1100.3.1 by Padraig O'Sullivan
Beginnings of reworking the mysql_execute_command() method.
53
2172.3.10 by Brian Aker
Fix parser type to not be a void.
54
int yylex(union ParserType *yylval, drizzled::Session *session);
1 by brian
clean slate
55
56
#define yyoverflow(A,B,C,D,E,F)               \
57
  {                                           \
2104.3.1 by Brian Aker
Merge in ulong typedef used.
58
    unsigned long val= *(F);                          \
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
59
    if (drizzled::my_yyoverflow((B), (D), &val)) \
1 by brian
clean slate
60
    {                                         \
2385.3.21 by Olaf van der Spek
Refactor
61
      yyerror(NULL, (A));                   \
1 by brian
clean slate
62
      return 2;                               \
63
    }                                         \
64
    else                                      \
65
    {                                         \
66
      *(F)= (YYSIZE_T)val;                    \
67
    }                                         \
68
  }
69
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
70
#define DRIZZLE_YYABORT                         \
1 by brian
clean slate
71
  do                                          \
72
  {                                           \
73
    YYABORT;                                  \
74
  } while (0)
75
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
76
#define DRIZZLE_YYABORT_UNLESS(A)         \
1 by brian
clean slate
77
  if (!(A))                             \
78
  {                                     \
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
79
    parser::my_parse_error(YYSession->m_lip);\
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
80
    DRIZZLE_YYABORT;                      \
1 by brian
clean slate
81
  }
82
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
83
namespace drizzled
84
{
85
86
class Table_ident;
87
class Item;
88
class Item_num;
89
2035.1.2 by Brian Aker
Make the item call a bit friendlier.
90
namespace item
91
{
92
class Boolean;
93
class True;
94
class False;
95
}
96
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
97
1 by brian
clean slate
98
/**
99
  @brief Bison callback to report a syntax/OOM error
100
101
  This function is invoked by the bison-generated parser
102
  when a syntax error, a parse error or an out-of-memory
103
  condition occurs. This function is not invoked when the
104
  parser is requested to abort by semantic action code
105
  by means of YYABORT or YYACCEPT macros. This is why these
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
106
  macros should not be used (use DRIZZLE_YYABORT/DRIZZLE_YYACCEPT
1 by brian
clean slate
107
  instead).
108
109
  The parser will abort immediately after invoking this callback.
110
111
  This function is not for use in semantic actions and is internal to
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
112
  the parser, as it performs some pre-return cleanup.
2096.1.14 by Brian Aker
Pull in more C code from parser.
113
  In semantic actions, please use parser::my_parse_error or my_error to
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
114
  push an error into the error stack and DRIZZLE_YYABORT
1 by brian
clean slate
115
  to abort from the parser.
116
*/
117
2385.3.22 by Olaf van der Spek
Refactor
118
static void base_sql_error(drizzled::Session *session, const char* s)
1 by brian
clean slate
119
{
2172.3.8 by Brian Aker
Modernize our call to the parser, no more casting required.
120
  parser::errorOn(session, s);
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
121
}
122
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
123
} /* namespace drizzled; */
124
125
using namespace drizzled;
1 by brian
clean slate
126
%}
2172.3.10 by Brian Aker
Fix parser type to not be a void.
127
%union ParserType {
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
128
  bool boolean;
1 by brian
clean slate
129
  int  num;
2104.3.1 by Brian Aker
Merge in ulong typedef used.
130
  unsigned long ulong_num;
151 by Brian Aker
Ulonglong to uint64_t
131
  uint64_t ulonglong_number;
154 by Brian Aker
Removed oddball types in my_global.h
132
  int64_t longlong_number;
2371.1.2 by Brian Aker
Remove the typedef on lexkey
133
  drizzled::lex_string_t lex_str;
134
  drizzled::lex_string_t *lex_str_ptr;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
135
  drizzled::LEX_SYMBOL symbol;
136
  drizzled::Table_ident *table;
2385.3.18 by Olaf van der Spek
Refactor
137
  const char* simple_string;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
138
  drizzled::Item *item;
139
  drizzled::Item_num *item_num;
140
  drizzled::List<drizzled::Item> *item_list;
141
  drizzled::List<drizzled::String> *string_list;
142
  drizzled::String *string;
143
  drizzled::Key_part_spec *key_part;
144
  const drizzled::plugin::Function *udf;
145
  drizzled::TableList *table_list;
2096.1.15 by Brian Aker
Additional parser cleanup.
146
  drizzled::enum_field_types field_val;
147
  drizzled::sys_var_with_base variable;
148
  drizzled::sql_var_t var_type;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
149
  drizzled::Key::Keytype key_type;
2096.1.15 by Brian Aker
Additional parser cleanup.
150
  drizzled::ha_key_alg key_alg;
151
  drizzled::ha_rkey_function ha_rkey_mode;
152
  drizzled::enum_tx_isolation tx_isolation;
153
  drizzled::Cast_target cast_type;
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
154
  const drizzled::charset_info_st *charset;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
155
  drizzled::thr_lock_type lock_type;
156
  drizzled::interval_type interval, interval_time_st;
2088.8.9 by Brian Aker
Merge in namespace of enum.
157
  drizzled::type::timestamp_t date_time_type;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
158
  drizzled::Select_Lex *select_lex;
159
  drizzled::chooser_compare_func_creator boolfunc2creator;
2252.1.25 by Olaf van der Spek
Common fwd
160
  drizzled::LEX *lex;
2096.1.15 by Brian Aker
Additional parser cleanup.
161
  drizzled::index_hint_type index_hint;
162
  drizzled::enum_filetype filetype;
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
163
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
164
  drizzled::execute_string_t execute_string;
1 by brian
clean slate
165
}
166
167
%{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
168
namespace drizzled
169
{
2172.3.10 by Brian Aker
Fix parser type to not be a void.
170
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
171
}
1 by brian
clean slate
172
%}
173
2029.1.21 by Brian Aker
Reduce dependency on LEX_HOME.
174
%debug
2325.2.1 by Brian Aker
Require bison version.
175
%require "2.4"
2178.1.2 by Brian Aker
Go back a version and see if this will make the bison on RHEL happy.
176
%pure-parser
2178.1.3 by Brian Aker
Merge in additional throw back in syntax for bison
177
%name-prefix="base_sql_"
2172.3.8 by Brian Aker
Modernize our call to the parser, no more casting required.
178
%parse-param { drizzled::Session *session }
2172.3.11 by Brian Aker
Fix lex to use modern param type add.
179
%lex-param { drizzled::Session *session }
2172.3.12 by Brian Aker
Adding verbose to be explicit in the parser.
180
%verbose
2172.3.8 by Brian Aker
Modernize our call to the parser, no more casting required.
181
2029.1.21 by Brian Aker
Reduce dependency on LEX_HOME.
182
1 by brian
clean slate
183
/*
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
184
  Currently there are 70 shift/reduce conflicts.
1 by brian
clean slate
185
  We should not introduce new conflicts any more.
186
*/
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
187
%expect 80
1 by brian
clean slate
188
189
/*
190
   Comments for TOKENS.
191
   For each token, please include in the same line a comment that contains
192
   the following tags:
193
   SQL-2003-R : Reserved keyword as per SQL-2003
194
   SQL-2003-N : Non Reserved keyword as per SQL-2003
195
   SQL-1999-R : Reserved keyword as per SQL-1999
196
   SQL-1999-N : Non Reserved keyword as per SQL-1999
197
   MYSQL      : MySQL extention (unspecified)
198
   MYSQL-FUNC : MySQL extention, function
199
   INTERNAL   : Not a real token, lex optimization
200
   OPERATOR   : SQL operator
201
   FUTURE-USE : Reserved for futur use
202
203
   This makes the code grep-able, and helps maintenance.
204
*/
205
206
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
207
%token  ACTION                        /* SQL-2003-N */
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
208
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
2030.1.1 by Brian Aker
Small set of symbol updates.
209
%token  ADD_SYM                           /* SQL-2003-R */
1 by brian
clean slate
210
%token  AFTER_SYM                     /* SQL-2003-N */
211
%token  AGGREGATE_SYM
212
%token  ALL                           /* SQL-2003-R */
2030.1.1 by Brian Aker
Small set of symbol updates.
213
%token  ALTER_SYM                         /* SQL-2003-R */
1 by brian
clean slate
214
%token  ANALYZE_SYM
215
%token  AND_SYM                       /* SQL-2003-R */
216
%token  ANY_SYM                       /* SQL-2003-R */
217
%token  AS                            /* SQL-2003-R */
218
%token  ASC                           /* SQL-2003-N */
219
%token  ASENSITIVE_SYM                /* FUTURE-USE */
220
%token  AT_SYM                        /* SQL-2003-R */
221
%token  AUTO_INC
222
%token  AVG_SYM                       /* SQL-2003-N */
223
%token  BEFORE_SYM                    /* SQL-2003-N */
224
%token  BEGIN_SYM                     /* SQL-2003-R */
225
%token  BETWEEN_SYM                   /* SQL-2003-R */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
226
%token  BIGINT_SYM                    /* SQL-2003-R */
1 by brian
clean slate
227
%token  BINARY                        /* SQL-2003-R */
228
%token  BIN_NUM
229
%token  BIT_SYM                       /* MYSQL-FUNC */
230
%token  BLOB_SYM                      /* SQL-2003-R */
231
%token  BOOLEAN_SYM                   /* SQL-2003-R */
232
%token  BOOL_SYM
233
%token  BOTH                          /* SQL-2003-R */
234
%token  BTREE_SYM
235
%token  BY                            /* SQL-2003-R */
236
%token  CALL_SYM                      /* SQL-2003-R */
237
%token  CASCADE                       /* SQL-2003-N */
238
%token  CASCADED                      /* SQL-2003-R */
239
%token  CASE_SYM                      /* SQL-2003-R */
240
%token  CAST_SYM                      /* SQL-2003-R */
2073.1.2 by Brian Aker
Basic DDL for catalog.
241
%token  CATALOG_SYM
1 by brian
clean slate
242
%token  CHAIN_SYM                     /* SQL-2003-N */
2030.1.1 by Brian Aker
Small set of symbol updates.
243
%token  CHANGE_SYM
2239.5.4 by Brian Aker
Compatibility issue with the output of other DB's for import
244
%token  CHARSET
1 by brian
clean slate
245
%token  CHAR_SYM                      /* SQL-2003-R */
246
%token  CHECKSUM_SYM
247
%token  CHECK_SYM                     /* SQL-2003-R */
248
%token  CLOSE_SYM                     /* SQL-2003-R */
249
%token  COALESCE                      /* SQL-2003-N */
250
%token  COLLATE_SYM                   /* SQL-2003-R */
251
%token  COLLATION_SYM                 /* SQL-2003-N */
252
%token  COLUMNS
253
%token  COLUMN_SYM                    /* SQL-2003-R */
254
%token  COMMENT_SYM
255
%token  COMMITTED_SYM                 /* SQL-2003-N */
256
%token  COMMIT_SYM                    /* SQL-2003-R */
257
%token  COMPACT_SYM
258
%token  COMPRESSED_SYM
259
%token  CONCURRENT
260
%token  CONDITION_SYM                 /* SQL-2003-N */
261
%token  CONNECTION_SYM
262
%token  CONSISTENT_SYM
263
%token  CONSTRAINT                    /* SQL-2003-R */
264
%token  CONTAINS_SYM                  /* SQL-2003-N */
265
%token  CONVERT_SYM                   /* SQL-2003-N */
266
%token  COUNT_SYM                     /* SQL-2003-N */
267
%token  CREATE                        /* SQL-2003-R */
268
%token  CROSS                         /* SQL-2003-R */
269
%token  CUBE_SYM                      /* SQL-2003-R */
270
%token  CURDATE                       /* MYSQL-FUNC */
271
%token  CURRENT_USER                  /* SQL-2003-R */
272
%token  CURSOR_SYM                    /* SQL-2003-R */
273
%token  DATABASE
274
%token  DATABASES
275
%token  DATA_SYM                      /* SQL-2003-N */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
276
%token  DATETIME_SYM
1 by brian
clean slate
277
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
278
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
279
%token  DATE_SYM                      /* SQL-2003-R */
280
%token  DAY_HOUR_SYM
281
%token  DAY_MICROSECOND_SYM
282
%token  DAY_MINUTE_SYM
283
%token  DAY_SECOND_SYM
284
%token  DAY_SYM                       /* SQL-2003-R */
285
%token  DEALLOCATE_SYM                /* SQL-2003-R */
286
%token  DECIMAL_NUM
287
%token  DECIMAL_SYM                   /* SQL-2003-R */
288
%token  DECLARE_SYM                   /* SQL-2003-R */
289
%token  DEFAULT                       /* SQL-2003-R */
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
290
%token  DEFINER
1 by brian
clean slate
291
%token  DELETE_SYM                    /* SQL-2003-R */
292
%token  DESC                          /* SQL-2003-N */
293
%token  DESCRIBE                      /* SQL-2003-R */
294
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
295
%token  DISABLE_SYM
296
%token  DISCARD
297
%token  DISTINCT                      /* SQL-2003-R */
298
%token  DIV_SYM
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
299
%token  DOUBLE_SYM                    /* SQL-2003-R */
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
300
%token  DO_SYM
1 by brian
clean slate
301
%token  DROP                          /* SQL-2003-R */
302
%token  DUMPFILE
303
%token  DUPLICATE_SYM
304
%token  DYNAMIC_SYM                   /* SQL-2003-R */
305
%token  EACH_SYM                      /* SQL-2003-R */
306
%token  ELSE                          /* SQL-2003-R */
307
%token  ENABLE_SYM
308
%token  ENCLOSED
309
%token  END                           /* SQL-2003-R */
310
%token  ENDS_SYM
311
%token  END_OF_INPUT                  /* INTERNAL */
312
%token  ENGINE_SYM
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
313
%token  ENUM_SYM
1 by brian
clean slate
314
%token  EQUAL_SYM                     /* OPERATOR */
315
%token  ERRORS
316
%token  ESCAPED
317
%token  ESCAPE_SYM                    /* SQL-2003-R */
318
%token  EXCLUSIVE_SYM
2029.1.25 by Brian Aker
Remove dead keywords from MySQL.
319
%token  EXECUTE_SYM                   /* SQL-2003-R */
1 by brian
clean slate
320
%token  EXISTS                        /* SQL-2003-R */
321
%token  EXTENDED_SYM
322
%token  EXTRACT_SYM                   /* SQL-2003-N */
323
%token  FALSE_SYM                     /* SQL-2003-R */
324
%token  FILE_SYM
325
%token  FIRST_SYM                     /* SQL-2003-N */
326
%token  FIXED_SYM
327
%token  FLOAT_NUM
328
%token  FLUSH_SYM
329
%token  FORCE_SYM
330
%token  FOREIGN                       /* SQL-2003-R */
331
%token  FOR_SYM                       /* SQL-2003-R */
332
%token  FOUND_SYM                     /* SQL-2003-R */
333
%token  FRAC_SECOND_SYM
334
%token  FROM
335
%token  FULL                          /* SQL-2003-R */
336
%token  GE
337
%token  GLOBAL_SYM                    /* SQL-2003-R */
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
338
%token  GROUP_CONCAT_SYM
1 by brian
clean slate
339
%token  GROUP_SYM                     /* SQL-2003-R */
340
%token  HASH_SYM
341
%token  HAVING                        /* SQL-2003-R */
342
%token  HEX_NUM
343
%token  HOUR_MICROSECOND_SYM
344
%token  HOUR_MINUTE_SYM
345
%token  HOUR_SECOND_SYM
346
%token  HOUR_SYM                      /* SQL-2003-R */
347
%token  IDENT
348
%token  IDENTIFIED_SYM
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
349
%token  IDENTITY_SYM                  /* SQL-2003-R */
1 by brian
clean slate
350
%token  IDENT_QUOTED
351
%token  IF
352
%token  IGNORE_SYM
353
%token  IMPORT
354
%token  INDEXES
355
%token  INDEX_SYM
356
%token  INFILE
357
%token  INNER_SYM                     /* SQL-2003-R */
358
%token  INOUT_SYM                     /* SQL-2003-R */
359
%token  INSENSITIVE_SYM               /* SQL-2003-R */
360
%token  INSERT                        /* SQL-2003-R */
361
%token  INTERVAL_SYM                  /* SQL-2003-R */
362
%token  INTO                          /* SQL-2003-R */
363
%token  INT_SYM                       /* SQL-2003-R */
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
364
%token  INVOKER
1 by brian
clean slate
365
%token  IN_SYM                        /* SQL-2003-R */
366
%token  IS                            /* SQL-2003-R */
367
%token  ISOLATION                     /* SQL-2003-R */
368
%token  ITERATE_SYM
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
369
%token  IPV6_SYM
1 by brian
clean slate
370
%token  JOIN_SYM                      /* SQL-2003-R */
371
%token  KEYS
372
%token  KEY_BLOCK_SIZE
373
%token  KEY_SYM                       /* SQL-2003-N */
374
%token  KILL_SYM
375
%token  LAST_SYM                      /* SQL-2003-N */
376
%token  LE                            /* OPERATOR */
377
%token  LEADING                       /* SQL-2003-R */
378
%token  LEFT                          /* SQL-2003-R */
379
%token  LEVEL_SYM
380
%token  LEX_HOSTNAME
381
%token  LIKE                          /* SQL-2003-R */
382
%token  LIMIT
383
%token  LINES
384
%token  LOAD
385
%token  LOCAL_SYM                     /* SQL-2003-R */
386
%token  LOCKS_SYM
387
%token  LOCK_SYM
388
%token  LOGS_SYM
389
%token  LONG_NUM
390
%token  LONG_SYM
391
%token  MATCH                         /* SQL-2003-R */
392
%token  MAX_SYM                       /* SQL-2003-N */
393
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
394
%token  MEDIUM_SYM
395
%token  MERGE_SYM                     /* SQL-2003-R */
396
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
397
%token  MINUTE_MICROSECOND_SYM
398
%token  MINUTE_SECOND_SYM
399
%token  MINUTE_SYM                    /* SQL-2003-R */
400
%token  MIN_SYM                       /* SQL-2003-N */
401
%token  MODE_SYM
402
%token  MODIFIES_SYM                  /* SQL-2003-R */
403
%token  MODIFY_SYM
404
%token  MOD_SYM                       /* SQL-2003-N */
405
%token  MONTH_SYM                     /* SQL-2003-R */
406
%token  NAMES_SYM                     /* SQL-2003-N */
407
%token  NAME_SYM                      /* SQL-2003-N */
408
%token  NATIONAL_SYM                  /* SQL-2003-R */
409
%token  NATURAL                       /* SQL-2003-R */
410
%token  NE                            /* OPERATOR */
411
%token  NEW_SYM                       /* SQL-2003-R */
412
%token  NEXT_SYM                      /* SQL-2003-N */
413
%token  NONE_SYM                      /* SQL-2003-R */
414
%token  NOT_SYM                       /* SQL-2003-R */
415
%token  NOW_SYM
416
%token  NO_SYM                        /* SQL-2003-R */
417
%token  NULL_SYM                      /* SQL-2003-R */
418
%token  NUM
419
%token  NUMERIC_SYM                   /* SQL-2003-R */
420
%token  OFFLINE_SYM
421
%token  OFFSET_SYM
422
%token  ON                            /* SQL-2003-R */
423
%token  ONE_SHOT_SYM
424
%token  ONE_SYM
425
%token  ONLINE_SYM
426
%token  OPEN_SYM                      /* SQL-2003-R */
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
427
%token  OPTIMIZE                      /* Leave assuming we might add it back */
1 by brian
clean slate
428
%token  OPTION                        /* SQL-2003-N */
429
%token  OPTIONALLY
430
%token  ORDER_SYM                     /* SQL-2003-R */
431
%token  OR_SYM                        /* SQL-2003-R */
432
%token  OUTER
433
%token  OUTFILE
434
%token  OUT_SYM                       /* SQL-2003-R */
435
%token  PARTIAL                       /* SQL-2003-N */
436
%token  POSITION_SYM                  /* SQL-2003-N */
437
%token  PRECISION                     /* SQL-2003-R */
438
%token  PREV_SYM
439
%token  PRIMARY_SYM                   /* SQL-2003-R */
440
%token  PROCESS
441
%token  PROCESSLIST_SYM
442
%token  QUARTER_SYM
443
%token  QUERY_SYM
444
%token  RANGE_SYM                     /* SQL-2003-R */
445
%token  READS_SYM                     /* SQL-2003-R */
446
%token  READ_SYM                      /* SQL-2003-N */
447
%token  READ_WRITE_SYM
448
%token  REAL                          /* SQL-2003-R */
449
%token  REDUNDANT_SYM
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
450
%token  REFERENCES                    /* SQL-2003-R */
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
451
%token  REGEXP_SYM
1 by brian
clean slate
452
%token  RELEASE_SYM                   /* SQL-2003-R */
453
%token  RENAME
454
%token  REPEATABLE_SYM                /* SQL-2003-N */
455
%token  REPEAT_SYM                    /* MYSQL-FUNC */
456
%token  REPLACE                       /* MYSQL-FUNC */
2187.7.4 by Brian Aker
Merge in change from REPLICATION to REPLICATE as keyword.
457
%token  REPLICATE
2168.3.1 by Brian Aker
Basic DDL working for replication.
458
%token  REPLICATION
1 by brian
clean slate
459
%token  RESTRICT
460
%token  RETURNS_SYM                   /* SQL-2003-R */
461
%token  RETURN_SYM                    /* SQL-2003-R */
462
%token  REVOKE                        /* SQL-2003-R */
463
%token  RIGHT                         /* SQL-2003-R */
464
%token  ROLLBACK_SYM                  /* SQL-2003-R */
465
%token  ROLLUP_SYM                    /* SQL-2003-R */
466
%token  ROUTINE_SYM                   /* SQL-2003-N */
467
%token  ROWS_SYM                      /* SQL-2003-R */
468
%token  ROW_FORMAT_SYM
469
%token  ROW_SYM                       /* SQL-2003-R */
470
%token  SAVEPOINT_SYM                 /* SQL-2003-R */
471
%token  SECOND_MICROSECOND_SYM
472
%token  SECOND_SYM                    /* SQL-2003-R */
473
%token  SECURITY_SYM                  /* SQL-2003-N */
474
%token  SELECT_SYM                    /* SQL-2003-R */
475
%token  SENSITIVE_SYM                 /* FUTURE-USE */
476
%token  SEPARATOR_SYM
477
%token  SERIALIZABLE_SYM              /* SQL-2003-N */
478
%token  SERIAL_SYM
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
479
%token  SERVER_SYM
1 by brian
clean slate
480
%token  SESSION_SYM                   /* SQL-2003-N */
2239.5.4 by Brian Aker
Compatibility issue with the output of other DB's for import
481
%token  SET_SYM                       /* SQL-2003-R */
1 by brian
clean slate
482
%token  SET_VAR
483
%token  SHARE_SYM
484
%token  SHOW
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
485
%token  SIGNED_SYM
1 by brian
clean slate
486
%token  SIMPLE_SYM                    /* SQL-2003-N */
487
%token  SNAPSHOT_SYM
488
%token  SPECIFIC_SYM                  /* SQL-2003-R */
489
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
490
%token  SQLSTATE_SYM                  /* SQL-2003-R */
491
%token  SQLWARNING_SYM                /* SQL-2003-R */
492
%token  SQL_BIG_RESULT
493
%token  SQL_BUFFER_RESULT
494
%token  SQL_CALC_FOUND_ROWS
495
%token  SQL_SMALL_RESULT
496
%token  SQL_SYM                       /* SQL-2003-R */
497
%token  STARTING
498
%token  START_SYM                     /* SQL-2003-R */
499
%token  STATUS_SYM
500
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
501
%token  STD_SYM
502
%token  STOP_SYM
383.7.1 by Andrey Zhakov
Initial submit of code and tests
503
%token  STORED_SYM
1 by brian
clean slate
504
%token  STRAIGHT_JOIN
505
%token  STRING_SYM
506
%token  SUBDATE_SYM
507
%token  SUBJECT_SYM
508
%token  SUBSTRING                     /* SQL-2003-N */
509
%token  SUM_SYM                       /* SQL-2003-N */
510
%token  SUSPEND_SYM
511
%token  SYSDATE
512
%token  TABLES
108 by Brian Aker
Removed unwanted ALTER TABLESPACE, left in valuable bits.
513
%token  TABLESPACE
1 by brian
clean slate
514
%token  TABLE_REF_PRIORITY
515
%token  TABLE_SYM                     /* SQL-2003-R */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
516
%token  TEMPORARY_SYM                 /* SQL-2003-N */
1 by brian
clean slate
517
%token  TERMINATED
518
%token  TEXT_STRING
519
%token  TEXT_SYM
520
%token  THEN_SYM                      /* SQL-2003-R */
521
%token  TIMESTAMP_ADD
522
%token  TIMESTAMP_DIFF
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
523
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
524
%token  TIME_SYM                 /* SQL-2003-R */
1 by brian
clean slate
525
%token  TO_SYM                        /* SQL-2003-R */
526
%token  TRAILING                      /* SQL-2003-R */
527
%token  TRANSACTION_SYM
528
%token  TRIM                          /* SQL-2003-N */
529
%token  TRUE_SYM                      /* SQL-2003-R */
530
%token  TRUNCATE_SYM
531
%token  TYPE_SYM                      /* SQL-2003-N */
532
%token  ULONGLONG_NUM
533
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
534
%token  UNDOFILE_SYM
535
%token  UNDO_SYM                      /* FUTURE-USE */
536
%token  UNION_SYM                     /* SQL-2003-R */
537
%token  UNIQUE_SYM
538
%token  UNKNOWN_SYM                   /* SQL-2003-R */
539
%token  UNLOCK_SYM
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
540
%token  UNSIGNED_SYM
1 by brian
clean slate
541
%token  UPDATE_SYM                    /* SQL-2003-R */
542
%token  USAGE                         /* SQL-2003-N */
543
%token  USER                          /* SQL-2003-R */
544
%token  USE_SYM
545
%token  USING                         /* SQL-2003-R */
546
%token  UTC_DATE_SYM
547
%token  UTC_TIMESTAMP_SYM
2239.5.4 by Brian Aker
Compatibility issue with the output of other DB's for import
548
%token  UTF8_SYM
1996.2.1 by Brian Aker
uuid type code.
549
%token  UUID_SYM
1 by brian
clean slate
550
%token  VALUES                        /* SQL-2003-R */
551
%token  VALUE_SYM                     /* SQL-2003-R */
552
%token  VARBINARY
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
553
%token  VARCHAR_SYM                   /* SQL-2003-R */
1 by brian
clean slate
554
%token  VARIABLES
555
%token  VARIANCE_SYM
556
%token  VARYING                       /* SQL-2003-R */
557
%token  VAR_SAMP_SYM
1958.1.1 by Brian Aker
Fix clash in parser with wait().
558
%token  WAIT_SYM
1 by brian
clean slate
559
%token  WARNINGS
560
%token  WEEK_SYM
561
%token  WHEN_SYM                      /* SQL-2003-R */
562
%token  WHERE                         /* SQL-2003-R */
563
%token  WITH                          /* SQL-2003-R */
564
%token  WITH_ROLLUP_SYM               /* INTERNAL */
565
%token  WORK_SYM                      /* SQL-2003-N */
566
%token  WRITE_SYM                     /* SQL-2003-N */
567
%token  XOR
568
%token  YEAR_MONTH_SYM
569
%token  YEAR_SYM                      /* SQL-2003-R */
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
570
%token  ZEROFILL_SYM
1 by brian
clean slate
571
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
572
/* Lowest to highest */
1 by brian
clean slate
573
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
574
/* A dummy token to force the priority of table_ref production in a join. */
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
575
%left  TABLE_REF_PRIORITY
576
%left  SET_VAR
577
%left  OR_SYM
578
%left  XOR
579
%left  AND_SYM
580
%right NOT_SYM
2172.3.16 by Brian Aker
Remove greedy use = for table alias allowance.
581
%right '='
2194.4.2 by Brian Aker
Bit functions/fix for <<
582
%nonassoc EQUAL_SYM GE GREATER_THAN LE LESS_THAN NE
2172.3.14 by Brian Aker
Small cleanup for precendense
583
%nonassoc LIKE REGEXP_SYM
584
%nonassoc BETWEEN_SYM
585
%nonassoc IN_SYM
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
586
%nonassoc IS NULL_SYM TRUE_SYM FALSE_SYM
2194.4.2 by Brian Aker
Bit functions/fix for <<
587
2312.3.1 by Brian Aker
Fix for bug 786509
588
%left CONCAT
2194.4.2 by Brian Aker
Bit functions/fix for <<
589
%nonassoc '|'
590
%nonassoc '&'
591
%nonassoc SHIFT_LEFT SHIFT_RIGHT
592
1 by brian
clean slate
593
%left   '-' '+'
594
%left   '*' '/' '%' DIV_SYM MOD_SYM
2194.4.2 by Brian Aker
Bit functions/fix for <<
595
%nonassoc   '^'
596
%nonassoc   '~'
1 by brian
clean slate
597
%right  BINARY COLLATE_SYM
598
%left  INTERVAL_SYM
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
599
%right UMINUS
600
%left  '(' ')'
2172.3.18 by Brian Aker
Additional clean up on non-typed terms
601
%left  '{' '}'
1 by brian
clean slate
602
603
%type <lex_str>
604
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
605
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
606
        ident
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
607
        ident_or_text
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
608
        internal_variable_ident
609
        user_variable_ident
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
610
        row_format_or_text
1 by brian
clean slate
611
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
612
        schema_name
2073.1.2 by Brian Aker
Basic DDL for catalog.
613
	catalog_name
1106.4.1 by Brian Aker
Remove user level key_cache
614
        opt_component
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
615
        engine_option_value
2029.1.29 by Brian Aker
Modify savepoint to not allow keyword usage.
616
        savepoint_ident
2029.1.19 by Brian Aker
Remove the "no name" option from ALTER SCHEMA.
617
        BIN_NUM TEXT_STRING_filesystem
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
618
        opt_constraint constraint opt_ident
619
620
%type <execute_string>
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
621
        execute_var_or_string
1 by brian
clean slate
622
623
%type <lex_str_ptr>
624
        opt_table_alias
625
626
%type <table>
627
        table_ident references
628
629
%type <simple_string>
630
        remember_name remember_end opt_db
631
632
%type <string>
633
        text_string opt_gconcat_separator
634
2029.1.3 by Brian Aker
Valid with enum in parser for type
635
%type <field_val>
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
636
      field_def
2029.1.3 by Brian Aker
Valid with enum in parser for type
637
      int_type
638
      real_type
639
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
640
%type <boolean>
641
        opt_wait
642
        opt_concurrent
643
        opt_status
644
        opt_zerofill
645
        opt_if_not_exists
2227.4.10 by Olaf van der Spek
Session::lex()
646
        if_exists
647
        opt_temporary
2029.1.13 by Brian Aker
Additional boolean usae in the parser.
648
        opt_field_number_signed
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
649
1 by brian
clean slate
650
%type <num>
2029.1.13 by Brian Aker
Additional boolean usae in the parser.
651
        order_dir
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
652
        opt_table_options
653
        all_or_any opt_distinct
59 by Brian Aker
Removed preload from parser.
654
        union_option
1 by brian
clean slate
655
        start_transaction_opts opt_chain opt_release
656
        union_opt select_derived_init option_type2
1963.2.1 by Brian Aker
Fixing up the kill function.
657
        kill_option
1 by brian
clean slate
658
659
%type <m_fk_option>
660
        delete_option
661
662
%type <ulong_num>
1296 by Brian Aker
Remove WEIGHT_STRING() from parser (where it does not belong). If someone
663
        ulong_num
1 by brian
clean slate
664
665
%type <ulonglong_number>
666
        ulonglong_num
667
668
%type <lock_type>
1008.1.5 by Brian Aker
Remove LOW_PRIORITY call.
669
        load_data_lock
1 by brian
clean slate
670
671
%type <item>
672
        literal text_literal insert_ident order_ident
673
        simple_ident expr opt_expr opt_else sum_expr in_sum_expr
674
        variable variable_aux bool_pri
675
        predicate bit_expr
676
        table_wild simple_expr udf_expr
677
        expr_or_default set_expr_or_default
2198.6.13 by Brian Aker
Merge fix such that default is better defined on numbers.
678
        opt_escape
679
        signed_literal
680
        integer_literal
2198.6.10 by Brian Aker
Scope out timestamp to only take certain types of values as default.
681
        date_literal
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
682
        boolean_literal
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
683
        simple_ident_q
1 by brian
clean slate
684
        field_or_var limit_option
685
        function_call_keyword
686
        function_call_nonkeyword
687
        function_call_generic
688
        function_call_conflict
689
690
%type <item_num>
691
        NUM_literal
692
693
%type <item_list>
694
        expr_list opt_udf_expr_list udf_expr_list when_list
695
696
%type <var_type>
697
        option_type opt_var_type opt_var_ident_type
698
699
%type <key_type>
700
        key_type opt_unique constraint_key_type
701
702
%type <key_alg>
703
        btree_or_rtree
704
705
%type <string_list>
706
        using_list
707
708
%type <key_part>
709
        key_part
710
711
%type <table_list>
712
        join_table_list  join_table
713
        table_factor table_ref esc_table_ref
714
        select_derived derived_table_list
715
        select_derived_union
716
717
%type <interval> interval
718
719
%type <interval_time_st> interval_time_st
720
721
%type <interval_time_st> interval_time_stamp
722
723
%type <tx_isolation> isolation_types
724
725
%type <cast_type> cast_type
726
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
727
%type <symbol>
728
        keyword
729
        keyword_sp
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
730
        keyword_exception_for_variable
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
731
        row_format
1 by brian
clean slate
732
733
%type <charset>
734
        collation_name
735
        collation_name_or_default
736
737
%type <variable> internal_variable_name
738
739
%type <select_lex> subselect
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
740
        get_select_lex query_specification
1 by brian
clean slate
741
        query_expression_body
742
743
%type <boolfunc2creator> comp_op
744
745
%type <NONE>
798.2.4 by Brian Aker
Removed CHANGE
746
        query verb_clause create select drop insert replace insert2
1 by brian
clean slate
747
        insert_values update delete truncate rename
1222.1.14 by Brian Aker
Remove OPTIMIZE, place in ALTER TABLE (which does the same thing).
748
        show describe load alter flush
798.2.2 by Brian Aker
Removed purge
749
        begin commit rollback savepoint release
1455.1.1 by Stewart Smith
remove CHECKSUM TABLE
750
        analyze check start
1 by brian
clean slate
751
        field_list field_list_item field_spec kill column_def key_def
752
        select_item_list select_item values_list no_braces
753
        opt_limit_clause delete_limit_clause fields opt_values values
184 by Brian Aker
Dead debug code removal (and a compatible "never used") bit in the
754
        opt_precision opt_ignore opt_column
1054.1.1 by Brian Aker
Remove guts in parser for LOCK TABLE.
755
        set unlock string_list
1 by brian
clean slate
756
        ref_list opt_match_clause opt_on_update_delete use
2172.3.19 by Brian Aker
Refactor DELETE so that it is a simple statement.
757
        opt_delete_option varchar
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
758
        opt_outer table_list table_name
1 by brian
clean slate
759
        opt_option opt_place
2198.6.12 by Brian Aker
Clean up the declaraion on attribute.
760
        opt_attribute
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
761
        opt_attribute_boolean
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
762
        opt_attribute_timestamp
763
        opt_attribute_number
764
        opt_attribute_string
1 by brian
clean slate
765
        flush_options flush_option
766
        equal optional_braces
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
767
        normal_join
2029.1.6 by Brian Aker
Refactor create table into sections.
768
        table_to_table_list table_to_table opt_table_list
1 by brian
clean slate
769
        union_clause union_list
520.1.1 by Brian Aker
Removed dead variables/dead parser piece.
770
        precision subselect_start
1 by brian
clean slate
771
        subselect_end select_var_list select_var_list_init opt_len
772
        opt_extended_describe
773
        statement
1874.2.3 by Brian Aker
Remove warning on EXECUTE
774
        execute
1 by brian
clean slate
775
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
776
        init_key_options key_options key_opts key_opt key_using_alg
777
END_OF_INPUT
778
779
%type <index_hint> index_hint_type
780
%type <num> index_hint_clause
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
781
%type <filetype> data_file
1 by brian
clean slate
782
783
%%
784
785
/*
786
  Indentation of grammar rules:
787
788
rule: <-- starts at col 1
789
          rule1a rule1b rule1c <-- starts at col 11
790
          { <-- starts at col 11
791
            code <-- starts at col 13, indentation is 2 spaces
792
          }
793
        | rule2a rule2b
794
          {
795
            code
796
          }
797
        ; <-- on a line by itself, starts at col 9
798
799
  Also, please do not use any <TAB>, but spaces.
800
  Having a uniform indentation in this file helps
801
  code reviews, patches, merges, and make maintenance easier.
802
  Tip: grep [[:cntrl:]] sql_yacc.yy
803
  Thanks.
804
*/
805
806
query:
807
          END_OF_INPUT
808
          {
2227.4.10 by Olaf van der Spek
Session::lex()
809
            if (!(YYSession->lex().select_lex.options & OPTION_FOUND_COMMENT))
1 by brian
clean slate
810
            {
811
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
812
              DRIZZLE_YYABORT;
1 by brian
clean slate
813
            }
814
            else
815
            {
2227.4.10 by Olaf van der Spek
Session::lex()
816
              YYSession->lex().statement= new statement::EmptyQuery(YYSession);
1 by brian
clean slate
817
            }
818
          }
819
        | verb_clause END_OF_INPUT {}
820
        ;
821
822
verb_clause:
823
          statement
824
        | begin
825
        ;
826
827
/* Verb clauses, except begin */
828
statement:
829
          alter
830
        | analyze
831
        | check
832
        | commit
833
        | create
834
        | delete
835
        | describe
836
        | drop
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
837
        | execute
1 by brian
clean slate
838
        | flush
839
        | insert
840
        | kill
841
        | load
842
        | release
843
        | rename
844
        | replace
845
        | rollback
846
        | savepoint
847
        | select
848
        | set
849
        | show
850
        | start
851
        | truncate
852
        | unlock
853
        | update
854
        | use
855
        ;
856
857
/* create a table */
858
859
create:
2073.1.2 by Brian Aker
Basic DDL for catalog.
860
          CREATE CATALOG_SYM catalog_name
861
          {
2227.4.10 by Olaf van der Spek
Session::lex()
862
            Lex.statement= new statement::catalog::Create(YYSession, $3);
2073.1.2 by Brian Aker
Basic DDL for catalog.
863
          }
864
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1 by brian
clean slate
865
          {
2227.4.10 by Olaf van der Spek
Session::lex()
866
            Lex.statement= new statement::CreateTable(YYSession, $5, $2);
2029.1.9 by Brian Aker
Remove usage of localized variable.
867
2227.4.10 by Olaf van der Spek
Session::lex()
868
            if (not Lex.select_lex.add_table_to_list(YYSession, $5, NULL,
2029.1.9 by Brian Aker
Remove usage of localized variable.
869
                                                     TL_OPTION_UPDATING,
870
                                                     TL_WRITE))
871
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
872
            Lex.col_list.clear();
1 by brian
clean slate
873
          }
2029.1.7 by Brian Aker
Clear up names in parser around create table
874
          create_table_definition
1 by brian
clean slate
875
          {
2227.4.10 by Olaf van der Spek
Session::lex()
876
            Lex.current_select= &Lex.select_lex;
1 by brian
clean slate
877
          }
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
878
        | CREATE build_method
1 by brian
clean slate
879
          {
2200.2.25 by Stewart Smith
Merge refactoring of default values work
880
            Lex.statement= new statement::CreateIndex(YYSession);
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
881
          }
882
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
883
          {
2227.4.10 by Olaf van der Spek
Session::lex()
884
            if (not Lex.current_select->add_table_to_list(Lex.session, $9,
2029.1.16 by Brian Aker
Fix unneeded move of Lex to a local variable.
885
                                                            NULL,
886
                                                            TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
887
              DRIZZLE_YYABORT;
2148.5.7 by Brian Aker
Make additional use of buildKey()
888
2227.4.10 by Olaf van der Spek
Session::lex()
889
            parser::buildKey(&Lex, $4, $6);
1 by brian
clean slate
890
          }
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
891
        | CREATE DATABASE opt_if_not_exists schema_name
1 by brian
clean slate
892
          {
2227.4.10 by Olaf van der Spek
Session::lex()
893
            Lex.statement= new statement::CreateSchema(YYSession);
1 by brian
clean slate
894
          }
895
          opt_create_database_options
896
          {
2227.4.10 by Olaf van der Spek
Session::lex()
897
            Lex.name= $4;
1 by brian
clean slate
898
          }
899
        ;
900
2029.1.7 by Brian Aker
Clear up names in parser around create table
901
create_table_definition:
2029.1.10 by Brian Aker
Merged in field_list rule.
902
          '(' field_list ')' opt_create_table_options  create_select_as
903
          { }
2029.1.11 by Brian Aker
PAren shift
904
        | '(' create_select ')'
905
           {
2227.4.10 by Olaf van der Spek
Session::lex()
906
             Lex.current_select->set_braces(1);
2029.1.11 by Brian Aker
PAren shift
907
           }
908
           union_opt {}
909
        |  '(' create_like ')' opt_create_table_options
2029.1.10 by Brian Aker
Merged in field_list rule.
910
          { }
2029.1.6 by Brian Aker
Refactor create table into sections.
911
        | create_like opt_create_table_options
912
          { }
2227.4.10 by Olaf van der Spek
Session::lex()
913
        | opt_create_table_options create_select_as
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
914
          { }
1 by brian
clean slate
915
        ;
916
2029.1.7 by Brian Aker
Clear up names in parser around create table
917
create_select_as:
1 by brian
clean slate
918
          /* empty */ {}
2029.1.6 by Brian Aker
Refactor create table into sections.
919
        | opt_duplicate_as create_select
2029.1.5 by Brian Aker
Move exists into LEX.
920
          {
2227.4.10 by Olaf van der Spek
Session::lex()
921
            Lex.current_select->set_braces(0);
2029.1.5 by Brian Aker
Move exists into LEX.
922
          }
1 by brian
clean slate
923
          union_clause {}
2029.1.6 by Brian Aker
Refactor create table into sections.
924
        | opt_duplicate_as '(' create_select ')'
2029.1.5 by Brian Aker
Move exists into LEX.
925
          {
2227.4.10 by Olaf van der Spek
Session::lex()
926
            Lex.current_select->set_braces(1);
2029.1.5 by Brian Aker
Move exists into LEX.
927
          }
1 by brian
clean slate
928
          union_opt {}
929
        ;
930
2029.1.6 by Brian Aker
Refactor create table into sections.
931
create_like:
2029.1.7 by Brian Aker
Clear up names in parser around create table
932
          LIKE table_ident
933
          {
2227.4.10 by Olaf van der Spek
Session::lex()
934
            ((statement::CreateTable *)(YYSession->lex().statement))->is_create_table_like= true;
2029.1.6 by Brian Aker
Refactor create table into sections.
935
2227.4.10 by Olaf van der Spek
Session::lex()
936
            if (not YYSession->lex().select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
2029.1.7 by Brian Aker
Clear up names in parser around create table
937
              DRIZZLE_YYABORT;
938
          }
939
        ;
2029.1.6 by Brian Aker
Refactor create table into sections.
940
1 by brian
clean slate
941
create_select:
2029.1.8 by Brian Aker
Cleanup naming.
942
          stored_select
943
          {
944
          }
945
        ;
946
947
/*
948
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
949
*/
950
stored_select:
1 by brian
clean slate
951
          SELECT_SYM
952
          {
2227.4.10 by Olaf van der Spek
Session::lex()
953
            Lex.lock_option= TL_READ;
954
            if (Lex.sql_command == SQLCOM_INSERT)
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
955
            {
2227.4.10 by Olaf van der Spek
Session::lex()
956
              delete Lex.statement;
957
              Lex.statement= new statement::InsertSelect(YYSession);
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
958
            }
2227.4.10 by Olaf van der Spek
Session::lex()
959
            else if (Lex.sql_command == SQLCOM_REPLACE)
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
960
            {
2227.4.10 by Olaf van der Spek
Session::lex()
961
              delete Lex.statement;
962
              Lex.statement= new statement::ReplaceSelect(YYSession);
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
963
            }
1 by brian
clean slate
964
            /*
965
              The following work only with the local list, the global list
966
              is created correctly in this case
967
            */
2227.4.10 by Olaf van der Spek
Session::lex()
968
            Lex.current_select->table_list.save_and_clear(&Lex.save_list);
969
            init_select(&Lex);
970
            Lex.current_select->parsing_place= SELECT_LIST;
1 by brian
clean slate
971
          }
972
          select_options select_item_list
973
          {
2227.4.10 by Olaf van der Spek
Session::lex()
974
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
975
          }
976
          opt_select_from
977
          {
978
            /*
979
              The following work only with the local list, the global list
980
              is created correctly in this case
981
            */
2227.4.10 by Olaf van der Spek
Session::lex()
982
            Lex.current_select->table_list.push_front(&Lex.save_list);
1 by brian
clean slate
983
          }
984
        ;
985
986
opt_create_database_options:
987
          /* empty */ {}
2293.2.1 by Joseph Daly
modify parser to work for DEFINER
988
        | default_collation_schema
989
        | default_collation_schema opt_database_custom_options
990
        | default_collation_schema ',' opt_database_custom_options
991
        | opt_database_custom_options
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
992
        ;
993
994
opt_database_custom_options:
995
        custom_database_option
2293.2.1 by Joseph Daly
modify parser to work for DEFINER
996
        | custom_database_option opt_database_custom_options
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
997
        | custom_database_option ',' opt_database_custom_options
998
        ;
999
1000
custom_database_option:
1001
          ident_or_text
2114.4.3 by Brian Aker
Merge in schema options enum.
1002
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1003
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex.statement;
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1004
            statement->schema_message.mutable_engine()->add_options()->set_name($1.data());
2114.4.3 by Brian Aker
Merge in schema options enum.
1005
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1006
        | REPLICATE '=' TRUE_SYM
2168.3.1 by Brian Aker
Basic DDL working for replication.
1007
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1008
            parser::buildReplicationOption(&Lex, true);
2168.3.1 by Brian Aker
Basic DDL working for replication.
1009
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1010
        | REPLICATE '=' FALSE_SYM
2168.3.1 by Brian Aker
Basic DDL working for replication.
1011
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1012
            parser::buildReplicationOption(&Lex, false);
2168.3.1 by Brian Aker
Basic DDL working for replication.
1013
          }
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
1014
        | DEFINER TEXT_STRING_sys
1015
          {
2440.2.28 by Olaf van der Spek
Refactor
1016
            parser::buildSchemaDefiner(&Lex, identifier::User($2));
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
1017
          }
1018
        | DEFINER CURRENT_USER optional_braces
1019
          {
1020
            parser::buildSchemaDefiner(&Lex, *session->user());
1021
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1022
        | ident_or_text '=' ident_or_text
2114.4.3 by Brian Aker
Merge in schema options enum.
1023
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1024
            parser::buildSchemaOption(&Lex, $1.data(), $3);
2114.4.3 by Brian Aker
Merge in schema options enum.
1025
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1026
        | ident_or_text '=' ulonglong_num
2114.4.3 by Brian Aker
Merge in schema options enum.
1027
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1028
            parser::buildSchemaOption(&Lex, $1.data(), $3);
2114.4.3 by Brian Aker
Merge in schema options enum.
1029
          }
1 by brian
clean slate
1030
        ;
1031
1032
opt_table_options:
1222.2.2 by Brian Aker
Remove last ofl HA_CREATE_INFO being involved with temporary tables (always
1033
          /* empty */ { $$= false; }
1034
        | TEMPORARY_SYM { $$= true; }
1 by brian
clean slate
1035
        ;
1036
1037
opt_if_not_exists:
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1038
          /* empty */ { $$= false; }
2227.4.10 by Olaf van der Spek
Session::lex()
1039
        | IF NOT_SYM EXISTS { $$= true; YYSession->lex().setExists(); }
1 by brian
clean slate
1040
        ;
1041
1042
opt_create_table_options:
1043
          /* empty */
1044
        | create_table_options
1045
        ;
1046
1047
create_table_options_space_separated:
1048
          create_table_option
1049
        | create_table_option create_table_options_space_separated
1050
        ;
1051
1052
create_table_options:
1053
          create_table_option
1054
        | create_table_option     create_table_options
1055
        | create_table_option ',' create_table_options
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1056
1 by brian
clean slate
1057
create_table_option:
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1058
          custom_engine_option;
1 by brian
clean slate
1059
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1060
custom_engine_option:
2241.6.1 by Brian Aker
Fix for bad usage of "="
1061
        ENGINE_SYM '=' ident_or_text
1 by brian
clean slate
1062
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1063
            Lex.table()->mutable_engine()->set_name($3.data());
1 by brian
clean slate
1064
          }
1065
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1066
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1067
            Lex.table()->mutable_options()->set_comment($3.data());
1 by brian
clean slate
1068
          }
1069
        | AUTO_INC opt_equal ulonglong_num
1070
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1071
            Lex.table()->mutable_options()->set_auto_increment_value($3);
1 by brian
clean slate
1072
          }
2239.4.2 by Brian Aker
Fix issue where the wrong sort of "=" could be used in some cases.
1073
        | REPLICATE '=' TRUE_SYM
2168.3.1 by Brian Aker
Basic DDL working for replication.
1074
          {
2227.4.15 by Olaf van der Spek
Merge trunk
1075
	    message::set_is_replicated(*Lex.table(), true);
2168.3.1 by Brian Aker
Basic DDL working for replication.
1076
          }
2239.4.2 by Brian Aker
Fix issue where the wrong sort of "=" could be used in some cases.
1077
        | REPLICATE '=' FALSE_SYM
2168.3.1 by Brian Aker
Basic DDL working for replication.
1078
          {
2227.4.15 by Olaf van der Spek
Merge trunk
1079
	    message::set_is_replicated(*Lex.table(), false);
2168.3.1 by Brian Aker
Basic DDL working for replication.
1080
          }
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
1081
        | DEFINER TEXT_STRING_sys
1082
          {
2440.2.28 by Olaf van der Spek
Refactor
1083
            message::set_definer(*Lex.table(), identifier::User($2));
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
1084
          }
1085
        | DEFINER CURRENT_USER optional_braces
1086
          {
1087
            message::set_definer(*Lex.table(), *session->user());
1088
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1089
        |  ROW_FORMAT_SYM '=' row_format_or_text
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
1090
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1091
            parser::buildEngineOption(&Lex, "ROW_FORMAT", $3);
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
1092
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1093
        |  FILE_SYM '=' TEXT_STRING_sys
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
1094
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1095
            parser::buildEngineOption(&Lex, "FILE", $3);
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
1096
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1097
        |  ident_or_text '=' engine_option_value
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1098
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1099
            parser::buildEngineOption(&Lex, $1.data(), $3);
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1100
          }
2241.6.1 by Brian Aker
Fix for bad usage of "="
1101
        | ident_or_text '=' ulonglong_num
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1102
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1103
            parser::buildEngineOption(&Lex, $1.data(), $3);
1 by brian
clean slate
1104
          }
2239.5.4 by Brian Aker
Compatibility issue with the output of other DB's for import
1105
        | default_charset
1 by brian
clean slate
1106
        | default_collation
1107
        ;
1108
2239.5.4 by Brian Aker
Compatibility issue with the output of other DB's for import
1109
charset:
1110
          CHAR_SYM SET_SYM {}
1111
        | CHARSET {}
1112
        ;
1113
1114
charset_name_or_default:
1115
          UTF8_SYM { } 
1116
        | DEFAULT    { }
1117
        ;
1118
1119
default_charset:
1120
          opt_default charset opt_equal charset_name_or_default
1121
        {
1122
        }
1123
1 by brian
clean slate
1124
default_collation:
1125
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1126
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1127
            if (not parser::buildCollation(&Lex, $4))
2148.5.4 by Brian Aker
Move over the collation test to a function outside of the parser.
1128
            {
1129
              DRIZZLE_YYABORT;
1130
            }
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1131
          }
1132
        ;
1133
1128.2.3 by Brian Aker
Remove create_info from global
1134
default_collation_schema:
1135
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1136
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1137
            ((statement::CreateSchema *)Lex.statement)->schema_message.set_collation($4->name);
1128.2.3 by Brian Aker
Remove create_info from global
1138
          }
1139
        ;
1140
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
1141
row_format:
1142
          COMPACT_SYM  {}
1143
        | COMPRESSED_SYM  {}
1144
        | DEFAULT  {}
1145
        | DYNAMIC_SYM  {}
1146
        | FIXED_SYM  {}
1147
        | REDUNDANT_SYM  {}
1148
        ;
1149
1150
row_format_or_text:
2029.1.23 by Brian Aker
Shuffle ROW_FORMAT.
1151
          row_format
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
1152
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1153
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
1154
          }
1155
        ;
1156
1 by brian
clean slate
1157
opt_select_from:
1158
          opt_limit_clause {}
1159
        | select_from select_lock_type
1160
        ;
1161
1162
field_list:
1163
          field_list_item
1164
        | field_list ',' field_list_item
1165
        ;
1166
1167
field_list_item:
1168
          column_def
1169
        | key_def
1170
        ;
1171
1172
column_def:
1173
          field_spec opt_check_constraint
1174
        | field_spec references
1175
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1176
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1177
          }
1178
        ;
1179
1180
key_def:
1181
          key_type opt_ident key_alg '(' key_list ')' key_options
1182
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1183
            parser::buildKey(&Lex, $1, $2);
1 by brian
clean slate
1184
          }
1185
        | opt_constraint constraint_key_type opt_ident key_alg
1186
          '(' key_list ')' key_options
1187
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1188
            parser::buildKey(&Lex, $2, $3.data() ? $3 : $1);
1 by brian
clean slate
1189
          }
1190
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1191
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1192
            parser::buildForeignKey(&Lex, $1.data() ? $1 : $4, $8);
1 by brian
clean slate
1193
          }
1194
        | constraint opt_check_constraint
1195
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1196
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1197
          }
1198
        | opt_constraint check_constraint
1199
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1200
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1201
          }
1202
        ;
1203
1204
opt_check_constraint:
1205
          /* empty */
1206
        | check_constraint
1207
        ;
1208
1209
check_constraint:
1210
          CHECK_SYM expr
1211
        ;
1212
1213
opt_constraint:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1214
          /* empty */ { $$= null_lex_string(); }
1 by brian
clean slate
1215
        | constraint { $$= $1; }
1216
        ;
1217
1218
constraint:
1219
          CONSTRAINT opt_ident { $$=$2; }
1220
        ;
1221
1222
field_spec:
1223
          field_ident
1224
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1225
            parser::buildCreateFieldIdent(&Lex);
1 by brian
clean slate
1226
          }
2198.6.6 by Brian Aker
Merge in comments.
1227
          field_def opt_attribute_comment
1 by brian
clean slate
1228
          {
2385.3.21 by Olaf van der Spek
Refactor
1229
            statement::CreateTable *statement= (statement::CreateTable*)Lex.statement;
1215.1.3 by stewart at flamingspork
[patch 03/17] set field name in parser, assert that its correct when filling out the rest of the table proto
1230
2227.4.10 by Olaf van der Spek
Session::lex()
1231
            if (Lex.field())
2029.1.20 by Brian Aker
Make use of lex for its pointer for field creation.
1232
            {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1233
              Lex.field()->set_name($1.data());
2029.1.20 by Brian Aker
Make use of lex for its pointer for field creation.
1234
            }
1215.1.3 by stewart at flamingspork
[patch 03/17] set field name in parser, assert that its correct when filling out the rest of the table proto
1235
2445.1.11 by Olaf van der Spek
Use str_ref
1236
            if (add_field_to_list(Lex.session, $1, (enum_field_types) $3,
2227.4.10 by Olaf van der Spek
Session::lex()
1237
                                  Lex.length, Lex.dec, Lex.type,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1238
                                  statement->column_format,
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1239
                                  statement->default_value, statement->on_update_value,
2440.2.9 by Olaf van der Spek
Refactor
1240
                                  statement->comment,
2227.4.10 by Olaf van der Spek
Session::lex()
1241
                                  statement->change, &Lex.interval_list, Lex.charset))
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1242
              DRIZZLE_YYABORT;
1215.1.1 by stewart at flamingspork
[patch 01/17] horrible hack to have one lonely codepath produce Fields in the table proto
1243
2227.4.10 by Olaf van der Spek
Session::lex()
1244
            Lex.setField(NULL);
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1245
          }
1246
        ;
2114.4.9 by Brian Aker
Try not to pass session quite as often
1247
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1248
field_def:
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1249
          TIMESTAMP_SYM opt_attribute_timestamp
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1250
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1251
            $$=parser::buildTimestampColumn(&Lex, NULL);
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1252
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1253
        | TIMESTAMP_SYM '(' NUM ')' opt_attribute_timestamp
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1254
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1255
            $$=parser::buildTimestampColumn(&Lex, $3.data());
2227.4.10 by Olaf van der Spek
Session::lex()
1256
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1257
        | DATETIME_SYM opt_attribute_timestamp
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1258
          {
1259
            $$=DRIZZLE_TYPE_DATETIME;
1260
2227.4.10 by Olaf van der Spek
Session::lex()
1261
            if (Lex.field())
1262
              Lex.field()->set_type(message::Table::Field::DATETIME);
1263
          }
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1264
        | int_type opt_attribute_number
2227.4.10 by Olaf van der Spek
Session::lex()
1265
          {
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1266
            $$= $1;
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1267
          }
2198.6.8 by Brian Aker
Clean up the varchar made type.
1268
        | CHAR_SYM opt_attribute_string
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1269
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1270
            $$= parser::buildVarcharColumn(&Lex, "1");
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1271
          }
1272
        | varchar '(' NUM ')' opt_attribute_string
1273
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1274
            $$= parser::buildVarcharColumn(&Lex, $3.data());
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1275
          }
1276
        | TEXT_SYM opt_attribute_string
1277
          {
1278
            $$=DRIZZLE_TYPE_BLOB;
2385.3.19 by Olaf van der Spek
Refactor
1279
            Lex.length= NULL; /* use default length */
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1280
2227.4.10 by Olaf van der Spek
Session::lex()
1281
            if (Lex.field())
1282
              Lex.field()->set_type(message::Table::Field::BLOB);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1283
          }
1284
        | ENUM_SYM
1285
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1286
            Lex.interval_list.clear();
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1287
          }
1288
          '(' string_list ')' opt_attribute_string
1289
          {
1290
            $$=DRIZZLE_TYPE_ENUM;
1291
2227.4.10 by Olaf van der Spek
Session::lex()
1292
            if (Lex.field())
1293
              Lex.field()->set_type(message::Table::Field::ENUM);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1294
          }
1295
        | VARBINARY '(' NUM ')' opt_attribute
1296
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1297
            $$= parser::buildVarbinaryColumn(&Lex, $3.data());
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1298
          }
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1299
        | real_type opt_attribute_number
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1300
          {
2148.5.11 by Brian Aker
Merge in varbinary build method.
1301
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
2227.4.10 by Olaf van der Spek
Session::lex()
1302
            $$= parser::buildDoubleColumn(&Lex);
1303
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1304
        | DATE_SYM opt_attribute
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1305
          {
1306
            $$=DRIZZLE_TYPE_DATE;
1307
2227.4.10 by Olaf van der Spek
Session::lex()
1308
            if (Lex.field())
1309
              Lex.field()->set_type(message::Table::Field::DATE);
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1310
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1311
        | TIME_SYM opt_attribute
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1312
          {
1313
            $$=DRIZZLE_TYPE_TIME;
1314
2227.4.10 by Olaf van der Spek
Session::lex()
1315
            if (Lex.field())
1316
              Lex.field()->set_type(message::Table::Field::TIME);
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1317
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1318
        | BLOB_SYM opt_attribute
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1319
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1320
            $$= parser::buildBlobColumn(&Lex);
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1321
          }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1322
        | DECIMAL_SYM float_options opt_attribute_number
1323
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1324
            $$= parser::buildDecimalColumn(&Lex);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1325
          }
1326
        | NUMERIC_SYM float_options opt_attribute_number
1327
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1328
            $$= parser::buildDecimalColumn(&Lex);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1329
          }
1330
        | FIXED_SYM float_options opt_attribute_number
1331
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1332
            $$= parser::buildDecimalColumn(&Lex);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1333
          }
1334
        | UUID_SYM opt_attribute
1996.2.1 by Brian Aker
uuid type code.
1335
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1336
            $$= parser::buildUuidColumn(&Lex);
1996.2.1 by Brian Aker
uuid type code.
1337
          }
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
1338
        | IPV6_SYM opt_attribute
1339
          {
1340
            $$= parser::buildIPv6Column(&Lex);
1341
          }
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
1342
        | BOOLEAN_SYM opt_attribute_boolean
2060.2.1 by Brian Aker
Merge in SQL reserved word patch
1343
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1344
            $$= parser::buildBooleanColumn(&Lex);
2060.2.1 by Brian Aker
Merge in SQL reserved word patch
1345
          }
2198.6.6 by Brian Aker
Merge in comments.
1346
        | SERIAL_SYM
1 by brian
clean slate
1347
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1348
            $$= parser::buildSerialColumn(&Lex);
1 by brian
clean slate
1349
          }
1350
        ;
1351
1352
varchar:
2198.6.8 by Brian Aker
Clean up the varchar made type.
1353
          CHAR_SYM VARYING
1354
          { }
1355
        | CHAR_SYM
1356
          { }
1357
        | VARCHAR_SYM
1358
          { }
1 by brian
clean slate
1359
        ;
1360
1361
int_type:
2227.4.10 by Olaf van der Spek
Session::lex()
1362
          INT_SYM  ignored_field_number_length opt_field_number_signed opt_zerofill
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1363
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1364
            $$= parser::buildIntegerColumn(&Lex, DRIZZLE_TYPE_LONG, ($3 or $4));
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1365
          }
2227.4.10 by Olaf van der Spek
Session::lex()
1366
        | BIGINT_SYM ignored_field_number_length opt_field_number_signed opt_zerofill
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1367
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1368
            $$= parser::buildIntegerColumn(&Lex, DRIZZLE_TYPE_LONGLONG, ($3 or $4));
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1369
          }
1 by brian
clean slate
1370
        ;
1371
1372
real_type:
2198.6.7 by Brian Aker
Push logic of int down into the type and remove BOOL as being different from
1373
          REAL opt_precision
1374
          {
1375
            $$= DRIZZLE_TYPE_DOUBLE;
1376
          }
1377
        | DOUBLE_SYM opt_precision
1378
          {
1379
            $$= DRIZZLE_TYPE_DOUBLE;
1380
          }
1381
        | DOUBLE_SYM PRECISION opt_precision
2136.3.4 by Brian Aker
Add documentation for BOOL/BOOLEAN type, and add a mysql compatible BOOL for
1382
          {
1383
            $$= DRIZZLE_TYPE_DOUBLE;
1384
          }
1 by brian
clean slate
1385
        ;
1386
1387
float_options:
1388
          /* empty */
2385.3.19 by Olaf van der Spek
Refactor
1389
          { Lex.dec=Lex.length= NULL; }
1 by brian
clean slate
1390
        | '(' NUM ')'
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1391
          { Lex.length=$2.data(); Lex.dec= NULL; }
1 by brian
clean slate
1392
        | precision
1393
          {}
1394
        ;
1395
1396
precision:
1397
          '(' NUM ',' NUM ')'
1398
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1399
            Lex.length= $2.data();
1400
            Lex.dec= $4.data();
1 by brian
clean slate
1401
          }
1402
        ;
1403
1404
opt_len:
2385.3.19 by Olaf van der Spek
Refactor
1405
          /* empty */ { Lex.length= NULL; /* use default length */ }
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1406
        | '(' NUM ')' { Lex.length= $2.data(); }
1 by brian
clean slate
1407
        ;
1408
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1409
opt_field_number_signed:
2029.1.13 by Brian Aker
Additional boolean usae in the parser.
1410
          /* empty */ { $$= false; }
1411
        | SIGNED_SYM { $$= false; }
2227.4.10 by Olaf van der Spek
Session::lex()
1412
        | UNSIGNED_SYM { $$= true; Lex.type|= UNSIGNED_FLAG; }
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1413
        ;
1414
1415
ignored_field_number_length:
1416
          /* empty */ { }
1417
        | '(' NUM ')' { }
1418
        ;
1419
1420
opt_zerofill:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
1421
          /* empty */ { $$= false; }
2227.4.10 by Olaf van der Spek
Session::lex()
1422
        | ZEROFILL_SYM { $$= true; Lex.type|= UNSIGNED_FLAG; }
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1423
        ;
1424
1 by brian
clean slate
1425
opt_precision:
2114.7.1 by Andrew Hutchings
Support float(N) in a create table statment, ignore the braces
1426
          /* empty */
2385.3.19 by Olaf van der Spek
Refactor
1427
          { Lex.dec=Lex.length= NULL; }
2114.7.1 by Andrew Hutchings
Support float(N) in a create table statment, ignore the braces
1428
        | '(' NUM ')'
2385.3.19 by Olaf van der Spek
Refactor
1429
          { Lex.length=Lex.dec= NULL; }
2114.7.1 by Andrew Hutchings
Support float(N) in a create table statment, ignore the braces
1430
        | precision
1431
          {}
1 by brian
clean slate
1432
        ;
1433
2198.6.9 by Brian Aker
Break out index types.
1434
opt_attribute_not_null:
1435
          NULL_SYM
1436
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1437
            Lex.type&= ~ NOT_NULL_FLAG;
2198.6.9 by Brian Aker
Break out index types.
1438
          }
1439
        | NOT_SYM NULL_SYM
1440
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1441
            Lex.type|= NOT_NULL_FLAG;
2198.6.9 by Brian Aker
Break out index types.
1442
2227.4.10 by Olaf van der Spek
Session::lex()
1443
            if (Lex.field())
2198.6.9 by Brian Aker
Break out index types.
1444
            {
2227.4.10 by Olaf van der Spek
Session::lex()
1445
              Lex.field()->mutable_constraints()->set_is_notnull(true);
2198.6.9 by Brian Aker
Break out index types.
1446
            }
1447
          }
1448
        ;
1449
1450
opt_attribute_index:
1451
          opt_primary KEY_SYM
1452
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1453
            parser::buildPrimaryOnColumn(&Lex);
2198.6.9 by Brian Aker
Break out index types.
1454
          }
1455
        | UNIQUE_SYM
1456
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1457
            parser::buildKeyOnColumn(&Lex);
2198.6.9 by Brian Aker
Break out index types.
1458
          }
1459
        | UNIQUE_SYM KEY_SYM
1460
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1461
            parser::buildKeyOnColumn(&Lex);
2198.6.9 by Brian Aker
Break out index types.
1462
          }
1463
        ;
1464
1 by brian
clean slate
1465
opt_attribute:
1466
          /* empty */ {}
2198.6.12 by Brian Aker
Clean up the declaraion on attribute.
1467
        | opt_attribute opt_attribute_not_null
2198.6.9 by Brian Aker
Break out index types.
1468
          { }
2198.6.12 by Brian Aker
Clean up the declaraion on attribute.
1469
        | opt_attribute DEFAULT signed_literal
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1470
          {
2385.3.21 by Olaf van der Spek
Refactor
1471
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1472
2198.6.12 by Brian Aker
Clean up the declaraion on attribute.
1473
            statement->default_value= $3;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1474
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
1475
          }
2198.6.12 by Brian Aker
Clean up the declaraion on attribute.
1476
        | opt_attribute opt_attribute_index
2198.6.9 by Brian Aker
Break out index types.
1477
          { }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1478
        ;
1479
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
1480
opt_attribute_boolean:
1481
          /* empty */ { }
1482
        | opt_attribute_boolean opt_attribute_not_null
1483
          { }
1484
        | opt_attribute_boolean DEFAULT boolean_literal
1485
          {
2385.3.21 by Olaf van der Spek
Refactor
1486
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
1487
1488
            statement->default_value= $3;
1489
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1490
          }
1491
        | opt_attribute_boolean opt_attribute_index
1492
          { }
1493
        ;
1494
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1495
opt_attribute_string:
1496
          /* empty */ {}
1497
        | opt_attribute_list_string {}
1498
        ;
1499
1500
opt_attribute_list_string:
1501
          opt_attribute_list_string attribute_string {}
1502
        | attribute_string
1503
        ;
1504
1505
attribute_string:
2198.6.9 by Brian Aker
Break out index types.
1506
          opt_attribute_not_null
1507
          { }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1508
        | DEFAULT signed_literal
1215.1.4 by stewart at flamingspork
[patch 04/17] field comment set in table proto in parser
1509
          {
2385.3.21 by Olaf van der Spek
Refactor
1510
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1215.1.4 by stewart at flamingspork
[patch 04/17] field comment set in table proto in parser
1511
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1512
            statement->default_value=$2;
1513
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1514
          }
1 by brian
clean slate
1515
        | COLLATE_SYM collation_name
1516
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1517
            if (Lex.charset && !my_charset_same(Lex.charset,$2))
1 by brian
clean slate
1518
            {
1519
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
2227.4.10 by Olaf van der Spek
Session::lex()
1520
                       $2->name,Lex.charset->csname);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1521
              DRIZZLE_YYABORT;
1 by brian
clean slate
1522
            }
1523
            else
1524
            {
2227.4.10 by Olaf van der Spek
Session::lex()
1525
              Lex.charset=$2;
1 by brian
clean slate
1526
            }
1527
          }
2198.6.9 by Brian Aker
Break out index types.
1528
        | opt_attribute_index
1529
          { }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1530
        ;
1531
1532
opt_attribute_number:
1533
          /* empty */ {}
1534
        | opt_attribute_list_integer {}
1535
        ;
1536
1537
opt_attribute_list_integer:
1538
          opt_attribute_list_integer attribute_integer {}
1539
        | attribute_integer
1540
        ;
1541
1542
attribute_integer:
2198.6.9 by Brian Aker
Break out index types.
1543
          opt_attribute_not_null
1544
          { }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1545
        | AUTO_INC
1546
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1547
            parser::buildAutoOnColumn(&Lex);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1548
          }
1549
        | SERIAL_SYM DEFAULT VALUE_SYM
1550
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1551
            (void)parser::buildSerialColumn(&Lex);
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1552
          }
2198.6.13 by Brian Aker
Merge fix such that default is better defined on numbers.
1553
        | DEFAULT integer_literal
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1554
          {
2385.3.21 by Olaf van der Spek
Refactor
1555
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1556
1557
            statement->default_value=$2;
1558
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1559
          }
2198.6.9 by Brian Aker
Break out index types.
1560
        | opt_attribute_index
1561
          { }
1 by brian
clean slate
1562
        ;
1563
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1564
opt_attribute_timestamp:
1565
          /* empty */ {}
1566
        | opt_attribute_list_timestamp {}
1567
        ;
1568
1569
opt_attribute_list_timestamp:
1570
          opt_attribute_list_timestamp attribute_timestamp {}
1571
        | attribute_timestamp
1572
        ;
1573
1574
attribute_timestamp:
2198.6.9 by Brian Aker
Break out index types.
1575
          opt_attribute_not_null
1576
          { }
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1577
        | DEFAULT NOW_SYM optional_braces
1578
          {
2385.3.21 by Olaf van der Spek
Refactor
1579
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1580
1581
            statement->default_value= new Item_func_now_local();
1582
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1583
          }
2198.6.10 by Brian Aker
Scope out timestamp to only take certain types of values as default.
1584
        | DEFAULT date_literal
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1585
          {
2385.3.21 by Olaf van der Spek
Refactor
1586
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1587
1588
            statement->default_value=$2;
1589
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1590
          }
1591
        | ON UPDATE_SYM NOW_SYM optional_braces
1592
          {
2385.3.21 by Olaf van der Spek
Refactor
1593
            ((statement::AlterTable*)Lex.statement)->on_update_value= new Item_func_now_local();
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1594
          }
2198.6.9 by Brian Aker
Break out index types.
1595
        | opt_attribute_index
1596
          { }
2198.6.5 by Brian Aker
Enforce field attributes via the parser.
1597
        ;
1598
1599
opt_attribute_comment:
1600
          /* empty */ { }
2198.6.6 by Brian Aker
Merge in comments.
1601
        | COMMENT_SYM TEXT_STRING_sys
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1602
          {
2385.3.21 by Olaf van der Spek
Refactor
1603
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1604
            statement->comment= $2;
1605
2227.4.10 by Olaf van der Spek
Session::lex()
1606
            if (Lex.field())
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1607
              Lex.field()->set_comment($2.data());
2198.6.4 by Brian Aker
First pass making sure parser enforces types.
1608
          }
1609
        ;
1610
1 by brian
clean slate
1611
collation_name:
1612
          ident_or_text
1613
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1614
            if (!($$=get_charset_by_name($1.data())))
1 by brian
clean slate
1615
            {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1616
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.data());
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1617
              DRIZZLE_YYABORT;
1 by brian
clean slate
1618
            }
1619
          }
1620
        ;
1621
1622
collation_name_or_default:
1623
          collation_name { $$=$1; }
1624
        | DEFAULT    { $$=NULL; }
1625
        ;
1626
1627
opt_default:
1628
          /* empty */ {}
1629
        | DEFAULT {}
1630
        ;
1631
1632
opt_primary:
1633
          /* empty */
1634
        | PRIMARY_SYM
1635
        ;
1636
1637
references:
2172.3.21 by Brian Aker
Clean up REFERENCE line in parser.
1638
          REFERENCES table_ident opt_ref_list opt_match_clause opt_on_update_delete
1 by brian
clean slate
1639
          {
1640
            $$=$2;
1641
          }
1642
        ;
1643
1644
opt_ref_list:
1645
          /* empty */
2227.4.10 by Olaf van der Spek
Session::lex()
1646
          { Lex.ref_list.clear(); }
1 by brian
clean slate
1647
        | '(' ref_list ')'
1648
        ;
1649
1650
ref_list:
1651
          ref_list ',' ident
2227.4.10 by Olaf van der Spek
Session::lex()
1652
          { Lex.ref_list.push_back(new Key_part_spec($3, 0)); }
1 by brian
clean slate
1653
        | ident
1654
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1655
            Lex.ref_list.clear();
1656
            Lex.ref_list.push_back(new Key_part_spec($1, 0));
1 by brian
clean slate
1657
          }
1658
        ;
1659
1660
opt_match_clause:
1661
          /* empty */
2385.3.21 by Olaf van der Spek
Refactor
1662
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
1 by brian
clean slate
1663
        | MATCH FULL
2385.3.21 by Olaf van der Spek
Refactor
1664
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
1 by brian
clean slate
1665
        | MATCH PARTIAL
2385.3.21 by Olaf van der Spek
Refactor
1666
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
1 by brian
clean slate
1667
        | MATCH SIMPLE_SYM
2385.3.21 by Olaf van der Spek
Refactor
1668
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
1 by brian
clean slate
1669
        ;
1670
1671
opt_on_update_delete:
1672
          /* empty */
1673
          {
2385.3.21 by Olaf van der Spek
Refactor
1674
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1675
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1 by brian
clean slate
1676
          }
1677
        | ON UPDATE_SYM delete_option
1678
          {
2385.3.21 by Olaf van der Spek
Refactor
1679
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= $3;
1680
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1 by brian
clean slate
1681
          }
1682
        | ON DELETE_SYM delete_option
1683
          {
2385.3.21 by Olaf van der Spek
Refactor
1684
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1685
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= $3;
1 by brian
clean slate
1686
          }
1687
        | ON UPDATE_SYM delete_option
1688
          ON DELETE_SYM delete_option
1689
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1690
            ((statement::CreateTable *)Lex.statement)->fk_update_opt= $3;
1691
            ((statement::CreateTable *)Lex.statement)->fk_delete_opt= $6;
1 by brian
clean slate
1692
          }
1693
        | ON DELETE_SYM delete_option
1694
          ON UPDATE_SYM delete_option
1695
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1696
            ((statement::CreateTable *)Lex.statement)->fk_update_opt= $6;
1697
            ((statement::CreateTable *)Lex.statement)->fk_delete_opt= $3;
1 by brian
clean slate
1698
          }
1699
        ;
1700
1701
delete_option:
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1702
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1703
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
2030.1.1 by Brian Aker
Small set of symbol updates.
1704
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1705
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
2030.1.1 by Brian Aker
Small set of symbol updates.
1706
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
1 by brian
clean slate
1707
        ;
1708
1709
key_type:
1710
          key_or_index { $$= Key::MULTIPLE; }
1711
        ;
1712
1713
constraint_key_type:
1714
          PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
1715
        | UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
1716
        ;
1717
1718
key_or_index:
1719
          KEY_SYM {}
1720
        | INDEX_SYM {}
1721
        ;
1722
1723
opt_key_or_index:
1724
          /* empty */ {}
1725
        | key_or_index
1726
        ;
1727
1728
keys_or_index:
1729
          KEYS {}
1730
        | INDEX_SYM {}
1731
        | INDEXES {}
1732
        ;
1733
1734
opt_unique:
1735
          /* empty */  { $$= Key::MULTIPLE; }
1736
        | UNIQUE_SYM   { $$= Key::UNIQUE; }
1737
        ;
1738
1739
init_key_options:
1740
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1741
            ((statement::CreateTable *)Lex.statement)->key_create_info= default_key_create_info;
1 by brian
clean slate
1742
          }
1743
        ;
1744
1745
/*
2227.4.10 by Olaf van der Spek
Session::lex()
1746
  For now, key_alg initializies Lex.key_create_info.
1 by brian
clean slate
1747
  In the future, when all key options are after key definition,
1748
  we can remove key_alg and move init_key_options to key_options
1749
*/
1750
1751
key_alg:
1752
          init_key_options
1753
        | init_key_options key_using_alg
1754
        ;
1755
1756
key_options:
1757
          /* empty */ {}
1758
        | key_opts
1759
        ;
1760
1761
key_opts:
1762
          key_opt
1763
        | key_opts key_opt
1764
        ;
1765
1766
key_using_alg:
2227.4.10 by Olaf van der Spek
Session::lex()
1767
          USING btree_or_rtree     { ((statement::CreateTable *)Lex.statement)->key_create_info.algorithm= $2; }
1 by brian
clean slate
1768
        ;
1769
1770
key_opt:
1771
          key_using_alg
1772
        | KEY_BLOCK_SIZE opt_equal ulong_num
2227.4.10 by Olaf van der Spek
Session::lex()
1773
          { ((statement::CreateTable *)Lex.statement)->key_create_info.block_size= $3; }
1 by brian
clean slate
1774
        | COMMENT_SYM TEXT_STRING_sys
2227.4.10 by Olaf van der Spek
Session::lex()
1775
          { ((statement::CreateTable *)Lex.statement)->key_create_info.comment= $2; }
1 by brian
clean slate
1776
        ;
1777
1778
btree_or_rtree:
1779
          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
1780
        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
1781
        ;
1782
1783
key_list:
2227.4.10 by Olaf van der Spek
Session::lex()
1784
          key_list ',' key_part order_dir { Lex.col_list.push_back($3); }
1785
        | key_part order_dir { Lex.col_list.push_back($1); }
1 by brian
clean slate
1786
        ;
1787
1788
key_part:
1789
          ident { $$=new Key_part_spec($1, 0); }
1790
        | ident '(' NUM ')'
1791
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1792
            int key_part_len= atoi($3.data());
1 by brian
clean slate
1793
            if (!key_part_len)
1794
            {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1795
              my_error(ER_KEY_PART_0, MYF(0), $1.data());
1 by brian
clean slate
1796
            }
1797
            $$=new Key_part_spec($1, (uint) key_part_len);
1798
          }
1799
        ;
1800
1801
opt_ident:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1802
          /* empty */ { $$= null_lex_string(); }
1 by brian
clean slate
1803
        | field_ident { $$= $1; }
1804
        ;
1805
1806
opt_component:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1807
          /* empty */    { $$= null_lex_string(); }
1 by brian
clean slate
1808
        | '.' ident      { $$= $2; }
1809
        ;
1810
1811
string_list:
2227.4.10 by Olaf van der Spek
Session::lex()
1812
          text_string { Lex.interval_list.push_back($1); }
1813
        | string_list ',' text_string { Lex.interval_list.push_back($3); };
1 by brian
clean slate
1814
1815
/*
1816
** Alter table
1817
*/
1818
1819
alter:
2030.1.1 by Brian Aker
Small set of symbol updates.
1820
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
1 by brian
clean slate
1821
          {
2200.2.15 by Stewart Smith
remove enum ha_build_method and instead use the build method in message::AlterTable.
1822
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5);
2227.4.10 by Olaf van der Spek
Session::lex()
1823
            Lex.statement= statement;
1824
            Lex.duplicates= DUP_ERROR;
1825
            if (not Lex.select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
1826
            {
2029.1.15 by Brian Aker
Remove useless copy.
1827
              DRIZZLE_YYABORT;
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
1828
            }
2029.1.15 by Brian Aker
Remove useless copy.
1829
2227.4.10 by Olaf van der Spek
Session::lex()
1830
            Lex.col_list.clear();
1831
            Lex.select_lex.init_order();
2430.1.10 by Olaf van der Spek
Add const
1832
            Lex.select_lex.db= ((TableList*) Lex.select_lex.table_list.first)->getSchemaName();
1 by brian
clean slate
1833
          }
1834
          alter_commands
1835
          {}
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
1836
        | ALTER_SYM DATABASE schema_name
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1837
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1838
            Lex.statement= new statement::AlterSchema(YYSession);
1128.2.3 by Brian Aker
Remove create_info from global
1839
          }
1128.2.7 by Brian Aker
Cleanup previous issues in create sql_yacc
1840
          default_collation_schema
1128.2.3 by Brian Aker
Remove create_info from global
1841
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1842
            Lex.name= $3;
2430.1.7 by Olaf van der Spek
Use size()
1843
            if (not Lex.name.data())
1844
            {
2430.1.9 by Olaf van der Spek
Add const
1845
              str_ref db = Lex.session->copy_db_to();
1846
              if (db.empty())
2430.1.7 by Olaf van der Spek
Use size()
1847
                DRIZZLE_YYABORT;
2430.1.9 by Olaf van der Spek
Add const
1848
              Lex.name.assign(db.data(), db.size());
2430.1.7 by Olaf van der Spek
Use size()
1849
            }
1 by brian
clean slate
1850
          }
1851
        ;
1852
1853
alter_commands:
1854
          /* empty */
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1855
        | DISCARD TABLESPACE
1856
          {
2200.2.3 by Stewart Smith
add code to store IMPORT/DISCARD TABLESPACE operation in the AlterTable protobuf message. assert that we get the right thing in alter table code
1857
            message::AlterTable::AlterTableOperation *alter_operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1858
            alter_operation= Lex.alter_table()->add_operations();
2200.2.3 by Stewart Smith
add code to store IMPORT/DISCARD TABLESPACE operation in the AlterTable protobuf message. assert that we get the right thing in alter table code
1859
            alter_operation->set_operation(message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1860
          }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1861
        | IMPORT TABLESPACE
1862
          {
2200.2.3 by Stewart Smith
add code to store IMPORT/DISCARD TABLESPACE operation in the AlterTable protobuf message. assert that we get the right thing in alter table code
1863
            message::AlterTable::AlterTableOperation *alter_operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1864
            alter_operation= Lex.alter_table()->add_operations();
2200.2.3 by Stewart Smith
add code to store IMPORT/DISCARD TABLESPACE operation in the AlterTable protobuf message. assert that we get the right thing in alter table code
1865
            alter_operation->set_operation(message::AlterTable::AlterTableOperation::IMPORT_TABLESPACE);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1866
          }
1 by brian
clean slate
1867
        | alter_list
1868
        ;
1869
1870
build_method:
1871
        /* empty */
1872
          {
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1873
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_DEFAULT);
1 by brian
clean slate
1874
          }
1875
        | ONLINE_SYM
1876
          {
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1877
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_ONLINE);
1 by brian
clean slate
1878
          }
1879
        | OFFLINE_SYM
1880
          {
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1881
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_OFFLINE);
1 by brian
clean slate
1882
          }
1883
        ;
1884
1885
alter_list:
1886
          alter_list_item
1887
        | alter_list ',' alter_list_item
1888
        ;
1889
1890
add_column:
2030.1.1 by Brian Aker
Small set of symbol updates.
1891
          ADD_SYM opt_column
1 by brian
clean slate
1892
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1893
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1894
1895
            statement->change=0;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1896
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1 by brian
clean slate
1897
          }
1898
        ;
1899
1900
alter_list_item:
1901
          add_column column_def opt_place { }
2030.1.1 by Brian Aker
Small set of symbol updates.
1902
        | ADD_SYM key_def
1 by brian
clean slate
1903
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1904
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1905
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1906
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
1907
          }
1908
        | add_column '(' field_list ')'
1909
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1910
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1911
1912
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1913
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
1914
          }
2030.1.1 by Brian Aker
Small set of symbol updates.
1915
        | CHANGE_SYM opt_column field_ident
1 by brian
clean slate
1916
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1917
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
2430.1.10 by Olaf van der Spek
Add const
1918
            statement->change= $3.data();
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1919
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1 by brian
clean slate
1920
          }
1921
          field_spec opt_place
1922
        | MODIFY_SYM opt_column field_ident
1923
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1924
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1925
            Lex.length= Lex.dec=0;
1926
            Lex.type= 0;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1927
            statement->default_value= statement->on_update_value= 0;
2371.1.2 by Brian Aker
Remove the typedef on lexkey
1928
            statement->comment= null_lex_string();
2227.4.10 by Olaf van der Spek
Session::lex()
1929
            Lex.charset= NULL;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1930
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1931
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1932
2227.4.10 by Olaf van der Spek
Session::lex()
1933
            Lex.setField(NULL);
1 by brian
clean slate
1934
          }
2198.6.6 by Brian Aker
Merge in comments.
1935
          field_def opt_attribute_comment
1 by brian
clean slate
1936
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1937
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1938
2445.1.11 by Olaf van der Spek
Use str_ref
1939
            if (add_field_to_list(Lex.session, $3,
1 by brian
clean slate
1940
                                  (enum enum_field_types) $5,
2227.4.10 by Olaf van der Spek
Session::lex()
1941
                                  Lex.length, Lex.dec, Lex.type,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1942
                                  statement->column_format,
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1943
                                  statement->default_value,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1944
                                  statement->on_update_value,
2440.2.9 by Olaf van der Spek
Refactor
1945
                                  statement->comment,
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1946
                                  $3.data(), &Lex.interval_list, Lex.charset))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1947
              DRIZZLE_YYABORT;
1 by brian
clean slate
1948
          }
1949
          opt_place
184 by Brian Aker
Dead debug code removal (and a compatible "never used") bit in the
1950
        | DROP opt_column field_ident
1 by brian
clean slate
1951
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1952
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1953
1954
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
2200.2.18 by Stewart Smith
add fields, indexes and foreign keys to drop in ALTER TABLE DROP and DROP INDEX to the AlterTable protobuf message in parser
1955
            message::AlterTable::AlterTableOperation *operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1956
            operation= Lex.alter_table()->add_operations();
2200.2.18 by Stewart Smith
add fields, indexes and foreign keys to drop in ALTER TABLE DROP and DROP INDEX to the AlterTable protobuf message in parser
1957
            operation->set_operation(message::AlterTable::AlterTableOperation::DROP_COLUMN);
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1958
            operation->set_drop_name($3.data());
1 by brian
clean slate
1959
          }
1960
        | DROP FOREIGN KEY_SYM opt_ident
1961
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1962
            parser::buildAddAlterDropIndex(&Lex, $4.data(), true);
1 by brian
clean slate
1963
          }
1964
        | DROP PRIMARY_SYM KEY_SYM
1965
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1966
            parser::buildAddAlterDropIndex(&Lex, "PRIMARY");
1 by brian
clean slate
1967
          }
1968
        | DROP key_or_index field_ident
1969
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1970
            parser::buildAddAlterDropIndex(&Lex, $3.data());
1 by brian
clean slate
1971
          }
1972
        | DISABLE_SYM KEYS
1973
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1974
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1975
1976
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
1977
1978
            message::AlterTable::AlterKeysOnOff *alter_keys_operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1979
            alter_keys_operation= Lex.alter_table()->mutable_alter_keys_onoff();
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
1980
            alter_keys_operation->set_enable(false);
1 by brian
clean slate
1981
          }
1982
        | ENABLE_SYM KEYS
1983
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1984
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1985
1986
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
1987
            message::AlterTable::AlterKeysOnOff *alter_keys_operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
1988
            alter_keys_operation= Lex.alter_table()->mutable_alter_keys_onoff();
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
1989
            alter_keys_operation->set_enable(true);
1 by brian
clean slate
1990
          }
2030.1.1 by Brian Aker
Small set of symbol updates.
1991
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
1 by brian
clean slate
1992
          {
2227.4.10 by Olaf van der Spek
Session::lex()
1993
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1994
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
1995
            statement->alter_info.alter_list.push_back(AlterColumn($3.data(),$6));
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1996
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
1997
          }
2030.1.1 by Brian Aker
Small set of symbol updates.
1998
        | ALTER_SYM opt_column field_ident DROP DEFAULT
1 by brian
clean slate
1999
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2000
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2001
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
2002
            statement->alter_info.alter_list.push_back(AlterColumn($3.data(), NULL));
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2003
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
2004
          }
2005
        | RENAME opt_to table_ident
2006
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2007
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
2430.1.10 by Olaf van der Spek
Add const
2008
            Lex.select_lex.db= $3->db.data();
2430.1.9 by Olaf van der Spek
Add const
2009
            if (not Lex.select_lex.db)
1 by brian
clean slate
2010
            {
2430.1.9 by Olaf van der Spek
Add const
2011
              str_ref db = Lex.session->copy_db_to();
2012
              if (db.empty())
2013
                DRIZZLE_YYABORT;
2014
              Lex.select_lex.db = db.data();
1 by brian
clean slate
2015
            }
1235.4.9 by Stewart Smith
remove check_db_name() from sql_yacc.yy and replace with NormalisedDatabaseName and friends. This check should really be down a layer... but let's not change everything at once
2016
2445.1.1 by Olaf van der Spek
Refactor
2017
            if (check_table_name($3->table))
1 by brian
clean slate
2018
            {
2433.1.6 by Olaf van der Spek
USe data() and size()
2019
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.data());
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2020
              DRIZZLE_YYABORT;
1 by brian
clean slate
2021
            }
1235.4.9 by Stewart Smith
remove check_db_name() from sql_yacc.yy and replace with NormalisedDatabaseName and friends. This check should really be down a layer... but let's not change everything at once
2022
2227.4.10 by Olaf van der Spek
Session::lex()
2023
            Lex.name= $3->table;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2024
            statement->alter_info.flags.set(ALTER_RENAME);
2200.2.12 by Stewart Smith
set RenameTable and AlterKeysOnOff protobuf messages inside the AlterTable protobuf message for ALTER TABLE in parser
2025
2026
            message::AlterTable::RenameTable *rename_operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
2027
            rename_operation= Lex.alter_table()->mutable_rename();
2028
            rename_operation->set_to_schema(Lex.select_lex.db);
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
2029
            rename_operation->set_to_name(Lex.name.data());
1 by brian
clean slate
2030
          }
383.1.27 by Brian Aker
Next pass in the unending saga of UTF-8.. now we can set in SQL collation
2031
        | CONVERT_SYM TO_SYM collation_name_or_default
1 by brian
clean slate
2032
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2033
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.3 by Brian Aker
Remove create_info from global
2034
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
2035
            statement->create_info().table_charset=
2036
            statement->create_info().default_table_charset= $3;
2037
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
1 by brian
clean slate
2038
              HA_CREATE_USED_DEFAULT_CHARSET);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2039
            statement->alter_info.flags.set(ALTER_CONVERT);
1 by brian
clean slate
2040
          }
2041
        | create_table_options_space_separated
2042
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2043
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2044
2045
            statement->alter_info.flags.set(ALTER_OPTIONS);
1 by brian
clean slate
2046
          }
2047
        | FORCE_SYM
2048
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2049
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2050
2051
            statement->alter_info.flags.set(ALTER_FORCE);
1 by brian
clean slate
2052
          }
2053
        | alter_order_clause
2054
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2055
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2056
2057
            statement->alter_info.flags.set(ALTER_ORDER);
1 by brian
clean slate
2058
          }
2059
        ;
2060
2061
opt_column:
2062
          /* empty */ {}
2063
        | COLUMN_SYM {}
2064
        ;
2065
2066
opt_ignore:
2227.4.10 by Olaf van der Spek
Session::lex()
2067
          /* empty */ { Lex.ignore= 0;}
2068
        | IGNORE_SYM { Lex.ignore= 1;}
1 by brian
clean slate
2069
        ;
2070
2071
opt_place:
2072
          /* empty */ {}
2073
        | AFTER_SYM ident
2074
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
2075
            parser::storeAlterColumnPosition(&Lex, $2.data());
1 by brian
clean slate
2076
          }
2077
        | FIRST_SYM
2078
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2079
            parser::storeAlterColumnPosition(&Lex, first_keyword);
1 by brian
clean slate
2080
          }
2081
        ;
2082
2083
opt_to:
2084
          /* empty */ {}
2085
        | TO_SYM {}
2086
        | AS {}
2087
        ;
2088
2089
start:
2090
          START_SYM TRANSACTION_SYM start_transaction_opts
2091
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2092
            Lex.statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
1 by brian
clean slate
2093
          }
2094
        ;
2095
2096
start_transaction_opts:
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
2097
          /*empty*/ { $$ = START_TRANS_NO_OPTIONS; }
1 by brian
clean slate
2098
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
2099
          {
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
2100
            $$= START_TRANS_OPT_WITH_CONS_SNAPSHOT;
1 by brian
clean slate
2101
          }
2102
        ;
2103
2104
analyze:
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
2105
          ANALYZE_SYM table_or_tables
1 by brian
clean slate
2106
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2107
            Lex.statement= new statement::Analyze(YYSession);
1 by brian
clean slate
2108
          }
2109
          table_list
2110
          {}
2111
        ;
2112
2113
check:
2114
          CHECK_SYM table_or_tables
2115
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2116
            Lex.statement= new statement::Check(YYSession);
1 by brian
clean slate
2117
          }
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
2118
          table_list
1 by brian
clean slate
2119
          {}
2120
        ;
2121
2122
rename:
2123
          RENAME table_or_tables
2124
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2125
            Lex.statement= new statement::RenameTable(YYSession);
1 by brian
clean slate
2126
          }
2127
          table_to_table_list
2128
          {}
2129
        ;
2130
2131
table_to_table_list:
2132
          table_to_table
2133
        | table_to_table_list ',' table_to_table
2134
        ;
2135
2136
table_to_table:
2137
          table_ident TO_SYM table_ident
2138
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2139
            Select_Lex *sl= Lex.current_select;
2140
            if (!sl->add_table_to_list(Lex.session, $1,NULL,TL_OPTION_UPDATING,
1 by brian
clean slate
2141
                                       TL_IGNORE) ||
2227.4.10 by Olaf van der Spek
Session::lex()
2142
                !sl->add_table_to_list(Lex.session, $3,NULL,TL_OPTION_UPDATING,
1 by brian
clean slate
2143
                                       TL_IGNORE))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2144
              DRIZZLE_YYABORT;
1 by brian
clean slate
2145
          }
2146
        ;
2147
2148
/*
2149
  Select : retrieve data from table
2150
*/
2151
2152
2153
select:
2154
          select_init
2155
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2156
            Lex.statement= new statement::Select(YYSession);
1 by brian
clean slate
2157
          }
2158
        ;
2159
2160
/* Need select_init2 for subselects. */
2161
select_init:
2162
          SELECT_SYM select_init2
2163
        | '(' select_paren ')' union_opt
2164
        ;
2165
2166
select_paren:
2167
          SELECT_SYM select_part2
2168
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2169
            if (parser::setup_select_in_parentheses(YYSession, &Lex))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2170
              DRIZZLE_YYABORT;
1 by brian
clean slate
2171
          }
2172
        | '(' select_paren ')'
2173
        ;
2174
2175
/* The equivalent of select_paren for nested queries. */
2176
select_paren_derived:
2177
          SELECT_SYM select_part2_derived
2178
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2179
            if (parser::setup_select_in_parentheses(YYSession, &Lex))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2180
              DRIZZLE_YYABORT;
1 by brian
clean slate
2181
          }
2182
        | '(' select_paren_derived ')'
2183
        ;
2184
2185
select_init2:
2186
          select_part2
2187
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2188
            Select_Lex * sel= Lex.current_select;
2189
            if (Lex.current_select->set_braces(0))
1 by brian
clean slate
2190
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
2191
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2192
              DRIZZLE_YYABORT;
1 by brian
clean slate
2193
            }
2194
            if (sel->linkage == UNION_TYPE &&
2195
                sel->master_unit()->first_select()->braces)
2196
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
2197
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2198
              DRIZZLE_YYABORT;
1 by brian
clean slate
2199
            }
2200
          }
2201
          union_clause
2202
        ;
2203
2204
select_part2:
2205
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2206
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
2207
            if (sel->linkage != UNION_TYPE)
2227.4.10 by Olaf van der Spek
Session::lex()
2208
              init_select(&Lex);
2209
            Lex.current_select->parsing_place= SELECT_LIST;
1 by brian
clean slate
2210
          }
2211
          select_options select_item_list
2212
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2213
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
2214
          }
2215
          select_into select_lock_type
2216
        ;
2217
2218
select_into:
2219
          opt_order_clause opt_limit_clause {}
2220
        | into
2221
        | select_from
2222
        | into select_from
2223
        | select_from into
2224
        ;
2225
2226
select_from:
2227
          FROM join_table_list where_clause group_clause having_clause
2228
          opt_order_clause opt_limit_clause
2229
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2230
            Lex.current_select->context.table_list=
2231
              Lex.current_select->context.first_name_resolution_table=
2232
                reinterpret_cast<TableList *>(Lex.current_select->table_list.first);
1 by brian
clean slate
2233
          }
2234
        ;
2235
2236
select_options:
2237
          /* empty*/
2238
        | select_option_list
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2239
          { }
1 by brian
clean slate
2240
        ;
2241
2242
select_option_list:
2243
          select_option_list select_option
2244
        | select_option
2245
        ;
2246
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2247
select_option_distinct_or_all:
2248
          DISTINCT
2249
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2250
            Lex.current_select->options|= SELECT_DISTINCT;
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2251
2227.4.10 by Olaf van der Spek
Session::lex()
2252
            if (Lex.current_select->options & SELECT_DISTINCT && Lex.current_select->options & SELECT_ALL)
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2253
            {
2254
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2255
              DRIZZLE_YYABORT;
2256
            }
2257
          }
2258
        | ALL
2259
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2260
            Lex.current_select->options|= SELECT_ALL;
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2261
2227.4.10 by Olaf van der Spek
Session::lex()
2262
            if (Lex.current_select->options & SELECT_DISTINCT && Lex.current_select->options & SELECT_ALL)
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2263
            {
2264
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2265
              DRIZZLE_YYABORT;
2266
            }
2267
          }
2268
        ;
2269
2270
select_option_small_or_big:
2271
          SQL_SMALL_RESULT
2272
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2273
            Lex.current_select->options|= SELECT_SMALL_RESULT;
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2274
2227.4.10 by Olaf van der Spek
Session::lex()
2275
            if (Lex.current_select->options & SELECT_SMALL_RESULT && Lex.current_select->options & SELECT_BIG_RESULT)
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2276
            {
2277
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2278
              DRIZZLE_YYABORT;
2279
            }
2280
          }
2281
        | SQL_BIG_RESULT
2282
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2283
            Lex.current_select->options|= SELECT_BIG_RESULT;
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2284
2227.4.10 by Olaf van der Spek
Session::lex()
2285
            if (Lex.current_select->options & SELECT_SMALL_RESULT && Lex.current_select->options & SELECT_BIG_RESULT)
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2286
            {
2287
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2288
              DRIZZLE_YYABORT;
2289
            }
2290
          }
2291
        ;
2292
2293
1 by brian
clean slate
2294
select_option:
2227.4.10 by Olaf van der Spek
Session::lex()
2295
          STRAIGHT_JOIN { Lex.current_select->options|= SELECT_STRAIGHT_JOIN; }
1 by brian
clean slate
2296
        | SQL_BUFFER_RESULT
2297
          {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
2298
            if (check_simple_select(YYSession))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2299
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
2300
            Lex.current_select->options|= OPTION_BUFFER_RESULT;
1 by brian
clean slate
2301
          }
2068.6.2 by Brian Aker
Cleanup issue of OR in tests.
2302
        | select_option_small_or_big
2303
          { }
2304
        | select_option_distinct_or_all
2305
          { }
1 by brian
clean slate
2306
        | SQL_CALC_FOUND_ROWS
2307
          {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
2308
            if (check_simple_select(YYSession))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2309
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
2310
            Lex.current_select->options|= OPTION_FOUND_ROWS;
1 by brian
clean slate
2311
          }
2312
        ;
2313
2314
select_lock_type:
2315
          /* empty */
2316
        | FOR_SYM UPDATE_SYM
2317
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2318
            Lex.current_select->set_lock_for_tables(TL_WRITE);
1 by brian
clean slate
2319
          }
2320
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2321
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2322
            Lex.current_select->
1 by brian
clean slate
2323
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2324
          }
2325
        ;
2326
2327
select_item_list:
2328
          select_item_list ',' select_item
2329
        | select_item
2330
        | '*'
2331
          {
2318.6.31 by Olaf van der Spek
Refactor
2332
            YYSession->add_item_to_list( new Item_field(&YYSession->lex().current_select->context, NULL, NULL, "*"));
2333
            YYSession->lex().current_select->with_wild++;
1 by brian
clean slate
2334
          }
2335
        ;
2336
2337
select_item:
2338
          remember_name table_wild remember_end
2339
          {
2318.6.31 by Olaf van der Spek
Refactor
2340
            YYSession->add_item_to_list($2);
1 by brian
clean slate
2341
          }
2342
        | remember_name expr remember_end select_alias
2343
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
2344
            assert($1 < $3);
1 by brian
clean slate
2345
2318.6.31 by Olaf van der Spek
Refactor
2346
            YYSession->add_item_to_list($2);
2029.1.15 by Brian Aker
Remove useless copy.
2347
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
2348
            if ($4.data())
1 by brian
clean slate
2349
            {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
2350
              $2->is_autogenerated_name= false;
2433.1.6 by Olaf van der Spek
USe data() and size()
2351
              $2->set_name($4.data(), $4.size(), system_charset_info);
1 by brian
clean slate
2352
            }
2353
            else if (!$2->name)
2354
            {
2029.1.15 by Brian Aker
Remove useless copy.
2355
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
1 by brian
clean slate
2356
            }
2357
          }
2358
        ;
2359
2360
remember_name:
2361
          {
2029.1.15 by Brian Aker
Remove useless copy.
2362
            Lex_input_stream *lip= YYSession->m_lip;
2385.3.19 by Olaf van der Spek
Refactor
2363
            $$= lip->get_cpp_tok_start();
1 by brian
clean slate
2364
          }
2365
        ;
2366
2367
remember_end:
2368
          {
2029.1.15 by Brian Aker
Remove useless copy.
2369
            Lex_input_stream *lip= YYSession->m_lip;
2385.3.19 by Olaf van der Spek
Refactor
2370
            $$= lip->get_cpp_tok_end();
1 by brian
clean slate
2371
          }
2372
        ;
2373
2374
select_alias:
2371.1.2 by Brian Aker
Remove the typedef on lexkey
2375
          /* empty */ { $$= null_lex_string();}
1 by brian
clean slate
2376
        | AS ident { $$=$2; }
2377
        | AS TEXT_STRING_sys { $$=$2; }
2378
        | ident { $$=$1; }
2379
        | TEXT_STRING_sys { $$=$1; }
2380
        ;
2381
2382
optional_braces:
2383
          /* empty */ {}
2384
        | '(' ')' {}
2385
        ;
2386
2387
/* all possible expressions */
2388
expr:
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2389
          expr OR_SYM expr %prec OR_SYM
1 by brian
clean slate
2390
          {
2391
            /*
2392
              Design notes:
2227.4.10 by Olaf van der Spek
Session::lex()
2393
              Do not use a manually maintained stack like session->Lex.xxx_list,
1 by brian
clean slate
2394
              but use the internal bison stack ($$, $1 and $3) instead.
2395
              Using the bison stack is:
2396
              - more robust to changes in the grammar,
2397
              - guaranteed to be in sync with the parser state,
2398
              - better for performances (no memory allocation).
2399
            */
2400
            Item_cond_or *item1;
2401
            Item_cond_or *item3;
2402
            if (is_cond_or($1))
2403
            {
2404
              item1= (Item_cond_or*) $1;
2405
              if (is_cond_or($3))
2406
              {
2407
                item3= (Item_cond_or*) $3;
2408
                /*
2409
                  (X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
2410
                */
2411
                item3->add_at_head(item1->argument_list());
2412
                $$ = $3;
2413
              }
2414
              else
2415
              {
2416
                /*
2417
                  (X1 OR X2) OR Y ==> OR (X1, X2, Y)
2418
                */
2419
                item1->add($3);
2420
                $$ = $1;
2421
              }
2422
            }
2423
            else if (is_cond_or($3))
2424
            {
2425
              item3= (Item_cond_or*) $3;
2426
              /*
2427
                X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
2428
              */
2429
              item3->add_at_head($1);
2430
              $$ = $3;
2431
            }
2432
            else
2433
            {
2434
              /* X OR Y */
520.1.22 by Brian Aker
Second pass of thd cleanup
2435
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
1 by brian
clean slate
2436
            }
2437
          }
2438
        | expr XOR expr %prec XOR
2439
          {
2440
            /* XOR is a proprietary extension */
520.1.22 by Brian Aker
Second pass of thd cleanup
2441
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
1 by brian
clean slate
2442
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2443
        | expr AND_SYM expr %prec AND_SYM
1 by brian
clean slate
2444
          {
2445
            /* See comments in rule expr: expr or expr */
2446
            Item_cond_and *item1;
2447
            Item_cond_and *item3;
2448
            if (is_cond_and($1))
2449
            {
2450
              item1= (Item_cond_and*) $1;
2451
              if (is_cond_and($3))
2452
              {
2453
                item3= (Item_cond_and*) $3;
2454
                /*
2455
                  (X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
2456
                */
2457
                item3->add_at_head(item1->argument_list());
2458
                $$ = $3;
2459
              }
2460
              else
2461
              {
2462
                /*
2463
                  (X1 AND X2) AND Y ==> AND (X1, X2, Y)
2464
                */
2465
                item1->add($3);
2466
                $$ = $1;
2467
              }
2468
            }
2469
            else if (is_cond_and($3))
2470
            {
2471
              item3= (Item_cond_and*) $3;
2472
              /*
2473
                X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
2474
              */
2475
              item3->add_at_head($1);
2476
              $$ = $3;
2477
            }
2478
            else
2479
            {
2480
              /* X AND Y */
520.1.22 by Brian Aker
Second pass of thd cleanup
2481
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
1 by brian
clean slate
2482
            }
2483
          }
2484
        | NOT_SYM expr %prec NOT_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
2485
          { $$= negate_expression(YYSession, $2); }
1 by brian
clean slate
2486
        | bool_pri IS TRUE_SYM %prec IS
2227.4.10 by Olaf van der Spek
Session::lex()
2487
          {
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2488
            $$= new (YYSession->mem_root) Item_func_istrue($1);
2489
          }
2490
        | bool_pri IS NOT_SYM TRUE_SYM %prec IS
2491
          {
2492
            $$= new (YYSession->mem_root) Item_func_isnottrue($1);
2493
          }
1 by brian
clean slate
2494
        | bool_pri IS FALSE_SYM %prec IS
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2495
          {
2496
            $$= new (YYSession->mem_root) Item_func_isfalse($1);
2497
          }
2498
        | bool_pri IS NOT_SYM FALSE_SYM %prec IS
2499
          {
2500
            $$= new (YYSession->mem_root) Item_func_isnotfalse($1);
2501
          }
1 by brian
clean slate
2502
        | bool_pri IS UNKNOWN_SYM %prec IS
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2503
          {
2504
            $$= new Item_func_isnull($1);
2505
          }
2506
        | bool_pri IS NOT_SYM UNKNOWN_SYM %prec IS
2507
          {
2508
            $$= new Item_func_isnotnull($1);
2509
          }
1 by brian
clean slate
2510
        | bool_pri
2511
        ;
2512
2513
bool_pri:
2514
          bool_pri IS NULL_SYM %prec IS
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2515
          {
2516
            $$= new Item_func_isnull($1);
2517
          }
2518
        | bool_pri IS NOT_SYM NULL_SYM %prec IS
2519
          {
2520
            $$= new Item_func_isnotnull($1);
2521
          }
1 by brian
clean slate
2522
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2523
          {
2524
            $$= new Item_func_equal($1,$3);
2525
          }
2172.3.16 by Brian Aker
Remove greedy use = for table alias allowance.
2526
        | bool_pri comp_op predicate %prec '='
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2527
          {
2528
            $$= (*$2)(0)->create($1,$3);
2529
          }
2172.3.16 by Brian Aker
Remove greedy use = for table alias allowance.
2530
        | bool_pri comp_op all_or_any '(' subselect ')' %prec '='
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2531
          {
2532
            $$= all_any_subquery_creator($1, $2, $3, $5);
2533
          }
1 by brian
clean slate
2534
        | predicate
2535
        ;
2536
2537
predicate:
2538
          bit_expr IN_SYM '(' subselect ')'
2539
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2540
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
1 by brian
clean slate
2541
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2542
        | bit_expr NOT_SYM IN_SYM '(' subselect ')'
1 by brian
clean slate
2543
          {
2029.1.15 by Brian Aker
Remove useless copy.
2544
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2545
            $$= negate_expression(YYSession, item);
1 by brian
clean slate
2546
          }
2547
        | bit_expr IN_SYM '(' expr ')'
2548
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
2549
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
1 by brian
clean slate
2550
          }
2551
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2552
          {
1 by brian
clean slate
2553
            $6->push_front($4);
2554
            $6->push_front($1);
520.1.22 by Brian Aker
Second pass of thd cleanup
2555
            $$= new (YYSession->mem_root) Item_func_in(*$6);
1 by brian
clean slate
2556
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2557
        | bit_expr NOT_SYM IN_SYM '(' expr ')'
1 by brian
clean slate
2558
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
2559
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
1 by brian
clean slate
2560
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2561
        | bit_expr NOT_SYM IN_SYM '(' expr ',' expr_list ')'
1 by brian
clean slate
2562
          {
2563
            $7->push_front($5);
2564
            $7->push_front($1);
520.1.22 by Brian Aker
Second pass of thd cleanup
2565
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
1 by brian
clean slate
2566
            item->negate();
2567
            $$= item;
2568
          }
2569
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2570
          {
2571
            $$= new Item_func_between($1,$3,$5);
2572
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2573
        | bit_expr NOT_SYM BETWEEN_SYM bit_expr AND_SYM predicate
1 by brian
clean slate
2574
          {
2575
            Item_func_between *item= new Item_func_between($1,$4,$6);
2576
            item->negate();
2577
            $$= item;
2578
          }
2579
        | bit_expr LIKE simple_expr opt_escape
2227.4.10 by Olaf van der Spek
Session::lex()
2580
          {
2581
            $$= new Item_func_like($1,$3,$4,Lex.escape_used);
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2582
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2583
        | bit_expr NOT_SYM LIKE simple_expr opt_escape
2227.4.10 by Olaf van der Spek
Session::lex()
2584
          {
2585
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex.escape_used));
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2586
          }
2587
        | bit_expr REGEXP_SYM bit_expr
2227.4.10 by Olaf van der Spek
Session::lex()
2588
          {
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2589
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2590
            args->push_back($1);
2591
            args->push_back($3);
2096.1.14 by Brian Aker
Pull in more C code from parser.
2592
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2593
            {
2594
              DRIZZLE_YYABORT;
2595
            }
2596
          }
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2597
        | bit_expr NOT_SYM REGEXP_SYM bit_expr
2227.4.10 by Olaf van der Spek
Session::lex()
2598
          {
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2599
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2600
            args->push_back($1);
2601
            args->push_back($4);
2602
            args->push_back(new (YYSession->mem_root) Item_int(1));
2096.1.14 by Brian Aker
Pull in more C code from parser.
2603
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
1976.7.1 by Brian Aker
Added compatible REGEX for Drizzle to MySQL's syntax.
2604
            {
2605
              DRIZZLE_YYABORT;
2606
            }
2607
          }
1 by brian
clean slate
2608
        | bit_expr
2609
        ;
2610
2611
bit_expr:
2194.4.2 by Brian Aker
Bit functions/fix for <<
2612
          bit_expr '|' bit_expr %prec '|'
2613
          {
2614
            $$= new function::bit::Or($1, $3);
2615
          }
2616
        | bit_expr '&' bit_expr %prec '&'
2617
          {
2618
            $$= new function::bit::And($1, $3);
2619
          }
2620
        | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
2621
          {
2622
            $$= new function::bit::ShiftRight($1, $3);
2623
          }
2624
        | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
2625
          {
2626
            $$= new function::bit::ShiftLeft($1, $3);
2627
          }
2628
        | bit_expr '+' bit_expr %prec '+'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2629
          {
2630
            $$= new Item_func_plus($1,$3);
2631
          }
1 by brian
clean slate
2632
        | bit_expr '-' bit_expr %prec '-'
2227.4.10 by Olaf van der Spek
Session::lex()
2633
          {
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2634
            $$= new Item_func_minus($1,$3);
2635
          }
1 by brian
clean slate
2636
        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2637
          {
2638
            $$= new Item_date_add_interval($1,$4,$5,0);
2639
          }
1 by brian
clean slate
2640
        | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2641
          {
2642
            $$= new Item_date_add_interval($1,$4,$5,1);
2643
          }
1 by brian
clean slate
2644
        | bit_expr '*' bit_expr %prec '*'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2645
          {
2646
            $$= new Item_func_mul($1,$3);
2647
          }
1 by brian
clean slate
2648
        | bit_expr '/' bit_expr %prec '/'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2649
          {
2650
            $$= new Item_func_div(YYSession,$1,$3);
2651
          }
1 by brian
clean slate
2652
        | bit_expr '%' bit_expr %prec '%'
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2653
          {
2654
            $$= new Item_func_mod($1,$3);
2655
          }
1 by brian
clean slate
2656
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2657
          {
2658
            $$= new Item_func_int_div($1,$3);
2659
          }
1 by brian
clean slate
2660
        | bit_expr MOD_SYM bit_expr %prec MOD_SYM
2198.6.3 by Brian Aker
Cleanup idention and remove and/not for straight usage.
2661
          {
2662
            $$= new Item_func_mod($1,$3);
2663
          }
2194.4.2 by Brian Aker
Bit functions/fix for <<
2664
        | bit_expr '^' bit_expr
2665
          {
2666
            $$= new (YYSession->mem_root) function::bit::Xor($1, $3);
2667
          }
1 by brian
clean slate
2668
        | simple_expr
2669
        ;
2670
2671
comp_op:
2172.3.16 by Brian Aker
Remove greedy use = for table alias allowance.
2672
          '='     { $$ = &comp_eq_creator; }
1 by brian
clean slate
2673
        | GE     { $$ = &comp_ge_creator; }
2194.4.2 by Brian Aker
Bit functions/fix for <<
2674
        | GREATER_THAN { $$ = &comp_gt_creator; }
1 by brian
clean slate
2675
        | LE     { $$ = &comp_le_creator; }
2194.4.2 by Brian Aker
Bit functions/fix for <<
2676
        | LESS_THAN     { $$ = &comp_lt_creator; }
1 by brian
clean slate
2677
        | NE     { $$ = &comp_ne_creator; }
2678
        ;
2679
2680
all_or_any:
2681
          ALL     { $$ = 1; }
2682
        | ANY_SYM { $$ = 0; }
2683
        ;
2684
2685
simple_expr:
2686
          simple_ident
2687
        | function_call_keyword
2688
        | function_call_nonkeyword
2689
        | function_call_generic
2690
        | function_call_conflict
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
2691
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
1 by brian
clean slate
2692
          {
2440.2.26 by Olaf van der Spek
Refactor
2693
            Item *i1= new (YYSession->mem_root) Item_string($3, YYSession->charset());
2029.1.15 by Brian Aker
Remove useless copy.
2694
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
1 by brian
clean slate
2695
          }
2696
        | literal
2697
        | variable
2698
        | sum_expr
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
2699
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2700
            Lex.setSumExprUsed();
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
2701
          }
2198.6.1 by Brian Aker
Add in an ANSI || operator.
2702
        | simple_expr CONCAT simple_expr
2703
          {
2704
            $$= new (YYSession->mem_root) Item_func_concat(*YYSession, $1, $3);
2705
          }
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
2706
        | '+' simple_expr %prec UMINUS { $$= $2; }
2707
        | '-' simple_expr %prec UMINUS
2194.4.2 by Brian Aker
Bit functions/fix for <<
2708
          {
2709
	    $$= new (YYSession->mem_root) Item_func_neg($2);
2710
	  }
2711
        | '~' simple_expr %prec UMINUS
2712
          {
2713
            $$= new (YYSession->mem_root) function::bit::Neg($2);
2714
          }
1 by brian
clean slate
2715
        | '(' subselect ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2716
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2717
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
1 by brian
clean slate
2718
          }
2719
        | '(' expr ')' { $$= $2; }
2720
        | '(' expr ',' expr_list ')'
2721
          {
2722
            $4->push_front($2);
520.1.22 by Brian Aker
Second pass of thd cleanup
2723
            $$= new (YYSession->mem_root) Item_row(*$4);
1 by brian
clean slate
2724
          }
2725
        | ROW_SYM '(' expr ',' expr_list ')'
2726
          {
2727
            $5->push_front($3);
520.1.22 by Brian Aker
Second pass of thd cleanup
2728
            $$= new (YYSession->mem_root) Item_row(*$5);
1 by brian
clean slate
2729
          }
2730
        | EXISTS '(' subselect ')'
2731
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2732
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
1 by brian
clean slate
2733
          }
2734
        | '{' ident expr '}' { $$= $3; }
2172.3.15 by Brian Aker
Cleanup additional precedence rules.
2735
        | BINARY simple_expr %prec UMINUS
1 by brian
clean slate
2736
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2737
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
1 by brian
clean slate
2738
                                 &my_charset_bin);
2739
          }
2740
        | CAST_SYM '(' expr AS cast_type ')'
2741
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2742
            $$= create_func_cast(YYSession, $3, $5, Lex.length, Lex.dec,
2743
                                 Lex.charset);
1 by brian
clean slate
2744
            if (!$$)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2745
              DRIZZLE_YYABORT;
1 by brian
clean slate
2746
          }
2747
        | CASE_SYM opt_expr when_list opt_else END
520.1.22 by Brian Aker
Second pass of thd cleanup
2748
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
1 by brian
clean slate
2749
        | CONVERT_SYM '(' expr ',' cast_type ')'
2750
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2751
            $$= create_func_cast(YYSession, $3, $5, Lex.length, Lex.dec,
2752
                                 Lex.charset);
1 by brian
clean slate
2753
            if (!$$)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2754
              DRIZZLE_YYABORT;
1 by brian
clean slate
2755
          }
2756
        | DEFAULT '(' simple_ident ')'
2757
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2758
            $$= new (YYSession->mem_root) Item_default_value(Lex.current_context(),
1 by brian
clean slate
2759
                                                         $3);
2760
          }
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
2761
        | VALUES '(' simple_ident ')'
1 by brian
clean slate
2762
          {
2227.4.10 by Olaf van der Spek
Session::lex()
2763
            $$= new (YYSession->mem_root) Item_insert_value(Lex.current_context(),
1 by brian
clean slate
2764
                                                        $3);
2765
          }
2766
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
2767
          /* we cannot put interval before - */
520.1.22 by Brian Aker
Second pass of thd cleanup
2768
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
1 by brian
clean slate
2769
        ;
2770
2771
/*
2772
  Function call syntax using official SQL 2003 keywords.
2773
  Because the function name is an official token,
2774
  a dedicated grammar rule is needed in the parser.
2775
  There is no potential for conflicts
2776
*/
2777
function_call_keyword:
2778
          CHAR_SYM '(' expr_list ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2779
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
1 by brian
clean slate
2780
        | CURRENT_USER optional_braces
2781
          {
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
2782
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
2783
            {
2784
              DRIZZLE_YYABORT;
2785
            }
2227.4.10 by Olaf van der Spek
Session::lex()
2786
            Lex.setCacheable(false);
1 by brian
clean slate
2787
          }
2788
        | DATE_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2789
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
1 by brian
clean slate
2790
        | DAY_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2791
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
1 by brian
clean slate
2792
        | HOUR_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2793
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
1 by brian
clean slate
2794
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
1633.4.5 by Brian Aker
More current_session.
2795
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
1 by brian
clean slate
2796
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2797
          {
2029.1.15 by Brian Aker
Remove useless copy.
2798
            List<Item> *list= new (YYSession->mem_root) List<Item>;
1 by brian
clean slate
2799
            list->push_front($5);
2800
            list->push_front($3);
2029.1.15 by Brian Aker
Remove useless copy.
2801
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2802
            $$= new (YYSession->mem_root) Item_func_interval(item);
1 by brian
clean slate
2803
          }
2804
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2805
          {
2806
            $7->push_front($5);
2807
            $7->push_front($3);
2029.1.15 by Brian Aker
Remove useless copy.
2808
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2809
            $$= new (YYSession->mem_root) Item_func_interval(item);
1 by brian
clean slate
2810
          }
2811
        | LEFT '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2812
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
1 by brian
clean slate
2813
        | MINUTE_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2814
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
1 by brian
clean slate
2815
        | MONTH_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2816
          { $$= new (YYSession->mem_root) Item_func_month($3); }
1 by brian
clean slate
2817
        | RIGHT '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2818
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
1 by brian
clean slate
2819
        | SECOND_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2820
          { $$= new (YYSession->mem_root) Item_func_second($3); }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
2821
        | TIMESTAMP_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2822
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
1 by brian
clean slate
2823
        | TRIM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2824
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
1 by brian
clean slate
2825
        | TRIM '(' LEADING expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2826
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
1 by brian
clean slate
2827
        | TRIM '(' TRAILING expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2828
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
1 by brian
clean slate
2829
        | TRIM '(' BOTH expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2830
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
1 by brian
clean slate
2831
        | TRIM '(' LEADING FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2832
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
1 by brian
clean slate
2833
        | TRIM '(' TRAILING FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2834
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
1 by brian
clean slate
2835
        | TRIM '(' BOTH FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2836
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
1 by brian
clean slate
2837
        | TRIM '(' expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2838
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
1 by brian
clean slate
2839
        | USER '(' ')'
2840
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
2841
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
2842
            {
2843
              DRIZZLE_YYABORT;
2844
            }
2227.4.10 by Olaf van der Spek
Session::lex()
2845
            Lex.setCacheable(false);
1 by brian
clean slate
2846
          }
2847
        | YEAR_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2848
          { $$= new (YYSession->mem_root) Item_func_year($3); }
1 by brian
clean slate
2849
        ;
2850
2851
/*
2852
  Function calls using non reserved keywords, with special syntaxic forms.
2853
  Dedicated grammar rules are needed because of the syntax,
2854
  but also have the potential to cause incompatibilities with other
2855
  parts of the language.
2856
  MAINTAINER:
2857
  The only reasons a function should be added here are:
2858
  - for compatibility reasons with another SQL syntax (CURDATE),
2859
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
2860
  discouraged.
2861
*/
2862
function_call_nonkeyword:
2863
          ADDDATE_SYM '(' expr ',' expr ')'
2864
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2865
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
1 by brian
clean slate
2866
                                                             INTERVAL_DAY, 0);
2867
          }
2868
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2869
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
1 by brian
clean slate
2870
        | CURDATE optional_braces
2871
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2872
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2227.4.10 by Olaf van der Spek
Session::lex()
2873
            Lex.setCacheable(false);
1 by brian
clean slate
2874
          }
2875
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
2876
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
1 by brian
clean slate
2877
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
2878
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
1 by brian
clean slate
2879
        | EXTRACT_SYM '(' interval FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2880
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
1 by brian
clean slate
2881
        | NOW_SYM optional_braces
2882
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2883
            $$= new (YYSession->mem_root) Item_func_now_local();
2227.4.10 by Olaf van der Spek
Session::lex()
2884
            Lex.setCacheable(false);
1 by brian
clean slate
2885
          }
2886
        | NOW_SYM '(' expr ')'
2887
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2888
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2227.4.10 by Olaf van der Spek
Session::lex()
2889
            Lex.setCacheable(false);
1 by brian
clean slate
2890
          }
2891
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2892
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
1 by brian
clean slate
2893
        | SUBDATE_SYM '(' expr ',' expr ')'
2894
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2895
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
1 by brian
clean slate
2896
                                                             INTERVAL_DAY, 1);
2897
          }
2898
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2899
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
1 by brian
clean slate
2900
        | SUBSTRING '(' expr ',' expr ',' expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2901
          {
2902
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2903
            args->push_back($3);
2904
            args->push_back($5);
2905
            args->push_back($7);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
2906
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2907
            {
2908
              DRIZZLE_YYABORT;
2909
            }
2910
          }
1 by brian
clean slate
2911
        | SUBSTRING '(' expr ',' expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2912
          {
2913
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2914
            args->push_back($3);
2915
            args->push_back($5);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
2916
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2917
            {
2918
              DRIZZLE_YYABORT;
2919
            }
2920
          }
1 by brian
clean slate
2921
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2922
          {
2923
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2924
            args->push_back($3);
2925
            args->push_back($5);
2926
            args->push_back($7);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
2927
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2928
            {
2929
              DRIZZLE_YYABORT;
2930
            }
2931
          }
1 by brian
clean slate
2932
        | SUBSTRING '(' expr FROM expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2933
          {
2934
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2935
            args->push_back($3);
2936
            args->push_back($5);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
2937
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
2938
            {
2939
              DRIZZLE_YYABORT;
2940
            }
2941
          }
1 by brian
clean slate
2942
        | SYSDATE optional_braces
2227.4.10 by Olaf van der Spek
Session::lex()
2943
          {
2944
            $$= new (YYSession->mem_root) Item_func_sysdate_local();
2945
            Lex.setCacheable(false);
1643.6.13 by Djellel E. Difallah
adding tests
2946
          }
1 by brian
clean slate
2947
        | SYSDATE '(' expr ')'
2227.4.10 by Olaf van der Spek
Session::lex()
2948
          {
2949
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
2950
            Lex.setCacheable(false);
1643.6.13 by Djellel E. Difallah
adding tests
2951
          }
1 by brian
clean slate
2952
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2953
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
1 by brian
clean slate
2954
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2955
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
1 by brian
clean slate
2956
        | UTC_DATE_SYM optional_braces
2957
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2958
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2227.4.10 by Olaf van der Spek
Session::lex()
2959
            Lex.setCacheable(false);
1 by brian
clean slate
2960
          }
2961
        | UTC_TIMESTAMP_SYM optional_braces
2962
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2963
            $$= new (YYSession->mem_root) Item_func_now_utc();
2227.4.10 by Olaf van der Spek
Session::lex()
2964
            Lex.setCacheable(false);
1 by brian
clean slate
2965
          }
2966
        ;
2967
2968
/*
2969
  Functions calls using a non reserved keyword, and using a regular syntax.
2970
  Because the non reserved keyword is used in another part of the grammar,
2971
  a dedicated rule is needed here.
2972
*/
2973
function_call_conflict:
1030.2.5 by devananda
refactored functin/ascii into plugin/ascii
2974
        COALESCE '(' expr_list ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2975
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
1 by brian
clean slate
2976
        | COLLATION_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
2977
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
1 by brian
clean slate
2978
        | DATABASE '(' ')'
2979
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
2980
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
2073.1.3 by Brian Aker
Fix for test on drop (error message change).
2981
            {
2982
              DRIZZLE_YYABORT;
2983
            }
2227.4.10 by Olaf van der Spek
Session::lex()
2984
            Lex.setCacheable(false);
2073.1.3 by Brian Aker
Fix for test on drop (error message change).
2985
	  }
2986
        | CATALOG_SYM '(' ')'
2987
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
2988
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
1300.4.1 by Stewart Smith
move DATABASE() to function plugin. modify parser so that it looks for a function named 'database' when DATABASE() is called. Special case still needed in parser due to hilarity of not-really-reserved words.
2989
            {
2990
              DRIZZLE_YYABORT;
2991
            }
2227.4.10 by Olaf van der Spek
Session::lex()
2992
            Lex.setCacheable(false);
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
2993
	  }
1976.7.4 by Brian Aker
Added WAIT to the execute() function.
2994
        | EXECUTE_SYM '(' expr ')' opt_wait
1976.7.2 by Brian Aker
Adding execute command to go along with main command.
2995
          {
2996
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2997
            args->push_back($3);
2998
1976.7.4 by Brian Aker
Added WAIT to the execute() function.
2999
            if ($5)
3000
            {
3001
              args->push_back(new (YYSession->mem_root) Item_int(1));
3002
            }
3003
2096.1.14 by Brian Aker
Pull in more C code from parser.
3004
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
1976.7.2 by Brian Aker
Adding execute command to go along with main command.
3005
            {
3006
              DRIZZLE_YYABORT;
3007
            }
3008
          }
1 by brian
clean slate
3009
        | IF '(' expr ',' expr ',' expr ')'
2363.1.4 by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly.
3010
          { 
3011
            $$= new (YYSession->mem_root) Item_func_if($3,$5,$7);
3012
          }
1963.2.1 by Brian Aker
Fixing up the kill function.
3013
        | KILL_SYM kill_option '(' expr ')'
3014
          {
3015
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3016
            args->push_back($4);
3017
3018
            if ($2)
3019
            {
3020
              args->push_back(new (YYSession->mem_root) Item_uint(1));
3021
            }
3022
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
3023
            if (! ($$= parser::reserved_keyword_function(YYSession, "kill", args)))
1963.2.1 by Brian Aker
Fixing up the kill function.
3024
            {
3025
              DRIZZLE_YYABORT;
3026
            }
3027
          }
1 by brian
clean slate
3028
        | MICROSECOND_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3029
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
1 by brian
clean slate
3030
        | MOD_SYM '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3031
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
1 by brian
clean slate
3032
        | QUARTER_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3033
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
1 by brian
clean slate
3034
        | REPEAT_SYM '(' expr ',' expr ')'
1633.4.5 by Brian Aker
More current_session.
3035
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
1 by brian
clean slate
3036
        | REPLACE '(' expr ',' expr ',' expr ')'
1633.4.4 by Brian Aker
Remove more of current_session
3037
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
1 by brian
clean slate
3038
        | TRUNCATE_SYM '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3039
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
1958.1.1 by Brian Aker
Fix clash in parser with wait().
3040
        | WAIT_SYM '(' expr ')'
3041
          {
3042
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3043
            args->push_back($3);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
3044
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
1958.1.1 by Brian Aker
Fix clash in parser with wait().
3045
            {
3046
              DRIZZLE_YYABORT;
3047
            }
3048
          }
1996.2.1 by Brian Aker
uuid type code.
3049
        | UUID_SYM '(' ')'
3050
          {
2096.1.14 by Brian Aker
Pull in more C code from parser.
3051
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
1996.2.1 by Brian Aker
uuid type code.
3052
            {
3053
              DRIZZLE_YYABORT;
3054
            }
2227.4.10 by Olaf van der Spek
Session::lex()
3055
            Lex.setCacheable(false);
1996.2.1 by Brian Aker
uuid type code.
3056
	  }
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
3057
        | IPV6_SYM '(' ')'
3058
          {
3059
            if (! ($$= parser::reserved_keyword_function(YYSession, "ipv6", NULL)))
3060
            {
3061
              DRIZZLE_YYABORT;
3062
            }
3063
            Lex.setCacheable(false);
3064
	  }
1958.1.1 by Brian Aker
Fix clash in parser with wait().
3065
        | WAIT_SYM '(' expr ',' expr ')'
3066
          {
3067
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3068
            args->push_back($3);
3069
            args->push_back($5);
2172.3.5 by Brian Aker
Cleanup a few locations where we should have just been using constant
3070
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
1958.1.1 by Brian Aker
Fix clash in parser with wait().
3071
            {
3072
              DRIZZLE_YYABORT;
3073
            }
3074
          }
1 by brian
clean slate
3075
        ;
3076
3077
/*
3078
  Regular function calls.
3079
  The function name is *not* a token, and therefore is guaranteed to not
3080
  introduce side effects to the language in general.
3081
  MAINTAINER:
3082
  All the new functions implemented for new features should fit into
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
3083
  this category.
1 by brian
clean slate
3084
*/
3085
function_call_generic:
3086
          IDENT_sys '('
3087
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
3088
            const plugin::Function *udf= plugin::Function::get(to_string($1));
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
3089
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
3090
            /* Temporary placing the result of getFunction in $3 */
1 by brian
clean slate
3091
            $<udf>$= udf;
3092
          }
3093
          opt_udf_expr_list ')'
3094
          {
3095
            Item *item= NULL;
3096
3097
            /*
3098
              Implementation note:
3099
              names are resolved with the following order:
3100
              - MySQL native functions,
3101
              - User Defined Functions,
3102
              - Stored Functions (assuming the current <use> database)
3103
3104
              This will be revised with WL#2128 (SQL PATH)
3105
            */
2385.2.12 by Olaf van der Spek
Refactor
3106
            if (Create_func* builder= find_native_function_builder($1))
1 by brian
clean slate
3107
            {
2029.1.15 by Brian Aker
Remove useless copy.
3108
              item= builder->create(YYSession, $1, $4);
1 by brian
clean slate
3109
            }
2385.2.12 by Olaf van der Spek
Refactor
3110
            else if (const plugin::Function* udf= $<udf>3) /* Retrieving the result of service::Function::get */
1 by brian
clean slate
3111
            {
2385.2.12 by Olaf van der Spek
Refactor
3112
	          item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
3113
            } 
3114
			else 
3115
			{
3116
              /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
3117
              my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.data());
1 by brian
clean slate
3118
            }
3119
2385.2.12 by Olaf van der Spek
Refactor
3120
            if (not ($$= item))
1 by brian
clean slate
3121
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3122
              DRIZZLE_YYABORT;
1 by brian
clean slate
3123
            }
2227.4.10 by Olaf van der Spek
Session::lex()
3124
            Lex.setCacheable(false);
1 by brian
clean slate
3125
          }
3126
        ;
3127
3128
opt_udf_expr_list:
3129
        /* empty */     { $$= NULL; }
3130
        | udf_expr_list { $$= $1; }
3131
        ;
3132
3133
udf_expr_list:
3134
          udf_expr
3135
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3136
            $$= new (YYSession->mem_root) List<Item>;
1 by brian
clean slate
3137
            $$->push_back($1);
3138
          }
3139
        | udf_expr_list ',' udf_expr
3140
          {
3141
            $1->push_back($3);
3142
            $$= $1;
3143
          }
3144
        ;
3145
3146
udf_expr:
3147
          remember_name expr remember_end select_alias
3148
          {
3149
            /*
3150
             Use Item::name as a storage for the attribute value of user
3151
             defined function argument. It is safe to use Item::name
3152
             because the syntax will not allow having an explicit name here.
3153
             See WL#1017 re. udf attributes.
3154
            */
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
3155
            if ($4.data())
1 by brian
clean slate
3156
            {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
3157
              $2->is_autogenerated_name= false;
2433.1.6 by Olaf van der Spek
USe data() and size()
3158
              $2->set_name($4.data(), $4.size(), system_charset_info);
1 by brian
clean slate
3159
            }
3160
            else
520.1.22 by Brian Aker
Second pass of thd cleanup
3161
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
1 by brian
clean slate
3162
            $$= $2;
3163
          }
3164
        ;
3165
3166
sum_expr:
3167
          AVG_SYM '(' in_sum_expr ')'
3168
          { $$=new Item_sum_avg($3); }
3169
        | AVG_SYM '(' DISTINCT in_sum_expr ')'
3170
          { $$=new Item_sum_avg_distinct($4); }
3171
        | COUNT_SYM '(' opt_all '*' ')'
2440.2.1 by Olaf van der Spek
Use str_ref
3172
          { $$=new Item_sum_count(new Item_int(0, 1)); }
1 by brian
clean slate
3173
        | COUNT_SYM '(' in_sum_expr ')'
3174
          { $$=new Item_sum_count($3); }
3175
        | COUNT_SYM '(' DISTINCT
2227.4.10 by Olaf van der Spek
Session::lex()
3176
          { Lex.current_select->in_sum_expr++; }
1 by brian
clean slate
3177
          expr_list
2227.4.10 by Olaf van der Spek
Session::lex()
3178
          { Lex.current_select->in_sum_expr--; }
1 by brian
clean slate
3179
          ')'
3180
          { $$=new Item_sum_count_distinct(* $5); }
3181
        | MIN_SYM '(' in_sum_expr ')'
3182
          { $$=new Item_sum_min($3); }
3183
        /*
3184
          According to ANSI SQL, DISTINCT is allowed and has
3185
          no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
3186
          is processed like an ordinary MIN | MAX()
3187
        */
3188
        | MIN_SYM '(' DISTINCT in_sum_expr ')'
3189
          { $$=new Item_sum_min($4); }
3190
        | MAX_SYM '(' in_sum_expr ')'
3191
          { $$=new Item_sum_max($3); }
3192
        | MAX_SYM '(' DISTINCT in_sum_expr ')'
3193
          { $$=new Item_sum_max($4); }
3194
        | STD_SYM '(' in_sum_expr ')'
3195
          { $$=new Item_sum_std($3, 0); }
3196
        | VARIANCE_SYM '(' in_sum_expr ')'
3197
          { $$=new Item_sum_variance($3, 0); }
3198
        | STDDEV_SAMP_SYM '(' in_sum_expr ')'
3199
          { $$=new Item_sum_std($3, 1); }
3200
        | VAR_SAMP_SYM '(' in_sum_expr ')'
3201
          { $$=new Item_sum_variance($3, 1); }
3202
        | SUM_SYM '(' in_sum_expr ')'
3203
          { $$=new Item_sum_sum($3); }
3204
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3205
          { $$=new Item_sum_sum_distinct($4); }
3206
        | GROUP_CONCAT_SYM '(' opt_distinct
2227.4.10 by Olaf van der Spek
Session::lex()
3207
          { Lex.current_select->in_sum_expr++; }
1 by brian
clean slate
3208
          expr_list opt_gorder_clause
3209
          opt_gconcat_separator
3210
          ')'
3211
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3212
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
3213
            sel->in_sum_expr--;
2227.4.10 by Olaf van der Spek
Session::lex()
3214
            $$=new Item_func_group_concat(Lex.current_context(), $3, $5,
1 by brian
clean slate
3215
                                          sel->gorder_list, $7);
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
3216
            $5->clear();
1 by brian
clean slate
3217
          }
3218
        ;
3219
3220
variable:
3221
          '@'
736 by Brian Aker
Remove dead variables.
3222
          { }
1 by brian
clean slate
3223
          variable_aux
3224
          {
3225
            $$= $3;
3226
          }
3227
        ;
3228
3229
variable_aux:
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
3230
          user_variable_ident SET_VAR expr
1 by brian
clean slate
3231
          {
3232
            $$= new Item_func_set_user_var($1, $3);
2227.4.10 by Olaf van der Spek
Session::lex()
3233
            Lex.setCacheable(false);
1 by brian
clean slate
3234
          }
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
3235
        | user_variable_ident
1 by brian
clean slate
3236
          {
1633.4.3 by Brian Aker
Remove session usage.
3237
            $$= new Item_func_get_user_var(*YYSession, $1);
2227.4.10 by Olaf van der Spek
Session::lex()
3238
            Lex.setCacheable(false);
1 by brian
clean slate
3239
          }
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
3240
        | '@' opt_var_ident_type user_variable_ident opt_component
1 by brian
clean slate
3241
          {
3242
            /* disallow "SELECT @@global.global.variable" */
2440.2.12 by Olaf van der Spek
Refactor
3243
            if ($3.data() && $4.data() && parser::check_reserved_words($3))
1 by brian
clean slate
3244
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3245
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3246
              DRIZZLE_YYABORT;
1 by brian
clean slate
3247
            }
520.1.22 by Brian Aker
Second pass of thd cleanup
3248
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3249
              DRIZZLE_YYABORT;
1 by brian
clean slate
3250
          }
3251
        ;
3252
3253
opt_distinct:
2029.1.14 by Brian Aker
Additional boolean
3254
          /* empty */ { $$ = false; }
3255
        | DISTINCT    { $$ = true; }
1 by brian
clean slate
3256
        ;
3257
3258
opt_gconcat_separator:
3259
          /* empty */
3260
            {
520.1.22 by Brian Aker
Second pass of thd cleanup
3261
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
1 by brian
clean slate
3262
            }
3263
        | SEPARATOR_SYM text_string { $$ = $2; }
3264
        ;
3265
3266
opt_gorder_clause:
3267
          /* empty */
3268
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3269
            Lex.current_select->gorder_list = NULL;
1 by brian
clean slate
3270
          }
3271
        | order_clause
3272
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3273
            Select_Lex *select= Lex.current_select;
2385.3.7 by Olaf van der Spek
Refactor DYNAMIC_ARRAY
3274
            select->gorder_list= (SQL_LIST*) memory::sql_memdup(&select->order_list, sizeof(SQL_LIST));
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
3275
            select->order_list.clear();
1 by brian
clean slate
3276
          }
3277
        ;
3278
3279
in_sum_expr:
3280
          opt_all
3281
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3282
            if (Lex.current_select->inc_in_sum_expr())
1 by brian
clean slate
3283
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3284
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3285
              DRIZZLE_YYABORT;
1 by brian
clean slate
3286
            }
3287
          }
3288
          expr
3289
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3290
            Lex.current_select->in_sum_expr--;
1 by brian
clean slate
3291
            $$= $3;
3292
          }
3293
        ;
3294
3295
cast_type:
3296
          BINARY opt_len
2227.4.10 by Olaf van der Spek
Session::lex()
3297
          { $$=ITEM_CAST_CHAR; Lex.charset= &my_charset_bin; Lex.dec= 0; }
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
3298
        | BOOLEAN_SYM
2227.4.10 by Olaf van der Spek
Session::lex()
3299
          { $$=ITEM_CAST_BOOLEAN; Lex.charset= &my_charset_bin; Lex.dec= 0; }
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
3300
        | SIGNED_SYM
2385.3.19 by Olaf van der Spek
Refactor
3301
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
3302
        | SIGNED_SYM INT_SYM
2385.3.19 by Olaf van der Spek
Refactor
3303
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
2039.3.4 by Brian Aker
Adding typeof() method to determine drizzle type returns
3304
        | INT_SYM
2385.3.19 by Olaf van der Spek
Refactor
3305
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
3306
        | UNSIGNED_SYM
2385.3.19 by Olaf van der Spek
Refactor
3307
          { $$=ITEM_CAST_UNSIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
3308
        | UNSIGNED_SYM INT_SYM
2385.3.19 by Olaf van der Spek
Refactor
3309
          { $$=ITEM_CAST_UNSIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
1217 by Brian Aker
Removed bits of charset support from the parser.
3310
        | CHAR_SYM opt_len
2227.4.10 by Olaf van der Spek
Session::lex()
3311
          { $$=ITEM_CAST_CHAR; Lex.dec= 0; }
1 by brian
clean slate
3312
        | DATE_SYM
2385.3.19 by Olaf van der Spek
Refactor
3313
          { $$=ITEM_CAST_DATE; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
1999.4.8 by Brian Aker
Adding in time type.
3314
        | TIME_SYM
2385.3.19 by Olaf van der Spek
Refactor
3315
          { $$=ITEM_CAST_TIME; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
3316
        | DATETIME_SYM
2385.3.19 by Olaf van der Spek
Refactor
3317
          { $$=ITEM_CAST_DATETIME; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
1 by brian
clean slate
3318
        | DECIMAL_SYM float_options
2227.4.10 by Olaf van der Spek
Session::lex()
3319
          { $$=ITEM_CAST_DECIMAL; Lex.charset= NULL; }
1 by brian
clean slate
3320
        ;
3321
3322
expr_list:
3323
          expr
3324
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3325
            $$= new (YYSession->mem_root) List<Item>;
1 by brian
clean slate
3326
            $$->push_back($1);
3327
          }
3328
        | expr_list ',' expr
3329
          {
3330
            $1->push_back($3);
3331
            $$= $1;
3332
          }
3333
        ;
3334
3335
opt_expr:
3336
          /* empty */    { $$= NULL; }
3337
        | expr           { $$= $1; }
3338
        ;
3339
3340
opt_else:
3341
          /* empty */  { $$= NULL; }
3342
        | ELSE expr    { $$= $2; }
3343
        ;
3344
3345
when_list:
3346
          WHEN_SYM expr THEN_SYM expr
3347
          {
3348
            $$= new List<Item>;
3349
            $$->push_back($2);
3350
            $$->push_back($4);
3351
          }
3352
        | when_list WHEN_SYM expr THEN_SYM expr
3353
          {
3354
            $1->push_back($3);
3355
            $1->push_back($5);
3356
            $$= $1;
3357
          }
3358
        ;
3359
3360
/* Equivalent to <table reference> in the SQL:2003 standard. */
3361
/* Warning - may return NULL in case of incomplete SELECT */
3362
table_ref:
3363
          table_factor { $$=$1; }
3364
        | join_table
3365
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3366
            if (!($$= Lex.current_select->nest_last_join(Lex.session)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3367
              DRIZZLE_YYABORT;
1 by brian
clean slate
3368
          }
3369
        ;
3370
3371
join_table_list:
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3372
          derived_table_list { DRIZZLE_YYABORT_UNLESS($$=$1); }
1 by brian
clean slate
3373
        ;
3374
3375
/*
3376
  The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
3377
  The parser does not define OJ as a token, any ident is accepted
3378
  instead in $2 (ident). Also, all productions from table_ref can
3379
  be escaped, not only join_table. Both syntax extensions are safe
3380
  and are ignored.
3381
*/
3382
esc_table_ref:
3383
        table_ref { $$=$1; }
3384
      | '{' ident table_ref '}' { $$=$3; }
3385
      ;
3386
3387
/* Equivalent to <table reference list> in the SQL:2003 standard. */
3388
/* Warning - may return NULL in case of incomplete SELECT */
3389
derived_table_list:
3390
          esc_table_ref { $$=$1; }
3391
        | derived_table_list ',' esc_table_ref
3392
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3393
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
1 by brian
clean slate
3394
          }
3395
        ;
3396
3397
/*
3398
  Notice that JOIN is a left-associative operation, and it must be parsed
3399
  as such, that is, the parser must process first the left join operand
3400
  then the right one. Such order of processing ensures that the parser
3401
  produces correct join trees which is essential for semantic analysis
3402
  and subsequent optimization phases.
3403
*/
3404
join_table:
3405
          /* INNER JOIN variants */
3406
          /*
3407
            Use %prec to evaluate production 'table_ref' before 'normal_join'
3408
            so that [INNER | CROSS] JOIN is properly nested as other
3409
            left-associative joins.
3410
          */
3411
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
2227.4.10 by Olaf van der Spek
Session::lex()
3412
          {
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3413
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
2227.4.10 by Olaf van der Spek
Session::lex()
3414
            Lex.is_cross= false;
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3415
          }
1 by brian
clean slate
3416
        | table_ref STRAIGHT_JOIN table_factor
2227.4.10 by Olaf van der Spek
Session::lex()
3417
          {
3418
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1;
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3419
          }
1 by brian
clean slate
3420
        | table_ref normal_join table_ref
3421
          ON
3422
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3423
            DRIZZLE_YYABORT_UNLESS($1 && $3);
2227.4.10 by Olaf van der Spek
Session::lex()
3424
            DRIZZLE_YYABORT_UNLESS( not Lex.is_cross );
1 by brian
clean slate
3425
            /* Change the current name resolution context to a local context. */
2241.2.13 by Olaf van der Spek
Refactor
3426
            push_new_name_resolution_context(*YYSession, *$1, *$3);
2227.4.10 by Olaf van der Spek
Session::lex()
3427
            Lex.current_select->parsing_place= IN_ON;
1 by brian
clean slate
3428
          }
3429
          expr
3430
          {
3431
            add_join_on($3,$6);
2227.4.10 by Olaf van der Spek
Session::lex()
3432
            Lex.pop_context();
3433
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3434
          }
3435
        | table_ref STRAIGHT_JOIN table_factor
3436
          ON
3437
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3438
            DRIZZLE_YYABORT_UNLESS($1 && $3);
1 by brian
clean slate
3439
            /* Change the current name resolution context to a local context. */
2241.2.13 by Olaf van der Spek
Refactor
3440
            push_new_name_resolution_context(*YYSession, *$1, *$3);
2227.4.10 by Olaf van der Spek
Session::lex()
3441
            Lex.current_select->parsing_place= IN_ON;
1 by brian
clean slate
3442
          }
3443
          expr
3444
          {
3445
            $3->straight=1;
3446
            add_join_on($3,$6);
2227.4.10 by Olaf van der Spek
Session::lex()
3447
            Lex.pop_context();
3448
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3449
          }
3450
        | table_ref normal_join table_ref
3451
          USING
3452
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3453
            DRIZZLE_YYABORT_UNLESS($1 && $3);
1 by brian
clean slate
3454
          }
3455
          '(' using_list ')'
2227.4.10 by Olaf van der Spek
Session::lex()
3456
          { add_join_natural($1,$3,$7,Lex.current_select); $$=$3; }
1 by brian
clean slate
3457
        | table_ref NATURAL JOIN_SYM table_factor
3458
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3459
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
2227.4.10 by Olaf van der Spek
Session::lex()
3460
            add_join_natural($1,$4,NULL,Lex.current_select);
1 by brian
clean slate
3461
          }
3462
3463
          /* LEFT JOIN variants */
3464
        | table_ref LEFT opt_outer JOIN_SYM table_ref
3465
          ON
3466
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3467
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3468
            /* Change the current name resolution context to a local context. */
2241.2.13 by Olaf van der Spek
Refactor
3469
            push_new_name_resolution_context(*YYSession, *$1, *$5);
2227.4.10 by Olaf van der Spek
Session::lex()
3470
            Lex.current_select->parsing_place= IN_ON;
1 by brian
clean slate
3471
          }
3472
          expr
3473
          {
3474
            add_join_on($5,$8);
2227.4.10 by Olaf van der Spek
Session::lex()
3475
            Lex.pop_context();
1 by brian
clean slate
3476
            $5->outer_join|=JOIN_TYPE_LEFT;
3477
            $$=$5;
2227.4.10 by Olaf van der Spek
Session::lex()
3478
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3479
          }
3480
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3481
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3482
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3483
          }
3484
          USING '(' using_list ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3485
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3486
            add_join_natural($1,$5,$9,Lex.current_select);
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3487
            $5->outer_join|=JOIN_TYPE_LEFT;
3488
            $$=$5;
1 by brian
clean slate
3489
          }
3490
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3491
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3492
            DRIZZLE_YYABORT_UNLESS($1 && $6);
2227.4.10 by Olaf van der Spek
Session::lex()
3493
            add_join_natural($1,$6,NULL,Lex.current_select);
1 by brian
clean slate
3494
            $6->outer_join|=JOIN_TYPE_LEFT;
3495
            $$=$6;
3496
          }
3497
3498
          /* RIGHT JOIN variants */
3499
        | table_ref RIGHT opt_outer JOIN_SYM table_ref
3500
          ON
3501
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3502
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3503
            /* Change the current name resolution context to a local context. */
2241.2.13 by Olaf van der Spek
Refactor
3504
            push_new_name_resolution_context(*YYSession, *$1, *$5);
2227.4.10 by Olaf van der Spek
Session::lex()
3505
            Lex.current_select->parsing_place= IN_ON;
1 by brian
clean slate
3506
          }
3507
          expr
3508
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3509
            if (!($$= Lex.current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3510
              DRIZZLE_YYABORT;
1 by brian
clean slate
3511
            add_join_on($$, $8);
2227.4.10 by Olaf van der Spek
Session::lex()
3512
            Lex.pop_context();
3513
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3514
          }
3515
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3516
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3517
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3518
          }
3519
          USING '(' using_list ')'
3520
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3521
            if (!($$= Lex.current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3522
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
3523
            add_join_natural($$,$5,$9,Lex.current_select);
1 by brian
clean slate
3524
          }
3525
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3526
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3527
            DRIZZLE_YYABORT_UNLESS($1 && $6);
2227.4.10 by Olaf van der Spek
Session::lex()
3528
            add_join_natural($6,$1,NULL,Lex.current_select);
3529
            if (!($$= Lex.current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3530
              DRIZZLE_YYABORT;
1 by brian
clean slate
3531
          }
3532
        ;
3533
3534
normal_join:
3535
          JOIN_SYM {}
3536
        | INNER_SYM JOIN_SYM {}
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
3537
        | CROSS JOIN_SYM
3538
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3539
            Lex.is_cross= true;
3540
            Lex.current_select->is_cross= true;
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
3541
          }
1 by brian
clean slate
3542
        ;
3543
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3544
/*
1 by brian
clean slate
3545
   This is a flattening of the rules <table factor> and <table primary>
3546
   in the SQL:2003 standard, since we don't have <sample clause>
3547
3548
   I.e.
3549
   <table factor> ::= <table primary> [ <sample clause> ]
2227.4.10 by Olaf van der Spek
Session::lex()
3550
*/
1 by brian
clean slate
3551
/* Warning - may return NULL in case of incomplete SELECT */
3552
table_factor:
3553
          {
3554
          }
3555
          table_ident opt_table_alias opt_key_definition
3556
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3557
            if (!($$= Lex.current_select->add_table_to_list(YYSession, $2, $3,
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
3558
                             0,
2227.4.10 by Olaf van der Spek
Session::lex()
3559
                             Lex.lock_option,
3560
                             Lex.current_select->pop_index_hints())))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3561
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
3562
            Lex.current_select->add_joined_table($$);
1 by brian
clean slate
3563
          }
3564
        | select_derived_init get_select_lex select_derived2
3565
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3566
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
3567
            if ($1)
3568
            {
3569
              if (sel->set_braces(1))
3570
              {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3571
                parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3572
                DRIZZLE_YYABORT;
1 by brian
clean slate
3573
              }
3574
              /* select in braces, can't contain global parameters */
3575
              if (sel->master_unit()->fake_select_lex)
3576
                sel->master_unit()->global_parameters=
3577
                   sel->master_unit()->fake_select_lex;
3578
            }
2318.6.26 by Olaf van der Spek
Refactor
3579
            $2->init_nested_join(*Lex.session);
1 by brian
clean slate
3580
            $$= 0;
3581
            /* incomplete derived tables return NULL, we must be
3582
               nested in select_derived rule to be here. */
3583
          }
3584
          /*
3585
            Represents a flattening of the following rules from the SQL:2003
3586
            standard. This sub-rule corresponds to the sub-rule
3587
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
2227.4.10 by Olaf van der Spek
Session::lex()
3588
1 by brian
clean slate
3589
            The following rules have been flattened into query_expression_body
3590
            (since we have no <with clause>).
3591
3592
            <derived table> ::= <table subquery>
3593
            <table subquery> ::= <subquery>
3594
            <subquery> ::= <left paren> <query expression> <right paren>
3595
            <query expression> ::= [ <with clause> ] <query expression body>
3596
3597
            For the time being we use the non-standard rule
3598
            select_derived_union which is a compromise between the standard
3599
            and our parser. Possibly this rule could be replaced by our
3600
            query_expression_body.
3601
          */
3602
        | '(' get_select_lex select_derived_union ')' opt_table_alias
3603
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3604
            /* Use $2 instead of Lex.current_select as derived table will
3605
               alter value of Lex.current_select. */
1 by brian
clean slate
3606
            if (!($3 || $5) && $2->embedding &&
2183.2.20 by Olaf van der Spek
Use List::size()
3607
                !$2->embedding->getNestedJoin()->join_list.size())
1 by brian
clean slate
3608
            {
3609
              /* we have a derived table ($3 == NULL) but no alias,
3610
                 Since we are nested in further parentheses so we
3611
                 can pass NULL to the outer level parentheses
3612
                 Permits parsing of "((((select ...))) as xyz)" */
3613
              $$= 0;
3614
            }
3615
            else if (!$3)
3616
            {
3617
              /* Handle case of derived table, alias may be NULL if there
3618
                 are no outer parentheses, add_table_to_list() will throw
3619
                 error in this case */
2227.4.10 by Olaf van der Spek
Session::lex()
3620
              Select_Lex *sel= Lex.current_select;
849 by Brian Aker
Remove dead keywords.
3621
              Select_Lex_Unit *unit= sel->master_unit();
2227.4.10 by Olaf van der Spek
Session::lex()
3622
              Lex.current_select= sel= unit->outer_select();
3623
              if (!($$= sel->add_table_to_list(Lex.session,
1 by brian
clean slate
3624
                                               new Table_ident(unit), $5, 0,
3625
                                               TL_READ)))
3626
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3627
                DRIZZLE_YYABORT;
1 by brian
clean slate
3628
              sel->add_joined_table($$);
2227.4.10 by Olaf van der Spek
Session::lex()
3629
              Lex.pop_context();
1 by brian
clean slate
3630
            }
3631
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3632
            {
3633
              /* simple nested joins cannot have aliases or unions */
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3634
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3635
              DRIZZLE_YYABORT;
1 by brian
clean slate
3636
            }
3637
            else
3638
              $$= $3;
3639
          }
3640
        ;
3641
3642
select_derived_union:
3643
          select_derived opt_order_clause opt_limit_clause
3644
        | select_derived_union
3645
          UNION_SYM
3646
          union_option
3647
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3648
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3649
              DRIZZLE_YYABORT;
1 by brian
clean slate
3650
          }
3651
          query_specification
3652
          {
3653
            /*
3654
              Remove from the name resolution context stack the context of the
3655
              last select in the union.
3656
             */
2227.4.10 by Olaf van der Spek
Session::lex()
3657
            Lex.pop_context();
1 by brian
clean slate
3658
          }
3659
          opt_order_clause opt_limit_clause
3660
        ;
3661
3662
/* The equivalent of select_init2 for nested queries. */
3663
select_init2_derived:
3664
          select_part2_derived
3665
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3666
            Select_Lex * sel= Lex.current_select;
3667
            if (Lex.current_select->set_braces(0))
1 by brian
clean slate
3668
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3669
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3670
              DRIZZLE_YYABORT;
1 by brian
clean slate
3671
            }
3672
            if (sel->linkage == UNION_TYPE &&
3673
                sel->master_unit()->first_select()->braces)
3674
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3675
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3676
              DRIZZLE_YYABORT;
1 by brian
clean slate
3677
            }
3678
          }
3679
        ;
3680
3681
/* The equivalent of select_part2 for nested queries. */
3682
select_part2_derived:
3683
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3684
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
3685
            if (sel->linkage != UNION_TYPE)
2227.4.10 by Olaf van der Spek
Session::lex()
3686
              init_select(&Lex);
3687
            Lex.current_select->parsing_place= SELECT_LIST;
1 by brian
clean slate
3688
          }
3689
          select_options select_item_list
3690
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3691
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3692
          }
3693
          opt_select_from select_lock_type
3694
        ;
3695
3696
/* handle contents of parentheses in join expression */
3697
select_derived:
3698
          get_select_lex
3699
          {
2318.6.26 by Olaf van der Spek
Refactor
3700
            $1->init_nested_join(*Lex.session);
1 by brian
clean slate
3701
          }
3702
          derived_table_list
3703
          {
3704
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3705
               for derived tables, both must equal NULL */
3706
2456.1.4 by Olaf van der Spek
Refactor
3707
            if (!($$= $1->end_nested_join()) && $3)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3708
              DRIZZLE_YYABORT;
2114.4.1 by Brian Aker
Convert just a single SE engine option to be a bit more concise in parser.
3709
1 by brian
clean slate
3710
            if (!$3 && $$)
3711
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3712
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3713
              DRIZZLE_YYABORT;
1 by brian
clean slate
3714
            }
3715
          }
3716
        ;
3717
3718
select_derived2:
3719
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3720
            Lex.derived_tables|= DERIVED_SUBQUERY;
3721
            if (not Lex.expr_allows_subselect)
1 by brian
clean slate
3722
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3723
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3724
              DRIZZLE_YYABORT;
1 by brian
clean slate
3725
            }
2227.4.10 by Olaf van der Spek
Session::lex()
3726
            if (Lex.current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(&Lex, 1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3727
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
3728
            init_select(&Lex);
3729
            Lex.current_select->linkage= DERIVED_TABLE_TYPE;
3730
            Lex.current_select->parsing_place= SELECT_LIST;
1 by brian
clean slate
3731
          }
3732
          select_options select_item_list
3733
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3734
            Lex.current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3735
          }
3736
          opt_select_from
3737
        ;
3738
3739
get_select_lex:
2227.4.10 by Olaf van der Spek
Session::lex()
3740
          /* Empty */ { $$= Lex.current_select; }
1 by brian
clean slate
3741
        ;
3742
3743
select_derived_init:
3744
          SELECT_SYM
3745
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3746
            Select_Lex *sel= Lex.current_select;
327.2.5 by Brian Aker
Refactoring show command
3747
            TableList *embedding;
2456.1.4 by Olaf van der Spek
Refactor
3748
            if (!sel->embedding || sel->end_nested_join())
1 by brian
clean slate
3749
            {
3750
              /* we are not in parentheses */
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
3751
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3752
              DRIZZLE_YYABORT;
1 by brian
clean slate
3753
            }
2227.4.10 by Olaf van der Spek
Session::lex()
3754
            embedding= Lex.current_select->embedding;
1 by brian
clean slate
3755
            $$= embedding &&
2183.2.20 by Olaf van der Spek
Use List::size()
3756
                !embedding->getNestedJoin()->join_list.size();
1 by brian
clean slate
3757
            /* return true if we are deeply nested */
3758
          }
3759
        ;
3760
3761
opt_outer:
3762
          /* empty */ {}
3763
        | OUTER {}
3764
        ;
3765
3766
index_hint_clause:
3767
          /* empty */
3768
          {
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3769
            $$= INDEX_HINT_MASK_ALL;
1 by brian
clean slate
3770
          }
3771
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
3772
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
3773
        | FOR_SYM GROUP_SYM BY  { $$= INDEX_HINT_MASK_GROUP; }
3774
        ;
3775
3776
index_hint_type:
3777
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3778
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
1 by brian
clean slate
3779
        ;
3780
3781
index_hint_definition:
3782
          index_hint_type key_or_index index_hint_clause
3783
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3784
            Lex.current_select->set_index_hint_type($1, $3);
1 by brian
clean slate
3785
          }
3786
          '(' key_usage_list ')'
3787
        | USE_SYM key_or_index index_hint_clause
3788
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3789
            Lex.current_select->set_index_hint_type(INDEX_HINT_USE, $3);
1 by brian
clean slate
3790
          }
3791
          '(' opt_key_usage_list ')'
3792
       ;
3793
3794
index_hints_list:
3795
          index_hint_definition
3796
        | index_hints_list index_hint_definition
3797
        ;
3798
3799
opt_index_hints_list:
3800
          /* empty */
2227.4.10 by Olaf van der Spek
Session::lex()
3801
        | { Lex.current_select->alloc_index_hints(YYSession); } index_hints_list
1 by brian
clean slate
3802
        ;
3803
3804
opt_key_definition:
2227.4.10 by Olaf van der Spek
Session::lex()
3805
          {  Lex.current_select->clear_index_hints(); }
1 by brian
clean slate
3806
          opt_index_hints_list
3807
        ;
3808
3809
opt_key_usage_list:
2385.3.21 by Olaf van der Spek
Refactor
3810
          /* empty */ { Lex.current_select->add_index_hint(YYSession, NULL); }
1 by brian
clean slate
3811
        | key_usage_list {}
3812
        ;
3813
3814
key_usage_element:
3815
          ident
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
3816
          { Lex.current_select->add_index_hint(YYSession, $1.data()); }
1 by brian
clean slate
3817
        | PRIMARY_SYM
2385.3.21 by Olaf van der Spek
Refactor
3818
          { Lex.current_select->add_index_hint(YYSession, "PRIMARY"); }
1 by brian
clean slate
3819
        ;
3820
3821
key_usage_list:
3822
          key_usage_element
3823
        | key_usage_list ',' key_usage_element
3824
        ;
3825
3826
using_list:
3827
          ident
3828
          {
2318.6.90 by Olaf van der Spek
Refactor
3829
            $$= new List<String>;
2433.1.6 by Olaf van der Spek
USe data() and size()
3830
            $$->push_back(new (YYSession->mem_root) String($1.data(), $1.size(), system_charset_info));
1 by brian
clean slate
3831
          }
3832
        | using_list ',' ident
3833
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
3834
            $1->push_back(new (YYSession->mem_root) String($3.data(), $3.size(), system_charset_info));
1 by brian
clean slate
3835
            $$= $1;
3836
          }
3837
        ;
3838
3839
interval:
3840
          interval_time_st {}
3841
        | DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
3842
        | DAY_MICROSECOND_SYM    { $$=INTERVAL_DAY_MICROSECOND; }
3843
        | DAY_MINUTE_SYM         { $$=INTERVAL_DAY_MINUTE; }
3844
        | DAY_SECOND_SYM         { $$=INTERVAL_DAY_SECOND; }
3845
        | HOUR_MICROSECOND_SYM   { $$=INTERVAL_HOUR_MICROSECOND; }
3846
        | HOUR_MINUTE_SYM        { $$=INTERVAL_HOUR_MINUTE; }
3847
        | HOUR_SECOND_SYM        { $$=INTERVAL_HOUR_SECOND; }
3848
        | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
3849
        | MINUTE_SECOND_SYM      { $$=INTERVAL_MINUTE_SECOND; }
3850
        | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
3851
        | YEAR_MONTH_SYM         { $$=INTERVAL_YEAR_MONTH; }
3852
        ;
3853
3854
interval_time_stamp:
3855
	interval_time_st	{}
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3856
	| FRAC_SECOND_SYM	{
3857
                                  $$=INTERVAL_MICROSECOND;
1 by brian
clean slate
3858
                                  /*
3859
                                    FRAC_SECOND was mistakenly implemented with
3860
                                    a wrong resolution. According to the ODBC
3861
                                    standard it should be nanoseconds, not
3862
                                    microseconds. Changing it to nanoseconds
3863
                                    in MySQL would mean making TIMESTAMPDIFF
3864
                                    and TIMESTAMPADD to return DECIMAL, since
3865
                                    the return value would be too big for BIGINT
3866
                                    Hence we just deprecate the incorrect
3867
                                    implementation without changing its
3868
                                    resolution.
3869
                                  */
3870
                                }
3871
	;
3872
3873
interval_time_st:
3874
          DAY_SYM         { $$=INTERVAL_DAY; }
3875
        | WEEK_SYM        { $$=INTERVAL_WEEK; }
3876
        | HOUR_SYM        { $$=INTERVAL_HOUR; }
3877
        | MINUTE_SYM      { $$=INTERVAL_MINUTE; }
3878
        | MONTH_SYM       { $$=INTERVAL_MONTH; }
3879
        | QUARTER_SYM     { $$=INTERVAL_QUARTER; }
3880
        | SECOND_SYM      { $$=INTERVAL_SECOND; }
3881
        | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
3882
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
3883
        ;
3884
3885
table_alias:
3886
          /* empty */
3887
        | AS
3888
        ;
3889
3890
opt_table_alias:
3891
          /* empty */ { $$=0; }
3892
        | table_alias ident
2114.4.2 by Brian Aker
Adding build engine options bit.
3893
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
3894
            $$= (drizzled::lex_string_t*) memory::sql_memdup(&$2,sizeof(drizzled::lex_string_t));
2114.4.2 by Brian Aker
Adding build engine options bit.
3895
          }
1 by brian
clean slate
3896
        ;
3897
3898
opt_all:
3899
          /* empty */
3900
        | ALL
3901
        ;
3902
3903
where_clause:
2227.4.10 by Olaf van der Spek
Session::lex()
3904
          /* empty */  { Lex.current_select->where= 0; }
1 by brian
clean slate
3905
        | WHERE
3906
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3907
            Lex.current_select->parsing_place= IN_WHERE;
1 by brian
clean slate
3908
          }
3909
          expr
3910
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3911
            Select_Lex *select= Lex.current_select;
1 by brian
clean slate
3912
            select->where= $3;
3913
            select->parsing_place= NO_MATTER;
3914
            if ($3)
3915
              $3->top_level_item();
3916
          }
3917
        ;
3918
3919
having_clause:
3920
          /* empty */
3921
        | HAVING
3922
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3923
            Lex.current_select->parsing_place= IN_HAVING;
1 by brian
clean slate
3924
          }
3925
          expr
3926
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3927
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
3928
            sel->having= $3;
3929
            sel->parsing_place= NO_MATTER;
3930
            if ($3)
3931
              $3->top_level_item();
3932
          }
3933
        ;
3934
3935
opt_escape:
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3936
          ESCAPE_SYM simple_expr
1 by brian
clean slate
3937
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3938
            Lex.escape_used= true;
1 by brian
clean slate
3939
            $$= $2;
3940
          }
3941
        | /* empty */
3942
          {
2227.4.10 by Olaf van der Spek
Session::lex()
3943
            Lex.escape_used= false;
2440.2.27 by Olaf van der Spek
Use str_ref
3944
            $$= new Item_string(str_ref("\\"), &my_charset_utf8_general_ci);
1 by brian
clean slate
3945
          }
3946
        ;
3947
3948
/*
3949
   group by statement in select
3950
*/
3951
3952
group_clause:
3953
          /* empty */
3954
        | GROUP_SYM BY group_list olap_opt
3955
        ;
3956
3957
group_list:
3958
          group_list ',' order_ident order_dir
2318.6.31 by Olaf van der Spek
Refactor
3959
          { YYSession->add_group_to_list($3,(bool) $4); }
1 by brian
clean slate
3960
        | order_ident order_dir
2318.6.31 by Olaf van der Spek
Refactor
3961
          { YYSession->add_group_to_list($1,(bool) $2); }
1 by brian
clean slate
3962
        ;
3963
3964
olap_opt:
3965
          /* empty */ {}
3966
        | WITH_ROLLUP_SYM
3967
          {
3968
            /*
3969
              'WITH ROLLUP' is needed for backward compatibility,
3970
              and cause LALR(2) conflicts.
3971
              This syntax is not standard.
3972
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3973
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3974
            */
2227.4.10 by Olaf van der Spek
Session::lex()
3975
            if (Lex.current_select->linkage == GLOBAL_OPTIONS_TYPE)
1 by brian
clean slate
3976
            {
3977
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3978
                       "global union parameters");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3979
              DRIZZLE_YYABORT;
1 by brian
clean slate
3980
            }
2227.4.10 by Olaf van der Spek
Session::lex()
3981
            Lex.current_select->olap= ROLLUP_TYPE;
1 by brian
clean slate
3982
          }
3983
        ;
3984
3985
/*
3986
  Order by statement in ALTER TABLE
3987
*/
3988
3989
alter_order_clause:
3990
          ORDER_SYM BY alter_order_list
3991
        ;
3992
3993
alter_order_list:
3994
          alter_order_list ',' alter_order_item
3995
        | alter_order_item
3996
        ;
3997
3998
alter_order_item:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
3999
          simple_ident order_dir
1 by brian
clean slate
4000
          {
2318.6.31 by Olaf van der Spek
Refactor
4001
            bool ascending= $2 == 1;
4002
            YYSession->add_order_to_list($1, ascending);
1 by brian
clean slate
4003
          }
4004
        ;
4005
4006
/*
4007
   Order by statement in select
4008
*/
4009
4010
opt_order_clause:
4011
          /* empty */
4012
        | order_clause
4013
        ;
4014
4015
order_clause:
4016
          ORDER_SYM BY
4017
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4018
            if (not parser::buildOrderBy(&Lex))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4019
              DRIZZLE_YYABORT;
1 by brian
clean slate
4020
          }
4021
          order_list
4022
        ;
4023
4024
order_list:
4025
          order_list ',' order_ident order_dir
2104.3.4 by Brian Aker
Encapsulate from parser buildOrderBy()
4026
          {
2318.6.31 by Olaf van der Spek
Refactor
4027
            YYSession->add_order_to_list($3,(bool) $4);
2104.3.4 by Brian Aker
Encapsulate from parser buildOrderBy()
4028
          }
1 by brian
clean slate
4029
        | order_ident order_dir
2104.3.4 by Brian Aker
Encapsulate from parser buildOrderBy()
4030
          {
2318.6.31 by Olaf van der Spek
Refactor
4031
            YYSession->add_order_to_list($1,(bool) $2);
2104.3.4 by Brian Aker
Encapsulate from parser buildOrderBy()
4032
          }
1 by brian
clean slate
4033
        ;
4034
4035
order_dir:
4036
          /* empty */ { $$ =  1; }
4037
        | ASC  { $$ =1; }
4038
        | DESC { $$ =0; }
4039
        ;
4040
4041
opt_limit_clause_init:
4042
          /* empty */
4043
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4044
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
4045
            sel->offset_limit= 0;
4046
            sel->select_limit= 0;
4047
          }
4048
        | limit_clause {}
4049
        ;
4050
4051
opt_limit_clause:
4052
          /* empty */ {}
4053
        | limit_clause {}
4054
        ;
4055
4056
limit_clause:
4057
          LIMIT limit_options {}
4058
        ;
4059
4060
limit_options:
4061
          limit_option
4062
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4063
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
4064
            sel->select_limit= $1;
4065
            sel->offset_limit= 0;
4066
            sel->explicit_limit= 1;
4067
          }
4068
        | limit_option ',' limit_option
4069
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4070
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
4071
            sel->select_limit= $3;
4072
            sel->offset_limit= $1;
4073
            sel->explicit_limit= 1;
4074
          }
4075
        | limit_option OFFSET_SYM limit_option
4076
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4077
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
4078
            sel->select_limit= $1;
4079
            sel->offset_limit= $3;
4080
            sel->explicit_limit= 1;
4081
          }
4082
        ;
4083
4084
limit_option:
2433.1.6 by Olaf van der Spek
USe data() and size()
4085
          ULONGLONG_NUM { $$= new Item_uint($1.data(), $1.size()); }
4086
        | LONG_NUM      { $$= new Item_uint($1.data(), $1.size()); }
4087
        | NUM           { $$= new Item_uint($1.data(), $1.size()); }
1 by brian
clean slate
4088
        ;
4089
4090
delete_limit_clause:
4091
          /* empty */
4092
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4093
            Lex.current_select->select_limit= 0;
1 by brian
clean slate
4094
          }
4095
        | LIMIT limit_option
4096
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4097
            Select_Lex *sel= Lex.current_select;
1 by brian
clean slate
4098
            sel->select_limit= $2;
4099
            sel->explicit_limit= 1;
4100
          }
4101
        ;
4102
4103
ulong_num:
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
4104
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
4105
        | HEX_NUM       { $$= (unsigned long) strtol($1.data(), NULL, 16); }
4106
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
4107
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
4108
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
4109
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
1 by brian
clean slate
4110
        ;
4111
4112
ulonglong_num:
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
4113
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
4114
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
4115
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
4116
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
4117
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
1 by brian
clean slate
4118
        ;
4119
4120
select_var_list_init:
4121
          {
2318.6.90 by Olaf van der Spek
Refactor
4122
            if (not Lex.describe)
4123
			  Lex.result= new select_dumpvar;
1 by brian
clean slate
4124
          }
4125
          select_var_list
4126
          {}
4127
        ;
4128
4129
select_var_list:
4130
          select_var_list ',' select_var_ident
4131
        | select_var_ident {}
4132
        ;
4133
2227.4.10 by Olaf van der Spek
Session::lex()
4134
select_var_ident:
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4135
          '@' user_variable_ident
1 by brian
clean slate
4136
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4137
            if (Lex.result)
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4138
            {
2227.4.10 by Olaf van der Spek
Session::lex()
4139
              ((select_dumpvar *)Lex.result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4140
            }
1 by brian
clean slate
4141
            else
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4142
            {
1 by brian
clean slate
4143
              /*
4144
                The parser won't create select_result instance only
4145
                if it's an EXPLAIN.
4146
              */
2227.4.10 by Olaf van der Spek
Session::lex()
4147
              assert(Lex.describe);
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4148
            }
1 by brian
clean slate
4149
          }
4150
        ;
4151
4152
into:
4153
          INTO
736 by Brian Aker
Remove dead variables.
4154
          { }
1 by brian
clean slate
4155
          into_destination
4156
        ;
4157
4158
into_destination:
4159
          OUTFILE TEXT_STRING_filesystem
4160
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4161
            Lex.setCacheable(false);
2430.1.9 by Olaf van der Spek
Add const
4162
            Lex.exchange= new file_exchange($2.data(), 0);
2275.2.7 by Olaf van der Spek
Refactor
4163
            Lex.result= new select_export(Lex.exchange);
1 by brian
clean slate
4164
          }
4165
          opt_field_term opt_line_term
4166
        | DUMPFILE TEXT_STRING_filesystem
4167
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4168
            if (not Lex.describe)
1 by brian
clean slate
4169
            {
2227.4.10 by Olaf van der Spek
Session::lex()
4170
              Lex.setCacheable(false);
2430.1.9 by Olaf van der Spek
Add const
4171
              Lex.exchange= new file_exchange($2.data(),1);
2275.2.7 by Olaf van der Spek
Refactor
4172
              Lex.result= new select_dump(Lex.exchange);
1 by brian
clean slate
4173
            }
4174
          }
4175
        | select_var_list_init
2227.4.10 by Olaf van der Spek
Session::lex()
4176
          {Lex.setCacheable(false);}
1 by brian
clean slate
4177
        ;
4178
4179
/*
4180
  Drop : delete tables or index or user
4181
*/
4182
4183
drop:
2073.1.2 by Brian Aker
Basic DDL for catalog.
4184
          DROP CATALOG_SYM catalog_name
4185
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4186
            Lex.statement= new statement::catalog::Drop(YYSession, $3);
2073.1.2 by Brian Aker
Basic DDL for catalog.
4187
          }
4188
        | DROP opt_temporary table_or_tables if_exists table_list
1 by brian
clean slate
4189
          {
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4190
            statement::DropTable *statement= new statement::DropTable(YYSession);
2227.4.10 by Olaf van der Spek
Session::lex()
4191
            Lex.statement= statement;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4192
            statement->drop_temporary= $2;
4193
            statement->drop_if_exists= $4;
1 by brian
clean slate
4194
          }
4195
        | DROP build_method INDEX_SYM ident ON table_ident {}
4196
          {
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4197
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
2227.4.10 by Olaf van der Spek
Session::lex()
4198
            Lex.statement= statement;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
4199
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2200.2.20 by Stewart Smith
remove drop_list from AlterInfo - is now only in the message::AlterTable protobuf message
4200
2227.4.10 by Olaf van der Spek
Session::lex()
4201
            if (not Lex.current_select->add_table_to_list(Lex.session, $6, NULL,
2029.1.17 by Brian Aker
Last of Lex remove.
4202
                                                          TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4203
              DRIZZLE_YYABORT;
2200.2.18 by Stewart Smith
add fields, indexes and foreign keys to drop in ALTER TABLE DROP and DROP INDEX to the AlterTable protobuf message in parser
4204
4205
            message::AlterTable::AlterTableOperation *operation;
2200.2.25 by Stewart Smith
Merge refactoring of default values work
4206
            operation= Lex.alter_table()->add_operations();
2200.2.18 by Stewart Smith
add fields, indexes and foreign keys to drop in ALTER TABLE DROP and DROP INDEX to the AlterTable protobuf message in parser
4207
            operation->set_operation(message::AlterTable::AlterTableOperation::DROP_KEY);
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
4208
            operation->set_drop_name($4.data());
2200.2.18 by Stewart Smith
add fields, indexes and foreign keys to drop in ALTER TABLE DROP and DROP INDEX to the AlterTable protobuf message in parser
4209
1 by brian
clean slate
4210
          }
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
4211
        | DROP DATABASE if_exists schema_name
1 by brian
clean slate
4212
          {
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4213
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
2227.4.10 by Olaf van der Spek
Session::lex()
4214
            Lex.statement= statement;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4215
            statement->drop_if_exists=$3;
2227.4.10 by Olaf van der Spek
Session::lex()
4216
            Lex.name= $4;
1 by brian
clean slate
4217
          }
2060.2.3 by Brian Aker
Clarify schema_ident definition.
4218
        ;
4219
1 by brian
clean slate
4220
table_list:
4221
          table_name
4222
        | table_list ',' table_name
4223
        ;
4224
4225
table_name:
4226
          table_ident
4227
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4228
            if (!Lex.current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4229
              DRIZZLE_YYABORT;
1 by brian
clean slate
4230
          }
4231
        ;
4232
4233
if_exists:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4234
          /* empty */ { $$= false; }
4235
        | IF EXISTS { $$= true; }
1 by brian
clean slate
4236
        ;
4237
4238
opt_temporary:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4239
          /* empty */ { $$= false; }
4240
        | TEMPORARY_SYM { $$= true; }
1 by brian
clean slate
4241
        ;
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4242
4243
/*
4244
  Execute a string as dynamic SQL.
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4245
*/
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4246
4247
execute:
1958.1.1 by Brian Aker
Fix clash in parser with wait().
4248
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4249
        {
2227.4.10 by Olaf van der Spek
Session::lex()
4250
          Lex.statement= new statement::Execute(YYSession, $2, $3, $4, $5);
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4251
        }
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4252
4253
4254
execute_var_or_string:
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4255
         user_variable_ident
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4256
         {
1921.4.4 by Brian Aker
Fix for Solaris.
4257
            $$.set($1);
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4258
         }
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4259
        | '@' user_variable_ident
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4260
        {
1921.4.4 by Brian Aker
Fix for Solaris.
4261
            $$.set($2, true);
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4262
        }
4263
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
4264
opt_status:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4265
          /* empty */ { $$= false; }
4266
        | WITH NO_SYM RETURN_SYM { $$= true; }
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
4267
        ;
4268
1921.4.2 by Brian Aker
Adding in concurrent execute support.
4269
opt_concurrent:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4270
          /* empty */ { $$= false; }
4271
        | CONCURRENT { $$= true; }
1921.4.2 by Brian Aker
Adding in concurrent execute support.
4272
        ;
4273
1958.1.1 by Brian Aker
Fix clash in parser with wait().
4274
opt_wait:
2029.1.12 by Brian Aker
Merge in boolean type that has been added to the parser.
4275
          /* empty */ { $$= false; }
4276
        | WAIT_SYM { $$= true; }
1958.1.1 by Brian Aker
Fix clash in parser with wait().
4277
        ;
4278
1 by brian
clean slate
4279
/*
4280
** Insert : add new data to table
4281
*/
4282
4283
insert:
4284
          INSERT
4285
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4286
            Lex.statement= new statement::Insert(YYSession);
4287
            Lex.duplicates= DUP_ERROR;
4288
            init_select(&Lex);
1 by brian
clean slate
4289
            /* for subselects */
2227.4.10 by Olaf van der Spek
Session::lex()
4290
            Lex.lock_option= TL_READ;
1 by brian
clean slate
4291
          }
4292
          opt_ignore insert2
4293
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4294
            Lex.current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4295
            Lex.current_select= &Lex.select_lex;
1 by brian
clean slate
4296
          }
4297
          insert_field_spec opt_insert_update
4298
          {}
4299
        ;
4300
4301
replace:
4302
          REPLACE
4303
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4304
            Lex.statement= new statement::Replace(YYSession);
4305
            Lex.duplicates= DUP_REPLACE;
4306
            init_select(&Lex);
1 by brian
clean slate
4307
          }
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
4308
          insert2
1 by brian
clean slate
4309
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4310
            Lex.current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4311
            Lex.current_select= &Lex.select_lex;
1 by brian
clean slate
4312
          }
4313
          insert_field_spec
4314
          {}
4315
        ;
4316
4317
insert2:
4318
          INTO insert_table {}
4319
        | insert_table {}
4320
        ;
4321
4322
insert_table:
4323
          table_name
4324
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4325
            Lex.field_list.clear();
4326
            Lex.many_values.clear();
4327
            Lex.insert_list=0;
1 by brian
clean slate
4328
          };
4329
4330
insert_field_spec:
4331
          insert_values {}
4332
        | '(' ')' insert_values {}
4333
        | '(' fields ')' insert_values {}
2030.1.1 by Brian Aker
Small set of symbol updates.
4334
        | SET_SYM
1 by brian
clean slate
4335
          {
2241.2.11 by Olaf van der Spek
Refactor
4336
            Lex.insert_list = new List_item;
4337
            Lex.many_values.push_back(Lex.insert_list);
1 by brian
clean slate
4338
          }
4339
          ident_eq_list
4340
        ;
4341
4342
fields:
2227.4.10 by Olaf van der Spek
Session::lex()
4343
          fields ',' insert_ident { Lex.field_list.push_back($3); }
4344
        | insert_ident { Lex.field_list.push_back($1); }
1 by brian
clean slate
4345
        ;
4346
4347
insert_values:
4348
          VALUES values_list {}
4349
        | VALUE_SYM values_list {}
2029.1.8 by Brian Aker
Cleanup naming.
4350
        | stored_select
4351
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4352
            Lex.current_select->set_braces(0);
2029.1.8 by Brian Aker
Cleanup naming.
4353
          }
1 by brian
clean slate
4354
          union_clause {}
2029.1.8 by Brian Aker
Cleanup naming.
4355
        | '(' stored_select ')'
4356
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4357
            Lex.current_select->set_braces(1);
2029.1.8 by Brian Aker
Cleanup naming.
4358
          }
1 by brian
clean slate
4359
          union_opt {}
4360
        ;
4361
4362
values_list:
4363
          values_list ','  no_braces
4364
        | no_braces
4365
        ;
4366
4367
ident_eq_list:
4368
          ident_eq_list ',' ident_eq_value
4369
        | ident_eq_value
4370
        ;
4371
4372
ident_eq_value:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
4373
          simple_ident equal expr_or_default
1 by brian
clean slate
4374
          {
2241.2.11 by Olaf van der Spek
Refactor
4375
            Lex.field_list.push_back($1);
4376
            Lex.insert_list->push_back($3);
1 by brian
clean slate
4377
          }
4378
        ;
4379
4380
equal:
2172.3.16 by Brian Aker
Remove greedy use = for table alias allowance.
4381
          '=' {}
1 by brian
clean slate
4382
        | SET_VAR {}
4383
        ;
4384
4385
opt_equal:
4386
          /* empty */ {}
2239.4.2 by Brian Aker
Fix issue where the wrong sort of "=" could be used in some cases.
4387
        | '=' {}
1 by brian
clean slate
4388
        ;
4389
4390
no_braces:
4391
          '('
4392
          {
2318.6.90 by Olaf van der Spek
Refactor
4393
              Lex.insert_list = new List_item;
1 by brian
clean slate
4394
          }
4395
          opt_values ')'
4396
          {
2241.2.11 by Olaf van der Spek
Refactor
4397
            Lex.many_values.push_back(Lex.insert_list);
1 by brian
clean slate
4398
          }
4399
        ;
4400
4401
opt_values:
4402
          /* empty */ {}
4403
        | values
4404
        ;
4405
4406
values:
4407
          values ','  expr_or_default
4408
          {
2241.2.11 by Olaf van der Spek
Refactor
4409
            Lex.insert_list->push_back($3);
1 by brian
clean slate
4410
          }
4411
        | expr_or_default
4412
          {
2241.2.11 by Olaf van der Spek
Refactor
4413
            Lex.insert_list->push_back($1);
1 by brian
clean slate
4414
          }
4415
        ;
4416
4417
expr_or_default:
4418
          expr { $$= $1;}
2227.4.10 by Olaf van der Spek
Session::lex()
4419
        | DEFAULT {$$= new Item_default_value(Lex.current_context()); }
1 by brian
clean slate
4420
        ;
4421
4422
opt_insert_update:
4423
          /* empty */
2227.4.10 by Olaf van der Spek
Session::lex()
4424
        | ON DUPLICATE_SYM { Lex.duplicates= DUP_UPDATE; }
1 by brian
clean slate
4425
          KEY_SYM UPDATE_SYM insert_update_list
4426
        ;
4427
4428
/* Update rows in a table */
4429
4430
update:
2172.3.20 by Brian Aker
Merge in UPDATE
4431
          UPDATE_SYM opt_ignore table_ident SET_SYM update_list
1 by brian
clean slate
4432
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4433
            init_select(&Lex);
4434
            Lex.statement= new statement::Update(YYSession);
4435
            Lex.lock_option= TL_UNLOCK; /* Will be set later */
4436
            Lex.duplicates= DUP_ERROR;
4437
            if (not Lex.select_lex.add_table_to_list(YYSession, $3, NULL,0))
1108.1.2 by Brian Aker
Removal multi-update/delete
4438
              DRIZZLE_YYABORT;
2172.3.20 by Brian Aker
Merge in UPDATE
4439
2227.4.10 by Olaf van der Spek
Session::lex()
4440
            if (Lex.select_lex.get_table_list()->derived)
1 by brian
clean slate
4441
            {
4442
              /* it is single table update and it is update of derived table */
4443
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
2227.4.10 by Olaf van der Spek
Session::lex()
4444
                       Lex.select_lex.get_table_list()->alias, "UPDATE");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4445
              DRIZZLE_YYABORT;
1 by brian
clean slate
4446
            }
4447
            /*
4448
              In case of multi-update setting write lock for all tables may
4449
              be too pessimistic. We will decrease lock level if possible in
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
4450
              multi_update().
1 by brian
clean slate
4451
            */
2227.4.10 by Olaf van der Spek
Session::lex()
4452
            Lex.current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
1 by brian
clean slate
4453
          }
4454
          where_clause opt_order_clause delete_limit_clause {}
4455
        ;
4456
4457
update_list:
4458
          update_list ',' update_elem
4459
        | update_elem
4460
        ;
4461
4462
update_elem:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
4463
          simple_ident equal expr_or_default
1 by brian
clean slate
4464
          {
2318.6.31 by Olaf van der Spek
Refactor
4465
            YYSession->add_item_to_list($1);
4466
			YYSession->add_value_to_list($3);
1 by brian
clean slate
4467
          }
4468
        ;
4469
4470
insert_update_list:
4471
          insert_update_list ',' insert_update_elem
4472
        | insert_update_elem
4473
        ;
4474
4475
insert_update_elem:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
4476
          simple_ident equal expr_or_default
1 by brian
clean slate
4477
          {
2241.2.11 by Olaf van der Spek
Refactor
4478
			Lex.update_list.push_back($1);
4479
            Lex.value_list.push_back($3);
1 by brian
clean slate
4480
          }
4481
        ;
4482
4483
/* Delete rows from a table */
4484
4485
delete:
2172.3.19 by Brian Aker
Refactor DELETE so that it is a simple statement.
4486
          DELETE_SYM opt_delete_option FROM table_ident
1 by brian
clean slate
4487
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4488
            Lex.statement= new statement::Delete(YYSession);
4489
            init_select(&Lex);
4490
            Lex.lock_option= TL_WRITE_DEFAULT;
4491
            Lex.select_lex.init_order();
2241.2.11 by Olaf van der Spek
Refactor
4492
            Lex.current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING, Lex.lock_option);
1 by brian
clean slate
4493
          }
4494
          where_clause opt_order_clause
4495
          delete_limit_clause {}
4496
        ;
4497
4498
opt_delete_option:
2227.4.10 by Olaf van der Spek
Session::lex()
4499
           /* empty */ { Lex.ignore= 0; }
4500
         | IGNORE_SYM  { Lex.ignore= 1; }
1 by brian
clean slate
4501
        ;
4502
4503
truncate:
4504
          TRUNCATE_SYM opt_table_sym table_name
4505
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4506
            Lex.statement= new statement::Truncate(YYSession);
4507
            Lex.select_lex.options= 0;
4508
            Lex.select_lex.init_order();
1 by brian
clean slate
4509
          }
4510
        ;
4511
4512
opt_table_sym:
4513
          /* empty */
4514
        | TABLE_SYM
4515
        ;
4516
4517
/* Show things */
4518
4519
show:
4520
          SHOW
4521
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4522
            Lex.lock_option= TL_READ;
4523
            init_select(&Lex);
4524
            Lex.current_select->parsing_place= SELECT_LIST;
1 by brian
clean slate
4525
          }
4526
          show_param
4527
          {}
4528
        ;
4529
1878.5.4 by Brian Aker
Update documentation.
4530
/* SHOW SCHEMAS */
1 by brian
clean slate
4531
show_param:
327.2.5 by Brian Aker
Refactoring show command
4532
           DATABASES show_wild
1 by brian
clean slate
4533
           {
2318.6.31 by Olaf van der Spek
Refactor
4534
             if (not show::buildSchemas(YYSession))
4535
				DRIZZLE_YYABORT;
1 by brian
clean slate
4536
           }
1878.5.4 by Brian Aker
Update documentation.
4537
           /* SHOW TABLES */
1273.13.37 by Brian Aker
Remove "full" syntax.
4538
         | TABLES opt_db show_wild
1 by brian
clean slate
4539
           {
2096.1.10 by Brian Aker
More shuffle of show into functions.
4540
             if (not show::buildTables(YYSession, $2))
4541
               DRIZZLE_YYABORT;
1 by brian
clean slate
4542
           }
1878.5.4 by Brian Aker
Update documentation.
4543
           /* SHOW TEMPORARY TABLES */
1429.1.2 by Brian Aker
Update for show temporary tables;
4544
         | TEMPORARY_SYM TABLES show_wild
4545
           {
2096.1.10 by Brian Aker
More shuffle of show into functions.
4546
             if (not show::buildTemporaryTables(YYSession))
4547
               DRIZZLE_YYABORT;
1429.1.2 by Brian Aker
Update for show temporary tables;
4548
           }
1878.5.4 by Brian Aker
Update documentation.
4549
           /* SHOW TABLE STATUS */
327.2.5 by Brian Aker
Refactoring show command
4550
         | TABLE_SYM STATUS_SYM opt_db show_wild
1 by brian
clean slate
4551
           {
2096.1.10 by Brian Aker
More shuffle of show into functions.
4552
             if (not show::buildTableStatus(YYSession, $3))
4553
               DRIZZLE_YYABORT;
1 by brian
clean slate
4554
           }
1878.5.4 by Brian Aker
Update documentation.
4555
           /* SHOW COLUMNS FROM table_name */
1273.13.37 by Brian Aker
Remove "full" syntax.
4556
        | COLUMNS from_or_in table_ident opt_db show_wild
2096.1.12 by Brian Aker
Additional show to functions.
4557
           {
4558
             if (not show::buildColumns(YYSession, $4, $3))
4559
               DRIZZLE_YYABORT;
4560
           }
1878.5.4 by Brian Aker
Update documentation.
4561
          /* SHOW INDEXES from table */
1 by brian
clean slate
4562
        | keys_or_index from_or_in table_ident opt_db where_clause
2096.1.12 by Brian Aker
Additional show to functions.
4563
           {
4564
             if (not show::buildIndex(YYSession, $4, $3))
4565
               DRIZZLE_YYABORT;
4566
           }
1 by brian
clean slate
4567
        | COUNT_SYM '(' '*' ')' WARNINGS
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4568
          {
2137.1.12 by Brian Aker
Remove current_session in building the error count.
4569
            show::buildSelectWarning(YYSession);
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
4570
          }
1 by brian
clean slate
4571
        | COUNT_SYM '(' '*' ')' ERRORS
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4572
          {
2137.1.12 by Brian Aker
Remove current_session in building the error count.
4573
            show::buildSelectError(YYSession);
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
4574
          }
1 by brian
clean slate
4575
        | WARNINGS opt_limit_clause_init
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4576
          {
2137.1.12 by Brian Aker
Remove current_session in building the error count.
4577
            show::buildWarnings(YYSession);
1100.3.10 by Padraig O'Sullivan
Extracted the SHOW WARNINGS command from the huge switch statement into its
4578
          }
1 by brian
clean slate
4579
        | ERRORS opt_limit_clause_init
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4580
          {
2137.1.12 by Brian Aker
Remove current_session in building the error count.
4581
            show::buildErrors(YYSession);
1100.3.11 by Padraig O'Sullivan
Extracted the SHOW ERRORS command into its own class and removed the
4582
          }
327.2.5 by Brian Aker
Refactoring show command
4583
        | opt_var_type STATUS_SYM show_wild
2096.1.12 by Brian Aker
Additional show to functions.
4584
          {
4585
            if (not show::buildStatus(YYSession, $1))
4586
              DRIZZLE_YYABORT;
4587
          }
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
4588
        | engine_option_value STATUS_SYM
4589
          {
4590
            if (not show::buildEngineStatus(YYSession, $1))
4591
              DRIZZLE_YYABORT;
4592
          }
1812.5.1 by Brian Aker
This removes the caller for show create table to be a derived table.
4593
        | CREATE TABLE_SYM table_ident
2096.1.12 by Brian Aker
Additional show to functions.
4594
          {
4595
            if (not show::buildCreateTable(YYSession, $3))
4596
              DRIZZLE_YYABORT;
4597
          }
1279 by Brian Aker
Remove show engine status, and show open tables (which no longer applies in
4598
        | PROCESSLIST_SYM
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4599
          {
2096.1.12 by Brian Aker
Additional show to functions.
4600
            if (not show::buildProcesslist(YYSession))
4601
              DRIZZLE_YYABORT;
1100.3.16 by Padraig O'Sullivan
Extracted the show processlist command into a class with its own
4602
          }
327.2.5 by Brian Aker
Refactoring show command
4603
        | opt_var_type  VARIABLES show_wild
2096.1.11 by Brian Aker
Additional show to function.
4604
          {
4605
            if (not show::buildVariables(YYSession, $1))
4606
              DRIZZLE_YYABORT;
4607
          }
1 by brian
clean slate
4608
        | CREATE DATABASE opt_if_not_exists ident
2096.1.8 by Brian Aker
Move show create schema into function.
4609
          {
4610
            if (not show::buildCreateSchema(YYSession, $4))
4611
              DRIZZLE_YYABORT;
4612
          }
1 by brian
clean slate
4613
4614
opt_db:
4615
          /* empty */  { $$= 0; }
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
4616
        | from_or_in ident { $$= $2.data(); }
1 by brian
clean slate
4617
        ;
4618
4619
from_or_in:
4620
          FROM
4621
        | IN_SYM
4622
        ;
4623
327.2.5 by Brian Aker
Refactoring show command
4624
show_wild:
1 by brian
clean slate
4625
          /* empty */
4626
        | LIKE TEXT_STRING_sys
4627
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
4628
            Lex.wild= new (YYSession->mem_root) String($2.data(), $2.size(), system_charset_info);
1055.1.1 by Padraig O'Sullivan
Modified the show_wild rule to also support WHERE clauses.
4629
          }
4630
        | WHERE expr
4631
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4632
            Lex.current_select->where= $2;
1055.1.1 by Padraig O'Sullivan
Modified the show_wild rule to also support WHERE clauses.
4633
            if ($2)
4634
              $2->top_level_item();
1 by brian
clean slate
4635
          }
4636
        ;
4637
4638
/* A Oracle compatible synonym for show */
4639
describe:
4640
          describe_command table_ident
4641
          {
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
4642
            if (not show::buildDescribe(YYSession, $2))
4643
            {
4644
              DRIZZLE_YYABORT;
4645
            }
1 by brian
clean slate
4646
          }
4647
          opt_describe_column {}
4648
        | describe_command opt_extended_describe
2227.4.10 by Olaf van der Spek
Session::lex()
4649
          { Lex.describe|= DESCRIBE_NORMAL; }
1 by brian
clean slate
4650
          select
4651
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4652
            Lex.select_lex.options|= SELECT_DESCRIBE;
1 by brian
clean slate
4653
          }
4654
        ;
4655
4656
describe_command:
4657
          DESC
4658
        | DESCRIBE
4659
        ;
4660
4661
opt_extended_describe:
4662
          /* empty */ {}
2227.4.10 by Olaf van der Spek
Session::lex()
4663
        | EXTENDED_SYM   { Lex.describe|= DESCRIBE_EXTENDED; }
1 by brian
clean slate
4664
        ;
4665
4666
opt_describe_column:
4667
          /* empty */ {}
2227.4.10 by Olaf van der Spek
Session::lex()
4668
        | text_string { Lex.wild= $1; }
1 by brian
clean slate
4669
        | ident
4670
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
4671
            Lex.wild= new (YYSession->mem_root) String($1.data(), $1.size(), system_charset_info);
1 by brian
clean slate
4672
          }
4673
        ;
4674
4675
4676
/* flush things */
4677
4678
flush:
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
4679
          FLUSH_SYM
1 by brian
clean slate
4680
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4681
            Lex.statement= new statement::Flush(YYSession);
1 by brian
clean slate
4682
          }
4683
          flush_options
4684
          {}
4685
        ;
4686
4687
flush_options:
4688
          flush_options ',' flush_option
4689
        | flush_option
4690
        ;
4691
4692
flush_option:
4693
          table_or_tables
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4694
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4695
            statement::Flush *statement= (statement::Flush*)Lex.statement;
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4696
            statement->setFlushTables(true);
4697
          }
1 by brian
clean slate
4698
          opt_table_list {}
4699
        | TABLES WITH READ_SYM LOCK_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4700
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4701
            statement::Flush *statement= (statement::Flush*)Lex.statement;
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4702
            statement->setFlushTablesWithReadLock(true);
4703
          }
1 by brian
clean slate
4704
        | LOGS_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4705
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4706
            statement::Flush *statement= (statement::Flush*)Lex.statement;
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4707
            statement->setFlushLog(true);
4708
          }
1 by brian
clean slate
4709
        | STATUS_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4710
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4711
            statement::Flush *statement= (statement::Flush*)Lex.statement;
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
4712
            statement->setFlushStatus(true);
4713
          }
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
4714
        | GLOBAL_SYM STATUS_SYM
4715
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4716
            statement::Flush *statement= (statement::Flush*)Lex.statement;
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
4717
            statement->setFlushGlobalStatus(true);
4718
          }
1 by brian
clean slate
4719
        ;
4720
4721
opt_table_list:
4722
          /* empty */  {}
4723
        | table_list {}
4724
        ;
4725
4726
/* kill threads */
4727
4728
kill:
4729
          KILL_SYM kill_option expr
4730
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4731
            Lex.statement= new statement::Kill(YYSession, $3, $2);
1 by brian
clean slate
4732
          }
4733
        ;
4734
4735
kill_option:
2029.1.14 by Brian Aker
Additional boolean
4736
          /* empty */ { $$= false; }
4737
        | CONNECTION_SYM { $$= false; }
4738
        | QUERY_SYM      { $$= true; }
1 by brian
clean slate
4739
        ;
4740
4741
/* change database */
4742
4743
use:
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
4744
          USE_SYM schema_name
1 by brian
clean slate
4745
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4746
            Lex.statement= new statement::ChangeSchema(YYSession);
2430.1.10 by Olaf van der Spek
Add const
4747
            Lex.select_lex.db= $2.data();
1 by brian
clean slate
4748
          }
4749
        ;
4750
4751
/* import, export of files */
4752
4753
load:
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
4754
          LOAD data_file
1 by brian
clean slate
4755
          {
2029.1.18 by Brian Aker
Rely on the try/catch above the parser to handle the unlikely case of a
4756
            statement::Load *statement= new statement::Load(YYSession);
2227.4.10 by Olaf van der Spek
Session::lex()
4757
            Lex.statement= statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
4758
2029.1.15 by Brian Aker
Remove useless copy.
4759
            Lex_input_stream *lip= YYSession->m_lip;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
4760
            statement->fname_start= lip->get_ptr();
1 by brian
clean slate
4761
          }
919.1.1 by Brian Aker
Remove LOAD DATA "LOCAL" INFILE
4762
          load_data_lock INFILE TEXT_STRING_filesystem
1 by brian
clean slate
4763
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4764
            Lex.lock_option= $4;
4765
            Lex.duplicates= DUP_ERROR;
4766
            Lex.ignore= 0;
2430.1.9 by Olaf van der Spek
Add const
4767
            Lex.exchange= new file_exchange($6.data(), 0, $2);
1 by brian
clean slate
4768
          }
4769
          opt_duplicate INTO
4770
          {
2029.1.15 by Brian Aker
Remove useless copy.
4771
            Lex_input_stream *lip= YYSession->m_lip;
2227.4.10 by Olaf van der Spek
Session::lex()
4772
            ((statement::Load *)Lex.statement)->fname_end= lip->get_ptr();
1 by brian
clean slate
4773
          }
4774
          TABLE_SYM table_ident
4775
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4776
            if (!Lex.current_select->add_table_to_list(YYSession,
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4777
                    $12, NULL, TL_OPTION_UPDATING,
2227.4.10 by Olaf van der Spek
Session::lex()
4778
                    Lex.lock_option))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4779
              DRIZZLE_YYABORT;
2227.4.10 by Olaf van der Spek
Session::lex()
4780
            Lex.field_list.clear();
4781
            Lex.update_list.clear();
4782
            Lex.value_list.clear();
1 by brian
clean slate
4783
          }
4784
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4785
          opt_load_data_set_spec
4786
          {}
4787
        ;
4788
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
4789
data_file:
4790
        DATA_SYM  { $$= FILETYPE_CSV; };
1 by brian
clean slate
4791
4792
load_data_lock:
4793
          /* empty */ { $$= TL_WRITE_DEFAULT; }
4794
        | CONCURRENT
4795
          {
4796
              $$= TL_WRITE_CONCURRENT_INSERT;
4797
          }
4798
        ;
4799
4800
opt_duplicate:
2227.4.10 by Olaf van der Spek
Session::lex()
4801
          /* empty */ { Lex.duplicates=DUP_ERROR; }
4802
        | REPLACE { Lex.duplicates=DUP_REPLACE; }
4803
        | IGNORE_SYM { Lex.ignore= 1; }
1 by brian
clean slate
4804
        ;
4805
2029.1.6 by Brian Aker
Refactor create table into sections.
4806
opt_duplicate_as:
2227.4.10 by Olaf van der Spek
Session::lex()
4807
          /* empty */ { Lex.duplicates=DUP_ERROR; }
4808
        | AS { Lex.duplicates=DUP_ERROR; }
4809
        | REPLACE { Lex.duplicates=DUP_REPLACE; }
4810
        | IGNORE_SYM { Lex.ignore= true; }
4811
        | REPLACE AS { Lex.duplicates=DUP_REPLACE; }
4812
        | IGNORE_SYM AS { Lex.ignore= true; }
2029.1.6 by Brian Aker
Refactor create table into sections.
4813
        ;
4814
1 by brian
clean slate
4815
opt_field_term:
4816
          /* empty */
4817
        | COLUMNS field_term_list
4818
        ;
4819
4820
field_term_list:
4821
          field_term_list field_term
4822
        | field_term
4823
        ;
4824
4825
field_term:
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4826
          TERMINATED BY text_string
1 by brian
clean slate
4827
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4828
            assert(Lex.exchange != 0);
4829
            Lex.exchange->field_term= $3;
1 by brian
clean slate
4830
          }
4831
        | OPTIONALLY ENCLOSED BY text_string
4832
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4833
            assert(Lex.exchange != 0);
4834
            Lex.exchange->enclosed= $4;
4835
            Lex.exchange->opt_enclosed= 1;
1 by brian
clean slate
4836
          }
4837
        | ENCLOSED BY text_string
4838
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4839
            assert(Lex.exchange != 0);
4840
            Lex.exchange->enclosed= $3;
1 by brian
clean slate
4841
          }
4842
        | ESCAPED BY text_string
4843
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4844
            assert(Lex.exchange != 0);
4845
            Lex.exchange->escaped= $3;
1 by brian
clean slate
4846
          }
4847
        ;
4848
4849
opt_line_term:
4850
          /* empty */
4851
        | LINES line_term_list
4852
        ;
4853
4854
line_term_list:
4855
          line_term_list line_term
4856
        | line_term
4857
        ;
4858
4859
line_term:
4860
          TERMINATED BY text_string
4861
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4862
            assert(Lex.exchange != 0);
4863
            Lex.exchange->line_term= $3;
1 by brian
clean slate
4864
          }
4865
        | STARTING BY text_string
4866
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4867
            assert(Lex.exchange != 0);
4868
            Lex.exchange->line_start= $3;
1 by brian
clean slate
4869
          }
4870
        ;
4871
4872
opt_ignore_lines:
4873
          /* empty */
4874
        | IGNORE_SYM NUM lines_or_rows
4875
          {
2227.4.10 by Olaf van der Spek
Session::lex()
4876
            assert(Lex.exchange != 0);
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
4877
            Lex.exchange->skip_lines= atol($2.data());
1 by brian
clean slate
4878
          }
4879
        ;
4880
4881
lines_or_rows:
4882
        LINES { }
4883
        | ROWS_SYM { }
4884
        ;
4885
4886
opt_field_or_var_spec:
4887
          /* empty */ {}
4888
        | '(' fields_or_vars ')' {}
4889
        | '(' ')' {}
4890
        ;
4891
4892
fields_or_vars:
4893
          fields_or_vars ',' field_or_var
2227.4.10 by Olaf van der Spek
Session::lex()
4894
          { Lex.field_list.push_back($3); }
1 by brian
clean slate
4895
        | field_or_var
2227.4.10 by Olaf van der Spek
Session::lex()
4896
          { Lex.field_list.push_back($1); }
1 by brian
clean slate
4897
        ;
4898
4899
field_or_var:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
4900
          simple_ident {$$= $1;}
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
4901
        | '@' user_variable_ident
1 by brian
clean slate
4902
          { $$= new Item_user_var_as_out_param($2); }
4903
        ;
4904
4905
opt_load_data_set_spec:
4906
          /* empty */ {}
2030.1.1 by Brian Aker
Small set of symbol updates.
4907
        | SET_SYM insert_update_list {}
1 by brian
clean slate
4908
        ;
4909
4910
/* Common definitions */
4911
4912
text_literal:
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
4913
        TEXT_STRING_literal
4914
        {
2433.1.6 by Olaf van der Spek
USe data() and size()
4915
          $$ = new Item_string($1.data(), $1.size(), YYSession->variables.getCollation());
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
4916
        }
1 by brian
clean slate
4917
        | text_literal TEXT_STRING_literal
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4918
          {
2430.1.10 by Olaf van der Spek
Add const
4919
            ((Item_string*) $1)->append($2);
1 by brian
clean slate
4920
          }
4921
        ;
4922
4923
text_string:
4924
          TEXT_STRING_literal
4925
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
4926
            $$= new (YYSession->mem_root) String($1.data(), $1.size(), YYSession->variables.getCollation());
1 by brian
clean slate
4927
          }
4928
        | HEX_NUM
4929
          {
2430.1.11 by Olaf van der Spek
Use str_ref
4930
            Item *tmp= new Item_hex_string($1);
1 by brian
clean slate
4931
            /*
4932
              it is OK only emulate fix_fields, because we need only
4933
              value of constant
4934
            */
2440.2.1 by Olaf van der Spek
Use str_ref
4935
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str(NULL) : NULL;
1 by brian
clean slate
4936
          }
4937
        | BIN_NUM
4938
          {
2440.2.1 by Olaf van der Spek
Use str_ref
4939
            Item *tmp= new Item_bin_string($1);
1 by brian
clean slate
4940
            /*
4941
              it is OK only emulate fix_fields, because we need only
4942
              value of constant
4943
            */
2440.2.1 by Olaf van der Spek
Use str_ref
4944
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str(NULL) : NULL;
1 by brian
clean slate
4945
          }
4946
        ;
4947
4948
signed_literal:
4949
          literal { $$ = $1; }
4950
        | '+' NUM_literal { $$ = $2; }
4951
        | '-' NUM_literal
4952
          {
4953
            $2->max_length++;
4954
            $$= $2->neg();
4955
          }
4956
        ;
4957
4958
literal:
4959
          text_literal { $$ = $1; }
4960
        | NUM_literal { $$ = $1; }
4961
        | NULL_SYM
4962
          {
4963
            $$ = new Item_null();
520.1.22 by Brian Aker
Second pass of thd cleanup
4964
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
1 by brian
clean slate
4965
          }
2035.1.2 by Brian Aker
Make the item call a bit friendlier.
4966
        | FALSE_SYM { $$= new drizzled::item::False(); }
4967
        | TRUE_SYM { $$= new drizzled::item::True(); }
2430.1.11 by Olaf van der Spek
Use str_ref
4968
        | HEX_NUM { $$ = new Item_hex_string($1);}
2440.2.1 by Olaf van der Spek
Use str_ref
4969
        | BIN_NUM { $$= new Item_bin_string($1); }
1 by brian
clean slate
4970
        | DATE_SYM text_literal { $$ = $2; }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
4971
        | TIMESTAMP_SYM text_literal { $$ = $2; }
1 by brian
clean slate
4972
        ;
4973
2198.6.13 by Brian Aker
Merge fix such that default is better defined on numbers.
4974
integer_literal:
4975
          text_literal { $$ = $1; }
2430.1.11 by Olaf van der Spek
Use str_ref
4976
        | HEX_NUM { $$ = new Item_hex_string($1);}
2440.2.1 by Olaf van der Spek
Use str_ref
4977
        | BIN_NUM { $$= new Item_bin_string($1); }
2198.6.13 by Brian Aker
Merge fix such that default is better defined on numbers.
4978
        | NUM_literal { $$ = $1; }
4979
        | NULL_SYM
4980
          {
4981
            $$ = new Item_null();
4982
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4983
          }
4984
        | '+' NUM_literal { $$ = $2; }
4985
        | '-' NUM_literal
4986
          {
4987
            $2->max_length++;
4988
            $$= $2->neg();
4989
          }
4990
        ;
4991
2198.6.11 by Brian Aker
Have the parser enforce propper default values for boolean.
4992
boolean_literal:
4993
          NULL_SYM
4994
          {
4995
            $$ = new Item_null();
4996
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4997
          }
4998
        | FALSE_SYM
4999
          {
5000
            $$= new drizzled::item::False();
5001
          }
5002
        | TRUE_SYM
5003
          {
5004
            $$= new drizzled::item::True();
5005
          }
5006
        ;
5007
2198.6.10 by Brian Aker
Scope out timestamp to only take certain types of values as default.
5008
date_literal:
5009
          text_literal { $$ = $1; }
5010
        | NULL_SYM
5011
          {
5012
            $$ = new Item_null();
5013
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5014
          }
5015
        | NUM_literal { $$ = $1; }
5016
        | DATE_SYM text_literal { $$ = $2; }
5017
        | TIMESTAMP_SYM text_literal { $$ = $2; }
5018
        ;
5019
1 by brian
clean slate
5020
NUM_literal:
5021
          NUM
5022
          {
5023
            int error;
2433.1.6 by Olaf van der Spek
USe data() and size()
5024
            $$ = new Item_int($1.data(), internal::my_strtoll10($1.data(), NULL, &error), $1.size());
1 by brian
clean slate
5025
          }
5026
        | LONG_NUM
5027
          {
5028
            int error;
2433.1.6 by Olaf van der Spek
USe data() and size()
5029
            $$ = new Item_int($1.data(), internal::my_strtoll10($1.data(), NULL, &error), $1.size());
1 by brian
clean slate
5030
          }
5031
        | ULONGLONG_NUM
2433.1.6 by Olaf van der Spek
USe data() and size()
5032
          { $$ = new Item_uint($1.data(), $1.size()); }
1 by brian
clean slate
5033
        | DECIMAL_NUM
5034
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
5035
            $$= new Item_decimal($1.data(), $1.size(), YYSession->charset());
520.1.22 by Brian Aker
Second pass of thd cleanup
5036
            if (YYSession->is_error())
1 by brian
clean slate
5037
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5038
              DRIZZLE_YYABORT;
1 by brian
clean slate
5039
            }
5040
          }
5041
        | FLOAT_NUM
5042
          {
2433.1.6 by Olaf van der Spek
USe data() and size()
5043
            $$ = new Item_float($1.data(), $1.size());
520.1.22 by Brian Aker
Second pass of thd cleanup
5044
            if (YYSession->is_error())
1 by brian
clean slate
5045
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5046
              DRIZZLE_YYABORT;
1 by brian
clean slate
5047
            }
5048
          }
5049
        ;
5050
5051
/**********************************************************************
5052
** Creating different items.
5053
**********************************************************************/
5054
5055
insert_ident:
2114.4.8 by Brian Aker
Merge in additional parser encapsulation.
5056
          simple_ident { $$=$1; }
1 by brian
clean slate
5057
        | table_wild { $$=$1; }
5058
        ;
5059
5060
table_wild:
5061
          ident '.' '*'
5062
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5063
            $$= parser::buildTableWild(&Lex, null_lex_string(), $1);
1 by brian
clean slate
5064
          }
5065
        | ident '.' ident '.' '*'
5066
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5067
            $$= parser::buildTableWild(&Lex, $1, $3);
1 by brian
clean slate
5068
          }
5069
        ;
5070
5071
order_ident:
5072
          expr { $$=$1; }
5073
        ;
5074
5075
simple_ident:
5076
          ident
5077
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5078
            $$= parser::buildIdent(&Lex, null_lex_string(), null_lex_string(), $1);
1 by brian
clean slate
5079
          }
5080
        | simple_ident_q { $$= $1; }
5081
        ;
5082
5083
simple_ident_q:
5084
          ident '.' ident
5085
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5086
            $$= parser::buildIdent(&Lex, null_lex_string(), $1, $3);
1 by brian
clean slate
5087
          }
5088
        | '.' ident '.' ident
5089
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5090
            $$= parser::buildIdent(&Lex, null_lex_string(), $2, $4);
1 by brian
clean slate
5091
          }
5092
        | ident '.' ident '.' ident
5093
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5094
            $$= parser::buildIdent(&Lex, $1, $3, $5);
1 by brian
clean slate
5095
          }
5096
        ;
5097
5098
field_ident:
2227.4.10 by Olaf van der Spek
Session::lex()
5099
          ident
2114.4.4 by Brian Aker
Merge in field ident wrap from parser.
5100
          {
5101
            $$=$1;
5102
          }
1 by brian
clean slate
5103
        | ident '.' ident '.' ident
5104
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5105
            if (not parser::checkFieldIdent(&Lex, $1, $3))
2114.4.4 by Brian Aker
Merge in field ident wrap from parser.
5106
              DRIZZLE_YYABORT;
5107
1 by brian
clean slate
5108
            $$=$5;
5109
          }
5110
        | ident '.' ident
5111
          {
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5112
            if (not parser::checkFieldIdent(&Lex, null_lex_string(), $1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5113
              DRIZZLE_YYABORT;
2114.4.4 by Brian Aker
Merge in field ident wrap from parser.
5114
1 by brian
clean slate
5115
            $$=$3;
5116
          }
2227.4.10 by Olaf van der Spek
Session::lex()
5117
        | '.' ident
2114.4.4 by Brian Aker
Merge in field ident wrap from parser.
5118
          { /* For Delphi */
5119
            $$=$2;
5120
          }
1 by brian
clean slate
5121
        ;
5122
5123
table_ident:
2114.4.7 by Brian Aker
Pull simple_ident into method.
5124
          ident
5125
          {
5126
            $$= new Table_ident($1);
5127
          }
5128
        | schema_name '.' ident
5129
          {
5130
            $$=new Table_ident($1,$3);
5131
          }
5132
        | '.' ident
5133
        { /* For Delphi */
5134
          $$= new Table_ident($2);
5135
        }
1 by brian
clean slate
5136
        ;
5137
2060.2.5 by Brian Aker
Adjust name, we aren't really return an ident, it is just a name.
5138
schema_name:
2060.2.6 by Brian Aker
Look ma, no shift conflicts, and we get the keywords back.
5139
          ident
2060.2.3 by Brian Aker
Clarify schema_ident definition.
5140
        ;
5141
2073.1.2 by Brian Aker
Basic DDL for catalog.
5142
catalog_name:
5143
          ident
5144
        ;
5145
1 by brian
clean slate
5146
IDENT_sys:
2227.4.10 by Olaf van der Spek
Session::lex()
5147
          IDENT
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5148
          {
5149
            $$= $1;
5150
          }
1 by brian
clean slate
5151
        | IDENT_QUOTED
5152
          {
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
5153
            const charset_info_st * const cs= system_charset_info;
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5154
            int dummy_error;
2440.2.24 by Olaf van der Spek
Use str_ref
5155
            uint32_t wlen= cs->cset->well_formed_len(*cs, $1, $1.size(), &dummy_error);
2433.1.6 by Olaf van der Spek
USe data() and size()
5156
            if (wlen < $1.size())
1 by brian
clean slate
5157
            {
2433.1.6 by Olaf van der Spek
USe data() and size()
5158
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0), cs->csname, $1.data() + wlen);
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5159
              DRIZZLE_YYABORT;
1 by brian
clean slate
5160
            }
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5161
            $$= $1;
1 by brian
clean slate
5162
          }
5163
        ;
5164
5165
TEXT_STRING_sys:
5166
          TEXT_STRING
5167
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5168
            $$= $1;
1 by brian
clean slate
5169
          }
5170
        ;
5171
5172
TEXT_STRING_literal:
5173
          TEXT_STRING
5174
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5175
            $$= $1;
1 by brian
clean slate
5176
          }
5177
        ;
5178
5179
TEXT_STRING_filesystem:
5180
          TEXT_STRING
5181
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5182
            $$= $1;
1 by brian
clean slate
5183
          }
5184
        ;
5185
5186
ident:
5187
          IDENT_sys    { $$=$1; }
5188
        | keyword
5189
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
5190
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
1 by brian
clean slate
5191
          }
5192
        ;
5193
5194
ident_or_text:
2029.1.22 by Brian Aker
Merge in change to use row_format spefically *this is backward compatible
5195
          IDENT_sys           { $$=$1;}
5196
        | TEXT_STRING_sys { $$=$1;}
5197
        ;
5198
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
5199
engine_option_value:
5200
          IDENT_sys           { $$=$1;}
1 by brian
clean slate
5201
        | TEXT_STRING_sys { $$=$1;}
2029.1.21 by Brian Aker
Reduce dependency on LEX_HOME.
5202
        ;
5203
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5204
keyword_exception_for_variable:
5205
          TIMESTAMP_SYM         {}
5206
        | SQL_BUFFER_RESULT     {}
5207
        | IDENTITY_SYM          {}
1 by brian
clean slate
5208
        ;
5209
5210
/* Keyword that we allow for identifiers (except SP labels) */
5211
keyword:
5212
          keyword_sp            {}
5213
        | BEGIN_SYM             {}
5214
        | CHECKSUM_SYM          {}
5215
        | CLOSE_SYM             {}
5216
        | COMMENT_SYM           {}
5217
        | COMMIT_SYM            {}
5218
        | CONTAINS_SYM          {}
5219
        | DEALLOCATE_SYM        {}
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
5220
        | DO_SYM                {}
1 by brian
clean slate
5221
        | END                   {}
5222
        | FLUSH_SYM             {}
5223
        | NO_SYM                {}
5224
        | OPEN_SYM              {}
5225
        | ROLLBACK_SYM          {}
5226
        | SAVEPOINT_SYM         {}
5227
        | SECURITY_SYM          {}
5228
        | SERVER_SYM            {}
2029.1.24 by Brian Aker
Reduce the conflicts based on engine options.
5229
        | SIGNED_SYM            {}
1 by brian
clean slate
5230
        | START_SYM             {}
5231
        | STOP_SYM              {}
5232
        | TRUNCATE_SYM          {}
5233
        ;
5234
5235
/*
5236
 * Keywords that we allow for labels in SPs.
5237
 * Anything that's the beginning of a statement or characteristics
5238
 * must be in keyword above, otherwise we get (harmful) shift/reduce
5239
 * conflicts.
5240
 */
5241
keyword_sp:
5242
          ACTION                   {}
5243
        | ADDDATE_SYM              {}
5244
        | AFTER_SYM                {}
5245
        | AGGREGATE_SYM            {}
5246
        | ANY_SYM                  {}
5247
        | AT_SYM                   {}
5248
        | AUTO_INC                 {}
5249
        | AVG_SYM                  {}
5250
        | BIT_SYM                  {}
5251
        | BOOL_SYM                 {}
5252
        | BOOLEAN_SYM              {}
5253
        | BTREE_SYM                {}
5254
        | CASCADED                 {}
5255
        | CHAIN_SYM                {}
5256
        | COALESCE                 {}
5257
        | COLLATION_SYM            {}
5258
        | COLUMNS                  {}
5259
        | COMMITTED_SYM            {}
5260
        | COMPACT_SYM              {}
5261
        | COMPRESSED_SYM           {}
5262
        | CONCURRENT               {}
2060.2.9 by Brian Aker
Document conflict.
5263
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
1 by brian
clean slate
5264
        | CONSISTENT_SYM           {}
5265
        | CUBE_SYM                 {}
5266
        | DATA_SYM                 {}
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
5267
        | DATABASES                {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5268
        | DATETIME_SYM             {}
2068.6.1 by Brian Aker
Cut down the number of keywords/small style cleanup.
5269
        | DATE_SYM                 {} /* Create conflict */
1 by brian
clean slate
5270
        | DAY_SYM                  {}
5271
        | DISABLE_SYM              {}
5272
        | DISCARD                  {}
5273
        | DUMPFILE                 {}
5274
        | DUPLICATE_SYM            {}
5275
        | DYNAMIC_SYM              {}
5276
        | ENDS_SYM                 {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5277
        | ENUM_SYM                 {}
1 by brian
clean slate
5278
        | ENGINE_SYM               {}
5279
        | ERRORS                   {}
5280
        | ESCAPE_SYM               {}
5281
        | EXCLUSIVE_SYM            {}
5282
        | EXTENDED_SYM             {}
5283
        | FOUND_SYM                {}
5284
        | ENABLE_SYM               {}
5285
        | FULL                     {}
5286
        | FILE_SYM                 {}
5287
        | FIRST_SYM                {}
5288
        | FIXED_SYM                {}
5289
        | FRAC_SECOND_SYM          {}
5290
        | GLOBAL_SYM               {}
5291
        | HASH_SYM                 {}
5292
        | HOUR_SYM                 {}
5293
        | IDENTIFIED_SYM           {}
5294
        | IMPORT                   {}
5295
        | INDEXES                  {}
5296
        | ISOLATION                {}
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
5297
        | IPV6_SYM                 {}
1 by brian
clean slate
5298
        | KEY_BLOCK_SIZE           {}
5299
        | LAST_SYM                 {}
5300
        | LEVEL_SYM                {}
5301
        | LOCAL_SYM                {}
5302
        | LOCKS_SYM                {}
5303
        | LOGS_SYM                 {}
5304
        | MAX_VALUE_SYM            {}
5305
        | MEDIUM_SYM               {}
5306
        | MERGE_SYM                {}
5307
        | MICROSECOND_SYM          {}
5308
        | MINUTE_SYM               {}
5309
        | MODIFY_SYM               {}
5310
        | MODE_SYM                 {}
5311
        | MONTH_SYM                {}
5312
        | NAME_SYM                 {}
5313
        | NAMES_SYM                {}
5314
        | NATIONAL_SYM             {}
5315
        | NEXT_SYM                 {}
5316
        | NEW_SYM                  {}
5317
        | NONE_SYM                 {}
5318
        | OFFLINE_SYM              {}
5319
        | OFFSET_SYM               {}
5320
        | ONE_SHOT_SYM             {}
5321
        | ONE_SYM                  {}
5322
        | ONLINE_SYM               {}
5323
        | PARTIAL                  {}
5324
        | PREV_SYM                 {}
5325
        | PROCESS                  {}
5326
        | PROCESSLIST_SYM          {}
5327
        | QUARTER_SYM              {}
2068.6.1 by Brian Aker
Cut down the number of keywords/small style cleanup.
5328
        | QUERY_SYM                {} // Causes conflict
1 by brian
clean slate
5329
        | REDUNDANT_SYM            {}
5330
        | REPEATABLE_SYM           {}
5331
        | RETURNS_SYM              {}
5332
        | ROLLUP_SYM               {}
5333
        | ROUTINE_SYM              {}
5334
        | ROWS_SYM                 {}
5335
        | ROW_FORMAT_SYM           {}
5336
        | ROW_SYM                  {}
5337
        | SECOND_SYM               {}
5338
        | SERIAL_SYM               {}
5339
        | SERIALIZABLE_SYM         {}
5340
        | SESSION_SYM              {}
5341
        | SIMPLE_SYM               {}
5342
        | SHARE_SYM                {}
5343
        | SNAPSHOT_SYM             {}
5344
        | STATUS_SYM               {}
5345
        | STRING_SYM               {}
5346
        | SUBDATE_SYM              {}
5347
        | SUBJECT_SYM              {}
5348
        | SUSPEND_SYM              {}
5349
        | TABLES                   {}
108 by Brian Aker
Removed unwanted ALTER TABLESPACE, left in valuable bits.
5350
        | TABLESPACE               {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5351
        | TEMPORARY_SYM            {}
1 by brian
clean slate
5352
        | TEXT_SYM                 {}
5353
        | TRANSACTION_SYM          {}
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
5354
        | TIME_SYM                 {}
1 by brian
clean slate
5355
        | TIMESTAMP_ADD            {}
5356
        | TIMESTAMP_DIFF           {}
5357
        | TYPE_SYM                 {}
5358
        | UNCOMMITTED_SYM          {}
5359
        | UNDOFILE_SYM             {}
5360
        | UNKNOWN_SYM              {}
2068.6.1 by Brian Aker
Cut down the number of keywords/small style cleanup.
5361
        | UUID_SYM                 {}
1 by brian
clean slate
5362
        | USER                     {}
5363
        | VARIABLES                {}
5364
        | VALUE_SYM                {}
5365
        | WARNINGS                 {}
5366
        | WEEK_SYM                 {}
5367
        | WORK_SYM                 {}
5368
        | YEAR_SYM                 {}
5369
        ;
5370
5371
/* Option functions */
5372
5373
set:
2030.1.1 by Brian Aker
Small set of symbol updates.
5374
          SET_SYM opt_option
1 by brian
clean slate
5375
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5376
            Lex.statement= new statement::SetOption(YYSession);
1 by brian
clean slate
5377
          }
5378
          option_value_list
5379
          {}
5380
        ;
5381
5382
opt_option:
5383
          /* empty */ {}
5384
        | OPTION {}
5385
        ;
5386
5387
option_value_list:
5388
          option_type_value
5389
        | option_value_list ',' option_type_value
5390
        ;
5391
5392
option_type_value:
2104.3.11 by Brian Aker
Encapsulate more out of the parser.
5393
          { }
1 by brian
clean slate
5394
          ext_option_value
2104.3.11 by Brian Aker
Encapsulate more out of the parser.
5395
          { }
1 by brian
clean slate
5396
        ;
5397
5398
option_type:
5399
          option_type2    {}
5400
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
5401
        | LOCAL_SYM   { $$=OPT_SESSION; }
5402
        | SESSION_SYM { $$=OPT_SESSION; }
5403
        ;
5404
5405
option_type2:
5406
          /* empty */ { $$= OPT_DEFAULT; }
2227.4.10 by Olaf van der Spek
Session::lex()
5407
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex.statement)->one_shot_set= true; $$= OPT_SESSION; }
1 by brian
clean slate
5408
        ;
5409
5410
opt_var_type:
5411
          /* empty */ { $$=OPT_SESSION; }
5412
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
5413
        | LOCAL_SYM   { $$=OPT_SESSION; }
5414
        | SESSION_SYM { $$=OPT_SESSION; }
5415
        ;
5416
5417
opt_var_ident_type:
5418
          /* empty */     { $$=OPT_DEFAULT; }
5419
        | GLOBAL_SYM '.'  { $$=OPT_GLOBAL; }
5420
        | LOCAL_SYM '.'   { $$=OPT_SESSION; }
5421
        | SESSION_SYM '.' { $$=OPT_SESSION; }
5422
        ;
5423
5424
ext_option_value:
5425
          sys_option_value
5426
        | option_type2 option_value
5427
        ;
5428
5429
sys_option_value:
5430
          option_type internal_variable_name equal set_expr_or_default
5431
          {
5432
            if ($2.var)
5433
            { /* System variable */
5434
              if ($1)
2060.2.1 by Brian Aker
Merge in SQL reserved word patch
5435
              {
2227.4.10 by Olaf van der Spek
Session::lex()
5436
                Lex.option_type= $1;
2060.2.1 by Brian Aker
Merge in SQL reserved word patch
5437
              }
2445.1.11 by Olaf van der Spek
Use str_ref
5438
              Lex.var_list.push_back(SetVarPtr(new set_var(Lex.option_type, $2.var, $2.base_name, $4)));
1 by brian
clean slate
5439
            }
5440
          }
5441
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5442
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5443
            Lex.option_type= $1;
2445.1.11 by Olaf van der Spek
Use str_ref
5444
            Lex.var_list.push_back(SetVarPtr(new set_var(Lex.option_type, find_sys_var("tx_isolation"), str_ref(), new Item_int((int32_t) $5))));
1 by brian
clean slate
5445
          }
5446
        ;
5447
5448
option_value:
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5449
          '@' user_variable_ident equal expr
1 by brian
clean slate
5450
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5451
            Lex.var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
1 by brian
clean slate
5452
          }
5453
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5454
          {
2445.1.11 by Olaf van der Spek
Use str_ref
5455
            Lex.var_list.push_back(SetVarPtr(new set_var($3, $4.var, $4.base_name, $6)));
1 by brian
clean slate
5456
          }
5457
        ;
5458
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5459
user_variable_ident:
5460
          internal_variable_ident { $$=$1;}
5461
        | TEXT_STRING_sys { $$=$1;}
5462
        | LEX_HOSTNAME { $$=$1;}
5463
        ;
5464
5465
internal_variable_ident:
5466
          keyword_exception_for_variable
5467
          {
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
5468
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5469
          }
5470
        | IDENT_sys    { $$=$1; }
5471
        ;
5472
1 by brian
clean slate
5473
internal_variable_name:
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
5474
          internal_variable_ident
1 by brian
clean slate
5475
          {
5476
            /* We have to lookup here since local vars can shadow sysvars */
5477
            {
5478
              /* Not an SP local variable */
2430.1.8 by Olaf van der Spek
Use assign(), data() and size()
5479
              sys_var *tmp= find_sys_var(to_string($1));
2440.2.25 by Olaf van der Spek
Use str_ref
5480
              if (not tmp)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5481
                DRIZZLE_YYABORT;
1 by brian
clean slate
5482
              $$.var= tmp;
2371.1.2 by Brian Aker
Remove the typedef on lexkey
5483
              $$.base_name= null_lex_string();
1 by brian
clean slate
5484
            }
5485
          }
5486
        ;
5487
5488
isolation_types:
5489
          READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
5490
        | READ_SYM COMMITTED_SYM   { $$= ISO_READ_COMMITTED; }
5491
        | REPEATABLE_SYM READ_SYM  { $$= ISO_REPEATABLE_READ; }
5492
        | SERIALIZABLE_SYM         { $$= ISO_SERIALIZABLE; }
5493
        ;
5494
5495
set_expr_or_default:
5496
          expr { $$=$1; }
5497
        | DEFAULT { $$=0; }
2440.2.25 by Olaf van der Spek
Use str_ref
5498
        | ON     { $$=new Item_string(str_ref("ON"), system_charset_info); }
5499
        | ALL    { $$=new Item_string(str_ref("ALL"), system_charset_info); }
5500
        | BINARY { $$=new Item_string(str_ref("binary"), system_charset_info); }
1 by brian
clean slate
5501
        ;
5502
5503
table_or_tables:
5504
          TABLE_SYM
5505
        | TABLES
5506
        ;
5507
5508
unlock:
5509
          UNLOCK_SYM
5510
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5511
            Lex.statement= new statement::UnlockTables(YYSession);
1 by brian
clean slate
5512
          }
5513
          table_or_tables
5514
          {}
5515
        ;
5516
5517
begin:
5518
          BEGIN_SYM
5519
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5520
            Lex.statement= new statement::StartTransaction(YYSession);
1 by brian
clean slate
5521
          }
5522
          opt_work {}
5523
        ;
5524
5525
opt_work:
5526
          /* empty */ {}
5527
        | WORK_SYM  {}
5528
        ;
5529
5530
opt_chain:
5531
          /* empty */
520.1.22 by Brian Aker
Second pass of thd cleanup
5532
          { $$= (YYSession->variables.completion_type == 1); }
1 by brian
clean slate
5533
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
5534
        | AND_SYM CHAIN_SYM        { $$=1; }
5535
        ;
5536
5537
opt_release:
5538
          /* empty */
520.1.22 by Brian Aker
Second pass of thd cleanup
5539
          { $$= (YYSession->variables.completion_type == 2); }
1 by brian
clean slate
5540
        | RELEASE_SYM        { $$=1; }
5541
        | NO_SYM RELEASE_SYM { $$=0; }
5542
;
5543
5544
opt_savepoint:
5545
          /* empty */ {}
5546
        | SAVEPOINT_SYM {}
5547
        ;
5548
5549
commit:
5550
          COMMIT_SYM opt_work opt_chain opt_release
5551
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5552
            Lex.statement= new statement::Commit(YYSession, $3, $4);
1 by brian
clean slate
5553
          }
5554
        ;
5555
5556
rollback:
5557
          ROLLBACK_SYM opt_work opt_chain opt_release
5558
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5559
            Lex.statement= new statement::Rollback(YYSession, $3, $4);
1 by brian
clean slate
5560
          }
2029.1.29 by Brian Aker
Modify savepoint to not allow keyword usage.
5561
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
1 by brian
clean slate
5562
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5563
            Lex.statement= new statement::RollbackToSavepoint(YYSession, $5);
1 by brian
clean slate
5564
          }
5565
        ;
5566
5567
savepoint:
2029.1.29 by Brian Aker
Modify savepoint to not allow keyword usage.
5568
          SAVEPOINT_SYM savepoint_ident
1 by brian
clean slate
5569
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5570
            Lex.statement= new statement::Savepoint(YYSession, $2);
1 by brian
clean slate
5571
          }
5572
        ;
5573
5574
release:
2029.1.29 by Brian Aker
Modify savepoint to not allow keyword usage.
5575
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
1 by brian
clean slate
5576
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5577
            Lex.statement= new statement::ReleaseSavepoint(YYSession, $3);
1 by brian
clean slate
5578
          }
5579
        ;
5580
2029.1.29 by Brian Aker
Modify savepoint to not allow keyword usage.
5581
savepoint_ident:
5582
               IDENT_sys
5583
               ;
5584
1 by brian
clean slate
5585
/*
5586
   UNIONS : glue selects together
5587
*/
5588
5589
5590
union_clause:
5591
          /* empty */ {}
5592
        | union_list
5593
        ;
5594
5595
union_list:
5596
          UNION_SYM union_option
5597
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5598
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$2))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5599
              DRIZZLE_YYABORT;
1 by brian
clean slate
5600
          }
5601
          select_init
5602
          {
5603
            /*
5604
              Remove from the name resolution context stack the context of the
5605
              last select in the union.
5606
            */
2227.4.10 by Olaf van der Spek
Session::lex()
5607
            Lex.pop_context();
1 by brian
clean slate
5608
          }
5609
        ;
5610
5611
union_opt:
5612
          /* Empty */ { $$= 0; }
5613
        | union_list { $$= 1; }
5614
        | union_order_or_limit { $$= 1; }
5615
        ;
5616
5617
union_order_or_limit:
5618
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5619
            assert(Lex.current_select->linkage != GLOBAL_OPTIONS_TYPE);
5620
            Select_Lex *sel= Lex.current_select;
849 by Brian Aker
Remove dead keywords.
5621
            Select_Lex_Unit *unit= sel->master_unit();
846 by Brian Aker
Removing on typedeffed class.
5622
            Select_Lex *fake= unit->fake_select_lex;
1 by brian
clean slate
5623
            if (fake)
5624
            {
5625
              unit->global_parameters= fake;
5626
              fake->no_table_names_allowed= 1;
2227.4.10 by Olaf van der Spek
Session::lex()
5627
              Lex.current_select= fake;
1 by brian
clean slate
5628
            }
2114.4.10 by Brian Aker
Remove current_session from a couple of locations, encapsulate where in
5629
            YYSession->setWhere("global ORDER clause");
1 by brian
clean slate
5630
          }
5631
          order_or_limit
5632
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5633
            YYSession->lex().current_select->no_table_names_allowed= 0;
2114.4.10 by Brian Aker
Remove current_session from a couple of locations, encapsulate where in
5634
            YYSession->setWhere("");
1 by brian
clean slate
5635
          }
5636
        ;
5637
5638
order_or_limit:
5639
          order_clause opt_limit_clause_init
5640
        | limit_clause
5641
        ;
5642
5643
union_option:
5644
          /* empty */ { $$=1; }
5645
        | DISTINCT  { $$=1; }
5646
        | ALL       { $$=0; }
5647
        ;
5648
5649
query_specification:
5650
          SELECT_SYM select_init2_derived
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5651
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5652
            $$= Lex.current_select->master_unit()->first_select();
1 by brian
clean slate
5653
          }
5654
        | '(' select_paren_derived ')'
5655
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5656
            $$= Lex.current_select->master_unit()->first_select();
1 by brian
clean slate
5657
          }
5658
        ;
5659
5660
query_expression_body:
5661
          query_specification
5662
        | query_expression_body
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5663
          UNION_SYM union_option
1 by brian
clean slate
5664
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5665
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5666
              DRIZZLE_YYABORT;
1 by brian
clean slate
5667
          }
5668
          query_specification
5669
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5670
            Lex.pop_context();
1 by brian
clean slate
5671
            $$= $1;
5672
          }
5673
        ;
5674
5675
/* Corresponds to <query expression> in the SQL:2003 standard. */
5676
subselect:
5677
          subselect_start query_expression_body subselect_end
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5678
          {
1 by brian
clean slate
5679
            $$= $2;
5680
          }
5681
        ;
5682
5683
subselect_start:
5684
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5685
            if (not Lex.expr_allows_subselect)
1 by brian
clean slate
5686
            {
2104.3.5 by Brian Aker
Fixed case where parser error message might be null.
5687
              parser::my_parse_error(YYSession->m_lip);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5688
              DRIZZLE_YYABORT;
1 by brian
clean slate
5689
            }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5690
            /*
1 by brian
clean slate
5691
              we are making a "derived table" for the parenthesis
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5692
              as we need to have a lex level to fit the union
5693
              after the parenthesis, e.g.
5694
              (SELECT .. ) UNION ...  becomes
1 by brian
clean slate
5695
              SELECT * FROM ((SELECT ...) UNION ...)
5696
            */
2227.4.10 by Olaf van der Spek
Session::lex()
5697
            if (new_select(&Lex, 1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5698
              DRIZZLE_YYABORT;
1 by brian
clean slate
5699
          }
5700
        ;
5701
5702
subselect_end:
5703
          {
2227.4.10 by Olaf van der Spek
Session::lex()
5704
            Lex.pop_context();
5705
            Select_Lex *child= Lex.current_select;
5706
            Lex.current_select= Lex.current_select->return_after_parsing();
5707
            Lex.nest_level--;
5708
            Lex.current_select->n_child_sum_items += child->n_sum_items;
1 by brian
clean slate
5709
            /*
5710
              A subselect can add fields to an outer select. Reserve space for
5711
              them.
5712
            */
2227.4.10 by Olaf van der Spek
Session::lex()
5713
            Lex.current_select->select_n_where_fields+=
1 by brian
clean slate
5714
            child->select_n_where_fields;
5715
          }
5716
        ;
5717
/**
5718
  @} (end of group Parser)
5719
*/