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