sql_yacc.yy
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:73k
源码类别:

MySQL数据库

开发平台:

Visual C++

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