~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to sql/sql_yacc.yy

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
   
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
   
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
   
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
/* sql_yacc.y */
 
18
 
 
19
%{
 
20
#define MYSQL_YACC
 
21
#define YYINITDEPTH 100
 
22
#define YYMAXDEPTH 3200                         /* Because of 64K stack */
 
23
#define Lex current_lex
 
24
#include "mysql_priv.h"
 
25
#include "sql_acl.h"
 
26
#include "lex_symbol.h"
 
27
#include <myisam.h>
 
28
  
 
29
extern void yyerror(const char*);
 
30
int yylex(void *yylval);
 
31
 
 
32
#define yyoverflow(A,B,C,D,E,F) if (my_yyoverflow((B),(D),(F))) { yyerror((char*) (A)); return 2; }
 
33
 
 
34
inline Item *or_or_concat(Item* A, Item* B)
 
35
{
 
36
  return (current_thd->options & OPTION_ANSI_MODE ?
 
37
          (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
 
38
}
 
39
 
 
40
%}
 
41
%union {
 
42
  int  num;
 
43
  ulong ulong_num;
 
44
  ulonglong ulonglong_num;
 
45
  LEX_STRING lex_str;
 
46
  LEX_STRING *lex_str_ptr;
 
47
  LEX_SYMBOL symbol;
 
48
  Table_ident *table;
 
49
  char *simple_string;
 
50
  Item *item;
 
51
  List<Item> *item_list;
 
52
  List<String> *string_list;
 
53
  Key::Keytype key_type;
 
54
  enum db_type db_type;
 
55
  enum row_type row_type;
 
56
  String *string;
 
57
  key_part_spec *key_part;
 
58
  TABLE_LIST *table_list;
 
59
  udf_func *udf;
 
60
  interval_type interval;
 
61
  LEX_USER *lex_user;
 
62
  enum Item_udftype udf_type;
 
63
}
 
64
 
 
65
%{
 
66
bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
 
67
%}
 
68
 
 
69
%pure_parser                                    /* We have threads */
 
70
 
 
71
%token  END_OF_INPUT
 
72
 
 
73
%token  EQ
 
74
%token  EQUAL_SYM
 
75
%token  GE
 
76
%token  GT_SYM
 
77
%token  LE
 
78
%token  LT
 
79
%token  NE
 
80
%token  IS
 
81
%token  SHIFT_LEFT
 
82
%token  SHIFT_RIGHT
 
83
%token  SET_VAR
 
84
 
 
85
%token  AVG_SYM
 
86
%token  COUNT_SYM
 
87
%token  MAX_SYM
 
88
%token  MIN_SYM
 
89
%token  SUM_SYM
 
90
%token  STD_SYM
 
91
 
 
92
%token  ADD
 
93
%token  ALTER
 
94
%token  AFTER_SYM
 
95
%token  ANALYZE_SYM
 
96
%token  BEGIN_SYM
 
97
%token  CHANGE
 
98
%token  COMMENT_SYM
 
99
%token  COMMIT_SYM
 
100
%token  CREATE
 
101
%token  CROSS
 
102
%token  DELETE_SYM
 
103
%token  DROP
 
104
%token  INSERT
 
105
%token  FLUSH_SYM
 
106
%token  SELECT_SYM
 
107
%token  MASTER_SYM
 
108
%token  REPAIR
 
109
%token  SLAVE
 
110
%token  START_SYM
 
111
%token  STOP_SYM
 
112
%token  ROLLBACK_SYM
 
113
%token  OPTIMIZE
 
114
%token  SHOW
 
115
%token  UPDATE_SYM
 
116
%token  KILL_SYM
 
117
%token  LOAD
 
118
%token  LOCK_SYM
 
119
%token  UNLOCK_SYM
 
120
 
 
121
%token  ACTION
 
122
%token  AGGREGATE_SYM
 
123
%token  ALL
 
124
%token  AND
 
125
%token  AS
 
126
%token  ASC
 
127
%token  AUTO_INC
 
128
%token  AUTOCOMMIT
 
129
%token  AVG_ROW_LENGTH
 
130
%token  BERKELEY_DB_SYM
 
131
%token  BINARY
 
132
%token  BIT_SYM
 
133
%token  BOOL_SYM
 
134
%token  BOTH
 
135
%token  BY
 
136
%token  CASCADE
 
137
%token  CHANGED_FILES
 
138
%token  CHECKSUM_SYM
 
139
%token  CHECK_SYM
 
140
%token  COLLECTION
 
141
%token  COLUMNS
 
142
%token  COLUMN_SYM
 
143
%token  CONSTRAINT
 
144
%token  DATABASES
 
145
%token  DATA_SYM
 
146
%token  DEFAULT
 
147
%token  DELAYED_SYM
 
148
%token  DELAY_KEY_WRITE_SYM
 
149
%token  DESC
 
150
%token  DESCRIBE
 
151
%token  DISTINCT
 
152
%token  DYNAMIC_SYM
 
153
%token  ENCLOSED
 
154
%token  ESCAPED
 
155
%token  ESCAPE_SYM
 
156
%token  EXISTS
 
157
%token  EXTENDED_SYM
 
158
%token  FILE_SYM
 
159
%token  FIRST_SYM
 
160
%token  FIXED_SYM
 
161
%token  FLOAT_NUM
 
162
%token  FOREIGN
 
163
%token  FROM
 
164
%token  FULL
 
165
%token  GRANT
 
166
%token  GRANTS
 
167
%token  GREATEST_SYM
 
168
%token  GROUP
 
169
%token  HAVING
 
170
%token  HEAP_SYM
 
171
%token  HEX_NUM
 
172
%token  HIGH_PRIORITY
 
173
%token  HOSTS_SYM
 
174
%token  IDENT
 
175
%token  IGNORE_SYM
 
176
%token  INDEX
 
177
%token  INFILE
 
178
%token  INNER_SYM
 
179
%token  INTO
 
180
%token  IN_SYM
 
181
%token  ISAM_SYM
 
182
%token  JOIN_SYM
 
183
%token  KEYS
 
184
%token  KEY_SYM
 
185
%token  LEADING
 
186
%token  LEAST_SYM
 
187
%token  LEX_HOSTNAME
 
188
%token  LIKE
 
189
%token  LINES
 
190
%token  LOCAL_SYM
 
191
%token  LOGS_SYM
 
192
%token  LONG_NUM
 
193
%token  LONG_SYM
 
194
%token  LOW_PRIORITY
 
195
%token  MASTER_HOST_SYM
 
196
%token  MASTER_USER_SYM
 
197
%token  MASTER_LOG_FILE_SYM
 
198
%token  MASTER_LOG_POS_SYM
 
199
%token  MASTER_PASSWORD_SYM
 
200
%token  MASTER_PORT_SYM
 
201
%token  MASTER_CONNECT_RETRY_SYM
 
202
%token  MATCH
 
203
%token  MAX_ROWS
 
204
%token  MERGE_SYM
 
205
%token  MIN_ROWS
 
206
%token  MYISAM_SYM
 
207
%token  NATIONAL_SYM
 
208
%token  NATURAL
 
209
%token  NCHAR_SYM
 
210
%token  NOT
 
211
%token  NO_SYM
 
212
%token  NULL_SYM
 
213
%token  NUM
 
214
%token  ON
 
215
%token  OPTION
 
216
%token  OPTIONALLY
 
217
%token  OR
 
218
%token  OR_OR_CONCAT
 
219
%token  ORDER_SYM
 
220
%token  OUTER
 
221
%token  OUTFILE
 
222
%token  DUMPFILE
 
223
%token  PACK_KEYS_SYM
 
224
%token  PARTIAL
 
225
%token  PRIMARY_SYM
 
226
%token  PRIVILEGES
 
227
%token  PROCESS
 
228
%token  PROCESSLIST_SYM
 
229
%token  RAID_0_SYM
 
230
%token  RAID_STRIPED_SYM
 
231
%token  RAID_TYPE
 
232
%token  RAID_CHUNKS
 
233
%token  RAID_CHUNKSIZE
 
234
%token  READ_SYM
 
235
%token  REAL_NUM
 
236
%token  REFERENCES
 
237
%token  REGEXP
 
238
%token  RELOAD
 
239
%token  RENAME
 
240
%token  RESTRICT
 
241
%token  REVOKE
 
242
%token  ROWS_SYM
 
243
%token  ROW_FORMAT_SYM
 
244
%token  ROW_SYM
 
245
%token  SET
 
246
%token  SHUTDOWN
 
247
%token  STARTING
 
248
%token  STATUS_SYM
 
249
%token  STRAIGHT_JOIN
 
250
%token  TABLES
 
251
%token  TABLE_SYM
 
252
%token  TEMPORARY
 
253
%token  TERMINATED
 
254
%token  TEXT_STRING
 
255
%token  TO_SYM
 
256
%token  TRAILING
 
257
%token  TYPE_SYM
 
258
%token  FUNC_ARG0
 
259
%token  FUNC_ARG1
 
260
%token  FUNC_ARG2
 
261
%token  FUNC_ARG3
 
262
%token  UDF_RETURNS_SYM
 
263
%token  UDF_SONAME_SYM
 
264
%token  UDF_SYM
 
265
%token  UNIQUE_SYM
 
266
%token  USAGE
 
267
%token  USE_SYM
 
268
%token  USING
 
269
%token  VALUES
 
270
%token  VARIABLES
 
271
%token  WHERE
 
272
%token  WITH
 
273
%token  WRITE_SYM
 
274
%token  COMPRESSED_SYM
 
275
 
 
276
%token  BIGINT
 
277
%token  BLOB_SYM
 
278
%token  CHAR_SYM
 
279
%token  COALESCE
 
280
%token  DATETIME
 
281
%token  DATE_SYM
 
282
%token  DECIMAL_SYM
 
283
%token  DOUBLE_SYM
 
284
%token  ENUM
 
285
%token  FLOAT_SYM
 
286
%token  INT_SYM
 
287
%token  LIMIT
 
288
%token  LONGBLOB
 
289
%token  LONGTEXT
 
290
%token  MEDIUMBLOB
 
291
%token  MEDIUMINT
 
292
%token  MEDIUMTEXT
 
293
%token  NUMERIC_SYM
 
294
%token  PRECISION
 
295
%token  QUICK
 
296
%token  REAL
 
297
%token  SMALLINT
 
298
%token  STRING_SYM
 
299
%token  TEXT_SYM
 
300
%token  TIMESTAMP
 
301
%token  TIME_SYM
 
302
%token  TINYBLOB
 
303
%token  TINYINT
 
304
%token  TINYTEXT
 
305
%token  UNSIGNED
 
306
%token  VARBINARY
 
307
%token  VARCHAR
 
308
%token  VARYING
 
309
%token  ZEROFILL
 
310
 
 
311
%token  AGAINST
 
312
%token  ATAN
 
313
%token  BETWEEN_SYM
 
314
%token  BIT_AND
 
315
%token  BIT_OR
 
316
%token  CASE_SYM
 
317
%token  CONCAT
 
318
%token  CONCAT_WS
 
319
%token  CURDATE
 
320
%token  CURTIME
 
321
%token  DATABASE
 
322
%token  DATE_ADD_INTERVAL
 
323
%token  DATE_SUB_INTERVAL
 
324
%token  DAY_HOUR_SYM
 
325
%token  DAY_MINUTE_SYM
 
326
%token  DAY_OF_WEEK
 
327
%token  DAY_OF_YEAR
 
328
%token  DAY_SECOND_SYM
 
329
%token  DAY_SYM
 
330
%token  DECODE_SYM
 
331
%token  ELSE
 
332
%token  ELT_FUNC
 
333
%token  ENCODE_SYM
 
334
%token  ENCRYPT
 
335
%token  EXPORT_SET
 
336
%token  EXTRACT_SYM
 
337
%token  FIELD_FUNC
 
338
%token  FORMAT_SYM
 
339
%token  FOR_SYM
 
340
%token  FROM_UNIXTIME
 
341
%token  GROUP_UNIQUE_USERS
 
342
%token  HOUR_MINUTE_SYM
 
343
%token  HOUR_SECOND_SYM
 
344
%token  HOUR_SYM
 
345
%token  IDENTIFIED_SYM
 
346
%token  IF
 
347
%token  INSERT_ID
 
348
%token  INTERVAL_SYM
 
349
%token  LAST_INSERT_ID
 
350
%token  LEFT
 
351
%token  LOCATE
 
352
%token  MAKE_SET_SYM
 
353
%token  MINUTE_SECOND_SYM
 
354
%token  MINUTE_SYM
 
355
%token  MODIFY_SYM
 
356
%token  MONTH_SYM
 
357
%token  NOW_SYM
 
358
%token  PASSWORD
 
359
%token  POSITION_SYM
 
360
%token  PROCEDURE
 
361
%token  RAND
 
362
%token  REPLACE
 
363
%token  RIGHT
 
364
%token  ROUND
 
365
%token  SECOND_SYM
 
366
%token  SEC_TO_TIME
 
367
%token  SUBSTRING
 
368
%token  SUBSTRING_INDEX
 
369
%token  TRIM
 
370
%token  UDA_CHAR_SUM
 
371
%token  UDA_FLOAT_SUM
 
372
%token  UDA_INT_SUM
 
373
%token  UDF_CHAR_FUNC
 
374
%token  UDF_FLOAT_FUNC
 
375
%token  UDF_INT_FUNC
 
376
%token  UNIQUE_USERS
 
377
%token  UNIX_TIMESTAMP
 
378
%token  USER
 
379
%token  VERSION_SYM
 
380
%token  WEEKDAY
 
381
%token  WEEK_SYM
 
382
%token  WHEN_SYM
 
383
%token  WORK_SYM
 
384
%token  YEAR_MONTH_SYM
 
385
%token  YEAR_SYM
 
386
%token  YEARWEEK
 
387
%token  BENCHMARK_SYM
 
388
%token  END
 
389
%token  THEN_SYM
 
390
 
 
391
%token  SQL_BIG_TABLES
 
392
%token  SQL_BIG_SELECTS
 
393
%token  SQL_SELECT_LIMIT
 
394
%token  SQL_MAX_JOIN_SIZE
 
395
%token  SQL_LOG_BIN
 
396
%token  SQL_LOG_OFF
 
397
%token  SQL_LOG_UPDATE
 
398
%token  SQL_LOW_PRIORITY_UPDATES
 
399
%token  SQL_SMALL_RESULT
 
400
%token  SQL_BIG_RESULT
 
401
%token  SQL_BUFFER_RESULT
 
402
%token  SQL_WARNINGS
 
403
%token  SQL_AUTO_IS_NULL
 
404
%token  SQL_SAFE_UPDATES
 
405
 
 
406
%left   SET_VAR
 
407
%left   OR_OR_CONCAT OR
 
408
%left   AND
 
409
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
410
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP IN_SYM
 
411
%left   '|'
 
412
%left   '&'
 
413
%left   SHIFT_LEFT SHIFT_RIGHT
 
414
%left   '-' '+'
 
415
%left   '*' '/' '%'
 
416
%left   NEG '~'
 
417
%right  NOT
 
418
%right  BINARY
 
419
 
 
420
%type <lex_str>
 
421
        IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
 
422
        field_ident select_alias ident ident_or_text
 
423
 
 
424
%type <lex_str_ptr>
 
425
        opt_table_alias
 
426
 
 
427
%type <table>
 
428
        table_ident
 
429
 
 
430
%type <simple_string>
 
431
        remember_name remember_end opt_len opt_ident opt_db text_or_password
 
432
        opt_escape
 
433
 
 
434
%type <string>
 
435
        text_string
 
436
 
 
437
%type <num>
 
438
        type int_type real_type order_dir opt_field_spec set_option lock_option
 
439
        udf_type if_exists opt_local opt_table_options table_options
 
440
        table_option opt_if_not_exists
 
441
 
 
442
%type <ulong_num>
 
443
        ULONG_NUM raid_types
 
444
 
 
445
%type <ulonglong_num>
 
446
        ULONGLONG_NUM
 
447
 
 
448
%type <item>
 
449
        literal text_literal insert_ident group_ident order_ident
 
450
        simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
 
451
        table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
 
452
        using_list 
 
453
 
 
454
%type <item_list>
 
455
        expr_list udf_expr_list when_list ident_list
 
456
 
 
457
%type <key_type>
 
458
        key_type opt_unique
 
459
 
 
460
%type <string_list>
 
461
        key_usage_list
 
462
 
 
463
%type <key_part>
 
464
        key_part
 
465
 
 
466
%type <table_list>
 
467
        join_table_list join_table
 
468
 
 
469
%type <udf>
 
470
        UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
 
471
        UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM
 
472
 
 
473
%type <interval> interval
 
474
 
 
475
%type <db_type> table_types
 
476
 
 
477
%type <row_type> row_types
 
478
 
 
479
%type <udf_type> udf_func_type
 
480
 
 
481
%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword
 
482
 
 
483
%type <lex_user> user grant_user
 
484
 
 
485
%type <NONE>
 
486
        query verb_clause create change select drop insert replace insert2
 
487
        insert_values update delete show describe load alter optimize flush
 
488
        begin commit rollback slave master_def master_defs
 
489
        repair analyze check field_list field_list_item field_spec kill
 
490
        select_item_list select_item values_list no_braces
 
491
        limit_clause delete_limit_clause fields opt_values values
 
492
        procedure_list procedure_list2 procedure_item
 
493
        when_list2 expr_list2
 
494
        opt_precision opt_ignore opt_column opt_restrict
 
495
        grant revoke set lock unlock string_list field_options field_option
 
496
        field_opt_list opt_binary table_lock_list table_lock varchar
 
497
        references opt_on_delete opt_on_delete_list opt_on_delete_item use
 
498
        opt_outer table_list table opt_option opt_place opt_low_priority
 
499
        opt_attribute opt_attribute_list attribute column_list column_list_id
 
500
        opt_column_list grant_privileges opt_table user_list grant_option
 
501
        grant_privilege grant_privilege_list
 
502
        flush_options flush_option insert_lock_option replace_lock_option
 
503
        equal optional_braces opt_key_definition key_usage_list2
 
504
        opt_mi_check_type opt_to mi_check_types normal_join
 
505
        END_OF_INPUT
 
506
 
 
507
%type <NONE>
 
508
        '-' '+' '*' '/' '%' '(' ')'
 
509
        ',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM THEN_SYM WHEN_SYM
 
510
%%
 
511
 
 
512
 
 
513
query:
 
514
        END_OF_INPUT
 
515
         {
 
516
           if (!current_thd->bootstrap)
 
517
             send_error(&current_thd->net,ER_EMPTY_QUERY);
 
518
           YYABORT;
 
519
        }
 
520
        | verb_clause END_OF_INPUT {}
 
521
 
 
522
verb_clause:
 
523
          alter
 
524
        | analyze
 
525
        | begin
 
526
        | change
 
527
        | check
 
528
        | commit
 
529
        | create
 
530
        | delete
 
531
        | describe
 
532
        | drop
 
533
        | grant
 
534
        | insert
 
535
        | flush
 
536
        | load
 
537
        | lock
 
538
        | kill
 
539
        | optimize
 
540
        | repair
 
541
        | replace
 
542
        | revoke
 
543
        | rollback
 
544
        | select
 
545
        | set
 
546
        | slave  
 
547
        | show
 
548
        | unlock
 
549
        | update
 
550
        | use
 
551
 
 
552
/* change master */
 
553
 
 
554
change:
 
555
       CHANGE MASTER_SYM TO_SYM 
 
556
        {
 
557
          LEX *lex = Lex;
 
558
          lex->sql_command = SQLCOM_CHANGE_MASTER;
 
559
          memset(&lex->mi, 0, sizeof(lex->mi));
 
560
        } master_defs
 
561
 
 
562
master_defs:
 
563
       master_def
 
564
       |
 
565
       master_defs ',' master_def
 
566
          
 
567
master_def:
 
568
       MASTER_HOST_SYM EQ TEXT_STRING
 
569
       {
 
570
         Lex->mi.host = $3.str;
 
571
       }
 
572
       |
 
573
       MASTER_USER_SYM EQ TEXT_STRING
 
574
       {
 
575
         Lex->mi.user = $3.str;
 
576
       }
 
577
       |
 
578
       MASTER_PASSWORD_SYM EQ TEXT_STRING
 
579
       {
 
580
         Lex->mi.password = $3.str;
 
581
       }
 
582
       |
 
583
       MASTER_LOG_FILE_SYM EQ TEXT_STRING
 
584
       {
 
585
         Lex->mi.log_file_name = $3.str;
 
586
       }
 
587
       |
 
588
       MASTER_PORT_SYM EQ ULONGLONG_NUM
 
589
       {
 
590
         Lex->mi.port = $3;
 
591
       }
 
592
       |
 
593
       MASTER_LOG_POS_SYM EQ ULONGLONG_NUM
 
594
       {
 
595
         Lex->mi.pos = $3;
 
596
       }
 
597
       |
 
598
       MASTER_CONNECT_RETRY_SYM EQ ULONGLONG_NUM
 
599
       {
 
600
         Lex->mi.connect_retry = $3;
 
601
       }
 
602
       
 
603
 
 
604
          
 
605
/* create a table */
 
606
 
 
607
create:
 
608
        CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
609
        {
 
610
          LEX *lex=Lex;
 
611
          lex->sql_command= SQLCOM_CREATE_TABLE;
 
612
          if (!add_table_to_list($5, 
 
613
                                 ($2 & HA_LEX_CREATE_TMP_TABLE ?
 
614
                                   &tmp_table_alias : (LEX_STRING*) 0)))
 
615
            YYABORT;
 
616
          lex->create_list.empty();
 
617
          lex->key_list.empty();
 
618
          lex->col_list.empty();
 
619
          lex->change=NullS;
 
620
          bzero((char*) &lex->create_info,sizeof(lex->create_info));
 
621
          lex->create_info.options=$2 | $4;
 
622
          lex->create_info.db_type= default_table_type;
 
623
        }
 
624
        create2
 
625
 
 
626
        | CREATE opt_unique INDEX ident ON table_ident
 
627
          {
 
628
            Lex->sql_command= SQLCOM_CREATE_INDEX;
 
629
            if (!add_table_to_list($6,NULL))
 
630
              YYABORT;
 
631
            Lex->create_list.empty();
 
632
            Lex->key_list.empty();
 
633
            Lex->col_list.empty();
 
634
            Lex->change=NullS;
 
635
          }
 
636
          '(' key_list ')'
 
637
          {
 
638
            Lex->key_list.push_back(new Key($2,$4.str,Lex->col_list));
 
639
            Lex->col_list.empty();
 
640
          }
 
641
        | CREATE COLLECTION ident ON table_ident
 
642
          {
 
643
            Lex->sql_command= SQLCOM_CREATE_INDEX;
 
644
            if (!add_table_to_list($5,NULL))
 
645
              YYABORT;
 
646
            Lex->create_list.empty();
 
647
            Lex->key_list.empty();
 
648
            Lex->col_list.empty();
 
649
            Lex->change=NullS;
 
650
          }
 
651
          '(' key_list ')'
 
652
          {
 
653
            Lex->key_list.push_back(new Key(Key::FULLTEXT,$3.str,Lex->col_list));
 
654
            Lex->col_list.empty();
 
655
          }
 
656
        | CREATE DATABASE opt_if_not_exists ident
 
657
          {
 
658
            Lex->sql_command=SQLCOM_CREATE_DB;
 
659
            Lex->name=$4.str;
 
660
            Lex->create_info.options=$3;
 
661
          }
 
662
        | CREATE udf_func_type UDF_SYM ident
 
663
          {
 
664
            Lex->sql_command = SQLCOM_CREATE_FUNCTION;
 
665
            Lex->udf.name=$4.str;
 
666
            Lex->udf.name_length=$4.length;
 
667
            Lex->udf.type= $2;
 
668
          }
 
669
          UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
 
670
          {
 
671
            Lex->udf.returns=(Item_result) $7;
 
672
            Lex->udf.dl=$9.str;
 
673
          }
 
674
 
 
675
create2:
 
676
        '(' field_list ')' opt_create_table_options create3 {} 
 
677
        | opt_create_table_options create3 {}
 
678
 
 
679
create3:
 
680
        /* empty*/ {}
 
681
        | opt_duplicate SELECT_SYM
 
682
          {
 
683
            LEX *lex=Lex;
 
684
            lex->where=lex->having=0;
 
685
            lex->select_limit=current_thd->default_select_limit;
 
686
            lex->offset_limit=0L;
 
687
            lex->options=0;
 
688
            lex->exchange = 0;
 
689
            lex->order_list.elements=lex->group_list.elements=0;
 
690
            lex->order_list.first=0;
 
691
            lex->order_list.next= (byte**) &lex->order_list.first;
 
692
            lex->group_list.first=0;
 
693
            lex->group_list.next= (byte**) &lex->group_list.first;
 
694
          }
 
695
          select_options select_item_list opt_select_from {}
 
696
 
 
697
opt_table_options:
 
698
        /* empty */      { $$= 0; } 
 
699
        | table_options  { $$= $1;}
 
700
 
 
701
table_options:
 
702
        table_option    { $$=$1; }
 
703
        | table_option table_options { $$= $1 | $2 }
 
704
        
 
705
table_option:
 
706
        TEMPORARY       { $$=HA_LEX_CREATE_TMP_TABLE; }
 
707
 
 
708
opt_if_not_exists:
 
709
        /* empty */      { $$= 0; } 
 
710
        | IF NOT EXISTS  { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
 
711
 
 
712
opt_create_table_options:
 
713
        /* empty */
 
714
        | create_table_options
 
715
 
 
716
create_table_options:
 
717
        create_table_option
 
718
        | create_table_option create_table_options
 
719
 
 
720
create_table_option:
 
721
        TYPE_SYM EQ table_types         { Lex->create_info.db_type= $3; }
 
722
        | MAX_ROWS EQ ULONGLONG_NUM     { Lex->create_info.max_rows= $3; }
 
723
        | MIN_ROWS EQ ULONGLONG_NUM     { Lex->create_info.min_rows= $3; }
 
724
        | AVG_ROW_LENGTH EQ ULONG_NUM   { Lex->create_info.avg_row_length=$3; }
 
725
        | PASSWORD EQ TEXT_STRING       { Lex->create_info.password=$3.str; }
 
726
        | COMMENT_SYM EQ TEXT_STRING    { Lex->create_info.comment=$3.str; }
 
727
        | AUTO_INC EQ ULONGLONG_NUM     { Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
 
728
        | PACK_KEYS_SYM EQ ULONG_NUM    { Lex->create_info.table_options|= $3 ? HA_OPTION_PACK_KEYS : HA_OPTION_NO_PACK_KEYS; }
 
729
        | CHECKSUM_SYM EQ ULONG_NUM     { Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; }
 
730
        | DELAY_KEY_WRITE_SYM EQ ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; }
 
731
        | ROW_FORMAT_SYM EQ row_types   { Lex->create_info.row_type= $3; } 
 
732
        | RAID_TYPE EQ raid_types       { Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
 
733
        | RAID_CHUNKS EQ ULONG_NUM      { Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
 
734
        | RAID_CHUNKSIZE EQ ULONG_NUM   { Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
 
735
 
 
736
table_types:
 
737
        ISAM_SYM        { $$= DB_TYPE_ISAM; }
 
738
        | MYISAM_SYM    { $$= DB_TYPE_MYISAM; }
 
739
        | MERGE_SYM     { $$= DB_TYPE_MRG_MYISAM; }
 
740
        | HEAP_SYM      { $$= DB_TYPE_HEAP; }
 
741
        | BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
 
742
 
 
743
row_types:
 
744
        DEFAULT         { $$= ROW_TYPE_DEFAULT; }
 
745
        | FIXED_SYM     { $$= ROW_TYPE_FIXED; }
 
746
        | DYNAMIC_SYM   { $$= ROW_TYPE_DYNAMIC; }
 
747
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
 
748
 
 
749
raid_types:
 
750
        RAID_STRIPED_SYM { $$= RAID_TYPE_0; }
 
751
        | RAID_0_SYM     { $$= RAID_TYPE_0; }
 
752
        | ULONG_NUM      { $$=$1;}
 
753
 
 
754
opt_select_from:
 
755
        /* empty */
 
756
        | select_from
 
757
 
 
758
udf_func_type:
 
759
        /* empty */     { $$ = UDFTYPE_FUNCTION; }
 
760
        | AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; }
 
761
 
 
762
udf_type:
 
763
        STRING_SYM {$$ = (int) STRING_RESULT; }
 
764
        | REAL {$$ = (int) REAL_RESULT; }
 
765
        | INT_SYM {$$ = (int) INT_RESULT; }
 
766
 
 
767
field_list:
 
768
          field_list_item
 
769
        | field_list ',' field_list_item
 
770
 
 
771
 
 
772
field_list_item:
 
773
          field_spec
 
774
        | field_spec references
 
775
          {
 
776
            Lex->col_list.empty();              /* Alloced by sql_alloc */
 
777
          }
 
778
        | key_type opt_ident '(' key_list ')'
 
779
          {
 
780
            Lex->key_list.push_back(new Key($1,$2,Lex->col_list));
 
781
            Lex->col_list.empty();              /* Alloced by sql_alloc */
 
782
          }
 
783
        | opt_constraint FOREIGN KEY_SYM '(' key_list ')' references
 
784
          {
 
785
            Lex->col_list.empty();              /* Alloced by sql_alloc */
 
786
          }
 
787
        | opt_constraint CHECK_SYM '(' expr ')'
 
788
          {
 
789
            Lex->col_list.empty();              /* Alloced by sql_alloc */
 
790
          }
 
791
 
 
792
opt_constraint:
 
793
        /* empty */
 
794
        | CONSTRAINT opt_ident
 
795
 
 
796
field_spec:
 
797
        field_ident
 
798
         {
 
799
           Lex->length=Lex->dec=0; Lex->type=0; Lex->interval=0;
 
800
           Lex->default_value=0;
 
801
         }
 
802
        type opt_attribute
 
803
        {
 
804
          if (add_field_to_list($1.str,
 
805
                                (enum enum_field_types) $3,
 
806
                                Lex->length,Lex->dec,Lex->type,
 
807
                                Lex->default_value,Lex->change,
 
808
                                Lex->interval))
 
809
            YYABORT;
 
810
        }
 
811
 
 
812
type:
 
813
        int_type opt_len field_options  { Lex->length=$2; $$=$1; }
 
814
        | real_type opt_precision field_options { $$=$1; }
 
815
        | FLOAT_SYM float_options field_options { $$=FIELD_TYPE_FLOAT; }
 
816
        | BIT_SYM opt_len               { Lex->length=(char*) "1";
 
817
                                          $$=FIELD_TYPE_TINY; }
 
818
        | BOOL_SYM                      { Lex->length=(char*) "1";
 
819
                                          $$=FIELD_TYPE_TINY; }
 
820
        | char '(' NUM ')' opt_binary { Lex->length=$3.str;
 
821
                                          $$=FIELD_TYPE_STRING; }
 
822
        | char opt_binary               { Lex->length=(char*) "1";
 
823
                                          $$=FIELD_TYPE_STRING; }
 
824
        | BINARY '(' NUM ')'            { Lex->length=$3.str;
 
825
                                          Lex->type|=BINARY_FLAG;
 
826
                                          $$=FIELD_TYPE_STRING; }
 
827
        | varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
 
828
                                          $$=FIELD_TYPE_VAR_STRING; }
 
829
        | VARBINARY '(' NUM ')'         { Lex->length=$3.str;
 
830
                                          Lex->type|=BINARY_FLAG;
 
831
                                          $$=FIELD_TYPE_VAR_STRING; }
 
832
        | YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; Lex->length=$2; }
 
833
        | DATE_SYM                      { $$=FIELD_TYPE_DATE; }
 
834
        | TIME_SYM                      { $$=FIELD_TYPE_TIME; }
 
835
        | TIMESTAMP                     { $$=FIELD_TYPE_TIMESTAMP; }
 
836
        | TIMESTAMP '(' NUM ')'         { Lex->length=$3.str;
 
837
                                          $$=FIELD_TYPE_TIMESTAMP; }
 
838
        | DATETIME                      { $$=FIELD_TYPE_DATETIME; }
 
839
        | TINYBLOB                      { Lex->type|=BINARY_FLAG;
 
840
                                          $$=FIELD_TYPE_TINY_BLOB; }
 
841
        | BLOB_SYM                      { Lex->type|=BINARY_FLAG;
 
842
                                          $$=FIELD_TYPE_BLOB; }
 
843
        | MEDIUMBLOB                    { Lex->type|=BINARY_FLAG;
 
844
                                          $$=FIELD_TYPE_MEDIUM_BLOB; }
 
845
        | LONGBLOB                      { Lex->type|=BINARY_FLAG;
 
846
                                          $$=FIELD_TYPE_LONG_BLOB; }
 
847
        | LONG_SYM VARBINARY            { Lex->type|=BINARY_FLAG;
 
848
                                          $$=FIELD_TYPE_MEDIUM_BLOB; }
 
849
        | LONG_SYM varchar              { $$=FIELD_TYPE_MEDIUM_BLOB; }
 
850
        | TINYTEXT                      { $$=FIELD_TYPE_TINY_BLOB; }
 
851
        | TEXT_SYM                      { $$=FIELD_TYPE_BLOB; }
 
852
        | MEDIUMTEXT                    { $$=FIELD_TYPE_MEDIUM_BLOB; }
 
853
        | LONGTEXT                      { $$=FIELD_TYPE_LONG_BLOB; }
 
854
        | DECIMAL_SYM float_options field_options
 
855
                                        { $$=FIELD_TYPE_DECIMAL;}
 
856
        | NUMERIC_SYM float_options field_options
 
857
                                        { $$=FIELD_TYPE_DECIMAL;}
 
858
        | ENUM {Lex->interval_list.empty();} '(' string_list ')'
 
859
          {
 
860
            Lex->interval=typelib(Lex->interval_list);
 
861
            $$=FIELD_TYPE_ENUM;
 
862
          }
 
863
        | SET { Lex->interval_list.empty();} '(' string_list ')'
 
864
          {
 
865
            Lex->interval=typelib(Lex->interval_list);
 
866
            $$=FIELD_TYPE_SET;
 
867
          }
 
868
 
 
869
char:
 
870
        CHAR_SYM {}
 
871
        | NCHAR_SYM {}
 
872
        | NATIONAL_SYM CHAR_SYM {}
 
873
        
 
874
varchar:
 
875
        char VARYING {}
 
876
        | VARCHAR {}
 
877
        | NATIONAL_SYM VARCHAR {}
 
878
        | NCHAR_SYM VARCHAR {}
 
879
 
 
880
int_type:
 
881
        INT_SYM         { $$=FIELD_TYPE_LONG; }
 
882
        | TINYINT       { $$=FIELD_TYPE_TINY; }
 
883
        | SMALLINT      { $$=FIELD_TYPE_SHORT; }
 
884
        | MEDIUMINT     { $$=FIELD_TYPE_INT24; }
 
885
        | BIGINT        { $$=FIELD_TYPE_LONGLONG; }
 
886
 
 
887
real_type:
 
888
        REAL            { $$= current_thd->options & OPTION_ANSI_MODE ?
 
889
                              FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
 
890
        | DOUBLE_SYM    { $$=FIELD_TYPE_DOUBLE; }
 
891
        | DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; }
 
892
 
 
893
 
 
894
float_options:
 
895
        /* empty */             {}
 
896
        | '(' NUM ')'           { Lex->length=$2.str; }
 
897
        | '(' NUM ',' NUM ')'   { Lex->length=$2.str; Lex->dec=$4.str; }
 
898
 
 
899
field_options:
 
900
        /* empty */             {}
 
901
        | field_opt_list        {}
 
902
 
 
903
field_opt_list:
 
904
        field_opt_list field_option {}
 
905
        | field_option {}
 
906
 
 
907
field_option:
 
908
        UNSIGNED        { Lex->type|= UNSIGNED_FLAG;}
 
909
        | ZEROFILL      { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
 
910
 
 
911
opt_len:
 
912
        /* empty */     { $$=(char*) 0; }       /* use default length */
 
913
        | '(' NUM ')'   { $$=$2.str; }
 
914
 
 
915
opt_precision:
 
916
        /* empty */     {}
 
917
        | '(' NUM ',' NUM ')'   { Lex->length=$2.str; Lex->dec=$4.str; }
 
918
 
 
919
opt_attribute:
 
920
        /* empty */ {}
 
921
        | opt_attribute_list {}
 
922
 
 
923
opt_attribute_list:
 
924
        opt_attribute_list attribute {}
 
925
        | attribute
 
926
 
 
927
attribute:
 
928
        NULL_SYM          { Lex->type&= ~ NOT_NULL_FLAG; }
 
929
        | NOT NULL_SYM    { Lex->type|= NOT_NULL_FLAG; }
 
930
        | DEFAULT literal { Lex->default_value=$2; }
 
931
        | AUTO_INC        { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
 
932
        | PRIMARY_SYM KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
 
933
        | UNIQUE_SYM      { Lex->type|= UNIQUE_FLAG; }
 
934
        | UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
 
935
 
 
936
opt_binary:
 
937
        /* empty */     {}
 
938
        | BINARY        { Lex->type|=BINARY_FLAG; }
 
939
 
 
940
references:
 
941
        REFERENCES table_ident opt_on_delete {}
 
942
        | REFERENCES table_ident '(' key_list ')' opt_on_delete
 
943
          {
 
944
            Lex->col_list.empty();              /* Alloced by sql_alloc */
 
945
          }
 
946
 
 
947
opt_on_delete:
 
948
        /* empty */ {}
 
949
        | opt_on_delete_list {}
 
950
 
 
951
opt_on_delete_list:
 
952
        opt_on_delete_list opt_on_delete_item {}
 
953
        | opt_on_delete_item {}
 
954
 
 
955
 
 
956
opt_on_delete_item:
 
957
        ON DELETE_SYM delete_option {}
 
958
        | ON UPDATE_SYM delete_option {}
 
959
        | MATCH FULL    {}
 
960
        | MATCH PARTIAL {}
 
961
 
 
962
delete_option:
 
963
        RESTRICT         {}
 
964
        | CASCADE        {}
 
965
        | SET NULL_SYM {}
 
966
        | NO_SYM ACTION {}
 
967
        | SET DEFAULT {}
 
968
 
 
969
key_type:
 
970
        opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
 
971
        | key_or_index                      { $$= Key::MULTIPLE; }
 
972
        | opt_constraint UNIQUE_SYM         { $$= Key::UNIQUE; }
 
973
        | opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; }
 
974
 
 
975
key_or_index:
 
976
        KEY_SYM {}
 
977
        | INDEX {}
 
978
 
 
979
keys_or_index:
 
980
        KEYS {}
 
981
        | INDEX {}
 
982
 
 
983
opt_unique:
 
984
        /* empty */     { $$= Key::MULTIPLE; }
 
985
        | UNIQUE_SYM    { $$= Key::UNIQUE; }
 
986
 
 
987
key_list:
 
988
        key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
 
989
        | key_part order_dir            { Lex->col_list.push_back($1); }
 
990
 
 
991
key_part:
 
992
        ident                   { $$=new key_part_spec($1.str); }
 
993
        | ident '(' NUM ')'     { $$=new key_part_spec($1.str,(uint) atoi($3.str)); }
 
994
 
 
995
opt_ident:
 
996
        /* empty */     { $$=(char*) 0; }       /* Defaultlength */
 
997
        | field_ident   { $$=$1.str; }
 
998
 
 
999
string_list:
 
1000
        text_string                     { Lex->interval_list.push_back($1); }
 
1001
        | string_list ',' text_string   { Lex->interval_list.push_back($3); }
 
1002
 
 
1003
/*
 
1004
** Alter table
 
1005
*/
 
1006
 
 
1007
alter:
 
1008
        ALTER opt_ignore TABLE_SYM table_ident
 
1009
        {
 
1010
          LEX *lex=Lex;
 
1011
          lex->sql_command = SQLCOM_ALTER_TABLE;
 
1012
          lex->name=0;
 
1013
          if (!add_table_to_list($4, NULL))
 
1014
            YYABORT;
 
1015
          lex->drop_primary=0;
 
1016
          lex->create_list.empty();
 
1017
          lex->key_list.empty();
 
1018
          lex->col_list.empty();
 
1019
          lex->drop_list.empty();
 
1020
          lex->alter_list.empty();
 
1021
          lex->db=lex->name=0;
 
1022
          bzero((char*) &lex->create_info,sizeof(lex->create_info));
 
1023
          lex->create_info.db_type= DB_TYPE_DEFAULT;
 
1024
        }
 
1025
        alter_list opt_create_table_options
 
1026
 
 
1027
alter_list:
 
1028
          alter_list_item
 
1029
        | alter_list ',' alter_list_item
 
1030
 
 
1031
add_column:
 
1032
        ADD opt_column { Lex->change=0;}
 
1033
 
 
1034
alter_list_item:
 
1035
        add_column field_list_item opt_place
 
1036
        | add_column '(' field_list ')'
 
1037
        | CHANGE opt_column field_ident { Lex->change= $3.str; } field_spec
 
1038
        | MODIFY_SYM opt_column field_ident
 
1039
          {
 
1040
            Lex->length=Lex->dec=0; Lex->type=0; Lex->interval=0;
 
1041
            Lex->default_value=0;
 
1042
          }
 
1043
          type opt_attribute
 
1044
          {
 
1045
            if (add_field_to_list($3.str,
 
1046
                                  (enum enum_field_types) $5,
 
1047
                                  Lex->length,Lex->dec,Lex->type,
 
1048
                                  Lex->default_value, $3.str,
 
1049
                                  Lex->interval))
 
1050
             YYABORT;
 
1051
          }
 
1052
        | DROP opt_column field_ident opt_restrict
 
1053
          { Lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
 
1054
                                                    $3.str)); }
 
1055
        | DROP PRIMARY_SYM KEY_SYM { Lex->drop_primary=1; }
 
1056
        | DROP FOREIGN KEY_SYM opt_ident {}
 
1057
        | DROP key_or_index field_ident
 
1058
          { Lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
1059
                                                    $3.str)); }
 
