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