1
/*****************************************************************************
3
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/pars0sym.h
1
/******************************************************
21
2
SQL parser symbol table
23
6
Created 12/15/1997 Heikki Tuuri
24
7
*******************************************************/
50
33
sym_tab_free_private(
51
34
/*=================*/
52
sym_tab_t* sym_tab); /*!< in, own: symbol table */
53
/******************************************************************//**
54
Adds an integer literal to a symbol table.
55
@return symbol table node */
35
sym_tab_t* sym_tab); /* in, own: symbol table */
36
/**********************************************************************
37
Adds an integer literal to a symbol table. */
58
40
sym_tab_add_int_lit(
59
41
/*================*/
60
sym_tab_t* sym_tab, /*!< in: symbol table */
61
ulint val); /*!< in: integer value */
62
/******************************************************************//**
63
Adds an string literal to a symbol table.
64
@return symbol table node */
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. */
67
49
sym_tab_add_str_lit(
68
50
/*================*/
69
sym_tab_t* sym_tab, /*!< in: symbol table */
70
byte* str, /*!< in: string with no quotes around
51
/* out: symbol table node */
52
sym_tab_t* sym_tab, /* in: symbol table */
53
byte* str, /* in: string with no quotes around
72
ulint len); /*!< in: string length */
73
/******************************************************************//**
74
Add a bound literal to a symbol table.
75
@return symbol table node */
55
ulint len); /* in: string length */
56
/**********************************************************************
57
Add a bound literal to a symbol table. */
78
60
sym_tab_add_bound_lit(
79
61
/*==================*/
80
sym_tab_t* sym_tab, /*!< in: symbol table */
81
const char* name, /*!< in: name of bound literal */
82
ulint* lit_type); /*!< out: type of literal (PARS_*_LIT) */
83
/******************************************************************//**
84
Adds an SQL null literal to a symbol table.
85
@return symbol table node */
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. */
88
70
sym_tab_add_null_lit(
89
71
/*=================*/
90
sym_tab_t* sym_tab); /*!< in: symbol table */
91
/******************************************************************//**
92
Adds an identifier to a symbol table.
93
@return symbol table node */
72
/* out: symbol table node */
73
sym_tab_t* sym_tab); /* in: symbol table */
74
/**********************************************************************
75
Adds an identifier to a symbol table. */
98
sym_tab_t* sym_tab, /*!< in: symbol table */
99
byte* name, /*!< in: identifier name */
100
ulint len); /*!< in: identifier length */
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 */
102
/******************************************************************//**
103
Add a bound identifier to a symbol table.
104
@return symbol table node */
85
/**********************************************************************
86
Add a bound identifier to a symbol table. */
107
89
sym_tab_add_bound_id(
109
sym_tab_t* sym_tab, /*!< in: symbol table */
110
const char* name); /*!< in: name of bound id */
91
/* out: symbol table node */
92
sym_tab_t* sym_tab, /* in: symbol table */
93
const char* name); /* in: name of bound id */
112
/** Index of sym_node_struct::field_nos corresponding to the clustered index */
113
95
#define SYM_CLUST_FIELD_NO 0
114
/** Index of sym_node_struct::field_nos corresponding to a secondary index */
115
96
#define SYM_SEC_FIELD_NO 1
117
/** Types of a symbol table node */
119
SYM_VAR = 91, /*!< declared parameter or local
120
variable of a procedure */
121
SYM_IMPLICIT_VAR, /*!< storage for a intermediate result
123
SYM_LIT, /*!< literal */
124
SYM_TABLE, /*!< database table name */
125
SYM_COLUMN, /*!< database table name */
126
SYM_CURSOR, /*!< named cursor */
127
SYM_PROCEDURE_NAME, /*!< stored procedure name */
128
SYM_INDEX, /*!< database index name */
129
SYM_FUNCTION /*!< user function name */
132
/** Symbol table node */
133
98
struct sym_node_struct{
134
que_common_t common; /*!< node type:
99
que_common_t common; /* node type:
135
100
QUE_NODE_SYMBOL */
136
101
/* NOTE: if the data field in 'common.val' is not NULL and the symbol
137
102
table node is not for a temporary column, the memory for the value has
181
146
use first; if not found
182
147
from the index, then
183
148
ULINT_UNDEFINED */
184
ibool resolved; /*!< TRUE if the
149
ibool resolved; /* TRUE if the
185
150
meaning of a variable
186
151
or a column has been
187
152
resolved; for literals
188
153
this is always TRUE */
189
enum sym_tab_entry token_type; /*!< type of the
191
const char* name; /*!< name of an id */
192
ulint name_len; /*!< id name length */
193
dict_table_t* table; /*!< table definition
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
194
161
if a table id or a
196
ulint col_no; /*!< column number if a
163
ulint col_no; /* column number if a
198
sel_buf_t* prefetch_buf; /*!< NULL, or a buffer
165
sel_buf_t* prefetch_buf; /* NULL, or a buffer
199
166
for cached column
200
167
values for prefetched
202
sel_node_t* cursor_def; /*!< cursor definition
169
sel_node_t* cursor_def; /* cursor definition
205
ulint param_type; /*!< PARS_INPUT,
172
ulint param_type; /* PARS_INPUT,
207
174
PARS_NOT_PARAM if not a
208
175
procedure parameter */
209
sym_tab_t* sym_table; /*!< back pointer to
176
sym_tab_t* sym_table; /* back pointer to
210
177
the symbol table */
211
UT_LIST_NODE_T(sym_node_t) sym_list; /*!< list of symbol
178
UT_LIST_NODE_T(sym_node_t) sym_list; /* list of symbol
216
182
struct sym_tab_struct{
217
183
que_t* query_graph;
218
/*!< query graph generated by the
184
/* query graph generated by the
220
186
const char* sql_string;
221
/*!< SQL string to parse */
187
/* SQL string to parse */
222
188
size_t string_len;
223
/*!< SQL string length */
189
/* SQL string length */
224
190
int next_char_pos;
225
/*!< position of the next character in
191
/* position of the next character in
226
192
sql_string to give to the lexical
228
pars_info_t* info; /*!< extra information, or NULL */
194
pars_info_t* info; /* extra information, or NULL */
229
195
sym_node_list_t sym_list;
230
/*!< list of symbol nodes in the symbol
196
/* list of symbol nodes in the symbol
232
198
UT_LIST_BASE_NODE_T(func_node_t)
234
/*!< list of function nodes in the
200
/* list of function nodes in the
235
201
parsed query graph */
236
mem_heap_t* heap; /*!< memory heap from which we can
202
mem_heap_t* heap; /* memory heap from which we can
237
203
allocate space */
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 */
240
219
#ifndef UNIV_NONINL
241
220
#include "pars0sym.ic"