1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/pars0pars.h
29 SQL parser
30 
31 Created 11/19/1996 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef pars0pars_h
35 #define pars0pars_h
36 
37 #include "univ.i"
38 #include "que0types.h"
39 #include "usr0types.h"
40 #include "pars0types.h"
41 #include "row0types.h"
42 #include "trx0types.h"
43 #include "ut0vec.h"
44 
45 /** Type of the user functions. The first argument is always InnoDB-supplied
46 and varies in type, while 'user_arg' is a user-supplied argument. The
47 meaning of the return type also varies. See the individual use cases, e.g.
48 the FETCH statement, for details on them. */
49 typedef ibool	(*pars_user_func_cb_t)(void* arg, void* user_arg);
50 
51 /** If the following is set TRUE, the parser will emit debugging
52 information */
53 extern int	yydebug;
54 
55 #ifdef UNIV_SQL_DEBUG
56 /** If the following is set TRUE, the lexer will print the SQL string
57 as it tokenizes it */
58 extern ibool	pars_print_lexed;
59 #endif /* UNIV_SQL_DEBUG */
60 
61 /* Global variable used while parsing a single procedure or query : the code is
62 NOT re-entrant */
63 extern sym_tab_t*	pars_sym_tab_global;
64 
65 extern pars_res_word_t	pars_to_char_token;
66 extern pars_res_word_t	pars_to_number_token;
67 extern pars_res_word_t	pars_to_binary_token;
68 extern pars_res_word_t	pars_binary_to_number_token;
69 extern pars_res_word_t	pars_substr_token;
70 extern pars_res_word_t	pars_replstr_token;
71 extern pars_res_word_t	pars_concat_token;
72 extern pars_res_word_t	pars_length_token;
73 extern pars_res_word_t	pars_instr_token;
74 extern pars_res_word_t	pars_sysdate_token;
75 extern pars_res_word_t	pars_printf_token;
76 extern pars_res_word_t	pars_assert_token;
77 extern pars_res_word_t	pars_rnd_token;
78 extern pars_res_word_t	pars_rnd_str_token;
79 extern pars_res_word_t	pars_count_token;
80 extern pars_res_word_t	pars_sum_token;
81 extern pars_res_word_t	pars_distinct_token;
82 extern pars_res_word_t	pars_binary_token;
83 extern pars_res_word_t	pars_blob_token;
84 extern pars_res_word_t	pars_int_token;
85 extern pars_res_word_t	pars_bigint_token;
86 extern pars_res_word_t	pars_char_token;
87 extern pars_res_word_t	pars_float_token;
88 extern pars_res_word_t	pars_update_token;
89 extern pars_res_word_t	pars_asc_token;
90 extern pars_res_word_t	pars_desc_token;
91 extern pars_res_word_t	pars_open_token;
92 extern pars_res_word_t	pars_close_token;
93 extern pars_res_word_t	pars_share_token;
94 extern pars_res_word_t	pars_unique_token;
95 extern pars_res_word_t	pars_clustered_token;
96 
97 extern ulint		pars_star_denoter;
98 
99 /* Procedure parameter types */
100 #define PARS_INPUT	0
101 #define PARS_OUTPUT	1
102 #define PARS_NOT_PARAM	2
103 
104 int
105 yyparse(void);
106 
107 /*************************************************************//**
108 Parses an SQL string returning the query graph.
109 @return	own: the query graph */
110 UNIV_INTERN
111 que_t*
112 pars_sql(
113 /*=====*/
114 	pars_info_t*	info,	/*!< in: extra information, or NULL */
115 	const char*	str);	/*!< in: SQL string */
116 /*************************************************************//**
117 Retrieves characters to the lexical analyzer.
118 @return number of characters copied or 0 on EOF */
119 UNIV_INTERN
120 int
121 pars_get_lex_chars(
122 /*===============*/
123 	char*	buf,		/*!< in/out: buffer where to copy */
124 	int	max_size);	/*!< in: maximum number of characters which fit
125 				in the buffer */
126 /*************************************************************//**
127 Called by yyparse on error. */
128 UNIV_INTERN
129 void
130 yyerror(
131 /*====*/
132 	const char*	s);	/*!< in: error message string */
133 /*********************************************************************//**
134 Parses a variable declaration.
135 @return	own: symbol table node of type SYM_VAR */
136 UNIV_INTERN
137 sym_node_t*
138 pars_variable_declaration(
139 /*======================*/
140 	sym_node_t*	node,	/*!< in: symbol table node allocated for the
141 				id of the variable */
142 	pars_res_word_t* type);	/*!< in: pointer to a type token */
143 /*********************************************************************//**
144 Parses a function expression.
145 @return	own: function node in a query tree */
146 UNIV_INTERN
147 func_node_t*
148 pars_func(
149 /*======*/
150 	que_node_t*	res_word,/*!< in: function name reserved word */
151 	que_node_t*	arg);	/*!< in: first argument in the argument list */
152 /*************************************************************************
153 Rebind a LIKE search string. NOTE: We ignore any '%' characters embedded
154 within the search string.
155 @return	own: function node in a query tree */
156 UNIV_INTERN
157 int
158 pars_like_rebind(
159 /*=============*/
160         sym_node_t*     node,   /* in: The search string node.*/
161         const byte*     ptr,    /* in: literal to (re) bind */
162         ulint           len);   /* in: length of literal to (re) bind*/
163 /*********************************************************************//**
164 Parses an operator expression.
165 @return	own: function node in a query tree */
166 UNIV_INTERN
167 func_node_t*
168 pars_op(
169 /*====*/
170 	int		func,	/*!< in: operator token code */
171 	que_node_t*	arg1,	/*!< in: first argument */
172 	que_node_t*	arg2);	/*!< in: second argument or NULL for an unary
173 				operator */
174 /*********************************************************************//**
175 Parses an ORDER BY clause. Order by a single column only is supported.
176 @return	own: order-by node in a query tree */
177 UNIV_INTERN
178 order_node_t*
179 pars_order_by(
180 /*==========*/
181 	sym_node_t*	column,	/*!< in: column name */
182 	pars_res_word_t* asc);	/*!< in: &pars_asc_token or pars_desc_token */
183 /*********************************************************************//**
184 Parses a select list; creates a query graph node for the whole SELECT
185 statement.
186 @return	own: select node in a query tree */
187 UNIV_INTERN
188 sel_node_t*
189 pars_select_list(
190 /*=============*/
191 	que_node_t*	select_list,	/*!< in: select list */
192 	sym_node_t*	into_list);	/*!< in: variables list or NULL */
193 /*********************************************************************//**
194 Parses a cursor declaration.
195 @return	sym_node */
196 UNIV_INTERN
197 que_node_t*
198 pars_cursor_declaration(
199 /*====================*/
200 	sym_node_t*	sym_node,	/*!< in: cursor id node in the symbol
201 					table */
202 	sel_node_t*	select_node);	/*!< in: select node */
203 /*********************************************************************//**
204 Parses a function declaration.
205 @return	sym_node */
206 UNIV_INTERN
207 que_node_t*
208 pars_function_declaration(
209 /*======================*/
210 	sym_node_t*	sym_node);	/*!< in: function id node in the symbol
211 					table */
212 /*********************************************************************//**
213 Parses a select statement.
214 @return	own: select node in a query tree */
215 UNIV_INTERN
216 sel_node_t*
217 pars_select_statement(
218 /*==================*/
219 	sel_node_t*	select_node,	/*!< in: select node already containing
220 					the select list */
221 	sym_node_t*	table_list,	/*!< in: table list */
222 	que_node_t*	search_cond,	/*!< in: search condition or NULL */
223 	pars_res_word_t* for_update,	/*!< in: NULL or &pars_update_token */
224 	pars_res_word_t* consistent_read,/*!< in: NULL or
225 						&pars_consistent_token */
226 	order_node_t*	order_by);	/*!< in: NULL or an order-by node */
227 /*********************************************************************//**
228 Parses a column assignment in an update.
229 @return	column assignment node */
230 UNIV_INTERN
231 col_assign_node_t*
232 pars_column_assignment(
233 /*===================*/
234 	sym_node_t*	column,	/*!< in: column to assign */
235 	que_node_t*	exp);	/*!< in: value to assign */
236 /*********************************************************************//**
237 Parses a delete or update statement start.
238 @return	own: update node in a query tree */
239 UNIV_INTERN
240 upd_node_t*
241 pars_update_statement_start(
242 /*========================*/
243 	ibool		is_delete,	/*!< in: TRUE if delete */
244 	sym_node_t*	table_sym,	/*!< in: table name node */
245 	col_assign_node_t* col_assign_list);/*!< in: column assignment list, NULL
246 					if delete */
247 /*********************************************************************//**
248 Parses an update or delete statement.
249 @return	own: update node in a query tree */
250 UNIV_INTERN
251 upd_node_t*
252 pars_update_statement(
253 /*==================*/
254 	upd_node_t*	node,		/*!< in: update node */
255 	sym_node_t*	cursor_sym,	/*!< in: pointer to a cursor entry in
256 					the symbol table or NULL */
257 	que_node_t*	search_cond);	/*!< in: search condition or NULL */
258 /*********************************************************************//**
259 Parses an insert statement.
260 @return	own: update node in a query tree */
261 UNIV_INTERN
262 ins_node_t*
263 pars_insert_statement(
264 /*==================*/
265 	sym_node_t*	table_sym,	/*!< in: table name node */
266 	que_node_t*	values_list,	/*!< in: value expression list or NULL */
267 	sel_node_t*	select);	/*!< in: select condition or NULL */
268 /*********************************************************************//**
269 Parses a procedure parameter declaration.
270 @return	own: symbol table node of type SYM_VAR */
271 UNIV_INTERN
272 sym_node_t*
273 pars_parameter_declaration(
274 /*=======================*/
275 	sym_node_t*	node,	/*!< in: symbol table node allocated for the
276 				id of the parameter */
277 	ulint		param_type,
278 				/*!< in: PARS_INPUT or PARS_OUTPUT */
279 	pars_res_word_t* type);	/*!< in: pointer to a type token */
280 /*********************************************************************//**
281 Parses an elsif element.
282 @return	elsif node */
283 UNIV_INTERN
284 elsif_node_t*
285 pars_elsif_element(
286 /*===============*/
287 	que_node_t*	cond,		/*!< in: if-condition */
288 	que_node_t*	stat_list);	/*!< in: statement list */
289 /*********************************************************************//**
290 Parses an if-statement.
291 @return	if-statement node */
292 UNIV_INTERN
293 if_node_t*
294 pars_if_statement(
295 /*==============*/
296 	que_node_t*	cond,		/*!< in: if-condition */
297 	que_node_t*	stat_list,	/*!< in: statement list */
298 	que_node_t*	else_part);	/*!< in: else-part statement list */
299 /*********************************************************************//**
300 Parses a for-loop-statement.
301 @return	for-statement node */
302 UNIV_INTERN
303 for_node_t*
304 pars_for_statement(
305 /*===============*/
306 	sym_node_t*	loop_var,	/*!< in: loop variable */
307 	que_node_t*	loop_start_limit,/*!< in: loop start expression */
308 	que_node_t*	loop_end_limit,	/*!< in: loop end expression */
309 	que_node_t*	stat_list);	/*!< in: statement list */
310 /*********************************************************************//**
311 Parses a while-statement.
312 @return	while-statement node */
313 UNIV_INTERN
314 while_node_t*
315 pars_while_statement(
316 /*=================*/
317 	que_node_t*	cond,		/*!< in: while-condition */
318 	que_node_t*	stat_list);	/*!< in: statement list */
319 /*********************************************************************//**
320 Parses an exit statement.
321 @return	exit statement node */
322 UNIV_INTERN
323 exit_node_t*
324 pars_exit_statement(void);
325 /*=====================*/
326 /*********************************************************************//**
327 Parses a return-statement.
328 @return	return-statement node */
329 UNIV_INTERN
330 return_node_t*
331 pars_return_statement(void);
332 /*=======================*/
333 /*********************************************************************//**
334 Parses a procedure call.
335 @return	function node */
336 UNIV_INTERN
337 func_node_t*
338 pars_procedure_call(
339 /*================*/
340 	que_node_t*	res_word,/*!< in: procedure name reserved word */
341 	que_node_t*	args);	/*!< in: argument list */
342 /*********************************************************************//**
343 Parses an assignment statement.
344 @return	assignment statement node */
345 UNIV_INTERN
346 assign_node_t*
347 pars_assignment_statement(
348 /*======================*/
349 	sym_node_t*	var,	/*!< in: variable to assign */
350 	que_node_t*	val);	/*!< in: value to assign */
351 /*********************************************************************//**
352 Parses a fetch statement. into_list or user_func (but not both) must be
353 non-NULL.
354 @return	fetch statement node */
355 UNIV_INTERN
356 fetch_node_t*
357 pars_fetch_statement(
358 /*=================*/
359 	sym_node_t*	cursor,		/*!< in: cursor node */
360 	sym_node_t*	into_list,	/*!< in: variables to set, or NULL */
361 	sym_node_t*	user_func);	/*!< in: user function name, or NULL */
362 /*********************************************************************//**
363 Parses an open or close cursor statement.
364 @return	fetch statement node */
365 UNIV_INTERN
366 open_node_t*
367 pars_open_statement(
368 /*================*/
369 	ulint		type,	/*!< in: ROW_SEL_OPEN_CURSOR
370 				or ROW_SEL_CLOSE_CURSOR */
371 	sym_node_t*	cursor);	/*!< in: cursor node */
372 /*********************************************************************//**
373 Parses a row_printf-statement.
374 @return	row_printf-statement node */
375 UNIV_INTERN
376 row_printf_node_t*
377 pars_row_printf_statement(
378 /*======================*/
379 	sel_node_t*	sel_node);	/*!< in: select node */
380 /*********************************************************************//**
381 Parses a commit statement.
382 @return	own: commit node struct */
383 UNIV_INTERN
384 commit_node_t*
385 pars_commit_statement(void);
386 /*=======================*/
387 /*********************************************************************//**
388 Parses a rollback statement.
389 @return	own: rollback node struct */
390 UNIV_INTERN
391 roll_node_t*
392 pars_rollback_statement(void);
393 /*=========================*/
394 /*********************************************************************//**
395 Parses a column definition at a table creation.
396 @return	column sym table node */
397 UNIV_INTERN
398 sym_node_t*
399 pars_column_def(
400 /*============*/
401 	sym_node_t*		sym_node,	/*!< in: column node in the
402 						symbol table */
403 	pars_res_word_t*	type,		/*!< in: data type */
404 	sym_node_t*		len,		/*!< in: length of column, or
405 						NULL */
406 	void*			is_unsigned,	/*!< in: if not NULL, column
407 						is of type UNSIGNED. */
408 	void*			is_not_null);	/*!< in: if not NULL, column
409 						is of type NOT NULL. */
410 /*********************************************************************//**
411 Parses a table creation operation.
412 @return	table create subgraph */
413 UNIV_INTERN
414 tab_node_t*
415 pars_create_table(
416 /*==============*/
417 	sym_node_t*	table_sym,	/*!< in: table name node in the symbol
418 					table */
419 	sym_node_t*	column_defs,	/*!< in: list of column names */
420 	sym_node_t*	compact,	/* in: non-NULL if COMPACT table. */
421 	sym_node_t*	block_size,	/* in: block size (can be NULL) */
422 	void*		not_fit_in_memory);
423 					/*!< in: a non-NULL pointer means that
424 					this is a table which in simulations
425 					should be simulated as not fitting
426 					in memory; thread is put to sleep
427 					to simulate disk accesses; NOTE that
428 					this flag is not stored to the data
429 					dictionary on disk, and the database
430 					will forget about non-NULL value if
431 					it has to reload the table definition
432 					from disk */
433 /*********************************************************************//**
434 Parses an index creation operation.
435 @return	index create subgraph */
436 UNIV_INTERN
437 ind_node_t*
438 pars_create_index(
439 /*==============*/
440 	pars_res_word_t* unique_def,	/*!< in: not NULL if a unique index */
441 	pars_res_word_t* clustered_def,	/*!< in: not NULL if a clustered index */
442 	sym_node_t*	index_sym,	/*!< in: index name node in the symbol
443 					table */
444 	sym_node_t*	table_sym,	/*!< in: table name node in the symbol
445 					table */
446 	sym_node_t*	column_list);	/*!< in: list of column names */
447 /*********************************************************************//**
448 Parses a procedure definition.
449 @return	query fork node */
450 UNIV_INTERN
451 que_fork_t*
452 pars_procedure_definition(
453 /*======================*/
454 	sym_node_t*	sym_node,	/*!< in: procedure id node in the symbol
455 					table */
456 	sym_node_t*	param_list,	/*!< in: parameter declaration list */
457 	que_node_t*	stat_list);	/*!< in: statement list */
458 
459 /*************************************************************//**
460 Parses a stored procedure call, when this is not within another stored
461 procedure, that is, the client issues a procedure call directly.
462 In MySQL/InnoDB, stored InnoDB procedures are invoked via the
463 parsed procedure tree, not via InnoDB SQL, so this function is not used.
464 @return	query graph */
465 UNIV_INTERN
466 que_fork_t*
467 pars_stored_procedure_call(
468 /*=======================*/
469 	sym_node_t*	sym_node);	/*!< in: stored procedure name */
470 /******************************************************************//**
471 Completes a query graph by adding query thread and fork nodes
472 above it and prepares the graph for running. The fork created is of
473 type QUE_FORK_MYSQL_INTERFACE.
474 @return	query thread node to run */
475 UNIV_INTERN
476 que_thr_t*
477 pars_complete_graph_for_exec(
478 /*=========================*/
479 	que_node_t*	node,	/*!< in: root node for an incomplete
480 				query graph, or NULL for dummy graph */
481 	trx_t*		trx,	/*!< in: transaction handle */
482 	mem_heap_t*	heap)	/*!< in: memory heap from which allocated */
483 	MY_ATTRIBUTE((nonnull(2,3), warn_unused_result));
484 
485 /****************************************************************//**
486 Create parser info struct.
487 @return	own: info struct */
488 UNIV_INTERN
489 pars_info_t*
490 pars_info_create(void);
491 /*==================*/
492 
493 /****************************************************************//**
494 Free info struct and everything it contains. */
495 UNIV_INTERN
496 void
497 pars_info_free(
498 /*===========*/
499 	pars_info_t*	info);	/*!< in, own: info struct */
500 
501 /****************************************************************//**
502 Add bound literal. */
503 UNIV_INTERN
504 void
505 pars_info_add_literal(
506 /*==================*/
507 	pars_info_t*	info,		/*!< in: info struct */
508 	const char*	name,		/*!< in: name */
509 	const void*	address,	/*!< in: address */
510 	ulint		length,		/*!< in: length of data */
511 	ulint		type,		/*!< in: type, e.g. DATA_FIXBINARY */
512 	ulint		prtype);	/*!< in: precise type, e.g.
513 					DATA_UNSIGNED */
514 
515 /****************************************************************//**
516 Equivalent to pars_info_add_literal(info, name, str, strlen(str),
517 DATA_VARCHAR, DATA_ENGLISH). */
518 UNIV_INTERN
519 void
520 pars_info_add_str_literal(
521 /*======================*/
522 	pars_info_t*	info,		/*!< in: info struct */
523 	const char*	name,		/*!< in: name */
524 	const char*	str);		/*!< in: string */
525 /********************************************************************
526 If the literal value already exists then it rebinds otherwise it
527 creates a new entry.*/
528 UNIV_INTERN
529 void
530 pars_info_bind_literal(
531 /*===================*/
532 	pars_info_t*	info,		/* in: info struct */
533 	const char*	name,		/* in: name */
534 	const void*	address,	/* in: address */
535 	ulint		length,		/* in: length of data */
536 	ulint		type,		/* in: type, e.g. DATA_FIXBINARY */
537 	ulint		prtype);	/* in: precise type, e.g. */
538 /********************************************************************
539 If the literal value already exists then it rebinds otherwise it
540 creates a new entry.*/
541 UNIV_INTERN
542 void
543 pars_info_bind_varchar_literal(
544 /*===========================*/
545 	pars_info_t*	info,		/*!< in: info struct */
546 	const char*	name,		/*!< in: name */
547 	const byte*	str,		/*!< in: string */
548 	ulint		str_len);	/*!< in: string length */
549 /****************************************************************//**
550 Equivalent to:
551 
552 char buf[4];
553 mach_write_to_4(buf, val);
554 pars_info_add_literal(info, name, buf, 4, DATA_INT, 0);
555 
556 except that the buffer is dynamically allocated from the info struct's
557 heap. */
558 UNIV_INTERN
559 void
560 pars_info_bind_int4_literal(
561 /*=======================*/
562 	pars_info_t*		info,		/*!< in: info struct */
563 	const char*		name,		/*!< in: name */
564 	const ib_uint32_t*	val);		/*!< in: value */
565 /********************************************************************
566 If the literal value already exists then it rebinds otherwise it
567 creates a new entry. */
568 UNIV_INTERN
569 void
570 pars_info_bind_int8_literal(
571 /*=======================*/
572 	pars_info_t*		info,		/*!< in: info struct */
573 	const char*		name,		/*!< in: name */
574 	const ib_uint64_t*	val);		/*!< in: value */
575 /****************************************************************//**
576 Add user function. */
577 UNIV_INTERN
578 void
579 pars_info_bind_function(
580 /*===================*/
581 	pars_info_t*		info,	/*!< in: info struct */
582 	const char*		name,	/*!< in: function name */
583 	pars_user_func_cb_t	func,	/*!< in: function address */
584 	void*			arg);	/*!< in: user-supplied argument */
585 /****************************************************************//**
586 Add bound id. */
587 UNIV_INTERN
588 void
589 pars_info_bind_id(
590 /*=============*/
591 	pars_info_t*		info,	/*!< in: info struct */
592 	ibool			copy_name,/* in: make a copy of name if TRUE */
593 	const char*		name,	/*!< in: name */
594 	const char*		id);	/*!< in: id */
595 /****************************************************************//**
596 Equivalent to:
597 
598 char buf[4];
599 mach_write_to_4(buf, val);
600 pars_info_add_literal(info, name, buf, 4, DATA_INT, 0);
601 
602 except that the buffer is dynamically allocated from the info struct's
603 heap. */
604 UNIV_INTERN
605 void
606 pars_info_add_int4_literal(
607 /*=======================*/
608 	pars_info_t*	info,		/*!< in: info struct */
609 	const char*	name,		/*!< in: name */
610 	lint		val);		/*!< in: value */
611 
612 /****************************************************************//**
613 Equivalent to:
614 
615 char buf[8];
616 mach_write_to_8(buf, val);
617 pars_info_add_literal(info, name, buf, 8, DATA_FIXBINARY, 0);
618 
619 except that the buffer is dynamically allocated from the info struct's
620 heap. */
621 UNIV_INTERN
622 void
623 pars_info_add_ull_literal(
624 /*======================*/
625 	pars_info_t*	info,		/*!< in: info struct */
626 	const char*	name,		/*!< in: name */
627 	ib_uint64_t	val);		/*!< in: value */
628 
629 /****************************************************************//**
630 If the literal value already exists then it rebinds otherwise it
631 creates a new entry. */
632 UNIV_INTERN
633 void
634 pars_info_bind_ull_literal(
635 /*=======================*/
636 	pars_info_t*		info,	/*!< in: info struct */
637 	const char*		name,	/*!< in: name */
638 	const ib_uint64_t*	val)	/*!< in: value */
639 	MY_ATTRIBUTE((nonnull));
640 
641 /****************************************************************//**
642 Add bound id. */
643 UNIV_INTERN
644 void
645 pars_info_add_id(
646 /*=============*/
647 	pars_info_t*	info,		/*!< in: info struct */
648 	const char*	name,		/*!< in: name */
649 	const char*	id);		/*!< in: id */
650 
651 /****************************************************************//**
652 Get bound literal with the given name.
653 @return	bound literal, or NULL if not found */
654 UNIV_INTERN
655 pars_bound_lit_t*
656 pars_info_get_bound_lit(
657 /*====================*/
658 	pars_info_t*		info,	/*!< in: info struct */
659 	const char*		name);	/*!< in: bound literal name to find */
660 
661 /****************************************************************//**
662 Get bound id with the given name.
663 @return	bound id, or NULL if not found */
664 UNIV_INTERN
665 pars_bound_id_t*
666 pars_info_get_bound_id(
667 /*===================*/
668 	pars_info_t*		info,	/*!< in: info struct */
669 	const char*		name);	/*!< in: bound id name to find */
670 
671 /******************************************************************//**
672 Release any resources used by the lexer. */
673 UNIV_INTERN
674 void
675 pars_lexer_close(void);
676 /*==================*/
677 
678 /** Extra information supplied for pars_sql(). */
679 struct pars_info_t {
680 	mem_heap_t*	heap;		/*!< our own memory heap */
681 
682 	ib_vector_t*	funcs;		/*!< user functions, or NUll
683 					(pars_user_func_t*) */
684 	ib_vector_t*	bound_lits;	/*!< bound literals, or NULL
685 					(pars_bound_lit_t*) */
686 	ib_vector_t*	bound_ids;	/*!< bound ids, or NULL
687 					(pars_bound_id_t*) */
688 
689 	ibool		graph_owns_us;	/*!< if TRUE (which is the default),
690 					que_graph_free() will free us */
691 };
692 
693 /** User-supplied function and argument. */
694 struct pars_user_func_t {
695 	const char*		name;	/*!< function name */
696 	pars_user_func_cb_t	func;	/*!< function address */
697 	void*			arg;	/*!< user-supplied argument */
698 };
699 
700 /** Bound literal. */
701 struct pars_bound_lit_t {
702 	const char*	name;		/*!< name */
703 	const void*	address;	/*!< address */
704 	ulint		length;		/*!< length of data */
705 	ulint		type;		/*!< type, e.g. DATA_FIXBINARY */
706 	ulint		prtype;		/*!< precise type, e.g. DATA_UNSIGNED */
707 	sym_node_t*	node;		/*!< symbol node */
708 };
709 
710 /** Bound identifier. */
711 struct pars_bound_id_t {
712 	const char*	name;		/*!< name */
713 	const char*	id;		/*!< identifier */
714 };
715 
716 /** Struct used to denote a reserved word in a parsing tree */
717 struct pars_res_word_t{
718 	int	code;	/*!< the token code for the reserved word from
719 			pars0grm.h */
720 };
721 
722 /** A predefined function or operator node in a parsing tree; this construct
723 is also used for some non-functions like the assignment ':=' */
724 struct func_node_t{
725 	que_common_t	common;	/*!< type: QUE_NODE_FUNC */
726 	int		func;	/*!< token code of the function name */
727 	ulint		fclass;	/*!< class of the function */
728 	que_node_t*	args;	/*!< argument(s) of the function */
729 	UT_LIST_NODE_T(func_node_t) cond_list;
730 				/*!< list of comparison conditions; defined
731 				only for comparison operator nodes except,
732 				presently, for OPT_SCROLL_TYPE ones */
733 	UT_LIST_NODE_T(func_node_t) func_node_list;
734 				/*!< list of function nodes in a parsed
735 				query graph */
736 };
737 
738 /** An order-by node in a select */
739 struct order_node_t{
740 	que_common_t	common;	/*!< type: QUE_NODE_ORDER */
741 	sym_node_t*	column;	/*!< order-by column */
742 	ibool		asc;	/*!< TRUE if ascending, FALSE if descending */
743 };
744 
745 /** Procedure definition node */
746 struct proc_node_t{
747 	que_common_t	common;		/*!< type: QUE_NODE_PROC */
748 	sym_node_t*	proc_id;	/*!< procedure name symbol in the symbol
749 					table of this same procedure */
750 	sym_node_t*	param_list;	/*!< input and output parameters */
751 	que_node_t*	stat_list;	/*!< statement list */
752 	sym_tab_t*	sym_tab;	/*!< symbol table of this procedure */
753 };
754 
755 /** elsif-element node */
756 struct elsif_node_t{
757 	que_common_t	common;		/*!< type: QUE_NODE_ELSIF */
758 	que_node_t*	cond;		/*!< if condition */
759 	que_node_t*	stat_list;	/*!< statement list */
760 };
761 
762 /** if-statement node */
763 struct if_node_t{
764 	que_common_t	common;		/*!< type: QUE_NODE_IF */
765 	que_node_t*	cond;		/*!< if condition */
766 	que_node_t*	stat_list;	/*!< statement list */
767 	que_node_t*	else_part;	/*!< else-part statement list */
768 	elsif_node_t*	elsif_list;	/*!< elsif element list */
769 };
770 
771 /** while-statement node */
772 struct while_node_t{
773 	que_common_t	common;		/*!< type: QUE_NODE_WHILE */
774 	que_node_t*	cond;		/*!< while condition */
775 	que_node_t*	stat_list;	/*!< statement list */
776 };
777 
778 /** for-loop-statement node */
779 struct for_node_t{
780 	que_common_t	common;		/*!< type: QUE_NODE_FOR */
781 	sym_node_t*	loop_var;	/*!< loop variable: this is the
782 					dereferenced symbol from the
783 					variable declarations, not the
784 					symbol occurrence in the for loop
785 					definition */
786 	que_node_t*	loop_start_limit;/*!< initial value of loop variable */
787 	que_node_t*	loop_end_limit;	/*!< end value of loop variable */
788 	lint		loop_end_value;	/*!< evaluated value for the end value:
789 					it is calculated only when the loop
790 					is entered, and will not change within
791 					the loop */
792 	que_node_t*	stat_list;	/*!< statement list */
793 };
794 
795 /** exit statement node */
796 struct exit_node_t{
797 	que_common_t	common;		/*!< type: QUE_NODE_EXIT */
798 };
799 
800 /** return-statement node */
801 struct return_node_t{
802 	que_common_t	common;		/*!< type: QUE_NODE_RETURN */
803 };
804 
805 /** Assignment statement node */
806 struct assign_node_t{
807 	que_common_t	common;		/*!< type: QUE_NODE_ASSIGNMENT */
808 	sym_node_t*	var;		/*!< variable to set */
809 	que_node_t*	val;		/*!< value to assign */
810 };
811 
812 /** Column assignment node */
813 struct col_assign_node_t{
814 	que_common_t	common;		/*!< type: QUE_NODE_COL_ASSIGN */
815 	sym_node_t*	col;		/*!< column to set */
816 	que_node_t*	val;		/*!< value to assign */
817 };
818 
819 /** Classes of functions */
820 /* @{ */
821 #define PARS_FUNC_ARITH		1	/*!< +, -, *, / */
822 #define	PARS_FUNC_LOGICAL	2	/*!< AND, OR, NOT */
823 #define PARS_FUNC_CMP		3	/*!< comparison operators */
824 #define	PARS_FUNC_PREDEFINED	4	/*!< TO_NUMBER, SUBSTR, ... */
825 #define	PARS_FUNC_AGGREGATE	5	/*!< COUNT, DISTINCT, SUM */
826 #define	PARS_FUNC_OTHER		6	/*!< these are not real functions,
827 					e.g., := */
828 /* @} */
829 
830 #ifndef UNIV_NONINL
831 #include "pars0pars.ic"
832 #endif
833 
834 #endif
835