1060
        | ALTER opt_column field_ident SET DEFAULT literal
 
1061
          { Lex->alter_list.push_back(new Alter_column($3.str,$6)); }
 
1062
        | ALTER opt_column field_ident DROP DEFAULT
 
1063
          { Lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0)); }
 
1064
        | RENAME opt_to table_alias table_ident
 
1065
          { Lex->db=$4->db.str ; Lex->name= $4->table.str; }
 
1066
        | create_table_option
 
1067
 
 
1068
opt_column:
 
1069
        /* empty */     {}
 
1070
        | COLUMN_SYM    {}
 
1071
 
 
1072
opt_ignore:
 
1073
        /* empty */     { Lex->duplicates=DUP_ERROR; }
 
1074
        | IGNORE_SYM    { Lex->duplicates=DUP_IGNORE; }
 
1075
 
 
1076
opt_restrict:
 
1077
        /* empty */     {}
 
1078
        | RESTRICT      {}
 
1079
        | CASCADE       {}
 
1080
 
 
1081
opt_place:
 
1082
        /* empty */     {}
 
1083
        | AFTER_SYM ident { store_position_for_column($2.str); }
 
1084
        | FIRST_SYM       { store_position_for_column(first_keyword); }
 
1085
 
 
1086
opt_to:
 
