1
/******************************************************
2
SQL parser symbol table
6
Created 12/15/1997 Heikki Tuuri
7
*******************************************************/
13
#include "que0types.h"
14
#include "usr0types.h"
15
#include "dict0types.h"
16
#include "pars0types.h"
17
#include "row0types.h"
19
/**********************************************************************
20
Creates a symbol table for a single stored procedure or query. */
25
/* out, own: symbol table */
26
mem_heap_t* heap); /* in: memory heap where to create */
27
/**********************************************************************
28
Frees the memory allocated dynamically AFTER parsing phase for variables
29
etc. in the symbol table. Does not free the mem heap where the table was
30
originally created. Frees also SQL explicit cursor definitions. */
35
sym_tab_t* sym_tab); /* in, own: symbol table */
36
/**********************************************************************
37
Adds an integer literal to a symbol table. */
42
/* out: symbol table node */
43
sym_tab_t* sym_tab, /* in: symbol table */
44
ulint val); /* in: integer value */
45
/**********************************************************************
46
Adds an string literal to a symbol table. */
51
/* out: symbol table node */
52
sym_tab_t* sym_tab, /* in: symbol table */
53
byte* str, /* in: string with no quotes around
55
ulint len); /* in: string length */
56
/**********************************************************************
57
Add a bound literal to a symbol table. */
60
sym_tab_add_bound_lit(
61
/*==================*/
62
/* out: symbol table node */
63
sym_tab_t* sym_tab, /* in: symbol table */
64
const char* name, /* in: name of bound literal */
65
ulint* lit_type); /* out: type of literal (PARS_*_LIT) */
66
/**********************************************************************
67
Adds an SQL null literal to a symbol table. */
72
/* out: symbol table node */
73
sym_tab_t* sym_tab); /* in: symbol table */
74
/**********************************************************************
75
Adds an identifier to a symbol table. */
80
/* out: symbol table node */
81
sym_tab_t* sym_tab, /* in: symbol table */
82
byte* name, /* in: identifier name */
83
ulint len); /* in: identifier length */
85
/**********************************************************************
86
Add a bound identifier to a symbol table. */
91
/* out: symbol table node */
92
sym_tab_t* sym_tab, /* in: symbol table */
93
const char* name); /* in: name of bound id */
95
#define SYM_CLUST_FIELD_NO 0
96
#define SYM_SEC_FIELD_NO 1
98
struct sym_node_struct{
99
que_common_t common; /* node type:
101
/* NOTE: if the data field in 'common.val' is not NULL and the symbol
102
table node is not for a temporary column, the memory for the value has
103
been allocated from dynamic memory and it should be freed when the
104
symbol table is discarded */
106
/* 'alias' and 'indirection' are almost the same, but not quite.
107
'alias' always points to the primary instance of the variable, while
108
'indirection' does the same only if we should use the primary
109
instance's values for the node's data. This is usually the case, but
110
when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
111
t WHERE id = x;"), we copy the values from the primary instance to
112
the cursor's instance so that they are fixed for the duration of the
113
cursor, and set 'indirection' to NULL. If we did not, the value of
114
'x' could change between fetches and things would break horribly.
116
TODO: It would be cleaner to make 'indirection' a boolean field and
117
always use 'alias' to refer to the primary node. */
119
sym_node_t* indirection; /* pointer to
123
node, NULL otherwise */
124
sym_node_t* alias; /* pointer to
129
UT_LIST_NODE_T(sym_node_t) col_var_list; /* list of table
131
input variables for an
133
ibool copy_val; /* TRUE if a column
136
memory when fetched */
137
ulint field_nos[2]; /* if a column, in
139
SYM_CLUST_FIELD_NO is
140
the field number in the
144
the field number in the
145
non-clustered index to
146
use first; if not found
149
ibool resolved; /* TRUE if the
150
meaning of a variable
152
resolved; for literals
153
this is always TRUE */
154
ulint token_type; /* SYM_VAR, SYM_COLUMN,
158
const char* name; /* name of an id */
159
ulint name_len; /* id name length */
160
dict_table_t* table; /* table definition
163
ulint col_no; /* column number if a
165
sel_buf_t* prefetch_buf; /* NULL, or a buffer
167
values for prefetched
169
sel_node_t* cursor_def; /* cursor definition
172
ulint param_type; /* PARS_INPUT,
174
PARS_NOT_PARAM if not a
175
procedure parameter */
176
sym_tab_t* sym_table; /* back pointer to
178
UT_LIST_NODE_T(sym_node_t) sym_list; /* list of symbol
182
struct sym_tab_struct{
184
/* query graph generated by the
186
const char* sql_string;
187
/* SQL string to parse */
189
/* SQL string length */
191
/* position of the next character in
192
sql_string to give to the lexical
194
pars_info_t* info; /* extra information, or NULL */
195
sym_node_list_t sym_list;
196
/* list of symbol nodes in the symbol
198
UT_LIST_BASE_NODE_T(func_node_t)
200
/* list of function nodes in the
201
parsed query graph */
202
mem_heap_t* heap; /* memory heap from which we can
206
/* Types of a symbol table entry */
207
#define SYM_VAR 91 /* declared parameter or local
208
variable of a procedure */
209
#define SYM_IMPLICIT_VAR 92 /* storage for a intermediate result
211
#define SYM_LIT 93 /* literal */
212
#define SYM_TABLE 94 /* database table name */
213
#define SYM_COLUMN 95 /* database table name */
214
#define SYM_CURSOR 96 /* named cursor */
215
#define SYM_PROCEDURE_NAME 97 /* stored procedure name */
216
#define SYM_INDEX 98 /* database index name */
217
#define SYM_FUNCTION 99 /* user function name */
220
#include "pars0sym.ic"