1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
/* A lexical scanner on a temporary buffer with a yacc interface */
|
|
18 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
19 |
#define DRIZZLE_LEX 1
|
934.2.1
by Jay Pipes
Split index hints out into their own file, removal from sql_lex.h and sql_select.cc |
20 |
#include "drizzled/server_includes.h" |
21 |
#include "drizzled/item/num.h" |
|
22 |
#include "drizzled/error.h" |
|
23 |
#include "drizzled/session.h" |
|
24 |
#include "drizzled/sql_base.h" |
|
25 |
#include "drizzled/lookup_symbol.h" |
|
26 |
#include "drizzled/index_hint.h" |
|
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
27 |
|
908.1.15
by Monty Taylor
Updated comment version indicators to handle drizzle versions. |
28 |
#include <ctype.h> |
29 |
||
30 |
using namespace std; |
|
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
31 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
32 |
static int lex_one_token(void *arg, void *yysession); |
1
by brian
clean slate |
33 |
|
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
34 |
|
1
by brian
clean slate |
35 |
/*
|
36 |
We are using pointer to this variable for distinguishing between assignment
|
|
37 |
to NEW row field (when parsing trigger definition) and structured variable.
|
|
38 |
*/
|
|
39 |
||
40 |
sys_var *trg_new_row_fake_var= (sys_var*) 0x01; |
|
41 |
||
42 |
/**
|
|
43 |
LEX_STRING constant for null-string to be used in parser and other places.
|
|
44 |
*/
|
|
45 |
const LEX_STRING null_lex_str= {NULL, 0}; |
|
46 |
||
47 |
void
|
|
48 |
st_parsing_options::reset() |
|
49 |
{
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
50 |
allows_select_procedure= true; |
1
by brian
clean slate |
51 |
}
|
52 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
53 |
Lex_input_stream::Lex_input_stream(Session *session, |
1
by brian
clean slate |
54 |
const char* buffer, |
55 |
unsigned int length) |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
56 |
: m_session(session), |
1
by brian
clean slate |
57 |
yylineno(1), |
58 |
yytoklen(0), |
|
59 |
yylval(NULL), |
|
60 |
lookahead_token(END_OF_INPUT), |
|
61 |
lookahead_yylval(NULL), |
|
62 |
m_ptr(buffer), |
|
63 |
m_tok_start(NULL), |
|
64 |
m_tok_end(NULL), |
|
65 |
m_end_of_query(buffer + length), |
|
66 |
m_tok_start_prev(NULL), |
|
67 |
m_buf(buffer), |
|
68 |
m_buf_length(length), |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
69 |
m_echo(true), |
1
by brian
clean slate |
70 |
m_cpp_tok_start(NULL), |
71 |
m_cpp_tok_start_prev(NULL), |
|
72 |
m_cpp_tok_end(NULL), |
|
73 |
m_body_utf8(NULL), |
|
74 |
m_cpp_utf8_processed_ptr(NULL), |
|
75 |
next_state(MY_LEX_START), |
|
76 |
found_semicolon(NULL), |
|
77 |
ignore_space(1), |
|
78 |
in_comment(NO_COMMENT), |
|
79 |
m_underscore_cs(NULL) |
|
80 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
81 |
m_cpp_buf= (char*) session->alloc(length + 1); |
1
by brian
clean slate |
82 |
m_cpp_ptr= m_cpp_buf; |
83 |
}
|
|
84 |
||
85 |
Lex_input_stream::~Lex_input_stream() |
|
86 |
{}
|
|
87 |
||
88 |
/**
|
|
89 |
The operation is called from the parser in order to
|
|
90 |
1) designate the intention to have utf8 body;
|
|
91 |
1) Indicate to the lexer that we will need a utf8 representation of this
|
|
92 |
statement;
|
|
93 |
2) Determine the beginning of the body.
|
|
94 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
95 |
@param session Thread context.
|
1
by brian
clean slate |
96 |
@param begin_ptr Pointer to the start of the body in the pre-processed
|
97 |
buffer.
|
|
98 |
*/
|
|
99 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
100 |
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr) |
1
by brian
clean slate |
101 |
{
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
102 |
assert(begin_ptr); |
103 |
assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length); |
|
1
by brian
clean slate |
104 |
|
482
by Brian Aker
Remove uint. |
105 |
uint32_t body_utf8_length= |
748
by Brian Aker
Removal of client side collation. |
106 |
(m_buf_length / default_charset_info->mbminlen) * |
1
by brian
clean slate |
107 |
my_charset_utf8_bin.mbmaxlen; |
108 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
109 |
m_body_utf8= (char *) session->alloc(body_utf8_length + 1); |
1
by brian
clean slate |
110 |
m_body_utf8_ptr= m_body_utf8; |
111 |
*m_body_utf8_ptr= 0; |
|
112 |
||
113 |
m_cpp_utf8_processed_ptr= begin_ptr; |
|
114 |
}
|
|
115 |
||
116 |
/**
|
|
117 |
@brief The operation appends unprocessed part of pre-processed buffer till
|
|
118 |
the given pointer (ptr) and sets m_cpp_utf8_processed_ptr to end_ptr.
|
|
119 |
||
120 |
The idea is that some tokens in the pre-processed buffer (like character
|
|
121 |
set introducers) should be skipped.
|
|
122 |
||
123 |
Example:
|
|
124 |
CPP buffer: SELECT 'str1', _latin1 'str2';
|
|
125 |
m_cpp_utf8_processed_ptr -- points at the "SELECT ...";
|
|
126 |
In order to skip "_latin1", the following call should be made:
|
|
127 |
body_utf8_append(<pointer to "_latin1 ...">, <pointer to " 'str2'...">)
|
|
128 |
||
129 |
@param ptr Pointer in the pre-processed buffer, which specifies the
|
|
130 |
end of the chunk, which should be appended to the utf8
|
|
131 |
body.
|
|
132 |
@param end_ptr Pointer in the pre-processed buffer, to which
|
|
133 |
m_cpp_utf8_processed_ptr will be set in the end of the
|
|
134 |
operation.
|
|
135 |
*/
|
|
136 |
||
137 |
void Lex_input_stream::body_utf8_append(const char *ptr, |
|
138 |
const char *end_ptr) |
|
139 |
{
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
140 |
assert(m_cpp_buf <= ptr && ptr <= m_cpp_buf + m_buf_length); |
141 |
assert(m_cpp_buf <= end_ptr && end_ptr <= m_cpp_buf + m_buf_length); |
|
1
by brian
clean slate |
142 |
|
143 |
if (!m_body_utf8) |
|
144 |
return; |
|
145 |
||
146 |
if (m_cpp_utf8_processed_ptr >= ptr) |
|
147 |
return; |
|
148 |
||
149 |
int bytes_to_copy= ptr - m_cpp_utf8_processed_ptr; |
|
150 |
||
151 |
memcpy(m_body_utf8_ptr, m_cpp_utf8_processed_ptr, bytes_to_copy); |
|
152 |
m_body_utf8_ptr += bytes_to_copy; |
|
153 |
*m_body_utf8_ptr= 0; |
|
154 |
||
155 |
m_cpp_utf8_processed_ptr= end_ptr; |
|
156 |
}
|
|
157 |
||
158 |
/**
|
|
159 |
The operation appends unprocessed part of the pre-processed buffer till
|
|
160 |
the given pointer (ptr) and sets m_cpp_utf8_processed_ptr to ptr.
|
|
161 |
||
162 |
@param ptr Pointer in the pre-processed buffer, which specifies the end
|
|
163 |
of the chunk, which should be appended to the utf8 body.
|
|
164 |
*/
|
|
165 |
||
166 |
void Lex_input_stream::body_utf8_append(const char *ptr) |
|
167 |
{
|
|
168 |
body_utf8_append(ptr, ptr); |
|
169 |
}
|
|
170 |
||
171 |
/**
|
|
172 |
The operation converts the specified text literal to the utf8 and appends
|
|
173 |
the result to the utf8-body.
|
|
174 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
175 |
@param session Thread context.
|
1
by brian
clean slate |
176 |
@param txt Text literal.
|
177 |
@param txt_cs Character set of the text literal.
|
|
178 |
@param end_ptr Pointer in the pre-processed buffer, to which
|
|
179 |
m_cpp_utf8_processed_ptr will be set in the end of the
|
|
180 |
operation.
|
|
181 |
*/
|
|
182 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
183 |
void Lex_input_stream::body_utf8_append_literal(Session *session, |
1
by brian
clean slate |
184 |
const LEX_STRING *txt, |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
185 |
const CHARSET_INFO * const txt_cs, |
1
by brian
clean slate |
186 |
const char *end_ptr) |
187 |
{
|
|
188 |
if (!m_cpp_utf8_processed_ptr) |
|
189 |
return; |
|
190 |
||
191 |
LEX_STRING utf_txt; |
|
192 |
||
193 |
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci)) |
|
194 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
195 |
session->convert_string(&utf_txt, |
1
by brian
clean slate |
196 |
&my_charset_utf8_general_ci, |
197 |
txt->str, txt->length, |
|
198 |
txt_cs); |
|
199 |
}
|
|
200 |
else
|
|
201 |
{
|
|
202 |
utf_txt.str= txt->str; |
|
203 |
utf_txt.length= txt->length; |
|
204 |
}
|
|
205 |
||
206 |
/* NOTE: utf_txt.length is in bytes, not in symbols. */
|
|
207 |
||
208 |
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length); |
|
209 |
m_body_utf8_ptr += utf_txt.length; |
|
210 |
*m_body_utf8_ptr= 0; |
|
211 |
||
212 |
m_cpp_utf8_processed_ptr= end_ptr; |
|
213 |
}
|
|
214 |
||
215 |
||
216 |
/*
|
|
217 |
This is called before every query that is to be parsed.
|
|
218 |
Because of this, it's critical to not do too much things here.
|
|
219 |
(We already do too much here)
|
|
220 |
*/
|
|
221 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
222 |
void lex_start(Session *session) |
1
by brian
clean slate |
223 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
224 |
LEX *lex= session->lex; |
1
by brian
clean slate |
225 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
226 |
lex->session= lex->unit.session= session; |
1
by brian
clean slate |
227 |
|
228 |
lex->context_stack.empty(); |
|
229 |
lex->unit.init_query(); |
|
230 |
lex->unit.init_select(); |
|
231 |
/* 'parent_lex' is used in init_query() so it must be before it. */
|
|
232 |
lex->select_lex.parent_lex= lex; |
|
233 |
lex->select_lex.init_query(); |
|
234 |
lex->value_list.empty(); |
|
235 |
lex->update_list.empty(); |
|
236 |
lex->param_list.empty(); |
|
237 |
lex->auxiliary_table_list.empty(); |
|
238 |
lex->unit.next= lex->unit.master= |
|
239 |
lex->unit.link_next= lex->unit.return_to= 0; |
|
240 |
lex->unit.prev= lex->unit.link_prev= 0; |
|
241 |
lex->unit.slave= lex->unit.global_parameters= lex->current_select= |
|
242 |
lex->all_selects_list= &lex->select_lex; |
|
243 |
lex->select_lex.master= &lex->unit; |
|
244 |
lex->select_lex.prev= &lex->unit.slave; |
|
245 |
lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0; |
|
847
by Brian Aker
More typdef class removal. |
246 |
lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list); |
1
by brian
clean slate |
247 |
lex->select_lex.options= 0; |
248 |
lex->select_lex.init_order(); |
|
249 |
lex->select_lex.group_list.empty(); |
|
250 |
lex->describe= 0; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
251 |
lex->subqueries= false; |
1
by brian
clean slate |
252 |
lex->derived_tables= 0; |
253 |
lex->lock_option= TL_READ; |
|
254 |
lex->leaf_tables_insert= 0; |
|
255 |
lex->parsing_options.reset(); |
|
256 |
lex->select_lex.select_number= 1; |
|
257 |
lex->length=0; |
|
258 |
lex->select_lex.in_sum_expr=0; |
|
259 |
lex->select_lex.ftfunc_list_alloc.empty(); |
|
260 |
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc; |
|
261 |
lex->select_lex.group_list.empty(); |
|
262 |
lex->select_lex.order_list.empty(); |
|
263 |
lex->sql_command= SQLCOM_END; |
|
264 |
lex->duplicates= DUP_ERROR; |
|
265 |
lex->ignore= 0; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
266 |
lex->escape_used= false; |
1
by brian
clean slate |
267 |
lex->query_tables= 0; |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
268 |
lex->reset_query_tables_list(false); |
269 |
lex->expr_allows_subselect= true; |
|
270 |
lex->use_only_table_context= false; |
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
271 |
lex->parse_vcol_expr= false; |
1
by brian
clean slate |
272 |
|
273 |
lex->name.str= 0; |
|
274 |
lex->name.length= 0; |
|
275 |
lex->nest_level=0 ; |
|
276 |
lex->allow_sum_func= 0; |
|
277 |
lex->in_sum_func= NULL; |
|
278 |
||
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
279 |
lex->is_lex_started= true; |
1
by brian
clean slate |
280 |
}
|
281 |
||
282 |
void lex_end(LEX *lex) |
|
283 |
{
|
|
284 |
if (lex->yacc_yyss) |
|
285 |
{
|
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
286 |
free(lex->yacc_yyss); |
287 |
free(lex->yacc_yyvs); |
|
1
by brian
clean slate |
288 |
lex->yacc_yyss= 0; |
289 |
lex->yacc_yyvs= 0; |
|
290 |
}
|
|
291 |
||
406
by Brian Aker
Cleanup around Query_arena. |
292 |
delete lex->result; |
293 |
lex->result= 0; |
|
1
by brian
clean slate |
294 |
}
|
295 |
||
296 |
||
482
by Brian Aker
Remove uint. |
297 |
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function) |
1
by brian
clean slate |
298 |
{
|
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
299 |
/* Plenty of memory for the largest lex symbol we have */
|
300 |
char tok_upper[64]; |
|
1
by brian
clean slate |
301 |
const char *tok= lip->get_tok_start(); |
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
302 |
uint32_t tok_pos= 0; |
303 |
for (;tok_pos<len && tok_pos<63;tok_pos++) |
|
304 |
tok_upper[tok_pos]=my_toupper(system_charset_info, tok[tok_pos]); |
|
305 |
tok_upper[tok_pos]=0; |
|
1
by brian
clean slate |
306 |
|
873.2.23
by Monty Taylor
Fixed a failure during gperf failure. |
307 |
const SYMBOL *symbol= lookup_symbol(tok_upper, len, function); |
1
by brian
clean slate |
308 |
if (symbol) |
309 |
{
|
|
310 |
lip->yylval->symbol.symbol=symbol; |
|
311 |
lip->yylval->symbol.str= (char*) tok; |
|
312 |
lip->yylval->symbol.length=len; |
|
313 |
||
314 |
return symbol->tok; |
|
315 |
}
|
|
686
by Brian Aker
Remove vector from lex for plugins. |
316 |
|
1
by brian
clean slate |
317 |
return 0; |
318 |
}
|
|
319 |
||
320 |
||
321 |
bool is_lex_native_function(const LEX_STRING *name) |
|
322 |
{
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
323 |
assert(name != NULL); |
873.2.23
by Monty Taylor
Fixed a failure during gperf failure. |
324 |
return (lookup_symbol(name->str, name->length, 1) != 0); |
1
by brian
clean slate |
325 |
}
|
326 |
||
327 |
/* make a copy of token before ptr and set yytoklen */
|
|
328 |
||
482
by Brian Aker
Remove uint. |
329 |
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length) |
1
by brian
clean slate |
330 |
{
|
331 |
LEX_STRING tmp; |
|
332 |
lip->yyUnget(); // ptr points now after last token char |
|
333 |
tmp.length=lip->yytoklen=length; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
334 |
tmp.str= lip->m_session->strmake(lip->get_tok_start() + skip, tmp.length); |
1
by brian
clean slate |
335 |
|
336 |
lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip; |
|
337 |
lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length; |
|
338 |
||
339 |
return tmp; |
|
340 |
}
|
|
341 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
342 |
/*
|
343 |
todo:
|
|
344 |
There are no dangerous charsets in mysql for function
|
|
345 |
get_quoted_token yet. But it should be fixed in the
|
|
1
by brian
clean slate |
346 |
future to operate multichar strings (like ucs2)
|
347 |
*/
|
|
348 |
||
349 |
static LEX_STRING get_quoted_token(Lex_input_stream *lip, |
|
482
by Brian Aker
Remove uint. |
350 |
uint32_t skip, |
351 |
uint32_t length, char quote) |
|
1
by brian
clean slate |
352 |
{
|
353 |
LEX_STRING tmp; |
|
354 |
const char *from, *end; |
|
355 |
char *to; |
|
356 |
lip->yyUnget(); // ptr points now after last token char |
|
357 |
tmp.length= lip->yytoklen=length; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
358 |
tmp.str=(char*) lip->m_session->alloc(tmp.length+1); |
1
by brian
clean slate |
359 |
from= lip->get_tok_start() + skip; |
360 |
to= tmp.str; |
|
361 |
end= to+length; |
|
362 |
||
363 |
lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip; |
|
364 |
lip->m_cpp_text_end= lip->m_cpp_text_start + length; |
|
365 |
||
366 |
for ( ; to != end; ) |
|
367 |
{
|
|
368 |
if ((*to++= *from++) == quote) |
|
369 |
{
|
|
370 |
from++; // Skip double quotes |
|
371 |
lip->m_cpp_text_start++; |
|
372 |
}
|
|
373 |
}
|
|
374 |
*to= 0; // End null for safety |
|
375 |
return tmp; |
|
376 |
}
|
|
377 |
||
378 |
||
379 |
/*
|
|
380 |
Return an unescaped text literal without quotes
|
|
381 |
Fix sometimes to do only one scan of the string
|
|
382 |
*/
|
|
383 |
||
384 |
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip) |
|
385 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
386 |
register unsigned char c,sep; |
482
by Brian Aker
Remove uint. |
387 |
uint32_t found_escape=0; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
388 |
const CHARSET_INFO * const cs= lip->m_session->charset(); |
1
by brian
clean slate |
389 |
|
390 |
lip->tok_bitmap= 0; |
|
391 |
sep= lip->yyGetLast(); // String should end with this |
|
392 |
while (! lip->eof()) |
|
393 |
{
|
|
394 |
c= lip->yyGet(); |
|
395 |
lip->tok_bitmap|= c; |
|
396 |
#ifdef USE_MB
|
|
397 |
{
|
|
398 |
int l; |
|
399 |
if (use_mb(cs) && |
|
400 |
(l = my_ismbchar(cs, |
|
401 |
lip->get_ptr() -1, |
|
402 |
lip->get_end_of_query()))) { |
|
403 |
lip->skip_binary(l-1); |
|
404 |
continue; |
|
405 |
}
|
|
406 |
}
|
|
407 |
#endif
|
|
408 |
if (c == '\\') |
|
409 |
{ // Escaped character |
|
410 |
found_escape=1; |
|
411 |
if (lip->eof()) |
|
412 |
return 0; |
|
413 |
lip->yySkip(); |
|
414 |
}
|
|
415 |
else if (c == sep) |
|
416 |
{
|
|
417 |
if (c == lip->yyGet()) // Check if two separators in a row |
|
418 |
{
|
|
419 |
found_escape=1; // duplicate. Remember for delete |
|
420 |
continue; |
|
421 |
}
|
|
422 |
else
|
|
423 |
lip->yyUnget(); |
|
424 |
||
425 |
/* Found end. Unescape and return string */
|
|
426 |
const char *str, *end; |
|
427 |
char *start; |
|
428 |
||
429 |
str= lip->get_tok_start(); |
|
430 |
end= lip->get_ptr(); |
|
431 |
/* Extract the text from the token */
|
|
432 |
str += pre_skip; |
|
433 |
end -= post_skip; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
434 |
assert(end >= str); |
1
by brian
clean slate |
435 |
|
895
by Brian Aker
Completion (?) of uint conversion. |
436 |
if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1))) |
1
by brian
clean slate |
437 |
return (char*) ""; // Sql_alloc has set error flag |
438 |
||
439 |
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip; |
|
440 |
lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip; |
|
441 |
||
442 |
if (!found_escape) |
|
443 |
{
|
|
895
by Brian Aker
Completion (?) of uint conversion. |
444 |
lip->yytoklen=(uint32_t) (end-str); |
1
by brian
clean slate |
445 |
memcpy(start,str,lip->yytoklen); |
446 |
start[lip->yytoklen]=0; |
|
447 |
}
|
|
448 |
else
|
|
449 |
{
|
|
450 |
char *to; |
|
451 |
||
452 |
for (to=start ; str != end ; str++) |
|
453 |
{
|
|
454 |
#ifdef USE_MB
|
|
455 |
int l; |
|
456 |
if (use_mb(cs) && |
|
457 |
(l = my_ismbchar(cs, str, end))) { |
|
458 |
while (l--) |
|
459 |
*to++ = *str++; |
|
460 |
str--; |
|
461 |
continue; |
|
462 |
}
|
|
463 |
#endif
|
|
360
by Brian Aker
More MODE removal. |
464 |
if (*str == '\\' && str+1 != end) |
1
by brian
clean slate |
465 |
{
|
466 |
switch(*++str) { |
|
467 |
case 'n': |
|
468 |
*to++='\n'; |
|
469 |
break; |
|
470 |
case 't': |
|
471 |
*to++= '\t'; |
|
472 |
break; |
|
473 |
case 'r': |
|
474 |
*to++ = '\r'; |
|
475 |
break; |
|
476 |
case 'b': |
|
477 |
*to++ = '\b'; |
|
478 |
break; |
|
479 |
case '0': |
|
480 |
*to++= 0; // Ascii null |
|
481 |
break; |
|
482 |
case 'Z': // ^Z must be escaped on Win32 |
|
483 |
*to++='\032'; |
|
484 |
break; |
|
485 |
case '_': |
|
486 |
case '%': |
|
487 |
*to++= '\\'; // remember prefix for wildcard |
|
488 |
/* Fall through */
|
|
489 |
default: |
|
490 |
*to++= *str; |
|
491 |
break; |
|
492 |
}
|
|
493 |
}
|
|
494 |
else if (*str == sep) |
|
495 |
*to++= *str++; // Two ' or " |
|
496 |
else
|
|
497 |
*to++ = *str; |
|
498 |
}
|
|
499 |
*to=0; |
|
895
by Brian Aker
Completion (?) of uint conversion. |
500 |
lip->yytoklen=(uint32_t) (to-start); |
1
by brian
clean slate |
501 |
}
|
502 |
return start; |
|
503 |
}
|
|
504 |
}
|
|
505 |
return 0; // unexpected end of query |
|
506 |
}
|
|
507 |
||
508 |
||
509 |
/*
|
|
152
by Brian Aker
longlong replacement |
510 |
** Calc type of integer; long integer, int64_t integer or real.
|
1
by brian
clean slate |
511 |
** Returns smallest type that match the string.
|
481.1.2
by Monty Taylor
Replaced all unsigned long long with uint64_t. |
512 |
** When using uint64_t values the result is converted to a real
|
1
by brian
clean slate |
513 |
** because else they will be unexpected sign changes because all calculation
|
152
by Brian Aker
longlong replacement |
514 |
** is done with int64_t or double.
|
1
by brian
clean slate |
515 |
*/
|
516 |
||
517 |
static const char *long_str="2147483647"; |
|
482
by Brian Aker
Remove uint. |
518 |
static const uint32_t long_len=10; |
1
by brian
clean slate |
519 |
static const char *signed_long_str="-2147483648"; |
152
by Brian Aker
longlong replacement |
520 |
static const char *int64_t_str="9223372036854775807"; |
482
by Brian Aker
Remove uint. |
521 |
static const uint32_t int64_t_len=19; |
152
by Brian Aker
longlong replacement |
522 |
static const char *signed_int64_t_str="-9223372036854775808"; |
482
by Brian Aker
Remove uint. |
523 |
static const uint32_t signed_int64_t_len=19; |
152
by Brian Aker
longlong replacement |
524 |
static const char *unsigned_int64_t_str="18446744073709551615"; |
482
by Brian Aker
Remove uint. |
525 |
static const uint32_t unsigned_int64_t_len=20; |
1
by brian
clean slate |
526 |
|
482
by Brian Aker
Remove uint. |
527 |
static inline uint32_t int_token(const char *str,uint32_t length) |
1
by brian
clean slate |
528 |
{
|
529 |
if (length < long_len) // quick normal case |
|
530 |
return NUM; |
|
531 |
bool neg=0; |
|
532 |
||
533 |
if (*str == '+') // Remove sign and pre-zeros |
|
534 |
{
|
|
535 |
str++; length--; |
|
536 |
}
|
|
537 |
else if (*str == '-') |
|
538 |
{
|
|
539 |
str++; length--; |
|
540 |
neg=1; |
|
541 |
}
|
|
542 |
while (*str == '0' && length) |
|
543 |
{
|
|
544 |
str++; length --; |
|
545 |
}
|
|
546 |
if (length < long_len) |
|
547 |
return NUM; |
|
548 |
||
482
by Brian Aker
Remove uint. |
549 |
uint32_t smaller,bigger; |
1
by brian
clean slate |
550 |
const char *cmp; |
551 |
if (neg) |
|
552 |
{
|
|
553 |
if (length == long_len) |
|
554 |
{
|
|
555 |
cmp= signed_long_str+1; |
|
556 |
smaller=NUM; // If <= signed_long_str |
|
557 |
bigger=LONG_NUM; // If >= signed_long_str |
|
558 |
}
|
|
152
by Brian Aker
longlong replacement |
559 |
else if (length < signed_int64_t_len) |
1
by brian
clean slate |
560 |
return LONG_NUM; |
152
by Brian Aker
longlong replacement |
561 |
else if (length > signed_int64_t_len) |
1
by brian
clean slate |
562 |
return DECIMAL_NUM; |
563 |
else
|
|
564 |
{
|
|
152
by Brian Aker
longlong replacement |
565 |
cmp=signed_int64_t_str+1; |
566 |
smaller=LONG_NUM; // If <= signed_int64_t_str |
|
1
by brian
clean slate |
567 |
bigger=DECIMAL_NUM; |
568 |
}
|
|
569 |
}
|
|
570 |
else
|
|
571 |
{
|
|
572 |
if (length == long_len) |
|
573 |
{
|
|
574 |
cmp= long_str; |
|
575 |
smaller=NUM; |
|
576 |
bigger=LONG_NUM; |
|
577 |
}
|
|
152
by Brian Aker
longlong replacement |
578 |
else if (length < int64_t_len) |
1
by brian
clean slate |
579 |
return LONG_NUM; |
152
by Brian Aker
longlong replacement |
580 |
else if (length > int64_t_len) |
1
by brian
clean slate |
581 |
{
|
152
by Brian Aker
longlong replacement |
582 |
if (length > unsigned_int64_t_len) |
1
by brian
clean slate |
583 |
return DECIMAL_NUM; |
152
by Brian Aker
longlong replacement |
584 |
cmp=unsigned_int64_t_str; |
1
by brian
clean slate |
585 |
smaller=ULONGLONG_NUM; |
586 |
bigger=DECIMAL_NUM; |
|
587 |
}
|
|
588 |
else
|
|
589 |
{
|
|
152
by Brian Aker
longlong replacement |
590 |
cmp=int64_t_str; |
1
by brian
clean slate |
591 |
smaller=LONG_NUM; |
592 |
bigger= ULONGLONG_NUM; |
|
593 |
}
|
|
594 |
}
|
|
595 |
while (*cmp && *cmp++ == *str++) ; |
|
481
by Brian Aker
Remove all of uchar. |
596 |
return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger; |
1
by brian
clean slate |
597 |
}
|
598 |
||
599 |
||
600 |
/*
|
|
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
601 |
DRIZZLElex remember the following states from the following DRIZZLElex()
|
1
by brian
clean slate |
602 |
|
603 |
- MY_LEX_EOQ Found end of query
|
|
604 |
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
|
|
605 |
(which can't be followed by a signed number)
|
|
606 |
*/
|
|
607 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
608 |
int DRIZZLElex(void *arg, void *yysession) |
1
by brian
clean slate |
609 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
610 |
Session *session= (Session *)yysession; |
611 |
Lex_input_stream *lip= session->m_lip; |
|
1
by brian
clean slate |
612 |
YYSTYPE *yylval=(YYSTYPE*) arg; |
613 |
int token; |
|
614 |
||
615 |
if (lip->lookahead_token != END_OF_INPUT) |
|
616 |
{
|
|
617 |
/*
|
|
618 |
The next token was already parsed in advance,
|
|
619 |
return it.
|
|
620 |
*/
|
|
621 |
token= lip->lookahead_token; |
|
622 |
lip->lookahead_token= END_OF_INPUT; |
|
623 |
*yylval= *(lip->lookahead_yylval); |
|
624 |
lip->lookahead_yylval= NULL; |
|
625 |
return token; |
|
626 |
}
|
|
627 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
628 |
token= lex_one_token(arg, yysession); |
1
by brian
clean slate |
629 |
|
630 |
switch(token) { |
|
631 |
case WITH: |
|
632 |
/*
|
|
436
by Brian Aker
Removed non-existent CUBE operator. |
633 |
Parsing 'WITH' 'ROLLUP' requires 2 look ups,
|
1
by brian
clean slate |
634 |
which makes the grammar LALR(2).
|
635 |
Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
|
|
636 |
to transform the grammar into a LALR(1) grammar,
|
|
637 |
which sql_yacc.yy can process.
|
|
638 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
639 |
token= lex_one_token(arg, yysession); |
436
by Brian Aker
Removed non-existent CUBE operator. |
640 |
if (token == ROLLUP_SYM) |
641 |
{
|
|
1
by brian
clean slate |
642 |
return WITH_ROLLUP_SYM; |
436
by Brian Aker
Removed non-existent CUBE operator. |
643 |
}
|
644 |
else
|
|
645 |
{
|
|
1
by brian
clean slate |
646 |
/*
|
647 |
Save the token following 'WITH'
|
|
648 |
*/
|
|
649 |
lip->lookahead_yylval= lip->yylval; |
|
650 |
lip->yylval= NULL; |
|
651 |
lip->lookahead_token= token; |
|
652 |
return WITH; |
|
653 |
}
|
|
654 |
default: |
|
655 |
break; |
|
656 |
}
|
|
657 |
||
658 |
return token; |
|
659 |
}
|
|
660 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
661 |
int lex_one_token(void *arg, void *yysession) |
1
by brian
clean slate |
662 |
{
|
663 |
register unsigned char c= 0; /* Just set to shutup GCC */ |
|
664 |
bool comment_closed; |
|
665 |
int tokval, result_state; |
|
666 |
unsigned int length; |
|
667 |
enum my_lex_states state; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
668 |
Session *session= (Session *)yysession; |
669 |
Lex_input_stream *lip= session->m_lip; |
|
670 |
LEX *lex= session->lex; |
|
1
by brian
clean slate |
671 |
YYSTYPE *yylval=(YYSTYPE*) arg; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
672 |
const CHARSET_INFO * const cs= session->charset(); |
481
by Brian Aker
Remove all of uchar. |
673 |
unsigned char *state_map= cs->state_map; |
674 |
unsigned char *ident_map= cs->ident_map; |
|
1
by brian
clean slate |
675 |
|
676 |
lip->yylval=yylval; // The global state |
|
677 |
||
678 |
lip->start_token(); |
|
679 |
state=lip->next_state; |
|
680 |
lip->next_state=MY_LEX_OPERATOR_OR_IDENT; |
|
681 |
for (;;) |
|
682 |
{
|
|
683 |
switch (state) { |
|
684 |
case MY_LEX_OPERATOR_OR_IDENT: // Next is operator or keyword |
|
685 |
case MY_LEX_START: // Start of token |
|
686 |
// Skip starting whitespace
|
|
687 |
while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP) |
|
688 |
{
|
|
689 |
if (c == '\n') |
|
690 |
lip->yylineno++; |
|
691 |
||
692 |
lip->yySkip(); |
|
693 |
}
|
|
694 |
||
695 |
/* Start of real token */
|
|
696 |
lip->restart_token(); |
|
697 |
c= lip->yyGet(); |
|
698 |
state= (enum my_lex_states) state_map[c]; |
|
699 |
break; |
|
700 |
case MY_LEX_ESCAPE: |
|
701 |
if (lip->yyGet() == 'N') |
|
702 |
{ // Allow \N as shortcut for NULL |
|
703 |
yylval->lex_str.str=(char*) "\\N"; |
|
704 |
yylval->lex_str.length=2; |
|
705 |
return NULL_SYM; |
|
706 |
}
|
|
707 |
case MY_LEX_CHAR: // Unknown or single char token |
|
708 |
case MY_LEX_SKIP: // This should not happen |
|
709 |
if (c == '-' && lip->yyPeek() == '-' && |
|
710 |
(my_isspace(cs,lip->yyPeekn(1)) || |
|
711 |
my_iscntrl(cs,lip->yyPeekn(1)))) |
|
712 |
{
|
|
713 |
state=MY_LEX_COMMENT; |
|
714 |
break; |
|
715 |
}
|
|
716 |
||
717 |
if (c != ')') |
|
718 |
lip->next_state= MY_LEX_START; // Allow signed numbers |
|
719 |
||
720 |
if (c == ',') |
|
721 |
{
|
|
722 |
/*
|
|
723 |
Warning:
|
|
724 |
This is a work around, to make the "remember_name" rule in
|
|
725 |
sql/sql_yacc.yy work properly.
|
|
726 |
The problem is that, when parsing "select expr1, expr2",
|
|
727 |
the code generated by bison executes the *pre* action
|
|
728 |
remember_name (see select_item) *before* actually parsing the
|
|
729 |
first token of expr2.
|
|
730 |
*/
|
|
731 |
lip->restart_token(); |
|
732 |
}
|
|
733 |
||
734 |
return((int) c); |
|
735 |
||
736 |
case MY_LEX_IDENT_OR_HEX: |
|
737 |
if (lip->yyPeek() == '\'') |
|
738 |
{ // Found x'hex-number' |
|
739 |
state= MY_LEX_HEX_NUMBER; |
|
740 |
break; |
|
741 |
}
|
|
742 |
case MY_LEX_IDENT_OR_BIN: |
|
743 |
if (lip->yyPeek() == '\'') |
|
744 |
{ // Found b'bin-number' |
|
745 |
state= MY_LEX_BIN_NUMBER; |
|
746 |
break; |
|
747 |
}
|
|
748 |
case MY_LEX_IDENT: |
|
749 |
const char *start; |
|
750 |
#if defined(USE_MB) && defined(USE_MB_IDENT)
|
|
751 |
if (use_mb(cs)) |
|
752 |
{
|
|
753 |
result_state= IDENT_QUOTED; |
|
754 |
if (my_mbcharlen(cs, lip->yyGetLast()) > 1) |
|
755 |
{
|
|
756 |
int l = my_ismbchar(cs, |
|
757 |
lip->get_ptr() -1, |
|
758 |
lip->get_end_of_query()); |
|
759 |
if (l == 0) { |
|
760 |
state = MY_LEX_CHAR; |
|
761 |
continue; |
|
762 |
}
|
|
763 |
lip->skip_binary(l - 1); |
|
764 |
}
|
|
765 |
while (ident_map[c=lip->yyGet()]) |
|
766 |
{
|
|
767 |
if (my_mbcharlen(cs, c) > 1) |
|
768 |
{
|
|
769 |
int l; |
|
770 |
if ((l = my_ismbchar(cs, |
|
771 |
lip->get_ptr() -1, |
|
772 |
lip->get_end_of_query())) == 0) |
|
773 |
break; |
|
774 |
lip->skip_binary(l-1); |
|
775 |
}
|
|
776 |
}
|
|
777 |
}
|
|
778 |
else
|
|
779 |
#endif
|
|
780 |
{
|
|
781 |
for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {}; |
|
782 |
/* If there were non-ASCII characters, mark that we must convert */
|
|
783 |
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; |
|
784 |
}
|
|
785 |
length= lip->yyLength(); |
|
786 |
start= lip->get_ptr(); |
|
787 |
if (lip->ignore_space) |
|
788 |
{
|
|
789 |
/*
|
|
790 |
If we find a space then this can't be an identifier. We notice this
|
|
791 |
below by checking start != lex->ptr.
|
|
792 |
*/
|
|
793 |
for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {}; |
|
794 |
}
|
|
795 |
if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()]) |
|
796 |
lip->next_state=MY_LEX_IDENT_SEP; |
|
797 |
else
|
|
798 |
{ // '(' must follow directly if function |
|
799 |
lip->yyUnget(); |
|
800 |
if ((tokval = find_keyword(lip, length, c == '('))) |
|
801 |
{
|
|
802 |
lip->next_state= MY_LEX_START; // Allow signed numbers |
|
803 |
return(tokval); // Was keyword |
|
804 |
}
|
|
805 |
lip->yySkip(); // next state does a unget |
|
806 |
}
|
|
807 |
yylval->lex_str=get_token(lip, 0, length); |
|
808 |
||
809 |
lip->body_utf8_append(lip->m_cpp_text_start); |
|
810 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
811 |
lip->body_utf8_append_literal(session, &yylval->lex_str, cs, |
1
by brian
clean slate |
812 |
lip->m_cpp_text_end); |
813 |
||
814 |
return(result_state); // IDENT or IDENT_QUOTED |
|
815 |
||
816 |
case MY_LEX_IDENT_SEP: // Found ident and now '.' |
|
817 |
yylval->lex_str.str= (char*) lip->get_ptr(); |
|
818 |
yylval->lex_str.length= 1; |
|
819 |
c= lip->yyGet(); // should be '.' |
|
820 |
lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword) |
|
821 |
if (!ident_map[(uint8_t)lip->yyPeek()]) // Probably ` or " |
|
822 |
lip->next_state= MY_LEX_START; |
|
823 |
return((int) c); |
|
824 |
||
825 |
case MY_LEX_NUMBER_IDENT: // number or ident which num-start |
|
826 |
if (lip->yyGetLast() == '0') |
|
827 |
{
|
|
828 |
c= lip->yyGet(); |
|
829 |
if (c == 'x') |
|
830 |
{
|
|
831 |
while (my_isxdigit(cs,(c = lip->yyGet()))) ; |
|
832 |
if ((lip->yyLength() >= 3) && !ident_map[c]) |
|
833 |
{
|
|
834 |
/* skip '0x' */
|
|
835 |
yylval->lex_str=get_token(lip, 2, lip->yyLength()-2); |
|
836 |
return (HEX_NUM); |
|
837 |
}
|
|
838 |
lip->yyUnget(); |
|
839 |
state= MY_LEX_IDENT_START; |
|
840 |
break; |
|
841 |
}
|
|
842 |
else if (c == 'b') |
|
843 |
{
|
|
844 |
while ((c= lip->yyGet()) == '0' || c == '1') {}; |
|
845 |
if ((lip->yyLength() >= 3) && !ident_map[c]) |
|
846 |
{
|
|
847 |
/* Skip '0b' */
|
|
848 |
yylval->lex_str= get_token(lip, 2, lip->yyLength()-2); |
|
849 |
return (BIN_NUM); |
|
850 |
}
|
|
851 |
lip->yyUnget(); |
|
852 |
state= MY_LEX_IDENT_START; |
|
853 |
break; |
|
854 |
}
|
|
855 |
lip->yyUnget(); |
|
856 |
}
|
|
857 |
||
858 |
while (my_isdigit(cs, (c = lip->yyGet()))) ; |
|
859 |
if (!ident_map[c]) |
|
860 |
{ // Can't be identifier |
|
861 |
state=MY_LEX_INT_OR_REAL; |
|
862 |
break; |
|
863 |
}
|
|
864 |
if (c == 'e' || c == 'E') |
|
865 |
{
|
|
866 |
// The following test is written this way to allow numbers of type 1e1
|
|
867 |
if (my_isdigit(cs,lip->yyPeek()) || |
|
868 |
(c=(lip->yyGet())) == '+' || c == '-') |
|
869 |
{ // Allow 1E+10 |
|
870 |
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign |
|
871 |
{
|
|
872 |
lip->yySkip(); |
|
873 |
while (my_isdigit(cs,lip->yyGet())) ; |
|
874 |
yylval->lex_str=get_token(lip, 0, lip->yyLength()); |
|
875 |
return(FLOAT_NUM); |
|
876 |
}
|
|
877 |
}
|
|
878 |
lip->yyUnget(); |
|
879 |
}
|
|
880 |
// fall through
|
|
881 |
case MY_LEX_IDENT_START: // We come here after '.' |
|
882 |
result_state= IDENT; |
|
883 |
#if defined(USE_MB) && defined(USE_MB_IDENT)
|
|
884 |
if (use_mb(cs)) |
|
885 |
{
|
|
886 |
result_state= IDENT_QUOTED; |
|
887 |
while (ident_map[c=lip->yyGet()]) |
|
888 |
{
|
|
889 |
if (my_mbcharlen(cs, c) > 1) |
|
890 |
{
|
|
891 |
int l; |
|
892 |
if ((l = my_ismbchar(cs, |
|
893 |
lip->get_ptr() -1, |
|
894 |
lip->get_end_of_query())) == 0) |
|
895 |
break; |
|
896 |
lip->skip_binary(l-1); |
|
897 |
}
|
|
898 |
}
|
|
899 |
}
|
|
900 |
else
|
|
901 |
#endif
|
|
902 |
{
|
|
903 |
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {}; |
|
904 |
/* If there were non-ASCII characters, mark that we must convert */
|
|
905 |
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; |
|
906 |
}
|
|
907 |
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()]) |
|
908 |
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.' |
|
909 |
||
910 |
yylval->lex_str= get_token(lip, 0, lip->yyLength()); |
|
911 |
||
912 |
lip->body_utf8_append(lip->m_cpp_text_start); |
|
913 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
914 |
lip->body_utf8_append_literal(session, &yylval->lex_str, cs, |
1
by brian
clean slate |
915 |
lip->m_cpp_text_end); |
916 |
||
917 |
return(result_state); |
|
918 |
||
919 |
case MY_LEX_USER_VARIABLE_DELIMITER: // Found quote char |
|
920 |
{
|
|
482
by Brian Aker
Remove uint. |
921 |
uint32_t double_quotes= 0; |
1
by brian
clean slate |
922 |
char quote_char= c; // Used char |
923 |
while ((c=lip->yyGet())) |
|
924 |
{
|
|
925 |
int var_length; |
|
926 |
if ((var_length= my_mbcharlen(cs, c)) == 1) |
|
927 |
{
|
|
928 |
if (c == quote_char) |
|
929 |
{
|
|
930 |
if (lip->yyPeek() != quote_char) |
|
931 |
break; |
|
932 |
c=lip->yyGet(); |
|
933 |
double_quotes++; |
|
934 |
continue; |
|
935 |
}
|
|
936 |
}
|
|
937 |
#ifdef USE_MB
|
|
938 |
else if (var_length < 1) |
|
939 |
break; // Error |
|
940 |
lip->skip_binary(var_length-1); |
|
941 |
#endif
|
|
942 |
}
|
|
943 |
if (double_quotes) |
|
944 |
yylval->lex_str=get_quoted_token(lip, 1, |
|
945 |
lip->yyLength() - double_quotes -1, |
|
946 |
quote_char); |
|
947 |
else
|
|
948 |
yylval->lex_str=get_token(lip, 1, lip->yyLength() -1); |
|
949 |
if (c == quote_char) |
|
950 |
lip->yySkip(); // Skip end ` |
|
951 |
lip->next_state= MY_LEX_START; |
|
952 |
||
953 |
lip->body_utf8_append(lip->m_cpp_text_start); |
|
954 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
955 |
lip->body_utf8_append_literal(session, &yylval->lex_str, cs, |
1
by brian
clean slate |
956 |
lip->m_cpp_text_end); |
957 |
||
958 |
return(IDENT_QUOTED); |
|
959 |
}
|
|
960 |
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real |
|
961 |
if (c != '.') |
|
962 |
{ // Found complete integer number. |
|
963 |
yylval->lex_str=get_token(lip, 0, lip->yyLength()); |
|
964 |
return int_token(yylval->lex_str.str,yylval->lex_str.length); |
|
965 |
}
|
|
966 |
// fall through
|
|
967 |
case MY_LEX_REAL: // Incomplete real number |
|
968 |
while (my_isdigit(cs,c = lip->yyGet())) ; |
|
969 |
||
970 |
if (c == 'e' || c == 'E') |
|
971 |
{
|
|
972 |
c = lip->yyGet(); |
|
973 |
if (c == '-' || c == '+') |
|
974 |
c = lip->yyGet(); // Skip sign |
|
975 |
if (!my_isdigit(cs,c)) |
|
976 |
{ // No digit after sign |
|
977 |
state= MY_LEX_CHAR; |
|
978 |
break; |
|
979 |
}
|
|
980 |
while (my_isdigit(cs,lip->yyGet())) ; |
|
981 |
yylval->lex_str=get_token(lip, 0, lip->yyLength()); |
|
982 |
return(FLOAT_NUM); |
|
983 |
}
|
|
984 |
yylval->lex_str=get_token(lip, 0, lip->yyLength()); |
|
985 |
return(DECIMAL_NUM); |
|
986 |
||
987 |
case MY_LEX_HEX_NUMBER: // Found x'hexstring' |
|
988 |
lip->yySkip(); // Accept opening ' |
|
989 |
while (my_isxdigit(cs, (c= lip->yyGet()))) ; |
|
990 |
if (c != '\'') |
|
991 |
return(ABORT_SYM); // Illegal hex constant |
|
992 |
lip->yySkip(); // Accept closing ' |
|
993 |
length= lip->yyLength(); // Length of hexnum+3 |
|
994 |
if ((length % 2) == 0) |
|
995 |
return(ABORT_SYM); // odd number of hex digits |
|
996 |
yylval->lex_str=get_token(lip, |
|
997 |
2, // skip x' |
|
998 |
length-3); // don't count x' and last ' |
|
999 |
return (HEX_NUM); |
|
1000 |
||
1001 |
case MY_LEX_BIN_NUMBER: // Found b'bin-string' |
|
1002 |
lip->yySkip(); // Accept opening ' |
|
1003 |
while ((c= lip->yyGet()) == '0' || c == '1') {}; |
|
1004 |
if (c != '\'') |
|
1005 |
return(ABORT_SYM); // Illegal hex constant |
|
1006 |
lip->yySkip(); // Accept closing ' |
|
1007 |
length= lip->yyLength(); // Length of bin-num + 3 |
|
1008 |
yylval->lex_str= get_token(lip, |
|
1009 |
2, // skip b' |
|
1010 |
length-3); // don't count b' and last ' |
|
1011 |
return (BIN_NUM); |
|
1012 |
||
1013 |
case MY_LEX_CMP_OP: // Incomplete comparison operator |
|
1014 |
if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP || |
|
1015 |
state_map[(uint8_t)lip->yyPeek()] == MY_LEX_LONG_CMP_OP) |
|
1016 |
lip->yySkip(); |
|
1017 |
if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0))) |
|
1018 |
{
|
|
1019 |
lip->next_state= MY_LEX_START; // Allow signed numbers |
|
1020 |
return(tokval); |
|
1021 |
}
|
|
1022 |
state = MY_LEX_CHAR; // Something fishy found |
|
1023 |
break; |
|
1024 |
||
1025 |
case MY_LEX_LONG_CMP_OP: // Incomplete comparison operator |
|
1026 |
if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP || |
|
1027 |
state_map[(uint8_t)lip->yyPeek()] == MY_LEX_LONG_CMP_OP) |
|
1028 |
{
|
|
1029 |
lip->yySkip(); |
|
1030 |
if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP) |
|
1031 |
lip->yySkip(); |
|
1032 |
}
|
|
1033 |
if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0))) |
|
1034 |
{
|
|
1035 |
lip->next_state= MY_LEX_START; // Found long op |
|
1036 |
return(tokval); |
|
1037 |
}
|
|
1038 |
state = MY_LEX_CHAR; // Something fishy found |
|
1039 |
break; |
|
1040 |
||
1041 |
case MY_LEX_BOOL: |
|
1042 |
if (c != lip->yyPeek()) |
|
1043 |
{
|
|
1044 |
state=MY_LEX_CHAR; |
|
1045 |
break; |
|
1046 |
}
|
|
1047 |
lip->yySkip(); |
|
1048 |
tokval = find_keyword(lip,2,0); // Is a bool operator |
|
1049 |
lip->next_state= MY_LEX_START; // Allow signed numbers |
|
1050 |
return(tokval); |
|
1051 |
||
1052 |
case MY_LEX_STRING_OR_DELIMITER: |
|
1053 |
if (0) |
|
1054 |
{
|
|
1055 |
state= MY_LEX_USER_VARIABLE_DELIMITER; |
|
1056 |
break; |
|
1057 |
}
|
|
1058 |
/* " used for strings */
|
|
1059 |
case MY_LEX_STRING: // Incomplete text string |
|
1060 |
if (!(yylval->lex_str.str = get_text(lip, 1, 1))) |
|
1061 |
{
|
|
1062 |
state= MY_LEX_CHAR; // Read char by char |
|
1063 |
break; |
|
1064 |
}
|
|
1065 |
yylval->lex_str.length=lip->yytoklen; |
|
1066 |
||
1067 |
lip->body_utf8_append(lip->m_cpp_text_start); |
|
1068 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1069 |
lip->body_utf8_append_literal(session, &yylval->lex_str, |
1
by brian
clean slate |
1070 |
lip->m_underscore_cs ? lip->m_underscore_cs : cs, |
1071 |
lip->m_cpp_text_end); |
|
1072 |
||
1073 |
lip->m_underscore_cs= NULL; |
|
1074 |
||
1075 |
lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1; |
|
1076 |
return(TEXT_STRING); |
|
1077 |
||
1078 |
case MY_LEX_COMMENT: // Comment |
|
1079 |
lex->select_lex.options|= OPTION_FOUND_COMMENT; |
|
1080 |
while ((c = lip->yyGet()) != '\n' && c) ; |
|
1081 |
lip->yyUnget(); // Safety against eof |
|
1082 |
state = MY_LEX_START; // Try again |
|
1083 |
break; |
|
1084 |
case MY_LEX_LONG_COMMENT: /* Long C comment? */ |
|
1085 |
if (lip->yyPeek() != '*') |
|
1086 |
{
|
|
1087 |
state=MY_LEX_CHAR; // Probable division |
|
1088 |
break; |
|
1089 |
}
|
|
1090 |
lex->select_lex.options|= OPTION_FOUND_COMMENT; |
|
1091 |
/* Reject '/' '*', since we might need to turn off the echo */
|
|
1092 |
lip->yyUnget(); |
|
1093 |
||
1094 |
if (lip->yyPeekn(2) == '!') |
|
1095 |
{
|
|
1096 |
lip->in_comment= DISCARD_COMMENT; |
|
1097 |
/* Accept '/' '*' '!', but do not keep this marker. */
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1098 |
lip->set_echo(false); |
1
by brian
clean slate |
1099 |
lip->yySkip(); |
1100 |
lip->yySkip(); |
|
1101 |
lip->yySkip(); |
|
1102 |
||
1103 |
/*
|
|
1104 |
The special comment format is very strict:
|
|
908.1.15
by Monty Taylor
Updated comment version indicators to handle drizzle versions. |
1105 |
'/' '*' '!', followed by digits ended by a non-digit.
|
1106 |
There must be at least 5 digits for it to count
|
|
1
by brian
clean slate |
1107 |
*/
|
908.1.15
by Monty Taylor
Updated comment version indicators to handle drizzle versions. |
1108 |
const int MAX_VERSION_SIZE= 16; |
1109 |
char version_str[MAX_VERSION_SIZE]; |
|
1110 |
||
1111 |
int pos= 0; |
|
1112 |
do
|
|
1113 |
{
|
|
1114 |
version_str[pos]= lip->yyPeekn(pos); |
|
1115 |
pos++; |
|
1116 |
} while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1])); |
|
1117 |
version_str[pos]= 0; |
|
1118 |
||
1119 |
/* To keep some semblance of compatibility, we impose a 5 digit floor */
|
|
1120 |
if (pos > 4) |
|
1121 |
{
|
|
1122 |
uint64_t version; |
|
1123 |
version=strtoll(version_str, NULL, 10); |
|
1
by brian
clean slate |
1124 |
|
1125 |
/* Accept 'M' 'm' 'm' 'd' 'd' */
|
|
908.1.15
by Monty Taylor
Updated comment version indicators to handle drizzle versions. |
1126 |
lip->yySkipn(pos-1); |
1
by brian
clean slate |
1127 |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
1128 |
if (version <= DRIZZLE_VERSION_ID) |
1
by brian
clean slate |
1129 |
{
|
1130 |
/* Expand the content of the special comment as real code */
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1131 |
lip->set_echo(true); |
1
by brian
clean slate |
1132 |
state=MY_LEX_START; |
1133 |
break; |
|
1134 |
}
|
|
1135 |
}
|
|
1136 |
else
|
|
1137 |
{
|
|
1138 |
state=MY_LEX_START; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1139 |
lip->set_echo(true); |
1
by brian
clean slate |
1140 |
break; |
1141 |
}
|
|
1142 |
}
|
|
1143 |
else
|
|
1144 |
{
|
|
1145 |
lip->in_comment= PRESERVE_COMMENT; |
|
1146 |
lip->yySkip(); // Accept / |
|
1147 |
lip->yySkip(); // Accept * |
|
1148 |
}
|
|
1149 |
/*
|
|
1150 |
Discard:
|
|
1151 |
- regular '/' '*' comments,
|
|
1152 |
- special comments '/' '*' '!' for a future version,
|
|
1153 |
by scanning until we find a closing '*' '/' marker.
|
|
1154 |
Note: There is no such thing as nesting comments,
|
|
1155 |
the first '*' '/' sequence seen will mark the end.
|
|
1156 |
*/
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1157 |
comment_closed= false; |
1
by brian
clean slate |
1158 |
while (! lip->eof()) |
1159 |
{
|
|
1160 |
c= lip->yyGet(); |
|
1161 |
if (c == '*') |
|
1162 |
{
|
|
1163 |
if (lip->yyPeek() == '/') |
|
1164 |
{
|
|
1165 |
lip->yySkip(); |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1166 |
comment_closed= true; |
1
by brian
clean slate |
1167 |
state = MY_LEX_START; |
1168 |
break; |
|
1169 |
}
|
|
1170 |
}
|
|
1171 |
else if (c == '\n') |
|
1172 |
lip->yylineno++; |
|
1173 |
}
|
|
1174 |
/* Unbalanced comments with a missing '*' '/' are a syntax error */
|
|
1175 |
if (! comment_closed) |
|
1176 |
return (ABORT_SYM); |
|
1177 |
state = MY_LEX_START; // Try again |
|
1178 |
lip->in_comment= NO_COMMENT; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1179 |
lip->set_echo(true); |
1
by brian
clean slate |
1180 |
break; |
1181 |
case MY_LEX_END_LONG_COMMENT: |
|
1182 |
if ((lip->in_comment != NO_COMMENT) && lip->yyPeek() == '/') |
|
1183 |
{
|
|
1184 |
/* Reject '*' '/' */
|
|
1185 |
lip->yyUnget(); |
|
1186 |
/* Accept '*' '/', with the proper echo */
|
|
1187 |
lip->set_echo(lip->in_comment == PRESERVE_COMMENT); |
|
1188 |
lip->yySkipn(2); |
|
1189 |
/* And start recording the tokens again */
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1190 |
lip->set_echo(true); |
1
by brian
clean slate |
1191 |
lip->in_comment=NO_COMMENT; |
1192 |
state=MY_LEX_START; |
|
1193 |
}
|
|
1194 |
else
|
|
1195 |
state=MY_LEX_CHAR; // Return '*' |
|
1196 |
break; |
|
1197 |
case MY_LEX_SET_VAR: // Check if ':=' |
|
1198 |
if (lip->yyPeek() != '=') |
|
1199 |
{
|
|
1200 |
state=MY_LEX_CHAR; // Return ':' |
|
1201 |
break; |
|
1202 |
}
|
|
1203 |
lip->yySkip(); |
|
1204 |
return (SET_VAR); |
|
1205 |
case MY_LEX_SEMICOLON: // optional line terminator |
|
1206 |
if (lip->yyPeek()) |
|
1207 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1208 |
if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS)) |
1
by brian
clean slate |
1209 |
{
|
1210 |
lip->found_semicolon= lip->get_ptr(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1211 |
session->server_status|= SERVER_MORE_RESULTS_EXISTS; |
1
by brian
clean slate |
1212 |
lip->next_state= MY_LEX_END; |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1213 |
lip->set_echo(true); |
1
by brian
clean slate |
1214 |
return (END_OF_INPUT); |
1215 |
}
|
|
1216 |
state= MY_LEX_CHAR; // Return ';' |
|
1217 |
break; |
|
1218 |
}
|
|
1219 |
lip->next_state=MY_LEX_END; // Mark for next loop |
|
1220 |
return(END_OF_INPUT); |
|
1221 |
case MY_LEX_EOL: |
|
1222 |
if (lip->eof()) |
|
1223 |
{
|
|
1224 |
lip->yyUnget(); // Reject the last '\0' |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1225 |
lip->set_echo(false); |
1
by brian
clean slate |
1226 |
lip->yySkip(); |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1227 |
lip->set_echo(true); |
1
by brian
clean slate |
1228 |
/* Unbalanced comments with a missing '*' '/' are a syntax error */
|
1229 |
if (lip->in_comment != NO_COMMENT) |
|
1230 |
return (ABORT_SYM); |
|
1231 |
lip->next_state=MY_LEX_END; // Mark for next loop |
|
1232 |
return(END_OF_INPUT); |
|
1233 |
}
|
|
1234 |
state=MY_LEX_CHAR; |
|
1235 |
break; |
|
1236 |
case MY_LEX_END: |
|
1237 |
lip->next_state=MY_LEX_END; |
|
1238 |
return(0); // We found end of input last time |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1239 |
|
1
by brian
clean slate |
1240 |
/* Actually real shouldn't start with . but allow them anyhow */
|
1241 |
case MY_LEX_REAL_OR_POINT: |
|
1242 |
if (my_isdigit(cs,lip->yyPeek())) |
|
1243 |
state = MY_LEX_REAL; // Real |
|
1244 |
else
|
|
1245 |
{
|
|
1246 |
state= MY_LEX_IDENT_SEP; // return '.' |
|
1247 |
lip->yyUnget(); // Put back '.' |
|
1248 |
}
|
|
1249 |
break; |
|
1250 |
case MY_LEX_USER_END: // end '@' of user@hostname |
|
1251 |
switch (state_map[(uint8_t)lip->yyPeek()]) { |
|
1252 |
case MY_LEX_STRING: |
|
1253 |
case MY_LEX_USER_VARIABLE_DELIMITER: |
|
1254 |
case MY_LEX_STRING_OR_DELIMITER: |
|
1255 |
break; |
|
1256 |
case MY_LEX_USER_END: |
|
1257 |
lip->next_state=MY_LEX_SYSTEM_VAR; |
|
1258 |
break; |
|
1259 |
default: |
|
1260 |
lip->next_state=MY_LEX_HOSTNAME; |
|
1261 |
break; |
|
1262 |
}
|
|
1263 |
yylval->lex_str.str=(char*) lip->get_ptr(); |
|
1264 |
yylval->lex_str.length=1; |
|
1265 |
return((int) '@'); |
|
1266 |
case MY_LEX_HOSTNAME: // end '@' of user@hostname |
|
1267 |
for (c=lip->yyGet() ; |
|
1268 |
my_isalnum(cs,c) || c == '.' || c == '_' || c == '$'; |
|
1269 |
c= lip->yyGet()) ; |
|
1270 |
yylval->lex_str=get_token(lip, 0, lip->yyLength()); |
|
1271 |
return(LEX_HOSTNAME); |
|
1272 |
case MY_LEX_SYSTEM_VAR: |
|
1273 |
yylval->lex_str.str=(char*) lip->get_ptr(); |
|
1274 |
yylval->lex_str.length=1; |
|
1275 |
lip->yySkip(); // Skip '@' |
|
1276 |
lip->next_state= (state_map[(uint8_t)lip->yyPeek()] == |
|
1277 |
MY_LEX_USER_VARIABLE_DELIMITER ? |
|
1278 |
MY_LEX_OPERATOR_OR_IDENT : |
|
1279 |
MY_LEX_IDENT_OR_KEYWORD); |
|
1280 |
return((int) '@'); |
|
1281 |
case MY_LEX_IDENT_OR_KEYWORD: |
|
1282 |
/*
|
|
1283 |
We come here when we have found two '@' in a row.
|
|
1284 |
We should now be able to handle:
|
|
1285 |
[(global | local | session) .]variable_name
|
|
1286 |
*/
|
|
1287 |
||
1288 |
for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {}; |
|
1289 |
/* If there were non-ASCII characters, mark that we must convert */
|
|
1290 |
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT; |
|
1291 |
||
1292 |
if (c == '.') |
|
1293 |
lip->next_state=MY_LEX_IDENT_SEP; |
|
1294 |
length= lip->yyLength(); |
|
1295 |
if (length == 0) |
|
1296 |
return(ABORT_SYM); // Names must be nonempty. |
|
1297 |
if ((tokval= find_keyword(lip, length,0))) |
|
1298 |
{
|
|
1299 |
lip->yyUnget(); // Put back 'c' |
|
1300 |
return(tokval); // Was keyword |
|
1301 |
}
|
|
1302 |
yylval->lex_str=get_token(lip, 0, length); |
|
1303 |
||
1304 |
lip->body_utf8_append(lip->m_cpp_text_start); |
|
1305 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1306 |
lip->body_utf8_append_literal(session, &yylval->lex_str, cs, |
1
by brian
clean slate |
1307 |
lip->m_cpp_text_end); |
1308 |
||
1309 |
return(result_state); |
|
1310 |
}
|
|
1311 |
}
|
|
1312 |
}
|
|
1313 |
||
1314 |
||
1315 |
/**
|
|
1316 |
Construct a copy of this object to be used for mysql_alter_table
|
|
1317 |
and mysql_create_table.
|
|
1318 |
||
1319 |
Historically, these two functions modify their Alter_info
|
|
1320 |
arguments. This behaviour breaks re-execution of prepared
|
|
1321 |
statements and stored procedures and is compensated by always
|
|
1322 |
supplying a copy of Alter_info to these functions.
|
|
1323 |
||
520.1.21
by Brian Aker
THD -> Session rename |
1324 |
@return You need to use check the error in Session for out
|
1
by brian
clean slate |
1325 |
of memory condition after calling this function.
|
1326 |
*/
|
|
1327 |
||
1328 |
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root) |
|
1329 |
:drop_list(rhs.drop_list, mem_root), |
|
1330 |
alter_list(rhs.alter_list, mem_root), |
|
1331 |
key_list(rhs.key_list, mem_root), |
|
1332 |
create_list(rhs.create_list, mem_root), |
|
1333 |
flags(rhs.flags), |
|
1334 |
keys_onoff(rhs.keys_onoff), |
|
1335 |
tablespace_op(rhs.tablespace_op), |
|
1336 |
no_parts(rhs.no_parts), |
|
1337 |
build_method(rhs.build_method), |
|
1338 |
datetime_field(rhs.datetime_field), |
|
1339 |
error_if_not_empty(rhs.error_if_not_empty) |
|
1340 |
{
|
|
1341 |
/*
|
|
1342 |
Make deep copies of used objects.
|
|
1343 |
This is not a fully deep copy - clone() implementations
|
|
1344 |
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
|
|
1345 |
do not copy string constants. At the same length the only
|
|
1346 |
reason we make a copy currently is that ALTER/CREATE TABLE
|
|
1347 |
code changes input Alter_info definitions, but string
|
|
1348 |
constants never change.
|
|
1349 |
*/
|
|
1350 |
list_copy_and_replace_each_value(drop_list, mem_root); |
|
1351 |
list_copy_and_replace_each_value(alter_list, mem_root); |
|
1352 |
list_copy_and_replace_each_value(key_list, mem_root); |
|
1353 |
list_copy_and_replace_each_value(create_list, mem_root); |
|
1354 |
}
|
|
1355 |
||
1356 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1357 |
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str) |
1
by brian
clean slate |
1358 |
{
|
1359 |
/*
|
|
1360 |
TODO:
|
|
1361 |
This code assumes that there are no multi-bytes characters
|
|
1362 |
that can be considered white-space.
|
|
1363 |
*/
|
|
1364 |
||
1365 |
while ((str->length > 0) && (my_isspace(cs, str->str[0]))) |
|
1366 |
{
|
|
1367 |
str->length --; |
|
1368 |
str->str ++; |
|
1369 |
}
|
|
1370 |
||
1371 |
/*
|
|
1372 |
FIXME:
|
|
1373 |
Also, parsing backward is not safe with multi bytes characters
|
|
1374 |
*/
|
|
1375 |
while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1]))) |
|
1376 |
{
|
|
1377 |
str->length --; |
|
1378 |
}
|
|
1379 |
}
|
|
1380 |
||
1381 |
||
1382 |
/*
|
|
846
by Brian Aker
Removing on typedeffed class. |
1383 |
Select_Lex structures initialisations
|
1
by brian
clean slate |
1384 |
*/
|
1385 |
||
847
by Brian Aker
More typdef class removal. |
1386 |
void Select_Lex_Node::init_query() |
1
by brian
clean slate |
1387 |
{
|
1388 |
options= 0; |
|
1389 |
linkage= UNSPECIFIED_TYPE; |
|
1390 |
no_error= no_table_names_allowed= 0; |
|
1391 |
uncacheable= 0; |
|
1392 |
}
|
|
1393 |
||
847
by Brian Aker
More typdef class removal. |
1394 |
void Select_Lex_Node::init_select() |
1
by brian
clean slate |
1395 |
{
|
1396 |
}
|
|
1397 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1398 |
void Select_Lex_Unit::init_query() |
1
by brian
clean slate |
1399 |
{
|
847
by Brian Aker
More typdef class removal. |
1400 |
Select_Lex_Node::init_query(); |
1
by brian
clean slate |
1401 |
linkage= GLOBAL_OPTIONS_TYPE; |
1402 |
global_parameters= first_select(); |
|
1403 |
select_limit_cnt= HA_POS_ERROR; |
|
1404 |
offset_limit_cnt= 0; |
|
1405 |
union_distinct= 0; |
|
1406 |
prepared= optimized= executed= 0; |
|
1407 |
item= 0; |
|
1408 |
union_result= 0; |
|
1409 |
table= 0; |
|
1410 |
fake_select_lex= 0; |
|
1411 |
cleaned= 0; |
|
1412 |
item_list.empty(); |
|
1413 |
describe= 0; |
|
1414 |
found_rows_for_union= 0; |
|
1415 |
}
|
|
1416 |
||
846
by Brian Aker
Removing on typedeffed class. |
1417 |
void Select_Lex::init_query() |
1
by brian
clean slate |
1418 |
{
|
847
by Brian Aker
More typdef class removal. |
1419 |
Select_Lex_Node::init_query(); |
1
by brian
clean slate |
1420 |
table_list.empty(); |
1421 |
top_join_list.empty(); |
|
1422 |
join_list= &top_join_list; |
|
1423 |
embedding= leaf_tables= 0; |
|
1424 |
item_list.empty(); |
|
1425 |
join= 0; |
|
177.1.1
by brian
Removed dead code around prep. |
1426 |
having= where= 0; |
1
by brian
clean slate |
1427 |
olap= UNSPECIFIED_OLAP_TYPE; |
1428 |
having_fix_field= 0; |
|
1429 |
context.select_lex= this; |
|
1430 |
context.init(); |
|
1431 |
/*
|
|
1432 |
Add the name resolution context of the current (sub)query to the
|
|
1433 |
stack of contexts for the whole query.
|
|
1434 |
TODO:
|
|
1435 |
push_context may return an error if there is no memory for a new
|
|
1436 |
element in the stack, however this method has no return value,
|
|
1437 |
thus push_context should be moved to a place where query
|
|
1438 |
initialization is checked for failure.
|
|
1439 |
*/
|
|
1440 |
parent_lex->push_context(&context); |
|
1441 |
cond_count= between_count= with_wild= 0; |
|
1442 |
max_equal_elems= 0; |
|
1443 |
ref_pointer_array= 0; |
|
1444 |
select_n_where_fields= 0; |
|
1445 |
select_n_having_items= 0; |
|
1446 |
subquery_in_having= explicit_limit= 0; |
|
1447 |
is_item_list_lookup= 0; |
|
1448 |
parsing_place= NO_MATTER; |
|
177.1.2
by brian
Removed dead variable, sorted authors file. |
1449 |
exclude_from_table_unique_test= false; |
1
by brian
clean slate |
1450 |
nest_level= 0; |
1451 |
link_next= 0; |
|
1452 |
}
|
|
1453 |
||
846
by Brian Aker
Removing on typedeffed class. |
1454 |
void Select_Lex::init_select() |
1
by brian
clean slate |
1455 |
{
|
847
by Brian Aker
More typdef class removal. |
1456 |
Select_Lex_Node::init_select(); |
1
by brian
clean slate |
1457 |
sj_nests.empty(); |
1458 |
group_list.empty(); |
|
1459 |
type= db= 0; |
|
1460 |
having= 0; |
|
1461 |
table_join_options= 0; |
|
1462 |
in_sum_expr= with_wild= 0; |
|
1463 |
options= 0; |
|
1464 |
braces= 0; |
|
1465 |
interval_list.empty(); |
|
1466 |
ftfunc_list_alloc.empty(); |
|
1467 |
inner_sum_func_list= 0; |
|
1468 |
ftfunc_list= &ftfunc_list_alloc; |
|
1469 |
linkage= UNSPECIFIED_TYPE; |
|
1470 |
order_list.elements= 0; |
|
1471 |
order_list.first= 0; |
|
481
by Brian Aker
Remove all of uchar. |
1472 |
order_list.next= (unsigned char**) &order_list.first; |
1
by brian
clean slate |
1473 |
/* Set limit and offset to default values */
|
1474 |
select_limit= 0; /* denotes the default limit = HA_POS_ERROR */ |
|
1475 |
offset_limit= 0; /* denotes the default offset = 0 */ |
|
1476 |
with_sum_func= 0; |
|
1477 |
is_correlated= 0; |
|
1478 |
cur_pos_in_select_list= UNDEF_POS; |
|
1479 |
non_agg_fields.empty(); |
|
1480 |
cond_value= having_value= Item::COND_UNDEF; |
|
1481 |
inner_refs_list.empty(); |
|
1482 |
full_group_by_flag= 0; |
|
1483 |
}
|
|
1484 |
||
1485 |
/*
|
|
846
by Brian Aker
Removing on typedeffed class. |
1486 |
Select_Lex structures linking
|
1
by brian
clean slate |
1487 |
*/
|
1488 |
||
1489 |
/* include on level down */
|
|
847
by Brian Aker
More typdef class removal. |
1490 |
void Select_Lex_Node::include_down(Select_Lex_Node *upper) |
1
by brian
clean slate |
1491 |
{
|
1492 |
if ((next= upper->slave)) |
|
1493 |
next->prev= &next; |
|
1494 |
prev= &upper->slave; |
|
1495 |
upper->slave= this; |
|
1496 |
master= upper; |
|
1497 |
slave= 0; |
|
1498 |
}
|
|
1499 |
||
1500 |
/*
|
|
1501 |
include on level down (but do not link)
|
|
1502 |
||
1503 |
SYNOPSYS
|
|
847
by Brian Aker
More typdef class removal. |
1504 |
Select_Lex_Node::include_standalone()
|
1
by brian
clean slate |
1505 |
upper - reference on node underr which this node should be included
|
1506 |
ref - references on reference on this node
|
|
1507 |
*/
|
|
847
by Brian Aker
More typdef class removal. |
1508 |
void Select_Lex_Node::include_standalone(Select_Lex_Node *upper, |
1509 |
Select_Lex_Node **ref) |
|
1
by brian
clean slate |
1510 |
{
|
1511 |
next= 0; |
|
1512 |
prev= ref; |
|
1513 |
master= upper; |
|
1514 |
slave= 0; |
|
1515 |
}
|
|
1516 |
||
1517 |
/* include neighbour (on same level) */
|
|
847
by Brian Aker
More typdef class removal. |
1518 |
void Select_Lex_Node::include_neighbour(Select_Lex_Node *before) |
1
by brian
clean slate |
1519 |
{
|
1520 |
if ((next= before->next)) |
|
1521 |
next->prev= &next; |
|
1522 |
prev= &before->next; |
|
1523 |
before->next= this; |
|
1524 |
master= before->master; |
|
1525 |
slave= 0; |
|
1526 |
}
|
|
1527 |
||
846
by Brian Aker
Removing on typedeffed class. |
1528 |
/* including in global Select_Lex list */
|
847
by Brian Aker
More typdef class removal. |
1529 |
void Select_Lex_Node::include_global(Select_Lex_Node **plink) |
1
by brian
clean slate |
1530 |
{
|
1531 |
if ((link_next= *plink)) |
|
1532 |
link_next->link_prev= &link_next; |
|
1533 |
link_prev= plink; |
|
1534 |
*plink= this; |
|
1535 |
}
|
|
1536 |
||
1537 |
//excluding from global list (internal function)
|
|
847
by Brian Aker
More typdef class removal. |
1538 |
void Select_Lex_Node::fast_exclude() |
1
by brian
clean slate |
1539 |
{
|
1540 |
if (link_prev) |
|
1541 |
{
|
|
1542 |
if ((*link_prev= link_next)) |
|
1543 |
link_next->link_prev= link_prev; |
|
1544 |
}
|
|
1545 |
// Remove slave structure
|
|
1546 |
for (; slave; slave= slave->next) |
|
1547 |
slave->fast_exclude(); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1548 |
|
1
by brian
clean slate |
1549 |
}
|
1550 |
||
1551 |
/*
|
|
1552 |
excluding select_lex structure (except first (first select can't be
|
|
1553 |
deleted, because it is most upper select))
|
|
1554 |
*/
|
|
847
by Brian Aker
More typdef class removal. |
1555 |
void Select_Lex_Node::exclude() |
1
by brian
clean slate |
1556 |
{
|
1557 |
//exclude from global list
|
|
1558 |
fast_exclude(); |
|
1559 |
//exclude from other structures
|
|
1560 |
if ((*prev= next)) |
|
1561 |
next->prev= prev; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1562 |
/*
|
1563 |
We do not need following statements, because prev pointer of first
|
|
1
by brian
clean slate |
1564 |
list element point to master->slave
|
1565 |
if (master->slave == this)
|
|
1566 |
master->slave= next;
|
|
1567 |
*/
|
|
1568 |
}
|
|
1569 |
||
1570 |
||
1571 |
/*
|
|
1572 |
Exclude level of current unit from tree of SELECTs
|
|
1573 |
||
1574 |
SYNOPSYS
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1575 |
Select_Lex_Unit::exclude_level()
|
1
by brian
clean slate |
1576 |
|
1577 |
NOTE: units which belong to current will be brought up on level of
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1578 |
currernt unit
|
1
by brian
clean slate |
1579 |
*/
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1580 |
void Select_Lex_Unit::exclude_level() |
1
by brian
clean slate |
1581 |
{
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1582 |
Select_Lex_Unit *units= 0, **units_last= &units; |
846
by Brian Aker
Removing on typedeffed class. |
1583 |
for (Select_Lex *sl= first_select(); sl; sl= sl->next_select()) |
1
by brian
clean slate |
1584 |
{
|
1585 |
// unlink current level from global SELECTs list
|
|
1586 |
if (sl->link_prev && (*sl->link_prev= sl->link_next)) |
|
1587 |
sl->link_next->link_prev= sl->link_prev; |
|
1588 |
||
1589 |
// bring up underlay levels
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1590 |
Select_Lex_Unit **last= 0; |
1591 |
for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit()) |
|
1
by brian
clean slate |
1592 |
{
|
1593 |
u->master= master; |
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1594 |
last= (Select_Lex_Unit**)&(u->next); |
1
by brian
clean slate |
1595 |
}
|
1596 |
if (last) |
|
1597 |
{
|
|
1598 |
(*units_last)= sl->first_inner_unit(); |
|
1599 |
units_last= last; |
|
1600 |
}
|
|
1601 |
}
|
|
1602 |
if (units) |
|
1603 |
{
|
|
1604 |
// include brought up levels in place of current
|
|
1605 |
(*prev)= units; |
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1606 |
(*units_last)= (Select_Lex_Unit*)next; |
1
by brian
clean slate |
1607 |
if (next) |
847
by Brian Aker
More typdef class removal. |
1608 |
next->prev= (Select_Lex_Node**)units_last; |
1
by brian
clean slate |
1609 |
units->prev= prev; |
1610 |
}
|
|
1611 |
else
|
|
1612 |
{
|
|
1613 |
// exclude currect unit from list of nodes
|
|
1614 |
(*prev)= next; |
|
1615 |
if (next) |
|
1616 |
next->prev= prev; |
|
1617 |
}
|
|
1618 |
}
|
|
1619 |
||
1620 |
||
1621 |
/*
|
|
1622 |
Exclude subtree of current unit from tree of SELECTs
|
|
1623 |
||
1624 |
SYNOPSYS
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1625 |
Select_Lex_Unit::exclude_tree()
|
1
by brian
clean slate |
1626 |
*/
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1627 |
void Select_Lex_Unit::exclude_tree() |
1
by brian
clean slate |
1628 |
{
|
846
by Brian Aker
Removing on typedeffed class. |
1629 |
for (Select_Lex *sl= first_select(); sl; sl= sl->next_select()) |
1
by brian
clean slate |
1630 |
{
|
1631 |
// unlink current level from global SELECTs list
|
|
1632 |
if (sl->link_prev && (*sl->link_prev= sl->link_next)) |
|
1633 |
sl->link_next->link_prev= sl->link_prev; |
|
1634 |
||
1635 |
// unlink underlay levels
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1636 |
for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit()) |
1
by brian
clean slate |
1637 |
{
|
1638 |
u->exclude_level(); |
|
1639 |
}
|
|
1640 |
}
|
|
1641 |
// exclude currect unit from list of nodes
|
|
1642 |
(*prev)= next; |
|
1643 |
if (next) |
|
1644 |
next->prev= prev; |
|
1645 |
}
|
|
1646 |
||
1647 |
||
1648 |
/*
|
|
847
by Brian Aker
More typdef class removal. |
1649 |
Select_Lex_Node::mark_as_dependent mark all Select_Lex struct from
|
1
by brian
clean slate |
1650 |
this to 'last' as dependent
|
1651 |
||
1652 |
SYNOPSIS
|
|
846
by Brian Aker
Removing on typedeffed class. |
1653 |
last - pointer to last Select_Lex struct, before wich all
|
1654 |
Select_Lex have to be marked as dependent
|
|
1
by brian
clean slate |
1655 |
|
1656 |
NOTE
|
|
847
by Brian Aker
More typdef class removal. |
1657 |
'last' should be reachable from this Select_Lex_Node
|
1
by brian
clean slate |
1658 |
*/
|
1659 |
||
846
by Brian Aker
Removing on typedeffed class. |
1660 |
void Select_Lex::mark_as_dependent(Select_Lex *last) |
1
by brian
clean slate |
1661 |
{
|
1662 |
/*
|
|
1663 |
Mark all selects from resolved to 1 before select where was
|
|
1664 |
found table as depended (of select where was found table)
|
|
1665 |
*/
|
|
846
by Brian Aker
Removing on typedeffed class. |
1666 |
for (Select_Lex *s= this; |
1
by brian
clean slate |
1667 |
s && s != last; |
1668 |
s= s->outer_select()) |
|
1669 |
{
|
|
1670 |
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT)) |
|
1671 |
{
|
|
1672 |
// Select is dependent of outer select
|
|
1673 |
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) | |
|
1674 |
UNCACHEABLE_DEPENDENT; |
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1675 |
Select_Lex_Unit *munit= s->master_unit(); |
1
by brian
clean slate |
1676 |
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) | |
1677 |
UNCACHEABLE_DEPENDENT; |
|
846
by Brian Aker
Removing on typedeffed class. |
1678 |
for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select()) |
1
by brian
clean slate |
1679 |
{
|
1680 |
if (sl != s && |
|
1681 |
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED))) |
|
1682 |
sl->uncacheable|= UNCACHEABLE_UNITED; |
|
1683 |
}
|
|
1684 |
}
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1685 |
s->is_correlated= true; |
1
by brian
clean slate |
1686 |
Item_subselect *subquery_predicate= s->master_unit()->item; |
1687 |
if (subquery_predicate) |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1688 |
subquery_predicate->is_correlated= true; |
1
by brian
clean slate |
1689 |
}
|
1690 |
}
|
|
1691 |
||
847
by Brian Aker
More typdef class removal. |
1692 |
bool Select_Lex_Node::set_braces(bool) |
77.1.15
by Monty Taylor
Bunch of warning cleanups. |
1693 |
{ return 1; } |
847
by Brian Aker
More typdef class removal. |
1694 |
bool Select_Lex_Node::inc_in_sum_expr() { return 1; } |
1695 |
uint32_t Select_Lex_Node::get_in_sum_expr() { return 0; } |
|
1696 |
TableList* Select_Lex_Node::get_table_list() { return 0; } |
|
1697 |
List<Item>* Select_Lex_Node::get_item_list() { return 0; } |
|
1698 |
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t, |
|
654
by Brian Aker
Remove unused (yet more) |
1699 |
thr_lock_type, List<Index_hint> *, LEX_STRING *) |
1
by brian
clean slate |
1700 |
{
|
1701 |
return 0; |
|
1702 |
}
|
|
847
by Brian Aker
More typdef class removal. |
1703 |
uint32_t Select_Lex_Node::get_table_join_options() |
1
by brian
clean slate |
1704 |
{
|
1705 |
return 0; |
|
1706 |
}
|
|
1707 |
||
1708 |
/*
|
|
1709 |
prohibit using LIMIT clause
|
|
1710 |
*/
|
|
846
by Brian Aker
Removing on typedeffed class. |
1711 |
bool Select_Lex::test_limit() |
1
by brian
clean slate |
1712 |
{
|
1713 |
if (select_limit != 0) |
|
1714 |
{
|
|
1715 |
my_error(ER_NOT_SUPPORTED_YET, MYF(0), |
|
1716 |
"LIMIT & IN/ALL/ANY/SOME subquery"); |
|
1717 |
return(1); |
|
1718 |
}
|
|
1719 |
return(0); |
|
1720 |
}
|
|
1721 |
||
1722 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1723 |
Select_Lex_Unit* Select_Lex_Unit::master_unit() |
1
by brian
clean slate |
1724 |
{
|
1725 |
return this; |
|
1726 |
}
|
|
1727 |
||
1728 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1729 |
Select_Lex* Select_Lex_Unit::outer_select() |
1
by brian
clean slate |
1730 |
{
|
846
by Brian Aker
Removing on typedeffed class. |
1731 |
return (Select_Lex*) master; |
1
by brian
clean slate |
1732 |
}
|
1733 |
||
1734 |
||
846
by Brian Aker
Removing on typedeffed class. |
1735 |
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc) |
1
by brian
clean slate |
1736 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1737 |
return add_to_list(session, order_list, item, asc); |
1
by brian
clean slate |
1738 |
}
|
1739 |
||
1740 |
||
846
by Brian Aker
Removing on typedeffed class. |
1741 |
bool Select_Lex::add_item_to_list(Session *, Item *item) |
1
by brian
clean slate |
1742 |
{
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1743 |
return(item_list.push_back(item)); |
1
by brian
clean slate |
1744 |
}
|
1745 |
||
1746 |
||
846
by Brian Aker
Removing on typedeffed class. |
1747 |
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc) |
1
by brian
clean slate |
1748 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1749 |
return add_to_list(session, group_list, item, asc); |
1
by brian
clean slate |
1750 |
}
|
1751 |
||
1752 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1753 |
Select_Lex_Unit* Select_Lex::master_unit() |
846
by Brian Aker
Removing on typedeffed class. |
1754 |
{
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1755 |
return (Select_Lex_Unit*) master; |
846
by Brian Aker
Removing on typedeffed class. |
1756 |
}
|
1757 |
||
1758 |
||
1759 |
Select_Lex* Select_Lex::outer_select() |
|
1760 |
{
|
|
1761 |
return (Select_Lex*) master->get_master(); |
|
1762 |
}
|
|
1763 |
||
1764 |
||
1765 |
bool Select_Lex::set_braces(bool value) |
|
1
by brian
clean slate |
1766 |
{
|
1767 |
braces= value; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1768 |
return 0; |
1
by brian
clean slate |
1769 |
}
|
1770 |
||
1771 |
||
846
by Brian Aker
Removing on typedeffed class. |
1772 |
bool Select_Lex::inc_in_sum_expr() |
1
by brian
clean slate |
1773 |
{
|
1774 |
in_sum_expr++; |
|
1775 |
return 0; |
|
1776 |
}
|
|
1777 |
||
1778 |
||
846
by Brian Aker
Removing on typedeffed class. |
1779 |
uint32_t Select_Lex::get_in_sum_expr() |
1
by brian
clean slate |
1780 |
{
|
1781 |
return in_sum_expr; |
|
1782 |
}
|
|
1783 |
||
1784 |
||
846
by Brian Aker
Removing on typedeffed class. |
1785 |
TableList* Select_Lex::get_table_list() |
1
by brian
clean slate |
1786 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1787 |
return (TableList*) table_list.first; |
1
by brian
clean slate |
1788 |
}
|
1789 |
||
846
by Brian Aker
Removing on typedeffed class. |
1790 |
List<Item>* Select_Lex::get_item_list() |
1
by brian
clean slate |
1791 |
{
|
1792 |
return &item_list; |
|
1793 |
}
|
|
1794 |
||
846
by Brian Aker
Removing on typedeffed class. |
1795 |
uint32_t Select_Lex::get_table_join_options() |
1
by brian
clean slate |
1796 |
{
|
1797 |
return table_join_options; |
|
1798 |
}
|
|
1799 |
||
1800 |
||
846
by Brian Aker
Removing on typedeffed class. |
1801 |
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num) |
1
by brian
clean slate |
1802 |
{
|
1803 |
if (ref_pointer_array) |
|
1804 |
return 0; |
|
1805 |
||
1806 |
return (ref_pointer_array= |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1807 |
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items + |
1
by brian
clean slate |
1808 |
item_list.elements + |
1809 |
select_n_having_items + |
|
1810 |
select_n_where_fields + |
|
1811 |
order_group_num)*5)) == 0; |
|
1812 |
}
|
|
1813 |
||
1814 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1815 |
void Select_Lex_Unit::print(String *str, enum_query_type query_type) |
1
by brian
clean slate |
1816 |
{
|
1817 |
bool union_all= !union_distinct; |
|
846
by Brian Aker
Removing on typedeffed class. |
1818 |
for (Select_Lex *sl= first_select(); sl; sl= sl->next_select()) |
1
by brian
clean slate |
1819 |
{
|
1820 |
if (sl != first_select()) |
|
1821 |
{
|
|
1822 |
str->append(STRING_WITH_LEN(" union ")); |
|
1823 |
if (union_all) |
|
1824 |
str->append(STRING_WITH_LEN("all ")); |
|
1825 |
else if (union_distinct == sl) |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1826 |
union_all= true; |
1
by brian
clean slate |
1827 |
}
|
1828 |
if (sl->braces) |
|
1829 |
str->append('('); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1830 |
sl->print(session, str, query_type); |
1
by brian
clean slate |
1831 |
if (sl->braces) |
1832 |
str->append(')'); |
|
1833 |
}
|
|
1834 |
if (fake_select_lex == global_parameters) |
|
1835 |
{
|
|
1836 |
if (fake_select_lex->order_list.elements) |
|
1837 |
{
|
|
1838 |
str->append(STRING_WITH_LEN(" order by ")); |
|
1839 |
fake_select_lex->print_order( |
|
1840 |
str, |
|
327.2.3
by Brian Aker
Refactoring of class Table |
1841 |
(order_st *) fake_select_lex->order_list.first, |
1
by brian
clean slate |
1842 |
query_type); |
1843 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1844 |
fake_select_lex->print_limit(session, str, query_type); |
1
by brian
clean slate |
1845 |
}
|
1846 |
}
|
|
1847 |
||
1848 |
||
846
by Brian Aker
Removing on typedeffed class. |
1849 |
void Select_Lex::print_order(String *str, |
327.2.3
by Brian Aker
Refactoring of class Table |
1850 |
order_st *order, |
1
by brian
clean slate |
1851 |
enum_query_type query_type) |
1852 |
{
|
|
1853 |
for (; order; order= order->next) |
|
1854 |
{
|
|
1855 |
if (order->counter_used) |
|
1856 |
{
|
|
1857 |
char buffer[20]; |
|
482
by Brian Aker
Remove uint. |
1858 |
uint32_t length= snprintf(buffer, 20, "%d", order->counter); |
1
by brian
clean slate |
1859 |
str->append(buffer, length); |
1860 |
}
|
|
1861 |
else
|
|
1862 |
(*order->item)->print(str, query_type); |
|
1863 |
if (!order->asc) |
|
1864 |
str->append(STRING_WITH_LEN(" desc")); |
|
1865 |
if (order->next) |
|
1866 |
str->append(','); |
|
1867 |
}
|
|
1868 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1869 |
|
1
by brian
clean slate |
1870 |
|
846
by Brian Aker
Removing on typedeffed class. |
1871 |
void Select_Lex::print_limit(Session *, String *str, |
1
by brian
clean slate |
1872 |
enum_query_type query_type) |
1873 |
{
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1874 |
Select_Lex_Unit *unit= master_unit(); |
1
by brian
clean slate |
1875 |
Item_subselect *item= unit->item; |
1876 |
||
1877 |
if (item && unit->global_parameters == this) |
|
1878 |
{
|
|
1879 |
Item_subselect::subs_type subs_type= item->substype(); |
|
1880 |
if (subs_type == Item_subselect::EXISTS_SUBS || |
|
1881 |
subs_type == Item_subselect::IN_SUBS || |
|
1882 |
subs_type == Item_subselect::ALL_SUBS) |
|
1883 |
{
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1884 |
assert(!item->fixed || |
1
by brian
clean slate |
1885 |
/*
|
1886 |
If not using materialization both:
|
|
1887 |
select_limit == 1, and there should be no offset_limit.
|
|
1888 |
*/
|
|
1889 |
(((subs_type == Item_subselect::IN_SUBS) && |
|
1890 |
((Item_in_subselect*)item)->exec_method == |
|
1891 |
Item_in_subselect::MATERIALIZATION) ? |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1892 |
true : |
398.1.8
by Monty Taylor
Enabled -Wlong-long. |
1893 |
(select_limit->val_int() == 1L) && |
1
by brian
clean slate |
1894 |
offset_limit == 0)); |
1895 |
return; |
|
1896 |
}
|
|
1897 |
}
|
|
1898 |
if (explicit_limit) |
|
1899 |
{
|
|
1900 |
str->append(STRING_WITH_LEN(" limit ")); |
|
1901 |
if (offset_limit) |
|
1902 |
{
|
|
1903 |
offset_limit->print(str, query_type); |
|
1904 |
str->append(','); |
|
1905 |
}
|
|
1906 |
select_limit->print(str, query_type); |
|
1907 |
}
|
|
1908 |
}
|
|
1909 |
||
1910 |
/**
|
|
520.1.21
by Brian Aker
THD -> Session rename |
1911 |
@brief Restore the LEX and Session in case of a parse error.
|
1
by brian
clean slate |
1912 |
|
1913 |
This is a clean up call that is invoked by the Bison generated
|
|
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1914 |
parser before returning an error from DRIZZLEparse. If your
|
1
by brian
clean slate |
1915 |
semantic actions manipulate with the global thread state (which
|
1916 |
is a very bad practice and should not normally be employed) and
|
|
1917 |
need a clean-up in case of error, and you can not use %destructor
|
|
1918 |
rule in the grammar file itself, this function should be used
|
|
1919 |
to implement the clean up.
|
|
1920 |
*/
|
|
1921 |
||
654
by Brian Aker
Remove unused (yet more) |
1922 |
void LEX::cleanup_lex_after_parse_error(Session *) |
1
by brian
clean slate |
1923 |
{
|
1924 |
}
|
|
1925 |
||
1926 |
/*
|
|
1927 |
Initialize (or reset) Query_tables_list object.
|
|
1928 |
||
1929 |
SYNOPSIS
|
|
1930 |
reset_query_tables_list()
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1931 |
init true - we should perform full initialization of object with
|
1
by brian
clean slate |
1932 |
allocating needed memory
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1933 |
false - object is already initialized so we should only reset
|
1
by brian
clean slate |
1934 |
its state so it can be used for parsing/processing
|
1935 |
of new statement
|
|
1936 |
||
1937 |
DESCRIPTION
|
|
1938 |
This method initializes Query_tables_list so it can be used as part
|
|
1939 |
of LEX object for parsing/processing of statement. One can also use
|
|
1940 |
this method to reset state of already initialized Query_tables_list
|
|
1941 |
so it can be used for processing of new statement.
|
|
1942 |
*/
|
|
1943 |
||
1944 |
void Query_tables_list::reset_query_tables_list(bool init) |
|
1945 |
{
|
|
1946 |
if (!init && query_tables) |
|
1947 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1948 |
TableList *table= query_tables; |
1
by brian
clean slate |
1949 |
for (;;) |
1950 |
{
|
|
1951 |
if (query_tables_last == &table->next_global || |
|
1952 |
!(table= table->next_global)) |
|
1953 |
break; |
|
1954 |
}
|
|
1955 |
}
|
|
1956 |
query_tables= 0; |
|
1957 |
query_tables_last= &query_tables; |
|
1958 |
query_tables_own_last= 0; |
|
1959 |
}
|
|
1960 |
||
1961 |
||
1962 |
/*
|
|
1963 |
Destroy Query_tables_list object with freeing all resources used by it.
|
|
1964 |
||
1965 |
SYNOPSIS
|
|
1966 |
destroy_query_tables_list()
|
|
1967 |
*/
|
|
1968 |
||
1969 |
void Query_tables_list::destroy_query_tables_list() |
|
1970 |
{
|
|
1971 |
}
|
|
1972 |
||
1973 |
||
1974 |
/*
|
|
1975 |
Initialize LEX object.
|
|
1976 |
||
1977 |
SYNOPSIS
|
|
575.4.7
by Monty Taylor
More header cleanup. |
1978 |
LEX::LEX()
|
1
by brian
clean slate |
1979 |
|
1980 |
NOTE
|
|
1981 |
LEX object initialized with this constructor can be used as part of
|
|
520.1.21
by Brian Aker
THD -> Session rename |
1982 |
Session object for which one can safely call open_tables(), lock_tables()
|
1
by brian
clean slate |
1983 |
and close_thread_tables() functions. But it is not yet ready for
|
1984 |
statement parsing. On should use lex_start() function to prepare LEX
|
|
1985 |
for this.
|
|
1986 |
*/
|
|
1987 |
||
575.4.7
by Monty Taylor
More header cleanup. |
1988 |
LEX::LEX() |
1
by brian
clean slate |
1989 |
:result(0), yacc_yyss(0), yacc_yyvs(0), |
1990 |
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0) |
|
1991 |
{
|
|
1992 |
||
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1993 |
reset_query_tables_list(true); |
1
by brian
clean slate |
1994 |
}
|
1995 |
||
1996 |
/*
|
|
1997 |
Detect that we need only table structure of derived table/view
|
|
1998 |
||
1999 |
SYNOPSIS
|
|
2000 |
only_view_structure()
|
|
2001 |
||
2002 |
RETURN
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2003 |
true yes, we need only structure
|
2004 |
false no, we need data
|
|
1
by brian
clean slate |
2005 |
*/
|
2006 |
||
575.4.7
by Monty Taylor
More header cleanup. |
2007 |
bool LEX::only_view_structure() |
1
by brian
clean slate |
2008 |
{
|
2009 |
switch (sql_command) { |
|
2010 |
case SQLCOM_SHOW_CREATE: |
|
2011 |
case SQLCOM_SHOW_TABLES: |
|
2012 |
case SQLCOM_SHOW_FIELDS: |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2013 |
return true; |
1
by brian
clean slate |
2014 |
default: |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2015 |
return false; |
1
by brian
clean slate |
2016 |
}
|
2017 |
}
|
|
2018 |
||
2019 |
||
2020 |
/*
|
|
2021 |
Should Items_ident be printed correctly
|
|
2022 |
||
2023 |
SYNOPSIS
|
|
2024 |
need_correct_ident()
|
|
2025 |
||
2026 |
RETURN
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2027 |
true yes, we need only structure
|
2028 |
false no, we need data
|
|
1
by brian
clean slate |
2029 |
*/
|
2030 |
||
2031 |
||
575.4.7
by Monty Taylor
More header cleanup. |
2032 |
bool LEX::need_correct_ident() |
1
by brian
clean slate |
2033 |
{
|
2034 |
switch(sql_command) |
|
2035 |
{
|
|
2036 |
case SQLCOM_SHOW_CREATE: |
|
2037 |
case SQLCOM_SHOW_TABLES: |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2038 |
return true; |
1
by brian
clean slate |
2039 |
default: |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2040 |
return false; |
1
by brian
clean slate |
2041 |
}
|
2042 |
}
|
|
2043 |
||
2044 |
||
2045 |
/**
|
|
2046 |
This method should be called only during parsing.
|
|
2047 |
It is aware of compound statements (stored routine bodies)
|
|
2048 |
and will initialize the destination with the default
|
|
2049 |
database of the stored routine, rather than the default
|
|
2050 |
database of the connection it is parsed in.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2051 |
E.g. if one has no current database selected, or current database
|
1
by brian
clean slate |
2052 |
set to 'bar' and then issues:
|
2053 |
||
2054 |
CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
|
|
2055 |
||
2056 |
t1 is meant to refer to foo.t1, not to bar.t1.
|
|
2057 |
||
2058 |
This method is needed to support this rule.
|
|
2059 |
||
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2060 |
@return true in case of error (parsing should be aborted, false in
|
1
by brian
clean slate |
2061 |
case of success
|
2062 |
*/
|
|
2063 |
||
2064 |
bool
|
|
575.4.7
by Monty Taylor
More header cleanup. |
2065 |
LEX::copy_db_to(char **p_db, size_t *p_db_length) const |
1
by brian
clean slate |
2066 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2067 |
return session->copy_db_to(p_db, p_db_length); |
1
by brian
clean slate |
2068 |
}
|
2069 |
||
2070 |
/*
|
|
2071 |
initialize limit counters
|
|
2072 |
||
2073 |
SYNOPSIS
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
2074 |
Select_Lex_Unit::set_limit()
|
846
by Brian Aker
Removing on typedeffed class. |
2075 |
values - Select_Lex with initial values for counters
|
1
by brian
clean slate |
2076 |
*/
|
2077 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
2078 |
void Select_Lex_Unit::set_limit(Select_Lex *sl) |
1
by brian
clean slate |
2079 |
{
|
2080 |
ha_rows select_limit_val; |
|
151
by Brian Aker
Ulonglong to uint64_t |
2081 |
uint64_t val; |
1
by brian
clean slate |
2082 |
|
2083 |
val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR; |
|
2084 |
select_limit_val= (ha_rows)val; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2085 |
/*
|
151
by Brian Aker
Ulonglong to uint64_t |
2086 |
Check for overflow : ha_rows can be smaller then uint64_t if
|
1
by brian
clean slate |
2087 |
BIG_TABLES is off.
|
2088 |
*/
|
|
151
by Brian Aker
Ulonglong to uint64_t |
2089 |
if (val != (uint64_t)select_limit_val) |
1
by brian
clean slate |
2090 |
select_limit_val= HA_POS_ERROR; |
2091 |
offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() : |
|
398.1.8
by Monty Taylor
Enabled -Wlong-long. |
2092 |
0UL); |
1
by brian
clean slate |
2093 |
select_limit_cnt= select_limit_val + offset_limit_cnt; |
2094 |
if (select_limit_cnt < select_limit_val) |
|
2095 |
select_limit_cnt= HA_POS_ERROR; // no limit |
|
2096 |
}
|
|
2097 |
||
2098 |
||
2099 |
/*
|
|
2100 |
Unlink the first table from the global table list and the first table from
|
|
2101 |
outer select (lex->select_lex) local list
|
|
2102 |
||
2103 |
SYNOPSIS
|
|
2104 |
unlink_first_table()
|
|
2105 |
link_to_local Set to 1 if caller should link this table to local list
|
|
2106 |
||
2107 |
NOTES
|
|
2108 |
We assume that first tables in both lists is the same table or the local
|
|
2109 |
list is empty.
|
|
2110 |
||
2111 |
RETURN
|
|
2112 |
0 If 'query_tables' == 0
|
|
2113 |
unlinked table
|
|
2114 |
In this case link_to_local is set.
|
|
2115 |
||
2116 |
*/
|
|
575.4.7
by Monty Taylor
More header cleanup. |
2117 |
TableList *LEX::unlink_first_table(bool *link_to_local) |
1
by brian
clean slate |
2118 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
2119 |
TableList *first; |
1
by brian
clean slate |
2120 |
if ((first= query_tables)) |
2121 |
{
|
|
2122 |
/*
|
|
2123 |
Exclude from global table list
|
|
2124 |
*/
|
|
2125 |
if ((query_tables= query_tables->next_global)) |
|
2126 |
query_tables->prev_global= &query_tables; |
|
2127 |
else
|
|
2128 |
query_tables_last= &query_tables; |
|
2129 |
first->next_global= 0; |
|
2130 |
||
2131 |
/*
|
|
2132 |
and from local list if it is not empty
|
|
2133 |
*/
|
|
2134 |
if ((*link_to_local= test(select_lex.table_list.first))) |
|
2135 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2136 |
select_lex.context.table_list= |
1
by brian
clean slate |
2137 |
select_lex.context.first_name_resolution_table= first->next_local; |
481
by Brian Aker
Remove all of uchar. |
2138 |
select_lex.table_list.first= (unsigned char*) (first->next_local); |
1
by brian
clean slate |
2139 |
select_lex.table_list.elements--; //safety |
2140 |
first->next_local= 0; |
|
2141 |
/*
|
|
2142 |
Ensure that the global list has the same first table as the local
|
|
2143 |
list.
|
|
2144 |
*/
|
|
2145 |
first_lists_tables_same(); |
|
2146 |
}
|
|
2147 |
}
|
|
2148 |
return first; |
|
2149 |
}
|
|
2150 |
||
2151 |
||
2152 |
/*
|
|
2153 |
Bring first local table of first most outer select to first place in global
|
|
2154 |
table list
|
|
2155 |
||
2156 |
SYNOPSYS
|
|
575.4.7
by Monty Taylor
More header cleanup. |
2157 |
LEX::first_lists_tables_same()
|
1
by brian
clean slate |
2158 |
|
2159 |
NOTES
|
|
2160 |
In many cases (for example, usual INSERT/DELETE/...) the first table of
|
|
846
by Brian Aker
Removing on typedeffed class. |
2161 |
main Select_Lex have special meaning => check that it is the first table
|
1
by brian
clean slate |
2162 |
in global list and re-link to be first in the global list if it is
|
2163 |
necessary. We need such re-linking only for queries with sub-queries in
|
|
2164 |
the select list, as only in this case tables of sub-queries will go to
|
|
2165 |
the global list first.
|
|
2166 |
*/
|
|
2167 |
||
575.4.7
by Monty Taylor
More header cleanup. |
2168 |
void LEX::first_lists_tables_same() |
1
by brian
clean slate |
2169 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
2170 |
TableList *first_table= (TableList*) select_lex.table_list.first; |
1
by brian
clean slate |
2171 |
if (query_tables != first_table && first_table != 0) |
2172 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
2173 |
TableList *next; |
1
by brian
clean slate |
2174 |
if (query_tables_last == &first_table->next_global) |
2175 |
query_tables_last= first_table->prev_global; |
|
2176 |
||
2177 |
if ((next= *first_table->prev_global= first_table->next_global)) |
|
2178 |
next->prev_global= first_table->prev_global; |
|
2179 |
/* include in new place */
|
|
2180 |
first_table->next_global= query_tables; |
|
2181 |
/*
|
|
2182 |
We are sure that query_tables is not 0, because first_table was not
|
|
2183 |
first table in the global list => we can use
|
|
2184 |
query_tables->prev_global without check of query_tables
|
|
2185 |
*/
|
|
2186 |
query_tables->prev_global= &first_table->next_global; |
|
2187 |
first_table->prev_global= &query_tables; |
|
2188 |
query_tables= first_table; |
|
2189 |
}
|
|
2190 |
}
|
|
2191 |
||
2192 |
||
2193 |
/*
|
|
2194 |
Link table back that was unlinked with unlink_first_table()
|
|
2195 |
||
2196 |
SYNOPSIS
|
|
2197 |
link_first_table_back()
|
|
2198 |
link_to_local do we need link this table to local
|
|
2199 |
||
2200 |
RETURN
|
|
2201 |
global list
|
|
2202 |
*/
|
|
2203 |
||
575.4.7
by Monty Taylor
More header cleanup. |
2204 |
void LEX::link_first_table_back(TableList *first, |
1
by brian
clean slate |
2205 |
bool link_to_local) |
2206 |
{
|
|
2207 |
if (first) |
|
2208 |
{
|
|
2209 |
if ((first->next_global= query_tables)) |
|
2210 |
query_tables->prev_global= &first->next_global; |
|
2211 |
else
|
|
2212 |
query_tables_last= &first->next_global; |
|
2213 |
query_tables= first; |
|
2214 |
||
2215 |
if (link_to_local) |
|
2216 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
2217 |
first->next_local= (TableList*) select_lex.table_list.first; |
1
by brian
clean slate |
2218 |
select_lex.context.table_list= first; |
481
by Brian Aker
Remove all of uchar. |
2219 |
select_lex.table_list.first= (unsigned char*) first; |
1
by brian
clean slate |
2220 |
select_lex.table_list.elements++; //safety |
2221 |
}
|
|
2222 |
}
|
|
2223 |
}
|
|
2224 |
||
2225 |
||
2226 |
||
2227 |
/*
|
|
2228 |
cleanup lex for case when we open table by table for processing
|
|
2229 |
||
2230 |
SYNOPSIS
|
|
575.4.7
by Monty Taylor
More header cleanup. |
2231 |
LEX::cleanup_after_one_table_open()
|
1
by brian
clean slate |
2232 |
|
2233 |
NOTE
|
|
2234 |
This method is mostly responsible for cleaning up of selects lists and
|
|
2235 |
derived tables state. To rollback changes in Query_tables_list one has
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
2236 |
to call Query_tables_list::reset_query_tables_list(false).
|
1
by brian
clean slate |
2237 |
*/
|
2238 |
||
575.4.7
by Monty Taylor
More header cleanup. |
2239 |
void LEX::cleanup_after_one_table_open() |
1
by brian
clean slate |
2240 |
{
|
2241 |
/*
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2242 |
session->lex->derived_tables & additional units may be set if we open
|
2243 |
a view. It is necessary to clear session->lex->derived_tables flag
|
|
1
by brian
clean slate |
2244 |
to prevent processing of derived tables during next open_and_lock_tables
|
2245 |
if next table is a real table and cleanup & remove underlying units
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2246 |
NOTE: all units will be connected to session->lex->select_lex, because we
|
1
by brian
clean slate |
2247 |
have not UNION on most upper level.
|
2248 |
*/
|
|
2249 |
if (all_selects_list != &select_lex) |
|
2250 |
{
|
|
2251 |
derived_tables= 0; |
|
2252 |
/* cleunup underlying units (units of VIEW) */
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
2253 |
for (Select_Lex_Unit *un= select_lex.first_inner_unit(); |
1
by brian
clean slate |
2254 |
un; |
2255 |
un= un->next_unit()) |
|
2256 |
un->cleanup(); |
|
2257 |
/* reduce all selects list to default state */
|
|
2258 |
all_selects_list= &select_lex; |
|
2259 |
/* remove underlying units (units of VIEW) subtree */
|
|
2260 |
select_lex.cut_subtree(); |
|
2261 |
}
|
|
2262 |
}
|
|
2263 |
||
2264 |
||
2265 |
/*
|
|
2266 |
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
|
|
2267 |
||
2268 |
SYNOPSIS
|
|
2269 |
fix_prepare_info_in_table_list()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2270 |
session Thread handle
|
1
by brian
clean slate |
2271 |
tbl List of tables to process
|
2272 |
||
2273 |
DESCRIPTION
|
|
2274 |
Perform end-end-of prepare fixup for list of tables, if any of the tables
|
|
2275 |
is a merge-algorithm VIEW, recursively fix up its underlying tables as
|
|
2276 |
well.
|
|
2277 |
||
2278 |
*/
|
|
2279 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2280 |
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl) |
1
by brian
clean slate |
2281 |
{
|
2282 |
for (; tbl; tbl= tbl->next_local) |
|
2283 |
{
|
|
2284 |
if (tbl->on_expr) |
|
2285 |
{
|
|
2286 |
tbl->prep_on_expr= tbl->on_expr; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2287 |
tbl->on_expr= tbl->on_expr->copy_andor_structure(session); |
1
by brian
clean slate |
2288 |
}
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2289 |
fix_prepare_info_in_table_list(session, tbl->merge_underlying_list); |
1
by brian
clean slate |
2290 |
}
|
2291 |
}
|
|
2292 |
||
2293 |
||
2294 |
/*
|
|
846
by Brian Aker
Removing on typedeffed class. |
2295 |
There are Select_Lex::add_table_to_list &
|
2296 |
Select_Lex::set_lock_for_tables are in sql_parse.cc
|
|
2297 |
||
2298 |
Select_Lex::print is in sql_select.cc
|
|
2299 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
2300 |
Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
|
2301 |
Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
|
|
2302 |
Select_Lex_Unit::change_result
|
|
1
by brian
clean slate |
2303 |
are in sql_union.cc
|
2304 |
*/
|
|
2305 |
||
2306 |
/*
|
|
2307 |
Sets the kind of hints to be added by the calls to add_index_hint().
|
|
2308 |
||
2309 |
SYNOPSIS
|
|
2310 |
set_index_hint_type()
|
|
2311 |
type_arg The kind of hints to be added from now on.
|
|
2312 |
clause The clause to use for hints to be added from now on.
|
|
2313 |
||
2314 |
DESCRIPTION
|
|
2315 |
Used in filling up the tagged hints list.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2316 |
This list is filled by first setting the kind of the hint as a
|
1
by brian
clean slate |
2317 |
context variable and then adding hints of the current kind.
|
2318 |
Then the context variable index_hint_type can be reset to the
|
|
2319 |
next hint type.
|
|
2320 |
*/
|
|
846
by Brian Aker
Removing on typedeffed class. |
2321 |
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, |
1
by brian
clean slate |
2322 |
index_clause_map clause) |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2323 |
{
|
1
by brian
clean slate |
2324 |
current_index_hint_type= type_arg; |
2325 |
current_index_hint_clause= clause; |
|
2326 |
}
|
|
2327 |
||
2328 |
||
2329 |
/*
|
|
2330 |
Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
|
|
2331 |
||
2332 |
SYNOPSIS
|
|
2333 |
alloc_index_hints()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2334 |
session current thread.
|
1
by brian
clean slate |
2335 |
*/
|
2336 |
||
846
by Brian Aker
Removing on typedeffed class. |
2337 |
void Select_Lex::alloc_index_hints (Session *session) |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2338 |
{
|
2339 |
index_hints= new (session->mem_root) List<Index_hint>(); |
|
1
by brian
clean slate |
2340 |
}
|
2341 |
||
2342 |
||
2343 |
||
2344 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2345 |
adds an element to the array storing index usage hints
|
1
by brian
clean slate |
2346 |
(ADD/FORCE/IGNORE INDEX).
|
2347 |
||
2348 |
SYNOPSIS
|
|
2349 |
add_index_hint()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2350 |
session current thread.
|
1
by brian
clean slate |
2351 |
str name of the index.
|
2352 |
length number of characters in str.
|
|
2353 |
||
2354 |
RETURN VALUE
|
|
2355 |
0 on success, non-zero otherwise
|
|
2356 |
*/
|
|
846
by Brian Aker
Removing on typedeffed class. |
2357 |
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length) |
1
by brian
clean slate |
2358 |
{
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
2359 |
return index_hints->push_front (new (session->mem_root) |
1
by brian
clean slate |
2360 |
Index_hint(current_index_hint_type, |
2361 |
current_index_hint_clause, |
|
2362 |
str, length)); |
|
2363 |
}
|