1087
        /* empty */     {}
 
1088
        | TO_SYM        {}
 
1089
 
 
1090
slave:
 
1091
        SLAVE START_SYM
 
1092
         {
 
1093
           Lex->sql_command = SQLCOM_SLAVE_START;
 
1094
           Lex->type = 0;
 
1095
         }
 
1096
         |
 
1097
        SLAVE STOP_SYM
 
1098
         {
 
1099
           Lex->sql_command = SQLCOM_SLAVE_STOP;
 
1100
           Lex->type = 0;
 
1101
         };
 
1102
        
 
1103
repair:
 
1104
        REPAIR table_or_tables
 
1105
        {
 
1106
           Lex->sql_command = SQLCOM_REPAIR;
 
1107
           Lex->check_opt.init();
 
1108
        }
 
1109
        table_list opt_mi_check_type
 
1110
 
 
1111
 
 
1112
opt_mi_check_type:
 
1113
        /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
1114
        | TYPE_SYM EQ mi_check_types {}
 
1115
 
 
1116
mi_check_types:
 
1117
        QUICK { Lex->check_opt.quick = 1; }
 
1118
        | EXTENDED_SYM { Lex->check_opt.flags = T_EXTEND; }
 
1119
 
 
1120
analyze:
 
1121
        ANALYZE_SYM table_or_tables table_list
 
1122
        {
 
1123
           Lex->sql_command = SQLCOM_ANALYZE;
 
1124
           Lex->check_opt.init();
 
1125
        }
 
1126
 
 
1127
check:
 
1128
        CHECK_SYM table_or_tables 
 
1129
        {
 
1130
           Lex->sql_command = SQLCOM_CHECK;
 
1131
           Lex->check_opt.init();
 
1132
        }
 
1133
        table_list opt_mi_check_type
 
1134
 
 
1135
optimize:
 
1136
        OPTIMIZE table_or_tables table_ident
 
1137
        {
 
1138
           Lex->sql_command = SQLCOM_OPTIMIZE;
 
1139
           if (!add_table_to_list($3, NULL))
 
1140
             YYABORT;
 
1141
        }
 
1142
 
 
1143
/*
 
1144
** Select : retrieve data from table
 
1145
*/
 
1146
 
 
1147
 
 
1148
select:
 
1149
        SELECT_SYM
 
1150
        {
 
1151
          LEX *lex=Lex;
 
1152
          lex->where=lex->having=0;
 
1153
          lex->select_limit=current_thd->default_select_limit;
 
1154
          lex->offset_limit=0L;
 
1155
          lex->options=0;
 
1156
          lex->sql_command= SQLCOM_SELECT;
 
1157
          lex->exchange = 0;
 
1158
          lex->order_list.elements=lex->group_list.elements=0;
 
1159
          lex->order_list.first=0;
 
1160
          lex->order_list.next= (byte**) &lex->order_list.first;
 
1161
          lex->group_list.first=0;
 
1162
          lex->group_list.next= (byte**) &lex->group_list.first;
 
1163
        }
 
1164
        select_options select_item_list select_into
 
1165
 
 
1166
select_into:
 
1167
        /* empty */
 
1168
        | select_from
 
1169
        | opt_into select_from
 
1170
        | select_from opt_into
 
1171
 
 
1172
select_from:
 
1173
        FROM join_table_list where_clause group_clause having_clause order_clause limit_clause procedure_clause
 
1174
 
 
1175
 
 
1176
select_options:
 
1177
        /* empty*/
 
1178
        | select_option_list
 
1179
 
 
1180
select_option_list:
 
1181
        select_option_list select_option
 
1182
        | select_option
 
1183
 
 
1184
select_option:
 
1185
        STRAIGHT_JOIN { Lex->options|= SELECT_STRAIGHT_JOIN; }
 
1186
        | HIGH_PRIORITY { Lex->options|= SELECT_HIGH_PRIORITY; }
 
1187
        | DISTINCT      { Lex->options|= SELECT_DISTINCT; }
 
1188
        | SQL_SMALL_RESULT { Lex->options|= SELECT_SMALL_RESULT; }
 
1189
        | SQL_BIG_RESULT { Lex->options|= SELECT_BIG_RESULT; }
 
1190
        | SQL_BUFFER_RESULT { Lex->options|= OPTION_BUFFER_RESULT; }
 
1191
        | ALL           {}
 
1192
 
 
1193
select_item_list:
 
1194
          select_item_list ',' select_item
 
1195
        | select_item
 
1196
        | '*'
 
1197
          {
 
1198
            if (add_item_to_list(new Item_field(NULL,NULL,"*")))
 
1199
              YYABORT;
 
1200
          }
 
1201
 
 
1202
 
 
1203
select_item:
 
1204
          remember_name select_item2 remember_end select_alias
 
1205
          {
 
1206
            if (add_item_to_list($2))
 
1207
              YYABORT;
 
1208
            if ($4.str)
 
1209
              $2->set_name($4.str);
 
1210
            else if (!$2->name)
 
1211
              $2->set_name($1,(uint) ($3 - $1));
 
1212
          }
 
1213
 
 
1214
remember_name:
 
1215
        { $$=(char*) Lex->tok_start; }
 
1216
 
 
1217
remember_end:
 
1218
        { $$=(char*) Lex->tok_end; }
 
1219
 
 
1220
select_item2:
 
1221
        table_wild      { $$=$1; } /* table.* */
 
1222
        | expr          { $$=$1; }
 
1223
 
 
1224
select_alias:
 
1225
        { $$.str=0;}
 
1226
        | AS ident { $$=$2; }
 
1227
        | AS TEXT_STRING  { $$=$2; }
 
1228
        | ident { $$=$1; }
 
1229
        | TEXT_STRING  { $$=$1; }
 
1230
 
 
1231
optional_braces:
 
1232
        /* empty */ {}
 
1233
        | '(' ')' {}
 
1234
        
 
1235
/* all possible expressions */
 
1236
expr:   expr_expr       {$$ = $1; }
 
1237
        | simple_expr   {$$ = $1; }
 
1238
 
 
1239
/* expressions that begin with 'expr' */
 
1240
expr_expr:
 
1241
        expr IN_SYM '(' expr_list ')'
 
1242
          { $$= new Item_func_in($1,*$4); }
 
1243
        | expr NOT IN_SYM '(' expr_list ')'
 
1244
          { $$= new Item_func_not(new Item_func_in($1,*$5)); }
 
1245
        | expr BETWEEN_SYM no_and_expr AND expr
 
1246
          { $$= new Item_func_between($1,$3,$5); }
 
1247
        | expr NOT BETWEEN_SYM no_and_expr AND expr
 
1248
          { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
 
1249
        | expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
 
1250
        | expr OR expr          { $$= new Item_cond_or($1,$3); }
 
1251
        | expr AND expr         { $$= new Item_cond_and($1,$3); }
 
1252
        | expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
 
1253
        | expr NOT LIKE simple_expr opt_escape  { $$= new Item_func_not(new Item_func_like($1,$4,$5));}
 
1254
        | expr REGEXP expr { $$= new Item_func_regex($1,$3); }
 
1255
        | expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
 
1256
        | expr IS NULL_SYM      { $$= new Item_func_isnull($1); }
 
1257
        | expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
 
1258
        | expr EQ expr          { $$= new Item_func_eq($1,$3); }
 
1259
        | expr EQUAL_SYM expr   { $$= new Item_func_equal($1,$3); }
 
1260
        | expr GE expr          { $$= new Item_func_ge($1,$3); }
 
1261
        | expr GT_SYM expr      { $$= new Item_func_gt($1,$3); }
 
1262
        | expr LE expr          { $$= new Item_func_le($1,$3); }
 
1263
        | expr LT expr          { $$= new Item_func_lt($1,$3); }
 
1264
        | expr NE expr          { $$= new Item_func_ne($1,$3); }
 
1265
        | expr SHIFT_LEFT expr  { $$= new Item_func_shift_left($1,$3); }
 
1266
        | expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
 
1267
        | expr '+' expr         { $$= new Item_func_plus($1,$3); }
 
1268
        | expr '-' expr         { $$= new Item_func_minus($1,$3); }
 
1269
        | expr '*' expr         { $$= new Item_func_mul($1,$3); }
 
1270
        | expr '/' expr         { $$= new Item_func_div($1,$3); }
 
1271
        | expr '|' expr         { $$= new Item_func_bit_or($1,$3); }
 
1272
        | expr '&' expr         { $$= new Item_func_bit_and($1,$3); }
 
1273
        | expr '%' expr         { $$= new Item_func_mod($1,$3); }
 
1274
        | expr '+' INTERVAL_SYM expr interval
 
1275
          { $$= new Item_date_add_interval($1,$4,$5,0); }
 
1276
        | expr '-' INTERVAL_SYM expr interval
 
1277
          { $$= new Item_date_add_interval($1,$4,$5,1); }
 
1278
 
 
1279
/* expressions that begin with 'expr' that do NOT follow IN_SYM */
 
1280
no_in_expr:
 
1281
        no_in_expr BETWEEN_SYM no_and_expr AND expr
 
1282
          { $$= new Item_func_between($1,$3,$5); }
 
1283
        | no_in_expr NOT BETWEEN_SYM no_and_expr AND expr
 
1284
          { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
 
1285
        | no_in_expr OR_OR_CONCAT expr  { $$= or_or_concat($1,$3); }
 
1286
        | no_in_expr OR expr            { $$= new Item_cond_or($1,$3); }
 
1287
        | no_in_expr AND expr           { $$= new Item_cond_and($1,$3); }
 
1288
        | no_in_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
 
1289
        | no_in_expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
 
1290
        | no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
 
1291
        | no_in_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
 
1292
        | no_in_expr IS NULL_SYM        { $$= new Item_func_isnull($1); }
 
1293
        | no_in_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
 
1294
        | no_in_expr EQ expr            { $$= new Item_func_eq($1,$3); }
 
1295
        | no_in_expr EQUAL_SYM expr     { $$= new Item_func_equal($1,$3); }
 
1296
        | no_in_expr GE expr            { $$= new Item_func_ge($1,$3); }
 
1297
        | no_in_expr GT_SYM expr        { $$= new Item_func_gt($1,$3); }
 
1298
        | no_in_expr LE expr            { $$= new Item_func_le($1,$3); }
 
1299
        | no_in_expr LT expr            { $$= new Item_func_lt($1,$3); }
 
1300
        | no_in_expr NE expr            { $$= new Item_func_ne($1,$3); }
 
1301
        | no_in_expr SHIFT_LEFT expr  { $$= new Item_func_shift_left($1,$3); }
 
1302
        | no_in_expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
 
1303
        | no_in_expr '+' expr           { $$= new Item_func_plus($1,$3); }
 
1304
        | no_in_expr '-' expr           { $$= new Item_func_minus($1,$3); }
 
1305
        | no_in_expr '*' expr           { $$= new Item_func_mul($1,$3); }
 
1306
        | no_in_expr '/' expr           { $$= new Item_func_div($1,$3); }
 
1307
        | no_in_expr '|' expr           { $$= new Item_func_bit_or($1,$3); }
 
1308
        | no_in_expr '&' expr           { $$= new Item_func_bit_and($1,$3); }
 
1309
        | no_in_expr '%' expr           { $$= new Item_func_mod($1,$3); }
 
1310
        | no_in_expr '+' INTERVAL_SYM expr interval
 
1311
          { $$= new Item_date_add_interval($1,$4,$5,0); }
 
1312
        | no_in_expr '-' INTERVAL_SYM expr interval
 
1313
          { $$= new Item_date_add_interval($1,$4,$5,1); }
 
1314
        | simple_expr
 
1315
 
 
1316
/* expressions that begin with 'expr' that does NOT follow AND */
 
1317
no_and_expr:
 
1318
        no_and_expr IN_SYM '(' expr_list ')'
 
1319
        { $$= new Item_func_in($1,*$4); }
 
1320
        | no_and_expr NOT IN_SYM '(' expr_list ')'
 
1321
          { $$= new Item_func_not(new Item_func_in($1,*$5)); }
 
1322
        | no_and_expr BETWEEN_SYM no_and_expr AND expr
 
1323
          { $$= new Item_func_between($1,$3,$5); }
 
1324
        | no_and_expr NOT BETWEEN_SYM no_and_expr AND expr
 
1325
          { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
 
1326
        | no_and_expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
 
1327
        | no_and_expr OR expr           { $$= new Item_cond_or($1,$3); }
 
1328
        | no_and_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
 
1329
        | no_and_expr NOT LIKE simple_expr opt_escape   { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
 
1330
        | no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
 
1331
        | no_and_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
 
1332
        | no_and_expr IS NULL_SYM       { $$= new Item_func_isnull($1); }
 
1333
        | no_and_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
 
1334
        | no_and_expr EQ expr           { $$= new Item_func_eq($1,$3); }
 
1335
        | no_and_expr EQUAL_SYM expr    { $$= new Item_func_equal($1,$3); }
 
1336
        | no_and_expr GE expr           { $$= new Item_func_ge($1,$3); }
 
1337
        | no_and_expr GT_SYM expr       { $$= new Item_func_gt($1,$3); }
 
1338
        | no_and_expr LE expr           { $$= new Item_func_le($1,$3); }
 
1339
        | no_and_expr LT expr           { $$= new Item_func_lt($1,$3); }
 
1340
        | no_and_expr NE expr           { $$= new Item_func_ne($1,$3); }
 
1341
        | no_and_expr SHIFT_LEFT expr  { $$= new Item_func_shift_left($1,$3); }
 
1342
        | no_and_expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
 
1343
        | no_and_expr '+' expr          { $$= new Item_func_plus($1,$3); }
 
1344
        | no_and_expr '-' expr          { $$= new Item_func_minus($1,$3); }
 
1345
        | no_and_expr '*' expr          { $$= new Item_func_mul($1,$3); }
 
1346
        | no_and_expr '/' expr          { $$= new Item_func_div($1,$3); }
 
1347
        | no_and_expr '|' expr          { $$= new Item_func_bit_or($1,$3); }
 
1348
        | no_and_expr '&' expr          { $$= new Item_func_bit_and($1,$3); }
 
1349
        | no_and_expr '%' expr          { $$= new Item_func_mod($1,$3); }
 
1350
        | no_and_expr '+' INTERVAL_SYM expr interval
 
1351
          { $$= new Item_date_add_interval($1,$4,$5,0); }
 
1352
        | no_and_expr '-' INTERVAL_SYM expr interval
 
1353
          { $$= new Item_date_add_interval($1,$4,$5,1); }
 
1354
        | simple_expr
 
1355
 
 
1356
simple_expr:
 
1357
        simple_ident
 
1358
        | literal
 
1359
        | '@' ident_or_text SET_VAR expr { $$= new Item_func_set_user_var($2,$4); }
 
1360
        | '@' ident_or_text      { $$= new Item_func_get_user_var($2); }
 
1361
        | sum_expr
 
1362
        | '-' expr %prec NEG    { $$= new Item_func_neg($2); }
 
1363
        | '~' expr %prec NEG    { $$= new Item_func_bit_neg($2); }
 
1364
        | NOT expr %prec NEG    { $$= new Item_func_not($2); }
 
1365
        | '!' expr %prec NEG    { $$= new Item_func_not($2); }
 
1366
        | '(' expr ')'          { $$= $2; }
 
1367
        | '{' ident expr '}'    { $$= $3; }
 
1368
        | MATCH '(' ident_list ')' AGAINST '(' expr ')'
 
1369
          { Lex->ftfunc_list.push_back(
 
1370
                   (Item_func_match *)($$=new Item_func_match(*$3,$7))); }
 
1371
        | MATCH ident_list AGAINST '(' expr ')'
 
1372
          { Lex->ftfunc_list.push_back(
 
1373
                   (Item_func_match *)($$=new Item_func_match(*$2,$5))); }
 
1374
        | BINARY expr %prec NEG { $$= new Item_func_binary($2); }
 
1375
        | CASE_SYM opt_expr WHEN_SYM when_list opt_else END
 
1376
          { $$= new Item_func_case(* $4, $2, $5 ) } 
 
1377
        | FUNC_ARG0 '(' ')'
 
1378
          { $$= ((Item*(*)(void))($1.symbol->create_func))();}
 
1379
        | FUNC_ARG1 '(' expr ')'
 
1380
          { $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);}
 
1381
        | FUNC_ARG2 '(' expr ',' expr ')'
 
1382
          { $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
 
1383
        | FUNC_ARG3 '(' expr ',' expr ',' expr ')'
 
1384
          { $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
 
1385
        | ATAN  '(' expr ')'
 
1386
          { $$= new Item_func_atan($3); }
 
1387
        | ATAN  '(' expr ',' expr ')'
 
1388
          { $$= new Item_func_atan($3,$5); }
 
1389
        | CHAR_SYM '(' expr_list ')'
 
1390
          { $$= new Item_func_char(*$3); }
 
1391
        | COALESCE '(' expr_list ')'
 
1392
          { $$= new Item_func_coalesce(* $3); }
 
1393
        | CONCAT '(' expr_list ')'
 
1394
          { $$= new Item_func_concat(* $3); }
 
1395
        | CONCAT_WS '(' expr ',' expr_list ')'
 
1396
          { $$= new Item_func_concat_ws($3, *$5); }
 
1397
        | CURDATE optional_braces
 
1398
          { $$= new Item_func_curdate(); }
 
1399
        | CURTIME optional_braces
 
1400
          { $$= new Item_func_curtime(); }
 
1401
        | CURTIME '(' expr ')'
 
1402
          { $$= new Item_func_curtime($3); }
 
1403
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
 
1404
          { $$= new Item_date_add_interval($3,$6,$7,0); }
 
1405
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
 
1406
          { $$= new Item_date_add_interval($3,$6,$7,1); }
 
1407
        | DATABASE '(' ')'
 
1408
          { $$= new Item_func_database(); }
 
1409
        | ELT_FUNC '(' expr ',' expr_list ')'
 
1410
          { $$= new Item_func_elt($3, *$5); }
 
1411
        | MAKE_SET_SYM '(' expr ',' expr_list ')'
 
1412
          { $$= new Item_func_make_set($3, *$5); }
 
1413
        | ENCRYPT '(' expr ')'            { $$= new Item_func_encrypt($3); }
 
1414
        | ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
 
1415
        | DECODE_SYM '(' expr ',' TEXT_STRING ')'
 
1416
          { $$= new Item_func_decode($3,$5.str); }
 
1417
        | ENCODE_SYM '(' expr ',' TEXT_STRING ')'
 
1418
         { $$= new Item_func_encode($3,$5.str); }
 
1419
        | EXPORT_SET '(' expr ',' expr ',' expr ')'
 
1420
                { $$= new Item_func_export_set($3, $5, $7); }
 
1421
        | EXPORT_SET '(' expr ',' expr ',' expr ',' expr ')'
 
1422
                { $$= new Item_func_export_set($3, $5, $7, $9); }
 
1423
        | EXPORT_SET '(' expr ',' expr ',' expr ',' expr ',' expr ')'
 
1424
                { $$= new Item_func_export_set($3, $5, $7, $9, $11); }
 
1425
        | FORMAT_SYM '(' expr ',' NUM ')'
 
1426
          { $$= new Item_func_format($3,atoi($5.str)); }
 
1427
        | FROM_UNIXTIME '(' expr ')'
 
1428
          { $$= new Item_func_from_unixtime($3); }
 
1429
        | FROM_UNIXTIME '(' expr ',' expr ')'
 
1430
          {
 
1431
            $$= new Item_func_date_format(new Item_func_from_unixtime($3),$5,0);
 
1432
          }
 
1433
        | FIELD_FUNC '(' expr ',' expr_list ')'
 
1434
          { $$= new Item_func_field($3, *$5); }
 
1435
        | HOUR_SYM '(' expr ')'
 
1436
          { $$= new Item_func_hour($3); }
 
1437
        | IF '(' expr ',' expr ',' expr ')'
 
1438
          { $$= new Item_func_if($3,$5,$7); }
 
1439
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
 
1440
          { $$= new Item_func_insert($3,$5,$7,$9); }
 
1441
        | INTERVAL_SYM expr interval '+' expr
 
1442
          /* we cannot put interval before - */
 
1443
          { $$= new Item_date_add_interval($5,$2,$3,0); }
 
1444
        | INTERVAL_SYM '(' expr ',' expr_list ')'
 
1445
          { $$= new Item_func_interval($3,* $5); }
 
1446
        | LAST_INSERT_ID '(' ')'
 
1447
          {
 
1448
            $$= new Item_int((char*) "last_insert_id()",
 
1449
                             current_thd->insert_id(),21);
 
1450
          }
 
1451
        | LAST_INSERT_ID '(' expr ')'
 
1452
          {
 
1453
            $$= new Item_func_set_last_insert_id($3);
 
1454
          }
 
1455
        | LEFT '(' expr ',' expr ')'
 
1456
          { $$= new Item_func_left($3,$5); }
 
1457
        | LOCATE '(' expr ',' expr ')'
 
1458
          { $$= new Item_func_locate($5,$3); }
 
1459
        | LOCATE '(' expr ',' expr ',' expr ')'
 
1460
          { $$= new Item_func_locate($5,$3,$7); }
 
1461
        | GREATEST_SYM '(' expr ',' expr_list ')'
 
1462
          { $5->push_front($3); $$= new Item_func_max(*$5); }
 
1463
        | LEAST_SYM '(' expr ',' expr_list ')'
 
1464
          { $5->push_front($3); $$= new Item_func_min(*$5); }
 
1465
        | MINUTE_SYM '(' expr ')'
 
1466
          { $$= new Item_func_minute($3); }
 
1467
        | MONTH_SYM '(' expr ')'
 
1468
          { $$= new Item_func_month($3); }
 
1469
        | NOW_SYM optional_braces
 
1470
          { $$= new Item_func_now(); }
 
1471
        | NOW_SYM '(' expr ')'
 
1472
          { $$= new Item_func_now($3); }
 
1473
        | PASSWORD '(' expr ')'           { $$= new Item_func_password($3); }
 
1474
        | POSITION_SYM '(' no_in_expr IN_SYM expr ')'
 
1475
          { $$ = new Item_func_locate($5,$3); }
 
1476
        | RAND '(' expr ')'     { $$= new Item_func_rand($3); }
 
1477
        | RAND '(' ')'          { $$= new Item_func_rand(); }
 
1478
        | REPLACE '(' expr ',' expr ',' expr ')'
 
1479
          { $$= new Item_func_replace($3,$5,$7); }
 
1480
        | RIGHT '(' expr ',' expr ')'
 
1481
          { $$= new Item_func_right($3,$5); }
 
1482
        | ROUND '(' expr ')'
 
1483
          { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
 
1484
        | ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
 
1485
        | SECOND_SYM '(' expr ')'
 
1486
          { $$= new Item_func_second($3); }
 
1487
        | SUBSTRING '(' expr ',' expr ',' expr ')'
 
1488
          { $$= new Item_func_substr($3,$5,$7); }
 
1489
        | SUBSTRING '(' expr ',' expr ')'
 
1490
          { $$= new Item_func_substr($3,$5); }
 
1491
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
 
1492
          { $$= new Item_func_substr($3,$5,$7); }
 
1493
        | SUBSTRING '(' expr FROM expr ')'
 
1494
          { $$= new Item_func_substr($3,$5); }
 
1495
        | SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
 
1496
          { $$= new Item_func_substr_index($3,$5,$7); }
 
1497
        | TRIM '(' expr ')'
 
1498
          { $$= new Item_func_trim($3,new Item_string(" ",1)); }
 
1499
        | TRIM '(' LEADING opt_pad FROM expr ')'
 
1500
          { $$= new Item_func_ltrim($6,$4); }
 
1501
        | TRIM '(' TRAILING opt_pad FROM expr ')'
 
1502
          { $$= new Item_func_rtrim($6,$4); }
 
1503
        | TRIM '(' BOTH opt_pad FROM expr ')'
 
1504
          { $$= new Item_func_trim($6,$4); }
 
1505
        | TRIM '(' expr FROM expr ')'
 
1506
          { $$= new Item_func_trim($5,$3); }
 
1507
 
 
1508
        | UDA_CHAR_SUM '(' udf_expr_list ')'
 
1509
          {
 
1510
            if ($3 != NULL)
 
1511
              $$ = new Item_sum_udf_str($1, *$3);
 
1512
            else
 
1513
              $$ = new Item_sum_udf_str($1);
 
1514
          }
 
1515
        | UDA_FLOAT_SUM '(' udf_expr_list ')'
 
1516
          {
 
1517
            if ($3 != NULL)
 
1518
              $$ = new Item_sum_udf_float($1, *$3);
 
1519
            else
 
1520
              $$ = new Item_sum_udf_float($1);
 
1521
          }
 
1522
        | UDA_INT_SUM '(' udf_expr_list ')'
 
1523
          {
 
1524
            if ($3 != NULL)
 
1525
              $$ = new Item_sum_udf_int($1, *$3);
 
1526
            else
 
1527
              $$ = new Item_sum_udf_int($1);
 
1528
          }
 
1529
        | UDF_CHAR_FUNC '(' udf_expr_list ')'
 
1530
          {
 
1531
            if ($3 != NULL)
 
1532
              $$ = new Item_func_udf_str($1, *$3);
 
1533
            else
 
1534
              $$ = new Item_func_udf_str($1);
 
1535
          }
 
1536
        | UDF_FLOAT_FUNC '(' udf_expr_list ')'
 
1537
          {
 
1538
            if ($3 != NULL)
 
1539
              $$ = new Item_func_udf_float($1, *$3);
 
1540
            else
 
1541
              $$ = new Item_func_udf_float($1);
 
1542
          }
 
1543
        | UDF_INT_FUNC '(' udf_expr_list ')'
 
1544
          {
 
1545
            if ($3 != NULL)
 
1546
              $$ = new Item_func_udf_int($1, *$3);
 
1547
            else
 
1548
              $$ = new Item_func_udf_int($1);
 
1549
          }
 
1550
        | UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
 
1551
          { $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9); }
 
1552
        | UNIX_TIMESTAMP '(' ')'
 
1553
          { $$= new Item_func_unix_timestamp(); }
 
1554
        | UNIX_TIMESTAMP '(' expr ')'
 
1555
          { $$= new Item_func_unix_timestamp($3); }
 
1556
        | USER '(' ')'
 
1557
          { $$= new Item_func_user(); }
 
1558
        | WEEK_SYM '(' expr ')'
 
1559
          { $$= new Item_func_week($3,new Item_int((char*) "0",0,1)); }
 
1560
        | WEEK_SYM '(' expr ',' expr ')'
 
1561
          { $$= new Item_func_week($3,$5); }
 
1562
        | YEAR_SYM '(' expr ')'
 
1563
          { $$= new Item_func_year($3); }
 
1564
        | YEARWEEK '(' expr ')'
 
1565
          { $$= new Item_func_yearweek($3,new Item_int((char*) "0",0,1)); }
 
1566
        | YEARWEEK '(' expr ',' expr ')'
 
1567
          { $$= new Item_func_yearweek($3, $5); }
 
1568
        | BENCHMARK_SYM '(' ULONG_NUM ',' expr ')'
 
1569
          { $$=new Item_func_benchmark($3,$5); }
 
1570
        | EXTRACT_SYM '(' interval FROM expr ')' 
 
1571
        { $$=new Item_extract( $3, $5); }
 
1572
 
 
1573
udf_expr_list:
 
1574
        /* empty */     { $$= NULL; }
 
1575
        | expr_list     { $$= $1;}
 
1576
 
 
1577
sum_expr:
 
1578
        AVG_SYM '(' in_sum_expr ')'
 
1579
          { $$=new Item_sum_avg($3); }
 
1580
        | BIT_AND  '(' in_sum_expr ')'
 
1581
          { $$=new Item_sum_and($3); }
 
1582
        | BIT_OR  '(' in_sum_expr ')'
 
1583
          { $$=new Item_sum_or($3); }
 
1584
        | COUNT_SYM '(' '*' ')'
 
1585
          { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
 
1586
        | COUNT_SYM '(' in_sum_expr ')'
 
1587
          { $$=new Item_sum_count($3); }
 
1588
        | COUNT_SYM '(' DISTINCT expr_list ')'
 
1589
          { $$=new Item_sum_count_distinct(* $4); }
 
1590
        | GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
 
1591
          { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
 
1592
        | MIN_SYM '(' in_sum_expr ')'
 
1593
          { $$=new Item_sum_min($3); }
 
1594
        | MAX_SYM '(' in_sum_expr ')'
 
1595
          { $$=new Item_sum_max($3); }
 
1596
        | STD_SYM '(' in_sum_expr ')'
 
1597
          { $$=new Item_sum_std($3); }
 
1598
        | SUM_SYM '(' in_sum_expr ')'
 
1599
          { $$=new Item_sum_sum($3); }
 
1600
 
 
1601
in_sum_expr:
 
1602
        { Lex->in_sum_expr++ }
 
1603
        expr
 
1604
        {
 
1605
          Lex->in_sum_expr--;
 
1606
          $$=$2;
 
1607
        }
 
1608
 
 
1609
expr_list:
 
1610
        { Lex->expr_list.push_front(new List<Item>); }
 
1611
        expr_list2
 
1612
        { $$= Lex->expr_list.pop(); }
 
1613
 
 
1614
expr_list2:
 
1615
        expr { Lex->expr_list.head()->push_back($1); }
 
1616
        | expr_list2 ',' expr { Lex->expr_list.head()->push_back($3); }
 
1617
 
 
1618
ident_list:
 
1619
        { Lex->expr_list.push_front(new List<Item>); }
 
1620
        ident_list2
 
1621
        { $$= Lex->expr_list.pop(); }
 
1622
 
 
1623
ident_list2:
 
1624
        simple_ident { Lex->expr_list.head()->push_back($1); }
 
1625
        | ident_list2 ',' simple_ident { Lex->expr_list.head()->push_back($3); }
 
1626
 
 
1627
opt_expr:
 
1628
        /* empty */      { $$= NULL; }
 
1629
        | expr           { $$= $1; }
 
1630
 
 
1631
opt_else:
 
1632
        /* empty */    { $$= NULL; }
 
1633
        | ELSE expr    { $$= $2; }
 
1634
 
 
1635
when_list:
 
1636
        { Lex->when_list.push_front(new List<Item>) }
 
1637
        when_list2
 
1638
        { $$= Lex->when_list.pop(); }
 
1639
 
 
1640
when_list2:
 
1641
        expr THEN_SYM expr 
 
1642
          {
 
1643
            Lex->when_list.head()->push_back($1);
 
1644
            Lex->when_list.head()->push_back($3);
 
1645
        }
 
1646
        | when_list2 WHEN_SYM expr THEN_SYM expr 
 
1647
          {
 
1648
            Lex->when_list.head()->push_back($3);
 
1649
            Lex->when_list.head()->push_back($5);
 
1650
          }
 
1651
 
 
1652
opt_pad:
 
1653
        /* empty */ { $$=new Item_string(" ",1); }
 
1654
        | expr      { $$=$1; }
 
1655
 
 
1656
join_table_list:
 
1657
        '(' join_table_list ')' { $$=$2; }
 
1658
        | join_table            { $$=$1; }
 
1659
        | join_table_list normal_join join_table { $$=$3 }
 
1660
        | join_table_list STRAIGHT_JOIN join_table { $$=$3 ; $$->straight=1; }
 
1661
        | join_table_list INNER_SYM JOIN_SYM join_table ON expr
 
1662
          { add_join_on($4,$6); $$=$4; }
 
1663
        | join_table_list INNER_SYM JOIN_SYM join_table
 
1664
          { Lex->db1=$1->db; Lex->table1=$1->name;
 
1665
            Lex->db2=$4->db; Lex->table2=$4->name; }
 
1666
          USING '(' using_list ')'
 
1667
          { add_join_on($4,$8); $$=$4; }
 
1668
        | join_table_list LEFT opt_outer JOIN_SYM join_table ON expr
 
1669
          { add_join_on($5,$7); $5->outer_join=1; $$=$5; }
 
1670
        | join_table_list LEFT opt_outer JOIN_SYM join_table
 
1671
          { Lex->db1=$1->db; Lex->table1=$1->name;
 
1672
            Lex->db2=$5->db; Lex->table2=$5->name; }
 
1673
          USING '(' using_list ')'
 
1674
          { add_join_on($5,$9); $5->outer_join=1; $$=$5; }
 
1675
        | join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table
 
1676
          { add_join_natural($1,$6); $6->outer_join=1; $$=$6; }
 
1677
        | join_table_list NATURAL JOIN_SYM join_table
 
1678
          { add_join_natural($1,$4); $$=$4; }
 
1679
 
 
1680
normal_join:
 
1681
        ',' {}
 
1682
        | JOIN_SYM {}
 
1683
        | CROSS JOIN_SYM {}
 
1684
 
 
1685
join_table:
 
1686
        { Lex->use_index_ptr=Lex->ignore_index_ptr=0; }
 
1687
        table_ident opt_table_alias opt_key_definition
 
1688
        { if (!($$=add_table_to_list($2,$3,TL_UNLOCK, Lex->use_index_ptr,
 
1689
                                     Lex->ignore_index_ptr))) YYABORT; }
 
1690
        | '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
 
1691
          { add_join_on($7,$9); $7->outer_join=1; $$=$7; }
 
1692
 
 
1693
opt_outer:
 
1694
        /* empty */     {}
 
1695
        | OUTER         {}
 
1696
 
 
1697
opt_key_definition:
 
1698
        /* empty */     {}
 
1699
        | USE_SYM    key_usage_list
 
1700
          { Lex->use_index= *$2; Lex->use_index_ptr= &Lex->use_index; }
 
1701
        | IGNORE_SYM key_usage_list
 
1702
          { Lex->ignore_index= *$2; Lex->ignore_index_ptr= &Lex->ignore_index;}
 
1703
 
 
1704
key_usage_list:
 
1705
        key_or_index { Lex->interval_list.empty() } '(' key_usage_list2 ')'
 
1706
        { $$= &Lex->interval_list; }
 
1707
 
 
1708
key_usage_list2:
 
1709
        key_usage_list2 ',' ident
 
1710
        { Lex->interval_list.push_back(new String((const char*) $3.str,$3.length)); }
 
1711
        | ident
 
1712
        { Lex->interval_list.push_back(new String((const char*) $1.str,$1.length)); }
 
1713
        | PRIMARY_SYM
 
1714
        { Lex->interval_list.push_back(new String("PRIMARY",7)); }
 
1715
 
 
1716
using_list:
 
1717
        ident
 
1718
          { if (!($$= new Item_func_eq(new Item_field(Lex->db1,Lex->table1, $1.str), new Item_field(Lex->db2,Lex->table2,$1.str))))
 
1719
              YYABORT;
 
1720
          }
 
1721
        | using_list ',' ident
 
1722
          {
 
1723
            if (!($$= new Item_cond_and(new Item_func_eq(new Item_field(Lex->db1,Lex->table1,$3.str), new Item_field(Lex->db2,Lex->table2,$3.str)), $1)))
 
1724
              YYABORT;
 
1725
          }
 
1726
 
 
1727
interval:
 
1728
         DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
 
1729
        | DAY_MINUTE_SYM        { $$=INTERVAL_DAY_MINUTE; }
 
1730
        | DAY_SECOND_SYM        { $$=INTERVAL_DAY_SECOND; }
 
1731
        | DAY_SYM               { $$=INTERVAL_DAY; }
 
1732
        | HOUR_MINUTE_SYM       { $$=INTERVAL_HOUR_MINUTE; }
 
1733
        | HOUR_SECOND_SYM       { $$=INTERVAL_HOUR_SECOND; }
 
1734
        | HOUR_SYM              { $$=INTERVAL_HOUR; }
 
1735
        | MINUTE_SECOND_SYM     { $$=INTERVAL_MINUTE_SECOND; }
 
1736
        | MINUTE_SYM            { $$=INTERVAL_MINUTE; }
 
1737
        | MONTH_SYM             { $$=INTERVAL_MONTH; }
 
1738
        | SECOND_SYM            { $$=INTERVAL_SECOND; }
 
1739
        | YEAR_MONTH_SYM        { $$=INTERVAL_YEAR_MONTH; }
 
1740
        | YEAR_SYM              { $$=INTERVAL_YEAR; }
 
1741
 
 
1742
table_alias:
 
1743
        /* empty */
 
1744
        | AS
 
1745
        | EQ
 
1746
 
 
1747
opt_table_alias:
 
1748
        /* empty */             { $$=0; }
 
1749
        | table_alias ident
 
1750
          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
 
1751
 
 
1752
 
 
1753
where_clause:
 
1754
        /* empty */  { Lex->where= 0; }
 
1755
        | WHERE expr { Lex->where= $2; }
 
1756
 
 
1757
having_clause:
 
1758
        /* empty */
 
1759
        | HAVING { Lex->create_refs=1; } expr
 
1760
        { Lex->having= $3; Lex->create_refs=0; }
 
1761
 
 
1762
opt_escape:
 
1763
        ESCAPE_SYM TEXT_STRING  { $$= $2.str; }
 
1764
        | /* empty */           { $$= (char*) "\\"; }
 
1765
 
 
1766
 
 
1767
/*
 
1768
** group by statement in select
 
1769
*/
 
1770
 
 
1771
group_clause:
 
1772
        /* empty */
 
1773
        | GROUP BY group_list
 
1774
 
 
1775
group_list:
 
1776
        group_list ',' group_ident
 
1777
                { if (add_group_to_list($3,(bool) 1)) YYABORT; }
 
1778
        | group_ident order_dir
 
1779
                { if (add_group_to_list($1,(bool) 1)) YYABORT; }
 
1780
 
 
1781
/*
 
1782
** Order by statement in select
 
1783
*/
 
1784
 
 
1785
order_clause:
 
1786
        /* empty */
 
1787
        | ORDER_SYM BY { Lex->sort_default=1; } order_list
 
1788
 
 
1789
order_list:
 
1790
        order_list ',' order_ident order_dir
 
1791
          { if (add_order_to_list($3,(bool) $4)) YYABORT; }
 
1792
        | order_ident order_dir
 
1793
          { if (add_order_to_list($1,(bool) $2)) YYABORT; }
 
1794
 
 
1795
order_dir:
 
1796
        /* empty */ { $$ =  1; }
 
1797
        | ASC  { $$ = Lex->sort_default=1; }
 
1798
        | DESC { $$ = Lex->sort_default=0; }
 
1799
 
 
1800
 
 
1801
limit_clause:
 
1802
        /* empty */
 
1803
        {
 
1804
          Lex->select_limit= current_thd->default_select_limit;
 
1805
          Lex->offset_limit= 0L;
 
1806
        }
 
1807
        | LIMIT ULONG_NUM
 
1808
          { Lex->select_limit= $2; Lex->offset_limit=0L; }
 
1809
        | LIMIT ULONG_NUM ',' ULONG_NUM
 
1810
          { Lex->select_limit= $4; Lex->offset_limit=$2; }
 
1811
 
 
1812
delete_limit_clause:
 
1813
        /* empty */
 
1814
        {
 
1815
          Lex->select_limit= HA_POS_ERROR;
 
1816
        }
 
1817
        | LIMIT ULONGLONG_NUM
 
1818
        { Lex->select_limit= (ha_rows) $2; }
 
1819
 
 
1820
ULONG_NUM:
 
1821
        NUM { $$= strtoul($1.str,NULL,10); }
 
1822
        | REAL_NUM { $$= strtoul($1.str,NULL,10); }
 
1823
        | FLOAT_NUM { $$= strtoul($1.str,NULL,10); }
 
1824
 
 
1825
ULONGLONG_NUM:
 
1826
        NUM        { $$= (ulonglong) strtoul($1.str,NULL,10); }
 
1827
        | LONG_NUM { $$= strtoull($1.str,NULL,10); }
 
1828
        | REAL_NUM { $$= strtoull($1.str,NULL,10); }
 
1829
        | FLOAT_NUM { $$= strtoull($1.str,NULL,10); }
 
1830
 
 
1831
procedure_clause:
 
1832
        /* empty */
 
1833
        | PROCEDURE ident                       /* Procedure name */
 
1834
          {
 
1835
            LEX *lex=Lex;
 
1836
            lex->proc_list.elements=0;
 
1837
            lex->proc_list.first=0;
 
1838
            lex->proc_list.next= (byte**) &lex->proc_list.first;
 
1839
            if (add_proc_to_list(new Item_field(NULL,NULL,$2.str)))
 
1840
              YYABORT;
 
1841
          }
 
1842
          '(' procedure_list ')'
 
1843
 
 
1844
 
 
1845
procedure_list:
 
1846
        /* empty */ {}
 
1847
        | procedure_list2 {}
 
1848
 
 
1849
procedure_list2:
 
1850
        procedure_list2 ',' procedure_item
 
1851
        | procedure_item
 
1852
 
 
1853
procedure_item:
 
1854
          remember_name expr
 
1855
          {
 
1856
            if (add_proc_to_list($2))
 
1857
              YYABORT;
 
1858
            if (!$2->name)
 
1859
              $2->set_name($1,(uint) ((char*) Lex->tok_end - $1));
 
1860
          }
 
1861
 
 
1862
opt_into:
 
1863
        INTO OUTFILE TEXT_STRING
 
1864
        {
 
1865
          if (!(Lex->exchange= new sql_exchange($3.str,0)))
 
1866
            YYABORT;
 
1867
        }
 
1868
        opt_field_term opt_line_term
 
1869
        | INTO DUMPFILE TEXT_STRING
 
1870
        {
 
1871
          if (!(Lex->exchange= new sql_exchange($3.str,1)))
 
1872
            YYABORT;
 
1873
        }
 
1874
 
 
1875
 
 
1876
/*
 
1877
** Drop : delete tables or index
 
1878
*/
 
1879
 
 
1880
drop:
 
1881
        DROP TABLE_SYM if_exists table_list
 
1882
        {
 
1883
          Lex->sql_command = SQLCOM_DROP_TABLE;
 
1884
          Lex->drop_if_exists = $3;
 
1885
        }
 
1886
        | DROP INDEX ident ON table_ident {}
 
1887
          {
 
1888
             Lex->sql_command= SQLCOM_DROP_INDEX;
 
1889
             Lex->drop_list.empty();
 
1890
             Lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
1891
                                                     $3.str));
 
1892
             if (!add_table_to_list($5,NULL))
 
1893
              YYABORT;
 
1894
          }
 
1895
        | DROP DATABASE if_exists ident
 
1896
          {
 
1897
            Lex->sql_command= SQLCOM_DROP_DB;
 
1898
            Lex->drop_if_exists=$3;
 
1899
            Lex->name=$4.str;
 
1900
         }
 
1901
        | DROP UDF_SYM ident
 
1902
          {
 
1903
            Lex->sql_command = SQLCOM_DROP_FUNCTION;
 
1904
            Lex->udf.name=$3.str;
 
1905
          }
 
1906
 
 
1907
 
 
1908
table_list:
 
1909
        table
 
1910
        | table_list ',' table
 
1911
 
 
1912
table:
 
1913
        table_ident
 
1914
        { if (!add_table_to_list($1,NULL)) YYABORT; }
 
1915
 
 
1916
if_exists:
 
1917
        /* empty */ { $$=0; }
 
1918
        | IF EXISTS { $$= 1; }
 
1919
 
 
1920
/*
 
1921
** Insert : add new data to table
 
1922
*/
 
1923
 
 
1924
insert:
 
1925
        INSERT { Lex->sql_command = SQLCOM_INSERT; } insert_lock_option opt_ignore insert2 insert_field_spec
 
1926
 
 
1927
replace:
 
1928
        REPLACE { Lex->sql_command = SQLCOM_REPLACE; } replace_lock_option insert2 insert_field_spec
 
1929
 
 
1930
insert_lock_option:
 
1931
        /* empty */     { Lex->lock_option= TL_WRITE_CONCURRENT_INSERT; }
 
1932
        | LOW_PRIORITY  { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
 
1933
        | DELAYED_SYM   { Lex->lock_option= TL_WRITE_DELAYED; }
 
1934
        | HIGH_PRIORITY { Lex->lock_option= TL_WRITE; }
 
1935
 
 
1936
replace_lock_option:
 
1937
        opt_low_priority {}
 
1938
        | DELAYED_SYM   { Lex->lock_option= TL_WRITE_DELAYED; }
 
1939
 
 
1940
insert2:
 
1941
        INTO insert_table {}
 
1942
        | insert_table {}
 
1943
 
 
1944
insert_table:
 
1945
        table
 
1946
        {
 
1947
          Lex->field_list.empty();
 
1948
          Lex->many_values.empty();
 
1949
          Lex->insert_list=0;
 
1950
        }
 
1951
 
 
1952
insert_field_spec:
 
1953
        opt_field_spec insert_values {}
 
1954
        | SET
 
1955
          {
 
1956
            if (!(Lex->insert_list = new List_item) ||
 
1957
                Lex->many_values.push_back(Lex->insert_list))
 
1958
              YYABORT;
 
1959
           }
 
1960
           ident_eq_list
 
1961
 
 
1962
opt_field_spec:
 
1963
        /* empty */       { }
 
1964
        | '(' fields ')'  { }
 
1965
        | '(' ')'         { }
 
1966
 
 
1967
fields:
 
1968
        fields ',' insert_ident { Lex->field_list.push_back($3); }
 
1969
        | insert_ident          { Lex->field_list.push_back($1); }
 
1970
 
 
1971
insert_values:
 
1972
        VALUES  values_list  {}
 
1973
        | SELECT_SYM
 
1974
          {
 
1975
            LEX *lex=Lex;
 
1976
            lex->where=lex->having=0;
 
1977
            lex->select_limit=current_thd->default_select_limit;
 
1978
            lex->offset_limit=0L;
 
1979
            lex->options=0;
 
1980
            lex->order_list.elements=lex->group_list.elements=0;
 
1981
            lex->order_list.first=0;
 
1982
            lex->order_list.next= (byte**) &lex->order_list.first;
 
1983
            lex->group_list.first=0;
 
1984
            lex->group_list.next= (byte**) &lex->group_list.first;
 
1985
            lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
 
1986
                                SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
 
1987
          }
 
1988
          select_options select_item_list select_from {}
 
1989
 
 
1990
values_list:
 
1991
        values_list ','  no_braces
 
1992
        | no_braces
 
1993
 
 
1994
ident_eq_list:
 
1995
        ident_eq_list ',' ident_eq_value
 
1996
        |
 
1997
        ident_eq_value
 
1998
 
 
1999
ident_eq_value:
 
2000
        simple_ident equal expr
 
2001
         {
 
2002
          if (Lex->field_list.push_back($1) ||
 
2003
              Lex->insert_list->push_back($3))
 
2004
            YYABORT;
 
2005
         }
 
2006
 
 
2007
equal:  EQ              {}
 
2008
        | SET_VAR       {}
 
2009
 
 
2010
no_braces:
 
2011
         '('
 
2012
         {
 
2013
            if (!(Lex->insert_list = new List_item))
 
2014
              YYABORT;
 
2015
         }
 
2016
         opt_values ')'
 
2017
         {
 
2018
          if (Lex->many_values.push_back(Lex->insert_list))
 
2019
            YYABORT;
 
2020
         }
 
2021
 
 
2022
opt_values:
 
2023
        /* empty */ {}
 
2024
        | values
 
2025
 
 
2026
values:
 
2027
        values ','  expr
 
2028
        {
 
2029
          if (Lex->insert_list->push_back($3))
 
2030
            YYABORT;
 
2031
        }
 
2032
        | expr
 
2033
        {
 
2034
          if (Lex->insert_list->push_back($1))
 
2035
            YYABORT;
 
2036
        }
 
2037
 
 
2038
/* Update rows in a table */
 
2039
 
 
2040
update:
 
2041
        UPDATE_SYM opt_low_priority opt_ignore table SET update_list where_clause delete_limit_clause
 
2042
        { Lex->sql_command = SQLCOM_UPDATE; }
 
2043
 
 
2044
update_list:
 
2045
        update_list ',' simple_ident equal expr
 
2046
        {
 
2047
          if (add_item_to_list($3) || add_value_to_list($5))
 
2048
            YYABORT;
 
2049
        }
 
2050
        | simple_ident equal expr
 
2051
          {
 
2052
            if (add_item_to_list($1) || add_value_to_list($3))
 
2053
              YYABORT;
 
2054
          }
 
2055
 
 
2056
opt_low_priority:
 
2057
        /* empty */     { Lex->lock_option= current_thd->update_lock_default; }
 
2058
        | LOW_PRIORITY  { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
 
2059
 
 
2060
/* Delete rows from a table */
 
2061
 
 
2062
delete:
 
2063
        DELETE_SYM opt_low_priority FROM table where_clause delete_limit_clause
 
2064
        { Lex->sql_command= SQLCOM_DELETE; }
 
2065
 
 
2066
 
 
2067
/* Show things */
 
2068
 
 
2069
show:   SHOW { Lex->wild=0;} show_param
 
2070
 
 
2071
show_param:
 
2072
        DATABASES wild
 
2073
          { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
 
2074
        | TABLES opt_db wild
 
2075
          { Lex->sql_command= SQLCOM_SHOW_TABLES; Lex->db= $2; Lex->options=0;}
 
2076
        | TABLE_SYM STATUS_SYM opt_db wild
 
2077
          { Lex->sql_command= SQLCOM_SHOW_TABLES;
 
2078
            Lex->options|= SELECT_DESCRIBE;
 
2079
            Lex->db= $3;
 
2080
          }
 
2081
        | COLUMNS FROM table_ident opt_db wild
 
2082
          {
 
2083
            Lex->sql_command= SQLCOM_SHOW_FIELDS;
 
2084
            if ($4)
 
2085
              $3->change_db($4);
 
2086
            if (!add_table_to_list($3,NULL))
 
2087
              YYABORT;
 
2088
          }
 
2089
        | keys_or_index FROM table_ident opt_db
 
2090
          {
 
2091
            Lex->sql_command= SQLCOM_SHOW_KEYS;
 
2092
            if ($4)
 
2093
              $3->change_db($4);
 
2094
            if (!add_table_to_list($3,NULL))
 
2095
              YYABORT;
 
2096
          }
 
2097
        | STATUS_SYM wild
 
2098
          { Lex->sql_command= SQLCOM_SHOW_STATUS; }
 
2099
        | PROCESSLIST_SYM
 
2100
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST; Lex->verbose=0; }
 
2101
        | FULL PROCESSLIST_SYM
 
2102
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST; Lex->verbose=1; }
 
2103
        | VARIABLES wild
 
2104
          { Lex->sql_command= SQLCOM_SHOW_VARIABLES; }
 
2105
        | GRANTS FOR_SYM user
 
2106
          { Lex->sql_command= SQLCOM_SHOW_GRANTS;
 
2107
            Lex->grant_user=$3; Lex->grant_user->password.str=NullS; }
 
2108
        | CREATE TABLE_SYM table_ident
 
2109
          {
 
2110
            Lex->sql_command = SQLCOM_SHOW_CREATE;
 
2111
            if(!add_table_to_list($3, NULL))
 
2112
              YYABORT;
 
2113
          }
 
2114
        | MASTER_SYM STATUS_SYM
 
2115
          {
 
2116
            Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
 
2117
          }       
 
2118
        | SLAVE STATUS_SYM
 
2119
          {
 
2120
            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
 
2121
          }       
 
2122
 
 
2123
opt_db:
 
2124
        /* empty */  { $$= 0; }
 
2125
        | FROM ident { $$= $2.str; }
 
2126
 
 
2127
wild:
 
2128
        /* empty */
 
2129
        | LIKE text_string { Lex->wild= $2; }
 
2130
 
 
2131
/* A Oracle compatible synonym for show */
 
2132
describe:
 
2133
        describe_command table_ident
 
2134
        {
 
2135
          Lex->wild=0;
 
2136
          Lex->sql_command=SQLCOM_SHOW_FIELDS;
 
2137
          if (!add_table_to_list($2, NULL))
 
2138
            YYABORT;
 
2139
        }
 
2140
        opt_describe_column
 
2141
        | describe_command select { Lex->options|= SELECT_DESCRIBE };
 
2142
 
 
2143
 
 
2144
describe_command:
 
2145
        DESC
 
2146
        | DESCRIBE
 
2147
 
 
2148
opt_describe_column:
 
2149
        /* empty */     {}
 
2150
        | text_string   { Lex->wild= $1; }
 
2151
        | ident         { Lex->wild= new String((const char*) $1.str,$1.length); }
 
2152
 
 
2153
 
 
2154
/* flush things */
 
2155
 
 
2156
flush:
 
2157
        FLUSH_SYM {Lex->sql_command= SQLCOM_FLUSH; Lex->type=0; } flush_options
 
2158
 
 
2159
flush_options:
 
2160
        flush_options ',' flush_option
 
2161
        | flush_option
 
2162
 
 
2163
flush_option:
 
2164
        TABLES          { Lex->type|= REFRESH_TABLES; }
 
2165
        | TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
 
2166
        | HOSTS_SYM     { Lex->type|= REFRESH_HOSTS; }
 
2167
        | PRIVILEGES    { Lex->type|= REFRESH_GRANT; }
 
2168
        | LOGS_SYM      { Lex->type|= REFRESH_LOG; }
 
2169
        | STATUS_SYM    { Lex->type|= REFRESH_STATUS; }
 
2170
        | SLAVE         { Lex->type|= REFRESH_SLAVE; } 
 
2171
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; } 
 
2172
 
 
2173
/* kill threads */
 
2174
 
 
2175
kill:
 
2176
        KILL_SYM NUM
 
2177
        {
 
2178
          Lex->sql_command=SQLCOM_KILL;
 
2179
          Lex->thread_id= (ulong) strtoul($2.str,NULL,10);
 
2180
        }
 
2181
 
 
2182
/* change database */
 
2183
 
 
2184
use:    USE_SYM ident
 
2185
        { Lex->sql_command=SQLCOM_CHANGE_DB; Lex->db= $2.str; }
 
2186
 
 
2187
/* import, export of files */
 
2188
 
 
2189
load:   LOAD DATA_SYM opt_low_priority opt_local INFILE TEXT_STRING
 
2190
        {
 
2191
          Lex->sql_command= SQLCOM_LOAD;
 
2192
          Lex->local_file= $4;
 
2193
          if (!(Lex->exchange= new sql_exchange($6.str,0)))
 
2194
            YYABORT;
 
2195
          Lex->field_list.empty();
 
2196
        }
 
2197
        opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
 
2198
        opt_ignore_lines opt_field_spec
 
2199
        {
 
2200
          if (!add_table_to_list($11,NULL))
 
2201
            YYABORT;
 
2202
        }
 
2203
        |
 
2204
        LOAD TABLE_SYM table_ident FROM MASTER_SYM 
 
2205
        {
 
2206
          Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
 
2207
          if (!add_table_to_list($3,NULL))
 
2208
            YYABORT;
 
2209
          
 
2210
        }   
 
2211
 
 
2212
opt_local:
 
2213
        /* empty */     { $$=0;}
 
2214
        | LOCAL_SYM     { $$=1;}
 
2215
 
 
2216
opt_duplicate:
 
2217
        /* empty */     { Lex->duplicates=DUP_ERROR; }
 
2218
        | REPLACE       { Lex->duplicates=DUP_REPLACE; }
 
2219
        | IGNORE_SYM    { Lex->duplicates=DUP_IGNORE; }
 
2220
 
 
2221
opt_field_term:
 
2222
        /* empty */
 
2223
        | COLUMNS field_term_list
 
2224
 
 
2225
field_term_list:
 
2226
        field_term_list field_term
 
2227
        | field_term
 
2228
 
 
2229
field_term:
 
2230
        TERMINATED BY text_string { Lex->exchange->field_term= $3;}
 
2231
        | OPTIONALLY ENCLOSED BY text_string
 
2232
          { Lex->exchange->enclosed= $4; Lex->exchange->opt_enclosed=1;}
 
2233
        | ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
 
2234
        | ESCAPED BY text_string  { Lex->exchange->escaped= $3;}
 
2235
 
 
2236
opt_line_term:
 
2237
        /* empty */
 
2238
        | LINES line_term_list
 
2239
 
 
2240
line_term_list:
 
2241
        line_term_list line_term
 
2242
        | line_term
 
2243
 
 
2244
line_term:
 
2245
        TERMINATED BY text_string { Lex->exchange->line_term= $3;}
 
2246
        | STARTING BY text_string { Lex->exchange->line_start= $3;}
 
2247
 
 
2248
opt_ignore_lines:
 
2249
        /* empty */
 
2250
        | IGNORE_SYM NUM LINES
 
2251
          { Lex->exchange->skip_lines=atol($2.str); }
 
2252
 
 
2253
/* Common definitions */
 
2254
 
 
2255
text_literal:
 
2256
        TEXT_STRING { $$ = new Item_string($1.str,$1.length); }
 
2257
        | text_literal TEXT_STRING
 
2258
        { ((Item_string*) $1)->append($2.str,$2.length); }
 
2259
 
 
2260
text_string:
 
2261
        TEXT_STRING     { $$=  new String($1.str,$1.length); }
 
2262
        | HEX_NUM
 
2263
          {
 
2264
            Item *tmp = new Item_varbinary($1.str,$1.length);
 
2265
            $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
 
2266
          }
 
2267
 
 
2268
literal:
 
2269
        text_literal    { $$ =  $1; }
 
2270
        | NUM           { $$ =  new Item_int($1.str, (longlong) atol($1.str),$1.length); }
 
2271
        | LONG_NUM      { $$ =  new Item_int($1.str); }
 
2272
        | REAL_NUM      { $$ =  new Item_real($1.str, $1.length); }
 
2273
        | FLOAT_NUM     { $$ =  new Item_float($1.str, $1.length); }
 
2274
        | NULL_SYM      { $$ =  new Item_null();
 
2275
                          Lex->next_state=STATE_OPERATOR_OR_IDENT;}
 
2276
        | HEX_NUM       { $$ =  new Item_varbinary($1.str,$1.length)};
 
2277
        | DATE_SYM text_literal { $$ = $2; }
 
2278
        | TIME_SYM text_literal { $$ = $2; }
 
2279
        | TIMESTAMP text_literal { $$ = $2; }
 
2280
 
 
2281
/**********************************************************************
 
2282
** Createing different items.
 
2283
**********************************************************************/
 
2284
 
 
2285
insert_ident:
 
2286
        simple_ident     { $$=$1; }
 
2287
        | table_wild     { $$=$1; }
 
2288
 
 
2289
table_wild:
 
2290
        ident '.' '*' { $$ = new Item_field(NullS,$1.str,"*"); }
 
2291
        | ident '.' ident '.' '*'
 
2292
        { $$ = new Item_field((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS : $1.str),$3.str,"*"); }
 
2293
 
 
2294
group_ident:
 
2295
        order_ident
 
2296
 
 
2297
order_ident:
 
2298
        expr { $$=$1; }
 
2299
 
 
2300
simple_ident:
 
2301
        ident
 
2302
        { $$ = !Lex->create_refs || Lex->in_sum_expr > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str); }
 
2303
        | ident '.' ident
 
2304
        { $$ = !Lex->create_refs || Lex->in_sum_expr > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str); }
 
2305
        | '.' ident '.' ident
 
2306
        { $$ = !Lex->create_refs || Lex->in_sum_expr > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str); }
 
2307
        | ident '.' ident '.' ident
 
2308
        { $$ = !Lex->create_refs || Lex->in_sum_expr > 0 ? (Item*) new Item_field((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str); }
 
2309
 
 
2310
 
 
2311
field_ident:
 
2312
        ident                   { $$=$1;}
 
2313
        | ident '.' ident       { $$=$3;}       /* Skipp schema name in create*/
 
2314
        | '.' ident             { $$=$2;}       /* For Delphi */
 
2315
 
 
2316
table_ident:
 
2317
        ident                   { $$=new Table_ident($1); }
 
2318
        | ident '.' ident       { $$=new Table_ident($1,$3,0);}
 
2319
        | '.' ident             { $$=new Table_ident($2);}      /* For Delphi */
 
2320
 
 
2321
ident:
 
2322
        IDENT       { $$=$1; }
 
2323
        | keyword
 
2324
        {
 
2325
          $$.str=sql_strmake($1.str,$1.length);
 
2326
          $$.length=$1.length;
 
2327
          if (Lex->next_state != STATE_END)
 
2328
            Lex->next_state=STATE_OPERATOR_OR_IDENT;
 
2329
        }
 
2330
 
 
2331
ident_or_text:
 
2332
        ident           { $$=$1;}
 
2333
        | TEXT_STRING   { $$=$1;} 
 
2334
        | LEX_HOSTNAME  { $$=$1;}
 
2335
 
 
2336
user:
 
2337
        ident_or_text
 
2338
        {
 
2339
          if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
 
2340
            YYABORT;
 
2341
          $$->user = $1; $$->host.str=NullS;
 
2342
          }
 
2343
        | ident_or_text '@' ident_or_text
 
2344
          {
 
2345
          if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
 
2346
              YYABORT;
 
2347
            $$->user = $1; $$->host=$3;
 
2348
          }
 
2349
 
 
2350
/* Keyword that we allow for identifiers */
 
2351
 
 
2352
keyword:
 
2353
        ACTION                  {}
 
2354
        | AFTER_SYM             {}
 
2355
        | AGGREGATE_SYM         {}
 
2356
        | AUTOCOMMIT            {}
 
2357
        | AVG_ROW_LENGTH        {}
 
2358
        | AVG_SYM               {}
 
2359
        | BEGIN_SYM             {}
 
2360
        | BIT_SYM               {}
 
2361
        | BOOL_SYM              {}
 
2362
        | CHECKSUM_SYM          {}
 
2363
        | CHECK_SYM             {}
 
2364
        | COMMENT_SYM           {}
 
2365
        | COMMIT_SYM            {}
 
2366
        | COMPRESSED_SYM        {}
 
2367
        | DATA_SYM              {}
 
2368
        | DATETIME              {}
 
2369
        | DATE_SYM              {}
 
2370
        | DAY_SYM               {}
 
2371
        | DELAY_KEY_WRITE_SYM   {}
 
2372
        | DUMPFILE              {}
 
2373
        | DYNAMIC_SYM           {}
 
2374
        | END                   {}
 
2375
        | ENUM                  {}
 
2376
        | ESCAPE_SYM            {}
 
2377
        | EXTENDED_SYM          {}
 
2378
        | FILE_SYM              {}
 
2379
        | FIRST_SYM             {}
 
2380
        | FIXED_SYM             {}
 
2381
        | FLUSH_SYM             {}
 
2382
        | GRANTS                {}
 
2383
        | HEAP_SYM              {}
 
2384
        | HOSTS_SYM             {}
 
2385
        | HOUR_SYM              {}
 
2386
        | IDENTIFIED_SYM        {}
 
2387
        | ISAM_SYM              {}
 
2388
        | LOCAL_SYM             {}
 
2389
        | LOGS_SYM              {}
 
2390
        | MAX_ROWS              {}
 
2391
        | MAX_SYM               {}
 
2392
        | MASTER_SYM            {}
 
2393
        | MASTER_HOST_SYM       {}
 
2394
        | MASTER_PORT_SYM       {}
 
2395
        | MASTER_LOG_FILE_SYM   {}
 
2396
        | MASTER_LOG_POS_SYM    {}
 
2397
        | MASTER_USER_SYM       {}
 
2398
        | MASTER_PASSWORD_SYM   {}
 
2399
        | MASTER_CONNECT_RETRY_SYM      {}
 
2400
        | MERGE_SYM             {}
 
2401
        | MINUTE_SYM            {}
 
2402
        | MIN_ROWS              {}
 
2403
        | MODIFY_SYM            {}
 
2404
        | MONTH_SYM             {}
 
2405
        | MYISAM_SYM            {}
 
2406
        | NATIONAL_SYM          {}
 
2407
        | NCHAR_SYM             {}
 
2408
        | NO_SYM                {}
 
2409
        | PACK_KEYS_SYM         {}
 
2410
        | PASSWORD              {}
 
2411
        | PROCESS               {}
 
2412
        | PROCESSLIST_SYM       {}
 
2413
        | RAID_0_SYM            {}
 
2414
        | RAID_CHUNKS           {} 
 
2415
        | RAID_CHUNKSIZE        {} 
 
2416
        | RAID_STRIPED_SYM      {}
 
2417
        | RAID_TYPE             {} 
 
2418
        | RELOAD                {}
 
2419
        | REPAIR                {}
 
2420
        | ROLLBACK_SYM          {}
 
2421
        | ROWS_SYM              {}
 
2422
        | ROW_FORMAT_SYM        {}
 
2423
        | ROW_SYM               {}
 
2424
        | SECOND_SYM            {}
 
2425
        | SHUTDOWN              {}
 
2426
        | START_SYM             {}
 
2427
        | STATUS_SYM            {}
 
2428
        | STOP_SYM              {}
 
2429
        | STRING_SYM            {}
 
2430
        | TEMPORARY             {}
 
2431
        | TEXT_SYM              {}
 
2432
        | TIMESTAMP             {}
 
2433
        | TIME_SYM              {}
 
2434
        | TYPE_SYM              {}
 
2435
        | UDF_SYM               {}
 
2436
        | VARIABLES             {}
 
2437
        | WORK_SYM              {}
 
2438
        | YEAR_SYM              {}
 
2439
        | SLAVE                 {}
 
2440
        | COLLECTION            {}
 
2441
 
 
2442
/* Option functions */
 
2443
 
 
2444
set:
 
2445
        SET opt_option
 
2446
        {
 
2447
          Lex->sql_command= SQLCOM_SET_OPTION;
 
2448
          Lex->options=current_thd->options;
 
2449
          Lex->select_limit=current_thd->default_select_limit;
 
2450
        }
 
2451
        option_value_list
 
2452
 
 
2453
opt_option:
 
2454
        /* empty */ {}
 
2455
        | OPTION {}
 
2456
 
 
2457
option_value_list:
 
2458
        option_value
 
2459
        | option_value_list ',' option_value
 
2460
 
 
2461
option_value:
 
2462
        set_option equal NUM
 
2463
        {
 
2464
          if (atoi($3.str) == 0)
 
2465
            Lex->options&= ~$1;
 
2466
          else
 
2467
            Lex->options|= $1;
 
2468
        }
 
2469
        | SQL_SELECT_LIMIT equal ULONG_NUM
 
2470
        {
 
2471
          Lex->select_limit= $3;
 
2472
        }
 
2473
        | SQL_SELECT_LIMIT equal DEFAULT
 
2474
        {
 
2475
          Lex->select_limit= HA_POS_ERROR;
 
2476
        }
 
2477
        | SQL_MAX_JOIN_SIZE equal ULONG_NUM
 
2478
        {
 
2479
          current_thd->max_join_size= $3;
 
2480
          Lex->options&= ~OPTION_BIG_SELECTS;
 
2481
        }
 
2482
        | SQL_MAX_JOIN_SIZE equal DEFAULT
 
2483
        {
 
2484
          current_thd->max_join_size= HA_POS_ERROR;
 
2485
        }
 
2486
        | TIMESTAMP equal ULONG_NUM
 
2487
        {
 
2488
          current_thd->set_time((time_t) $3);
 
2489
        }
 
2490
        | TIMESTAMP equal DEFAULT
 
2491
        {
 
2492
          current_thd->user_time=0;
 
2493
        }
 
2494
        | LAST_INSERT_ID equal ULONGLONG_NUM
 
2495
        {
 
2496
          current_thd->insert_id($3);
 
2497
        }
 
2498
        | INSERT_ID equal ULONGLONG_NUM
 
2499
        {
 
2500
          current_thd->next_insert_id=$3;
 
2501
        }
 
2502
        | CHAR_SYM SET IDENT
 
2503
        {
 
2504
          CONVERT *tmp;
 
2505
          if (!(tmp=get_convert_set($3.str)))
 
2506
          {
 
2507
            net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$3);
 
2508
            YYABORT;
 
2509
          }
 
2510
          current_thd->convert_set=tmp;
 
2511
        }
 
2512
        | CHAR_SYM SET DEFAULT
 
2513
        {
 
2514
          current_thd->convert_set=0;
 
2515
        }
 
2516
        | PASSWORD equal text_or_password
 
2517
         {
 
2518
           if (change_password(current_thd,current_thd->host,
 
2519
                               current_thd->priv_user,$3))
 
2520
             YYABORT;
 
2521
         }
 
2522
        | PASSWORD FOR_SYM user equal text_or_password
 
2523
         {
 
2524
           if (change_password(current_thd,
 
2525
                               $3->host.str ? $3->host.str : current_thd->host,
 
2526
                               $3->user.str,$5))
 
2527
             YYABORT;
 
2528
         }
 
2529
        | '@' ident_or_text equal expr
 
2530
          {
 
2531
             Item_func_set_user_var *item = new Item_func_set_user_var($2,$4);
 
2532
             if (item->fix_fields(current_thd,0) || item->update())
 
2533
                YYABORT;
 
2534
          }
 
2535
 
 
2536
text_or_password:
 
2537
        TEXT_STRING { $$=$1.str;}
 
2538
        | PASSWORD '(' TEXT_STRING ')'
 
2539
          {
 
2540
            if (!$3.length)
 
2541
              $$=$3.str;
 
2542
            else
 
2543
            {
 
2544
              char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
 
2545
              make_scrambled_password(buff,$3.str);
 
2546
              $$=buff;
 
2547
            }
 
2548
          }
 
2549
 
 
2550
set_option:
 
2551
        SQL_BIG_TABLES          { $$= OPTION_BIG_TABLES; }
 
2552
        | AUTOCOMMIT            { $$= OPTION_AUTO_COMMIT; }
 
2553
        | SQL_BIG_SELECTS       { $$= OPTION_BIG_SELECTS; }
 
2554
        | SQL_LOG_OFF           { $$= OPTION_LOG_OFF; }
 
2555
        | SQL_LOG_UPDATE
 
2556
           {
 
2557
             $$= (opt_sql_bin_update)? OPTION_UPDATE_LOG|OPTION_BIN_LOG: OPTION_UPDATE_LOG ;
 
2558
           }
 
2559
        | SQL_LOG_BIN
 
2560
           {
 
2561
             $$= (opt_sql_bin_update)? OPTION_UPDATE_LOG|OPTION_BIN_LOG: OPTION_BIN_LOG ;
 
2562
           }
 
2563
        | SQL_WARNINGS          { $$= OPTION_WARNINGS; }
 
2564
        | SQL_LOW_PRIORITY_UPDATES { $$= OPTION_LOW_PRIORITY_UPDATES; }
 
2565
        | SQL_AUTO_IS_NULL      { $$= OPTION_AUTO_IS_NULL; }
 
2566
        | SQL_SAFE_UPDATES      { $$= OPTION_SAFE_UPDATES; }
 
2567
        | SQL_BUFFER_RESULT     { $$= OPTION_BUFFER_RESULT; }
 
2568
 
 
2569
/* Lock function */
 
2570
 
 
2571
lock:
 
2572
        LOCK_SYM table_or_tables
 
2573
        {
 
2574
          Lex->sql_command=SQLCOM_LOCK_TABLES;
 
2575
        }
 
2576
        table_lock_list
 
2577
 
 
2578
table_or_tables:
 
2579
        TABLE_SYM
 
2580
        | TABLES
 
2581
 
 
2582
table_lock_list:
 
2583
        table_lock
 
2584
        | table_lock_list ',' table_lock
 
2585
 
 
2586
table_lock:
 
2587
        table_ident opt_table_alias lock_option
 
2588
        { if (!add_table_to_list($1,$2,(thr_lock_type) $3)) YYABORT; }
 
2589
 
 
2590
lock_option:
 
2591
        READ_SYM        { $$=TL_READ_NO_INSERT; }
 
2592
        | WRITE_SYM     { $$=current_thd->update_lock_default; }
 
2593
        | LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
 
2594
        | READ_SYM LOCAL_SYM { $$= TL_READ; }
 
2595
 
 
2596
unlock:
 
2597
        UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
 
2598
 
 
2599
 
 
2600
/* GRANT / REVOKE */
 
2601
 
 
2602
revoke:
 
2603
        REVOKE
 
2604
        {
 
2605
          Lex->sql_command = SQLCOM_REVOKE;
 
2606
          Lex->users_list.empty();
 
2607
          Lex->columns.empty();
 
2608
          Lex->grant= Lex->grant_tot_col=0;
 
2609
          Lex->db=0;
 
2610
        }
 
2611
        grant_privileges ON opt_table FROM user_list
 
2612
 
 
2613
grant:
 
2614
        GRANT
 
2615
        {
 
2616
          Lex->sql_command = SQLCOM_GRANT;
 
2617
          Lex->users_list.empty();
 
2618
          Lex->columns.empty();
 
2619
          Lex->grant= Lex->grant_tot_col=0;
 
2620
          Lex->db=0;
 
2621
        }
 
2622
        grant_privileges ON opt_table TO_SYM user_list
 
2623
        grant_option
 
2624
 
 
2625
grant_privileges:
 
2626
        grant_privilege_list {}
 
2627
        | ALL PRIVILEGES        { Lex->grant = UINT_MAX;}
 
2628
        | ALL                   { Lex->grant = UINT_MAX;}
 
2629
 
 
2630
grant_privilege_list:
 
2631
        grant_privilege
 
2632
        | grant_privilege_list ',' grant_privilege
 
2633
 
 
2634
grant_privilege:
 
2635
        SELECT_SYM
 
2636
          { Lex->which_columns = SELECT_ACL;}
 
2637
          opt_column_list
 
2638
        | INSERT
 
2639
          { Lex->which_columns = INSERT_ACL; }
 
2640
          opt_column_list
 
2641
        | UPDATE_SYM
 
2642
          { Lex->which_columns = UPDATE_ACL; }
 
2643
          opt_column_list
 
2644
        | DELETE_SYM { Lex->grant |= DELETE_ACL;}
 
2645
        | REFERENCES { Lex->which_columns = REFERENCES_ACL;} opt_column_list
 
2646
        | USAGE {}
 
2647
        | INDEX         { Lex->grant |= INDEX_ACL;}
 
2648
        | ALTER         { Lex->grant |= ALTER_ACL;}
 
2649
        | CREATE        { Lex->grant |= CREATE_ACL;}
 
2650
        | DROP          { Lex->grant |= DROP_ACL;}
 
2651
        | RELOAD        { Lex->grant |= RELOAD_ACL;}
 
2652
        | SHUTDOWN      { Lex->grant |= SHUTDOWN_ACL;}
 
2653
        | PROCESS       { Lex->grant |= PROCESS_ACL;}
 
2654
        | FILE_SYM      { Lex->grant |= FILE_ACL;}
 
2655
        | GRANT OPTION  { Lex->grant |= GRANT_ACL;}
 
2656
 
 
2657
opt_table:
 
2658
        '*'
 
2659
          {
 
2660
            Lex->db=current_thd->db;
 
2661
            if (Lex->grant == UINT_MAX)
 
2662
              Lex->grant = DB_ACLS & ~GRANT_ACL;
 
2663
            else if (Lex->columns.elements)
 
2664
            {
 
2665
               net_printf(&current_thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
 
2666
               YYABORT;
 
2667
             }
 
2668
          }
 
2669
        | ident '.' '*'
 
2670
          {
 
2671
            Lex->db = $1.str;
 
2672
            if (Lex->grant == UINT_MAX)
 
2673
              Lex->grant = DB_ACLS & ~GRANT_ACL;
 
2674
            else if (Lex->columns.elements)
 
2675
            {
 
2676
              net_printf(&current_thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
 
2677
              YYABORT;
 
2678
            }
 
2679
          }
 
2680
        | '*' '.' '*'
 
2681
          {
 
2682
            Lex->db = NULL;
 
2683
            if (Lex->grant == UINT_MAX)
 
2684
              Lex->grant = GLOBAL_ACLS & ~GRANT_ACL;
 
2685
            else if (Lex->columns.elements)
 
2686
            {
 
2687
              net_printf(&current_thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
 
2688
              YYABORT;
 
2689
            }
 
2690
          }
 
2691
        | table_ident
 
2692
          {
 
2693
            if (!add_table_to_list($1,NULL))
 
2694
              YYABORT;
 
2695
            if (Lex->grant == UINT_MAX)
 
2696
              Lex->grant =  TABLE_ACLS & ~GRANT_ACL;
 
2697
          }
 
2698
 
 
2699
 
 
2700
user_list:
 
2701
        grant_user           { if (Lex->users_list.push_back($1)) YYABORT;}
 
2702
        | user_list ',' grant_user { if (Lex->users_list.push_back($3)) YYABORT;}
 
2703
 
 
2704
 
 
2705
grant_user:
 
2706
        user IDENTIFIED_SYM BY TEXT_STRING
 
2707
        {
 
2708
           $$=$1; $1->password=$4;
 
2709
           if ($4.length)
 
2710
           {
 
2711
             char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
 
2712
             if (buff)
 
2713
             {
 
2714
               make_scrambled_password(buff,$4.str);
 
2715
               $1->password.str=buff;
 
2716
               $1->password.length=HASH_PASSWORD_LENGTH;
 
2717
             }
 
2718
          }
 
2719
        }
 
2720
        | user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
 
2721
          { $$=$1; $1->password=$5 ; }
 
2722
        | user
 
2723
          { $$=$1; $1->password.str=NullS; }
 
2724
 
 
2725
 
 
2726
opt_column_list:
 
2727
        /* empty */ { Lex->grant |= Lex->which_columns; }
 
2728
        | '(' column_list ')'
 
2729
 
 
2730
column_list:
 
2731
        column_list ',' column_list_id
 
2732
        | column_list_id
 
2733
 
 
2734
column_list_id:
 
2735
        ident
 
2736
        {
 
2737
          String *new_str = new String((const char*) $1.str,$1.length);
 
2738
          List_iterator <LEX_COLUMN> iter(Lex->columns);
 
2739
          class LEX_COLUMN *point;
 
2740
          while ((point=iter++))
 
2741
          {
 
2742
            if (!my_strcasecmp(point->column.ptr(),new_str->ptr()))
 
2743
                break;
 
2744
          }
 
2745
          Lex->grant_tot_col|= Lex->which_columns;
 
2746
          if (point)
 
2747
            point->rights |= Lex->which_columns;
 
2748
          else
 
2749
            Lex->columns.push_back(new LEX_COLUMN (*new_str,Lex->which_columns));
 
2750
        }
 
2751
 
 
2752
grant_option:
 
2753
        /* empty */ {}
 
2754
        | WITH GRANT OPTION { Lex->grant |= GRANT_ACL;}
 
2755
 
 
2756
begin:
 
2757
        BEGIN_SYM   { Lex->sql_command = SQLCOM_COMMIT;} opt_work
 
2758
 
 
2759
opt_work:
 
2760
        /* empty */ {}
 
2761
        | WORK_SYM {}
 
2762
 
 
2763
commit:
 
2764
        COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;}
 
2765
 
 
2766
rollback:
 
2767
        ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;}