~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Moriyoshi Koizumi
  • Date: 2008-11-15 18:36:31 UTC
  • mto: (584.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 588.
  • Revision ID: mozo@mozo.jp-20081115183631-81d0clowyot42mk7
Incorporating changes proposed by mtaylor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
 
#include <config.h>
20
 
 
21
19
#define DRIZZLE_LEX 1
22
 
 
23
 
#include <drizzled/sql_reserved_words.h>
24
 
 
25
 
#include <drizzled/configmake.h>
26
 
#include <drizzled/item/num.h>
 
20
#include <drizzled/server_includes.h>
27
21
#include <drizzled/error.h>
28
 
#include <drizzled/session.h>
29
 
#include <drizzled/sql_base.h>
30
 
#include <drizzled/lookup_symbol.h>
31
 
#include <drizzled/index_hint.h>
32
 
#include <drizzled/select_result.h>
33
 
 
34
 
#include <cstdio>
35
 
#include <ctype.h>
36
 
 
37
 
union ParserType;
38
 
 
39
 
using namespace std;
40
 
 
41
 
/* Stay outside of the namespace because otherwise bison goes nuts */
42
 
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
43
 
 
44
 
namespace drizzled
45
 
{
46
 
 
47
 
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
48
 
 
49
 
/**
50
 
  save order by and tables in own lists.
 
22
 
 
23
static int lex_one_token(void *arg, void *yysession);
 
24
 
 
25
/*
 
26
  We are using pointer to this variable for distinguishing between assignment
 
27
  to NEW row field (when parsing trigger definition) and structured variable.
51
28
*/
52
 
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
53
 
{
54
 
  Order *order;
55
 
 
56
 
  if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
57
 
    return true;
58
 
 
59
 
  order->item_ptr= item;
60
 
  order->item= &order->item_ptr;
61
 
  order->asc = asc;
62
 
  order->free_me=0;
63
 
  order->used=0;
64
 
  order->counter_used= 0;
65
 
  list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
66
 
 
67
 
  return false;
68
 
}
 
29
 
 
30
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
69
31
 
70
32
/**
71
33
  LEX_STRING constant for null-string to be used in parser and other places.
72
34
*/
73
35
const LEX_STRING null_lex_str= {NULL, 0};
74
36
 
 
37
 
 
38
/*
 
39
  The following data is based on the latin1 character set, and is only
 
40
  used when comparing keywords
 
41
*/
 
42
 
 
43
static unsigned char to_upper_lex[]=
 
44
{
 
45
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
 
46
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
 
47
   32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
 
48
   48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
 
49
   64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
 
50
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
 
51
   96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
 
52
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
 
53
  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
 
54
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
 
55
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
 
56
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
 
57
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
 
58
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
 
59
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
 
60
  208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
 
61
};
 
62
 
 
63
/* 
 
64
  Names of the index hints (for error messages). Keep in sync with 
 
65
  index_hint_type 
 
66
*/
 
67
 
 
68
const char * index_hint_type_name[] =
 
69
{
 
70
  "IGNORE INDEX", 
 
71
  "USE INDEX", 
 
72
  "FORCE INDEX"
 
73
};
 
74
 
 
75
inline int lex_casecmp(const char *s, const char *t, uint32_t len)
 
76
{
 
77
  while (len-- != 0 &&
 
78
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
 
79
  return (int) len+1;
 
80
}
 
81
 
 
82
#include <lex_hash.h>
 
83
 
 
84
 
 
85
void lex_init(void)
 
86
{
 
87
  uint32_t i;
 
88
  for (i=0 ; i < array_elements(symbols) ; i++)
 
89
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
 
90
  for (i=0 ; i < array_elements(sql_functions) ; i++)
 
91
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
 
92
 
 
93
  return;
 
94
}
 
95
 
 
96
 
 
97
void lex_free(void)
 
98
{                                       // Call this when daemon ends
 
99
  return;
 
100
}
 
101
 
 
102
 
 
103
void
 
104
st_parsing_options::reset()
 
105
{
 
106
  allows_variable= true;
 
107
  allows_select_into= true;
 
108
  allows_select_procedure= true;
 
109
  allows_derived= true;
 
110
}
 
111
 
75
112
Lex_input_stream::Lex_input_stream(Session *session,
76
113
                                   const char* buffer,
77
 
                                   unsigned int length) :
78
 
  m_session(session),
 
114
                                   unsigned int length)
 
115
: m_session(session),
79
116
  yylineno(1),
80
117
  yytoklen(0),
81
118
  yylval(NULL),
95
132
  m_body_utf8(NULL),
96
133
  m_cpp_utf8_processed_ptr(NULL),
97
134
  next_state(MY_LEX_START),
 
135
  found_semicolon(NULL),
98
136
  ignore_space(1),
99
 
  in_comment(NO_COMMENT)
 
137
  in_comment(NO_COMMENT),
 
138
  m_underscore_cs(NULL)
100
139
{
101
 
  m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
 
140
  m_cpp_buf= (char*) session->alloc(length + 1);
102
141
  m_cpp_ptr= m_cpp_buf;
103
142
}
104
143
 
116
155
  @param begin_ptr  Pointer to the start of the body in the pre-processed
117
156
                    buffer.
118
157
*/
 
158
 
119
159
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
120
160
{
121
161
  assert(begin_ptr);
122
162
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
123
163
 
124
164
  uint32_t body_utf8_length=
125
 
    (m_buf_length / default_charset_info->mbminlen) *
 
165
    (m_buf_length / session->variables.character_set_client->mbminlen) *
126
166
    my_charset_utf8_bin.mbmaxlen;
127
167
 
128
 
  m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
 
168
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
129
169
  m_body_utf8_ptr= m_body_utf8;
130
170
  *m_body_utf8_ptr= 0;
131
171
 
152
192
                  m_cpp_utf8_processed_ptr will be set in the end of the
153
193
                  operation.
154
194
*/
 
195
 
155
196
void Lex_input_stream::body_utf8_append(const char *ptr,
156
197
                                        const char *end_ptr)
157
198
{
180
221
  @param ptr  Pointer in the pre-processed buffer, which specifies the end
181
222
              of the chunk, which should be appended to the utf8 body.
182
223
*/
 
224
 
183
225
void Lex_input_stream::body_utf8_append(const char *ptr)
184
226
{
185
227
  body_utf8_append(ptr, ptr);
196
238
                  m_cpp_utf8_processed_ptr will be set in the end of the
197
239
                  operation.
198
240
*/
199
 
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
 
241
 
 
242
void Lex_input_stream::body_utf8_append_literal(Session *session,
 
243
                                                const LEX_STRING *txt,
 
244
                                                const CHARSET_INFO * const txt_cs,
200
245
                                                const char *end_ptr)
201
246
{
202
247
  if (!m_cpp_utf8_processed_ptr)
203
248
    return;
204
249
 
 
250
  LEX_STRING utf_txt;
 
251
 
 
252
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
 
253
  {
 
254
    session->convert_string(&utf_txt,
 
255
                        &my_charset_utf8_general_ci,
 
256
                        txt->str, txt->length,
 
257
                        txt_cs);
 
258
  }
 
259
  else
 
260
  {
 
261
    utf_txt.str= txt->str;
 
262
    utf_txt.length= txt->length;
 
263
  }
 
264
 
205
265
  /* NOTE: utf_txt.length is in bytes, not in symbols. */
206
266
 
207
 
  memcpy(m_body_utf8_ptr, txt->str, txt->length);
208
 
  m_body_utf8_ptr += txt->length;
 
267
  memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
 
268
  m_body_utf8_ptr += utf_txt.length;
209
269
  *m_body_utf8_ptr= 0;
210
270
 
211
271
  m_cpp_utf8_processed_ptr= end_ptr;
212
272
}
213
273
 
 
274
 
214
275
/*
215
276
  This is called before every query that is to be parsed.
216
277
  Because of this, it's critical to not do too much things here.
217
278
  (We already do too much here)
218
279
*/
219
 
void LEX::start(Session *arg)
220
 
{
221
 
  lex_start(arg);
222
 
}
223
280
 
224
281
void lex_start(Session *session)
225
282
{
226
 
  LEX *lex= session->getLex();
 
283
  LEX *lex= session->lex;
227
284
 
228
285
  lex->session= lex->unit.session= session;
229
286
 
230
 
  lex->context_stack.clear();
 
287
  lex->context_stack.empty();
231
288
  lex->unit.init_query();
232
289
  lex->unit.init_select();
233
290
  /* 'parent_lex' is used in init_query() so it must be before it. */
234
291
  lex->select_lex.parent_lex= lex;
235
292
  lex->select_lex.init_query();
236
 
  lex->value_list.clear();
237
 
  lex->update_list.clear();
238
 
  lex->auxiliary_table_list.clear();
 
293
  lex->value_list.empty();
 
294
  lex->update_list.empty();
 
295
  lex->param_list.empty();
 
296
  lex->auxiliary_table_list.empty();
239
297
  lex->unit.next= lex->unit.master=
240
298
    lex->unit.link_next= lex->unit.return_to= 0;
241
299
  lex->unit.prev= lex->unit.link_prev= 0;
244
302
  lex->select_lex.master= &lex->unit;
245
303
  lex->select_lex.prev= &lex->unit.slave;
246
304
  lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
247
 
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
 
305
  lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
248
306
  lex->select_lex.options= 0;
249
307
  lex->select_lex.init_order();
250
 
  lex->select_lex.group_list.clear();
 
308
  lex->select_lex.group_list.empty();
251
309
  lex->describe= 0;
 
310
  lex->subqueries= false;
252
311
  lex->derived_tables= 0;
253
312
  lex->lock_option= TL_READ;
254
313
  lex->leaf_tables_insert= 0;
255
 
  lex->var_list.clear();
 
314
  lex->parsing_options.reset();
 
315
  lex->empty_field_list_on_rset= 0;
256
316
  lex->select_lex.select_number= 1;
257
317
  lex->length=0;
258
318
  lex->select_lex.in_sum_expr=0;
259
 
  lex->select_lex.group_list.clear();
260
 
  lex->select_lex.order_list.clear();
 
319
  lex->select_lex.ftfunc_list_alloc.empty();
 
320
  lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
 
321
  lex->select_lex.group_list.empty();
 
322
  lex->select_lex.order_list.empty();
261
323
  lex->sql_command= SQLCOM_END;
262
324
  lex->duplicates= DUP_ERROR;
263
325
  lex->ignore= 0;
 
326
  lex->proc_list.first= 0;
264
327
  lex->escape_used= false;
265
328
  lex->query_tables= 0;
266
329
  lex->reset_query_tables_list(false);
267
330
  lex->expr_allows_subselect= true;
268
331
  lex->use_only_table_context= false;
 
332
  lex->parse_vcol_expr= false;
269
333
 
270
334
  lex->name.str= 0;
271
335
  lex->name.length= 0;
272
336
  lex->nest_level=0 ;
273
337
  lex->allow_sum_func= 0;
274
338
  lex->in_sum_func= NULL;
275
 
  lex->type= 0;
 
339
  /*
 
340
    ok, there must be a better solution for this, long-term
 
341
    I tried "memset" in the sql_yacc.yy code, but that for
 
342
    some reason made the values zero, even if they were set
 
343
  */
 
344
  lex->server_options.server_name= 0;
 
345
  lex->server_options.server_name_length= 0;
 
346
  lex->server_options.host= 0;
 
347
  lex->server_options.db= 0;
 
348
  lex->server_options.username= 0;
 
349
  lex->server_options.password= 0;
 
350
  lex->server_options.scheme= 0;
 
351
  lex->server_options.owner= 0;
 
352
  lex->server_options.port= -1;
276
353
 
277
354
  lex->is_lex_started= true;
278
 
  lex->statement= NULL;
279
 
  
280
 
  lex->is_cross= false;
281
 
  lex->reset();
 
355
  return;
282
356
}
283
357
 
284
 
void LEX::end()
 
358
void lex_end(LEX *lex)
285
359
{
286
 
  if (yacc_yyss)
 
360
  if (lex->yacc_yyss)
287
361
  {
288
 
    free(yacc_yyss);
289
 
    free(yacc_yyvs);
290
 
    yacc_yyss= 0;
291
 
    yacc_yyvs= 0;
 
362
    free(lex->yacc_yyss);
 
363
    free(lex->yacc_yyvs);
 
364
    lex->yacc_yyss= 0;
 
365
    lex->yacc_yyvs= 0;
292
366
  }
293
367
 
294
 
  safe_delete(result);
295
 
  safe_delete(_create_table);
296
 
  _create_table= NULL;
297
 
  _create_field= NULL;
298
 
 
299
 
  result= 0;
300
 
  setCacheable(true);
301
 
 
302
 
  safe_delete(statement);
 
368
  /* release used plugins */
 
369
  plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer, 
 
370
                     lex->plugins.elements);
 
371
  reset_dynamic(&lex->plugins);
 
372
 
 
373
  delete lex->result;
 
374
  lex->result= 0;
 
375
 
 
376
  return;
303
377
}
304
378
 
 
379
 
305
380
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
306
381
{
307
 
  /* Plenty of memory for the largest lex symbol we have */
308
 
  char tok_upper[64];
309
382
  const char *tok= lip->get_tok_start();
310
 
  uint32_t tok_pos= 0;
311
 
  for (;tok_pos<len && tok_pos<63;tok_pos++)
312
 
    tok_upper[tok_pos]=my_toupper(system_charset_info, tok[tok_pos]);
313
 
  tok_upper[tok_pos]=0;
314
383
 
315
 
  const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
 
384
  SYMBOL *symbol= get_hash_symbol(tok, len, function);
316
385
  if (symbol)
317
386
  {
318
387
    lip->yylval->symbol.symbol=symbol;
321
390
 
322
391
    return symbol->tok;
323
392
  }
324
 
 
325
393
  return 0;
326
394
}
327
395
 
 
396
/*
 
397
  Check if name is a keyword
 
398
 
 
399
  SYNOPSIS
 
400
    is_keyword()
 
401
    name      checked name (must not be empty)
 
402
    len       length of checked name
 
403
 
 
404
  RETURN VALUES
 
405
    0         name is a keyword
 
406
    1         name isn't a keyword
 
407
*/
 
408
 
 
409
bool is_keyword(const char *name, uint32_t len)
 
410
{
 
411
  assert(len != 0);
 
412
  return get_hash_symbol(name,len,0)!=0;
 
413
}
 
414
 
328
415
bool is_lex_native_function(const LEX_STRING *name)
329
416
{
330
417
  assert(name != NULL);
331
 
  return (lookup_symbol(name->str, name->length, 1) != 0);
 
418
  return (get_hash_symbol(name->str, name->length, 1) != 0);
332
419
}
333
420
 
334
421
/* make a copy of token before ptr and set yytoklen */
 
422
 
335
423
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
336
424
{
337
425
  LEX_STRING tmp;
345
433
  return tmp;
346
434
}
347
435
 
348
 
/*
349
 
 todo:
350
 
   There are no dangerous charsets in mysql for function
351
 
   get_quoted_token yet. But it should be fixed in the
 
436
/* 
 
437
 todo: 
 
438
   There are no dangerous charsets in mysql for function 
 
439
   get_quoted_token yet. But it should be fixed in the 
352
440
   future to operate multichar strings (like ucs2)
353
441
*/
 
442
 
354
443
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
355
444
                                   uint32_t skip,
356
445
                                   uint32_t length, char quote)
360
449
  char *to;
361
450
  lip->yyUnget();                       // ptr points now after last token char
362
451
  tmp.length= lip->yytoklen=length;
363
 
  tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
 
452
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
364
453
  from= lip->get_tok_start() + skip;
365
454
  to= tmp.str;
366
455
  end= to+length;
385
474
  Return an unescaped text literal without quotes
386
475
  Fix sometimes to do only one scan of the string
387
476
*/
 
477
 
388
478
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
389
479
{
390
 
  unsigned char c,sep;
391
 
  bool found_escape= false;
 
480
  register unsigned char c,sep;
 
481
  uint32_t found_escape=0;
392
482
  const CHARSET_INFO * const cs= lip->m_session->charset();
393
483
 
394
484
  lip->tok_bitmap= 0;
397
487
  {
398
488
    c= lip->yyGet();
399
489
    lip->tok_bitmap|= c;
 
490
#ifdef USE_MB
400
491
    {
401
 
      if (use_mb(cs))
402
 
      {
403
 
        int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
404
 
        if (l != 0) 
405
 
        {
406
 
          lip->skip_binary(l-1);
407
 
          continue;
408
 
        }
 
492
      int l;
 
493
      if (use_mb(cs) &&
 
494
          (l = my_ismbchar(cs,
 
495
                           lip->get_ptr() -1,
 
496
                           lip->get_end_of_query()))) {
 
497
        lip->skip_binary(l-1);
 
498
        continue;
409
499
      }
410
500
    }
 
501
#endif
411
502
    if (c == '\\')
412
503
    {                                   // Escaped character
413
 
      found_escape= true;
 
504
      found_escape=1;
414
505
      if (lip->eof())
415
 
        return 0;
 
506
        return 0;
416
507
      lip->yySkip();
417
508
    }
418
509
    else if (c == sep)
419
510
    {
420
511
      if (c == lip->yyGet())            // Check if two separators in a row
421
512
      {
422
 
        found_escape= true;                 // duplicate. Remember for delete
423
 
        continue;
 
513
        found_escape=1;                 // duplicate. Remember for delete
 
514
        continue;
424
515
      }
425
516
      else
426
517
        lip->yyUnget();
432
523
      str= lip->get_tok_start();
433
524
      end= lip->get_ptr();
434
525
      /* Extract the text from the token */
435
 
      str+= pre_skip;
436
 
      end-= post_skip;
 
526
      str += pre_skip;
 
527
      end -= post_skip;
437
528
      assert(end >= str);
438
529
 
439
 
      if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
440
 
        return (char*) "";              // memory::SqlAlloc has set error flag
 
530
      if (!(start= (char*) lip->m_session->alloc((uint) (end-str)+1)))
 
531
        return (char*) "";              // Sql_alloc has set error flag
441
532
 
442
533
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
443
534
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
444
535
 
445
 
      if (! found_escape)
 
536
      if (!found_escape)
446
537
      {
447
 
        lip->yytoklen= (uint32_t) (end-str);
448
 
        memcpy(start, str, lip->yytoklen);
449
 
        start[lip->yytoklen]= 0;
 
538
        lip->yytoklen=(uint) (end-str);
 
539
        memcpy(start,str,lip->yytoklen);
 
540
        start[lip->yytoklen]=0;
450
541
      }
451
542
      else
452
543
      {
453
544
        char *to;
454
545
 
455
 
        for (to= start; str != end; str++)
456
 
        {
457
 
          if (use_mb(cs))
458
 
          {
459
 
            int l= my_ismbchar(cs, str, end);
460
 
            if (l != 0)
461
 
            {
462
 
              while (l--)
463
 
                *to++= *str++;
464
 
              str--;
465
 
              continue;
466
 
            }
467
 
          }
468
 
          if (*str == '\\' && (str + 1) != end)
469
 
          {
470
 
            switch (*++str) {
471
 
            case 'n':
472
 
              *to++= '\n';
473
 
              break;
474
 
            case 't':
475
 
              *to++= '\t';
476
 
              break;
477
 
            case 'r':
478
 
              *to++= '\r';
479
 
              break;
480
 
            case 'b':
481
 
              *to++= '\b';
482
 
              break;
483
 
            case '0':
484
 
              *to++= 0;                 // Ascii null
485
 
              break;
486
 
            case 'Z':                   // ^Z must be escaped on Win32
487
 
              *to++= '\032';
488
 
              break;
489
 
            case '_':
490
 
            case '%':
491
 
              *to++= '\\';              // remember prefix for wildcard
492
 
              /* Fall through */
493
 
            default:
 
546
        for (to=start ; str != end ; str++)
 
547
        {
 
548
#ifdef USE_MB
 
549
          int l;
 
550
          if (use_mb(cs) &&
 
551
              (l = my_ismbchar(cs, str, end))) {
 
552
              while (l--)
 
553
                  *to++ = *str++;
 
554
              str--;
 
555
              continue;
 
556
          }
 
557
#endif
 
558
          if (*str == '\\' && str+1 != end)
 
559
          {
 
560
            switch(*++str) {
 
561
            case 'n':
 
562
              *to++='\n';
 
563
              break;
 
564
            case 't':
 
565
              *to++= '\t';
 
566
              break;
 
567
            case 'r':
 
568
              *to++ = '\r';
 
569
              break;
 
570
            case 'b':
 
571
              *to++ = '\b';
 
572
              break;
 
573
            case '0':
 
574
              *to++= 0;                 // Ascii null
 
575
              break;
 
576
            case 'Z':                   // ^Z must be escaped on Win32
 
577
              *to++='\032';
 
578
              break;
 
579
            case '_':
 
580
            case '%':
 
581
              *to++= '\\';              // remember prefix for wildcard
 
582
              /* Fall through */
 
583
            default:
494
584
              *to++= *str;
495
 
              break;
496
 
            }
497
 
          }
498
 
          else if (*str == sep)
499
 
            *to++= *str++;              // Two ' or "
500
 
          else
501
 
            *to++ = *str;
502
 
        }
503
 
        *to= 0;
504
 
        lip->yytoklen= (uint32_t) (to - start);
 
585
              break;
 
586
            }
 
587
          }
 
588
          else if (*str == sep)
 
589
            *to++= *str++;              // Two ' or "
 
590
          else
 
591
            *to++ = *str;
 
592
        }
 
593
        *to=0;
 
594
        lip->yytoklen=(uint) (to-start);
505
595
      }
506
596
      return start;
507
597
    }
518
608
** is done with int64_t or double.
519
609
*/
520
610
 
521
 
static const char *long_str= "2147483647";
522
 
static const uint32_t long_len= 10;
523
 
static const char *signed_long_str= "-2147483648";
524
 
static const char *int64_t_str= "9223372036854775807";
525
 
static const uint32_t int64_t_len= 19;
526
 
static const char *signed_int64_t_str= "-9223372036854775808";
527
 
static const uint32_t signed_int64_t_len= 19;
528
 
static const char *unsigned_int64_t_str= "18446744073709551615";
529
 
static const uint32_t unsigned_int64_t_len= 20;
 
611
static const char *long_str="2147483647";
 
612
static const uint32_t long_len=10;
 
613
static const char *signed_long_str="-2147483648";
 
614
static const char *int64_t_str="9223372036854775807";
 
615
static const uint32_t int64_t_len=19;
 
616
static const char *signed_int64_t_str="-9223372036854775808";
 
617
static const uint32_t signed_int64_t_len=19;
 
618
static const char *unsigned_int64_t_str="18446744073709551615";
 
619
static const uint32_t unsigned_int64_t_len=20;
530
620
 
531
621
static inline uint32_t int_token(const char *str,uint32_t length)
532
622
{
600
690
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
601
691
}
602
692
 
603
 
} /* namespace drizzled */
 
693
 
604
694
/*
605
 
  base_sql_lex remember the following states from the following sql_baselex()
 
695
  DRIZZLElex remember the following states from the following DRIZZLElex()
606
696
 
607
697
  - MY_LEX_EOQ                  Found end of query
608
698
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
609
699
                                (which can't be followed by a signed number)
610
700
*/
611
 
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
 
701
 
 
702
int DRIZZLElex(void *arg, void *yysession)
612
703
{
613
 
  drizzled::Lex_input_stream *lip= session->m_lip;
 
704
  Session *session= (Session *)yysession;
 
705
  Lex_input_stream *lip= session->m_lip;
 
706
  YYSTYPE *yylval=(YYSTYPE*) arg;
614
707
  int token;
615
708
 
616
709
  if (lip->lookahead_token != END_OF_INPUT)
626
719
    return token;
627
720
  }
628
721
 
629
 
  token= drizzled::lex_one_token(yylval, session);
 
722
  token= lex_one_token(arg, yysession);
630
723
 
631
724
  switch(token) {
632
725
  case WITH:
637
730
      to transform the grammar into a LALR(1) grammar,
638
731
      which sql_yacc.yy can process.
639
732
    */
640
 
    token= drizzled::lex_one_token(yylval, session);
 
733
    token= lex_one_token(arg, yysession);
641
734
    if (token == ROLLUP_SYM)
642
735
    {
643
736
      return WITH_ROLLUP_SYM;
652
745
      lip->lookahead_token= token;
653
746
      return WITH;
654
747
    }
 
748
    break;
655
749
  default:
656
750
    break;
657
751
  }
659
753
  return token;
660
754
}
661
755
 
662
 
namespace drizzled
663
 
{
664
 
 
665
 
int lex_one_token(ParserType *yylval, drizzled::Session *session)
666
 
{
667
 
  unsigned char c= 0; /* Just set to shutup GCC */
 
756
int lex_one_token(void *arg, void *yysession)
 
757
{
 
758
  register unsigned char c= 0; /* Just set to shutup GCC */
668
759
  bool comment_closed;
669
760
  int   tokval, result_state;
670
761
  unsigned int length;
671
762
  enum my_lex_states state;
 
763
  Session *session= (Session *)yysession;
672
764
  Lex_input_stream *lip= session->m_lip;
673
 
  LEX *lex= session->getLex();
 
765
  LEX *lex= session->lex;
 
766
  YYSTYPE *yylval=(YYSTYPE*) arg;
674
767
  const CHARSET_INFO * const cs= session->charset();
675
768
  unsigned char *state_map= cs->state_map;
676
769
  unsigned char *ident_map= cs->ident_map;
688
781
      // Skip starting whitespace
689
782
      while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
690
783
      {
691
 
        if (c == '\n')
692
 
          lip->yylineno++;
 
784
        if (c == '\n')
 
785
          lip->yylineno++;
693
786
 
694
787
        lip->yySkip();
695
788
      }
702
795
    case MY_LEX_ESCAPE:
703
796
      if (lip->yyGet() == 'N')
704
797
      {                                 // Allow \N as shortcut for NULL
705
 
        yylval->lex_str.str=(char*) "\\N";
706
 
        yylval->lex_str.length=2;
707
 
        return NULL_SYM;
 
798
        yylval->lex_str.str=(char*) "\\N";
 
799
        yylval->lex_str.length=2;
 
800
        return NULL_SYM;
708
801
      }
709
802
    case MY_LEX_CHAR:                   // Unknown or single char token
710
803
    case MY_LEX_SKIP:                   // This should not happen
717
810
      }
718
811
 
719
812
      if (c != ')')
720
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
813
        lip->next_state= MY_LEX_START;  // Allow signed numbers
721
814
 
722
815
      if (c == ',')
723
816
      {
738
831
    case MY_LEX_IDENT_OR_HEX:
739
832
      if (lip->yyPeek() == '\'')
740
833
      {                                 // Found x'hex-number'
741
 
        state= MY_LEX_HEX_NUMBER;
742
 
        break;
 
834
        state= MY_LEX_HEX_NUMBER;
 
835
        break;
743
836
      }
744
837
    case MY_LEX_IDENT_OR_BIN:
745
838
      if (lip->yyPeek() == '\'')
749
842
      }
750
843
    case MY_LEX_IDENT:
751
844
      const char *start;
 
845
#if defined(USE_MB) && defined(USE_MB_IDENT)
752
846
      if (use_mb(cs))
753
847
      {
754
 
        result_state= IDENT_QUOTED;
 
848
        result_state= IDENT_QUOTED;
755
849
        if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
756
850
        {
757
851
          int l = my_ismbchar(cs,
767
861
        {
768
862
          if (my_mbcharlen(cs, c) > 1)
769
863
          {
770
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
771
 
            if (l == 0)
 
864
            int l;
 
865
            if ((l = my_ismbchar(cs,
 
866
                                 lip->get_ptr() -1,
 
867
                                 lip->get_end_of_query())) == 0)
772
868
              break;
773
869
            lip->skip_binary(l-1);
774
870
          }
775
871
        }
776
872
      }
777
873
      else
 
874
#endif
778
875
      {
779
876
        for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {};
780
877
        /* If there were non-ASCII characters, mark that we must convert */
791
888
        for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
792
889
      }
793
890
      if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
794
 
              lip->next_state=MY_LEX_IDENT_SEP;
 
891
        lip->next_state=MY_LEX_IDENT_SEP;
795
892
      else
796
893
      {                                 // '(' must follow directly if function
797
894
        lip->yyUnget();
798
 
        if ((tokval = find_keyword(lip, length, c == '(')))
799
 
        {
800
 
          lip->next_state= MY_LEX_START;        // Allow signed numbers
801
 
          return(tokval);               // Was keyword
802
 
        }
 
895
        if ((tokval = find_keyword(lip, length, c == '(')))
 
896
        {
 
897
          lip->next_state= MY_LEX_START;        // Allow signed numbers
 
898
          return(tokval);               // Was keyword
 
899
        }
803
900
        lip->yySkip();                  // next state does a unget
804
901
      }
805
902
      yylval->lex_str=get_token(lip, 0, length);
806
903
 
 
904
      /*
 
905
         Note: "SELECT _bla AS 'alias'"
 
906
         _bla should be considered as a IDENT if charset haven't been found.
 
907
         So we don't use MYF(MY_WME) with get_charset_by_csname to avoid
 
908
         producing an error.
 
909
      */
 
910
 
 
911
      if (yylval->lex_str.str[0] == '_')
 
912
      {
 
913
        const CHARSET_INFO * const cs= get_charset_by_csname(yylval->lex_str.str + 1,
 
914
                                                             MY_CS_PRIMARY, MYF(0));
 
915
        if (cs)
 
916
        {
 
917
          yylval->charset= cs;
 
918
          lip->m_underscore_cs= cs;
 
919
 
 
920
          lip->body_utf8_append(lip->m_cpp_text_start,
 
921
                                lip->get_cpp_tok_start() + length);
 
922
          return(UNDERSCORE_CHARSET);
 
923
        }
 
924
      }
 
925
 
807
926
      lip->body_utf8_append(lip->m_cpp_text_start);
808
927
 
809
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
928
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
929
                                    lip->m_cpp_text_end);
810
930
 
811
931
      return(result_state);                     // IDENT or IDENT_QUOTED
812
932
 
816
936
      c= lip->yyGet();                  // should be '.'
817
937
      lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
818
938
      if (!ident_map[(uint8_t)lip->yyPeek()])            // Probably ` or "
819
 
        lip->next_state= MY_LEX_START;
 
939
        lip->next_state= MY_LEX_START;
820
940
      return((int) c);
821
941
 
822
942
    case MY_LEX_NUMBER_IDENT:           // number or ident which num-start
855
975
      while (my_isdigit(cs, (c = lip->yyGet()))) ;
856
976
      if (!ident_map[c])
857
977
      {                                 // Can't be identifier
858
 
        state=MY_LEX_INT_OR_REAL;
859
 
        break;
 
978
        state=MY_LEX_INT_OR_REAL;
 
979
        break;
860
980
      }
861
981
      if (c == 'e' || c == 'E')
862
982
      {
863
 
        // The following test is written this way to allow numbers of type 1e1
 
983
        // The following test is written this way to allow numbers of type 1e1
864
984
        if (my_isdigit(cs,lip->yyPeek()) ||
865
985
            (c=(lip->yyGet())) == '+' || c == '-')
866
 
        {                               // Allow 1E+10
 
986
        {                               // Allow 1E+10
867
987
          if (my_isdigit(cs,lip->yyPeek()))     // Number must have digit after sign
868
 
          {
 
988
          {
869
989
            lip->yySkip();
870
990
            while (my_isdigit(cs,lip->yyGet())) ;
871
991
            yylval->lex_str=get_token(lip, 0, lip->yyLength());
872
 
            return(FLOAT_NUM);
873
 
          }
874
 
        }
 
992
            return(FLOAT_NUM);
 
993
          }
 
994
        }
875
995
        lip->yyUnget();
876
996
      }
877
997
      // fall through
878
998
    case MY_LEX_IDENT_START:                    // We come here after '.'
879
999
      result_state= IDENT;
 
1000
#if defined(USE_MB) && defined(USE_MB_IDENT)
880
1001
      if (use_mb(cs))
881
1002
      {
882
 
        result_state= IDENT_QUOTED;
 
1003
        result_state= IDENT_QUOTED;
883
1004
        while (ident_map[c=lip->yyGet()])
884
1005
        {
885
1006
          if (my_mbcharlen(cs, c) > 1)
886
1007
          {
887
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
888
 
            if (l == 0)
 
1008
            int l;
 
1009
            if ((l = my_ismbchar(cs,
 
1010
                                 lip->get_ptr() -1,
 
1011
                                 lip->get_end_of_query())) == 0)
889
1012
              break;
890
1013
            lip->skip_binary(l-1);
891
1014
          }
892
1015
        }
893
1016
      }
894
1017
      else
 
1018
#endif
895
1019
      {
896
1020
        for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
897
1021
        /* If there were non-ASCII characters, mark that we must convert */
898
1022
        result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
899
1023
      }
900
1024
      if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
901
 
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
 
1025
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
902
1026
 
903
1027
      yylval->lex_str= get_token(lip, 0, lip->yyLength());
904
1028
 
905
1029
      lip->body_utf8_append(lip->m_cpp_text_start);
906
1030
 
907
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1031
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1032
                                    lip->m_cpp_text_end);
908
1033
 
909
1034
      return(result_state);
910
1035
 
914
1039
      char quote_char= c;                       // Used char
915
1040
      while ((c=lip->yyGet()))
916
1041
      {
917
 
        int var_length;
918
 
        if ((var_length= my_mbcharlen(cs, c)) == 1)
919
 
        {
920
 
          if (c == quote_char)
921
 
          {
922
 
                  if (lip->yyPeek() != quote_char)
923
 
              break;
924
 
                  c=lip->yyGet();
925
 
            double_quotes++;
926
 
            continue;
927
 
          }
928
 
        }
929
 
        else if (var_length < 1)
930
 
          break;                                // Error
 
1042
        int var_length;
 
1043
        if ((var_length= my_mbcharlen(cs, c)) == 1)
 
1044
        {
 
1045
          if (c == quote_char)
 
1046
          {
 
1047
            if (lip->yyPeek() != quote_char)
 
1048
              break;
 
1049
            c=lip->yyGet();
 
1050
            double_quotes++;
 
1051
            continue;
 
1052
          }
 
1053
        }
 
1054
#ifdef USE_MB
 
1055
        else if (var_length < 1)
 
1056
          break;                                // Error
931
1057
        lip->skip_binary(var_length-1);
 
1058
#endif
932
1059
      }
933
1060
      if (double_quotes)
934
 
              yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
 
1061
        yylval->lex_str=get_quoted_token(lip, 1,
 
1062
                                         lip->yyLength() - double_quotes -1,
 
1063
                                         quote_char);
935
1064
      else
936
1065
        yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
937
1066
      if (c == quote_char)
938
1067
        lip->yySkip();                  // Skip end `
939
1068
      lip->next_state= MY_LEX_START;
 
1069
 
940
1070
      lip->body_utf8_append(lip->m_cpp_text_start);
941
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1071
 
 
1072
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1073
                                    lip->m_cpp_text_end);
 
1074
 
942
1075
      return(IDENT_QUOTED);
943
1076
    }
944
1077
    case MY_LEX_INT_OR_REAL:            // Complete int or incomplete real
945
1078
      if (c != '.')
946
1079
      {                                 // Found complete integer number.
947
1080
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
948
 
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
 
1081
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
949
1082
      }
950
1083
      // fall through
951
1084
    case MY_LEX_REAL:                   // Incomplete real number
954
1087
      if (c == 'e' || c == 'E')
955
1088
      {
956
1089
        c = lip->yyGet();
957
 
        if (c == '-' || c == '+')
958
 
                c = lip->yyGet();                     // Skip sign
959
 
        if (!my_isdigit(cs,c))
960
 
        {                               // No digit after sign
961
 
          state= MY_LEX_CHAR;
962
 
          break;
963
 
        }
 
1090
        if (c == '-' || c == '+')
 
1091
          c = lip->yyGet();                     // Skip sign
 
1092
        if (!my_isdigit(cs,c))
 
1093
        {                               // No digit after sign
 
1094
          state= MY_LEX_CHAR;
 
1095
          break;
 
1096
        }
964
1097
        while (my_isdigit(cs,lip->yyGet())) ;
965
1098
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
966
 
        return(FLOAT_NUM);
 
1099
        return(FLOAT_NUM);
967
1100
      }
968
1101
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
969
1102
      return(DECIMAL_NUM);
1000
1133
        lip->yySkip();
1001
1134
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1002
1135
      {
1003
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
1004
 
        return(tokval);
 
1136
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
1137
        return(tokval);
1005
1138
      }
1006
1139
      state = MY_LEX_CHAR;              // Something fishy found
1007
1140
      break;
1016
1149
      }
1017
1150
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1018
1151
      {
1019
 
        lip->next_state= MY_LEX_START;  // Found long op
1020
 
        return(tokval);
 
1152
        lip->next_state= MY_LEX_START;  // Found long op
 
1153
        return(tokval);
1021
1154
      }
1022
1155
      state = MY_LEX_CHAR;              // Something fishy found
1023
1156
      break;
1025
1158
    case MY_LEX_BOOL:
1026
1159
      if (c != lip->yyPeek())
1027
1160
      {
1028
 
        state=MY_LEX_CHAR;
1029
 
        break;
 
1161
        state=MY_LEX_CHAR;
 
1162
        break;
1030
1163
      }
1031
1164
      lip->yySkip();
1032
1165
      tokval = find_keyword(lip,2,0);   // Is a bool operator
1043
1176
    case MY_LEX_STRING:                 // Incomplete text string
1044
1177
      if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1045
1178
      {
1046
 
        state= MY_LEX_CHAR;             // Read char by char
1047
 
        break;
 
1179
        state= MY_LEX_CHAR;             // Read char by char
 
1180
        break;
1048
1181
      }
1049
1182
      yylval->lex_str.length=lip->yytoklen;
1050
1183
 
1051
1184
      lip->body_utf8_append(lip->m_cpp_text_start);
1052
1185
 
1053
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1186
      lip->body_utf8_append_literal(session, &yylval->lex_str,
 
1187
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
 
1188
        lip->m_cpp_text_end);
 
1189
 
 
1190
      lip->m_underscore_cs= NULL;
1054
1191
 
1055
1192
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1056
1193
      return(TEXT_STRING);
1064
1201
    case MY_LEX_LONG_COMMENT:           /* Long C comment? */
1065
1202
      if (lip->yyPeek() != '*')
1066
1203
      {
1067
 
        state=MY_LEX_CHAR;              // Probable division
1068
 
        break;
 
1204
        state=MY_LEX_CHAR;              // Probable division
 
1205
        break;
1069
1206
      }
1070
1207
      lex->select_lex.options|= OPTION_FOUND_COMMENT;
1071
1208
      /* Reject '/' '*', since we might need to turn off the echo */
1082
1219
 
1083
1220
        /*
1084
1221
          The special comment format is very strict:
1085
 
          '/' '*' '!', followed by digits ended by a non-digit.
1086
 
          There must be at least 5 digits for it to count
 
1222
          '/' '*' '!', followed by exactly
 
1223
          1 digit (major), 2 digits (minor), then 2 digits (dot).
 
1224
          32302 -> 3.23.02
 
1225
          50032 -> 5.0.32
 
1226
          50114 -> 5.1.14
1087
1227
        */
1088
 
        const int MAX_VERSION_SIZE= 16;
1089
 
        char version_str[MAX_VERSION_SIZE];
1090
 
 
1091
 
        int pos= 0;
1092
 
        do
1093
 
        {
1094
 
          version_str[pos]= lip->yyPeekn(pos);
1095
 
          pos++;
1096
 
        } while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1097
 
        version_str[pos]= 0;
1098
 
 
1099
 
        /* To keep some semblance of compatibility, we impose a 5 digit floor */
1100
 
        if (pos > 4)
1101
 
        {
1102
 
          uint64_t version;
1103
 
          version=strtoll(version_str, NULL, 10);
 
1228
        char version_str[6];
 
1229
        version_str[0]= lip->yyPeekn(0);
 
1230
        version_str[1]= lip->yyPeekn(1);
 
1231
        version_str[2]= lip->yyPeekn(2);
 
1232
        version_str[3]= lip->yyPeekn(3);
 
1233
        version_str[4]= lip->yyPeekn(4);
 
1234
        version_str[5]= 0;
 
1235
        if (  my_isdigit(cs, version_str[0])
 
1236
           && my_isdigit(cs, version_str[1])
 
1237
           && my_isdigit(cs, version_str[2])
 
1238
           && my_isdigit(cs, version_str[3])
 
1239
           && my_isdigit(cs, version_str[4])
 
1240
           )
 
1241
        {
 
1242
          ulong version;
 
1243
          version=strtol(version_str, NULL, 10);
1104
1244
 
1105
1245
          /* Accept 'M' 'm' 'm' 'd' 'd' */
1106
 
          lip->yySkipn(pos-1);
 
1246
          lip->yySkipn(5);
1107
1247
 
1108
1248
          if (version <= DRIZZLE_VERSION_ID)
1109
1249
          {
1172
1312
        state=MY_LEX_START;
1173
1313
      }
1174
1314
      else
1175
 
        state=MY_LEX_CHAR;              // Return '*'
 
1315
        state=MY_LEX_CHAR;              // Return '*'
1176
1316
      break;
1177
1317
    case MY_LEX_SET_VAR:                // Check if ':='
1178
1318
      if (lip->yyPeek() != '=')
1179
1319
      {
1180
 
        state=MY_LEX_CHAR;              // Return ':'
1181
 
        break;
 
1320
        state=MY_LEX_CHAR;              // Return ':'
 
1321
        break;
1182
1322
      }
1183
1323
      lip->yySkip();
1184
1324
      return (SET_VAR);
1185
1325
    case MY_LEX_SEMICOLON:                      // optional line terminator
1186
1326
      if (lip->yyPeek())
1187
1327
      {
 
1328
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1329
        {
 
1330
          lip->found_semicolon= lip->get_ptr();
 
1331
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1332
          lip->next_state= MY_LEX_END;
 
1333
          lip->set_echo(true);
 
1334
          return (END_OF_INPUT);
 
1335
        }
1188
1336
        state= MY_LEX_CHAR;             // Return ';'
1189
 
        break;
 
1337
        break;
1190
1338
      }
1191
1339
      lip->next_state=MY_LEX_END;       // Mark for next loop
1192
1340
      return(END_OF_INPUT);
1207
1355
      break;
1208
1356
    case MY_LEX_END:
1209
1357
      lip->next_state=MY_LEX_END;
1210
 
      return false;                     // We found end of input last time
1211
 
 
 
1358
      return(0);                        // We found end of input last time
 
1359
      
1212
1360
      /* Actually real shouldn't start with . but allow them anyhow */
1213
1361
    case MY_LEX_REAL_OR_POINT:
1214
1362
      if (my_isdigit(cs,lip->yyPeek()))
1215
 
        state= MY_LEX_REAL;             // Real
 
1363
        state = MY_LEX_REAL;            // Real
1216
1364
      else
1217
1365
      {
1218
 
        state= MY_LEX_IDENT_SEP;        // return '.'
 
1366
        state= MY_LEX_IDENT_SEP;        // return '.'
1219
1367
        lip->yyUnget();                 // Put back '.'
1220
1368
      }
1221
1369
      break;
1224
1372
      case MY_LEX_STRING:
1225
1373
      case MY_LEX_USER_VARIABLE_DELIMITER:
1226
1374
      case MY_LEX_STRING_OR_DELIMITER:
1227
 
        break;
 
1375
        break;
1228
1376
      case MY_LEX_USER_END:
1229
 
        lip->next_state=MY_LEX_SYSTEM_VAR;
1230
 
        break;
 
1377
        lip->next_state=MY_LEX_SYSTEM_VAR;
 
1378
        break;
1231
1379
      default:
1232
 
        lip->next_state=MY_LEX_HOSTNAME;
1233
 
        break;
 
1380
        lip->next_state=MY_LEX_HOSTNAME;
 
1381
        break;
1234
1382
      }
1235
1383
      yylval->lex_str.str=(char*) lip->get_ptr();
1236
1384
      yylval->lex_str.length=1;
1237
1385
      return((int) '@');
1238
1386
    case MY_LEX_HOSTNAME:               // end '@' of user@hostname
1239
1387
      for (c=lip->yyGet() ;
1240
 
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
 
1388
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
1241
1389
           c= lip->yyGet()) ;
1242
1390
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1243
1391
      return(LEX_HOSTNAME);
1252
1400
      return((int) '@');
1253
1401
    case MY_LEX_IDENT_OR_KEYWORD:
1254
1402
      /*
1255
 
        We come here when we have found two '@' in a row.
1256
 
        We should now be able to handle:
1257
 
        [(global | local | session) .]variable_name
 
1403
        We come here when we have found two '@' in a row.
 
1404
        We should now be able to handle:
 
1405
        [(global | local | session) .]variable_name
1258
1406
      */
1259
1407
 
1260
1408
      for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1262
1410
      result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1263
1411
 
1264
1412
      if (c == '.')
1265
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
1413
        lip->next_state=MY_LEX_IDENT_SEP;
1266
1414
      length= lip->yyLength();
1267
1415
      if (length == 0)
1268
1416
        return(ABORT_SYM);              // Names must be nonempty.
1269
1417
      if ((tokval= find_keyword(lip, length,0)))
1270
1418
      {
1271
1419
        lip->yyUnget();                         // Put back 'c'
1272
 
        return(tokval);                         // Was keyword
 
1420
        return(tokval);                         // Was keyword
1273
1421
      }
1274
1422
      yylval->lex_str=get_token(lip, 0, length);
1275
1423
 
1276
1424
      lip->body_utf8_append(lip->m_cpp_text_start);
1277
1425
 
1278
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1426
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1427
                                    lip->m_cpp_text_end);
1279
1428
 
1280
1429
      return(result_state);
1281
1430
    }
1282
1431
  }
1283
1432
}
1284
1433
 
 
1434
 
 
1435
/**
 
1436
  Construct a copy of this object to be used for mysql_alter_table
 
1437
  and mysql_create_table.
 
1438
 
 
1439
  Historically, these two functions modify their Alter_info
 
1440
  arguments. This behaviour breaks re-execution of prepared
 
1441
  statements and stored procedures and is compensated by always
 
1442
  supplying a copy of Alter_info to these functions.
 
1443
 
 
1444
  @return You need to use check the error in Session for out
 
1445
  of memory condition after calling this function.
 
1446
*/
 
1447
 
 
1448
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
 
1449
  :drop_list(rhs.drop_list, mem_root),
 
1450
  alter_list(rhs.alter_list, mem_root),
 
1451
  key_list(rhs.key_list, mem_root),
 
1452
  create_list(rhs.create_list, mem_root),
 
1453
  flags(rhs.flags),
 
1454
  keys_onoff(rhs.keys_onoff),
 
1455
  tablespace_op(rhs.tablespace_op),
 
1456
  no_parts(rhs.no_parts),
 
1457
  build_method(rhs.build_method),
 
1458
  datetime_field(rhs.datetime_field),
 
1459
  error_if_not_empty(rhs.error_if_not_empty)
 
1460
{
 
1461
  /*
 
1462
    Make deep copies of used objects.
 
1463
    This is not a fully deep copy - clone() implementations
 
1464
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
 
1465
    do not copy string constants. At the same length the only
 
1466
    reason we make a copy currently is that ALTER/CREATE TABLE
 
1467
    code changes input Alter_info definitions, but string
 
1468
    constants never change.
 
1469
  */
 
1470
  list_copy_and_replace_each_value(drop_list, mem_root);
 
1471
  list_copy_and_replace_each_value(alter_list, mem_root);
 
1472
  list_copy_and_replace_each_value(key_list, mem_root);
 
1473
  list_copy_and_replace_each_value(create_list, mem_root);
 
1474
}
 
1475
 
 
1476
 
1285
1477
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1286
1478
{
1287
1479
  /*
1289
1481
    This code assumes that there are no multi-bytes characters
1290
1482
    that can be considered white-space.
1291
1483
  */
 
1484
 
1292
1485
  while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1293
1486
  {
1294
 
    str->length--;
1295
 
    str->str++;
 
1487
    str->length --;
 
1488
    str->str ++;
1296
1489
  }
1297
1490
 
1298
1491
  /*
1301
1494
  */
1302
1495
  while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1303
1496
  {
1304
 
    str->length--;
 
1497
    str->length --;
1305
1498
  }
1306
1499
}
1307
1500
 
 
1501
 
1308
1502
/*
1309
 
  Select_Lex structures initialisations
 
1503
  st_select_lex structures initialisations
1310
1504
*/
1311
 
void Select_Lex_Node::init_query()
 
1505
 
 
1506
void st_select_lex_node::init_query()
1312
1507
{
1313
1508
  options= 0;
1314
1509
  linkage= UNSPECIFIED_TYPE;
1315
1510
  no_error= no_table_names_allowed= 0;
1316
 
  uncacheable.reset();
1317
 
}
1318
 
 
1319
 
void Select_Lex_Node::init_select()
1320
 
{
1321
 
}
1322
 
 
1323
 
void Select_Lex_Unit::init_query()
1324
 
{
1325
 
  Select_Lex_Node::init_query();
 
1511
  uncacheable= 0;
 
1512
}
 
1513
 
 
1514
void st_select_lex_node::init_select()
 
1515
{
 
1516
}
 
1517
 
 
1518
void st_select_lex_unit::init_query()
 
1519
{
 
1520
  st_select_lex_node::init_query();
1326
1521
  linkage= GLOBAL_OPTIONS_TYPE;
1327
1522
  global_parameters= first_select();
1328
1523
  select_limit_cnt= HA_POS_ERROR;
1334
1529
  table= 0;
1335
1530
  fake_select_lex= 0;
1336
1531
  cleaned= 0;
1337
 
  item_list.clear();
 
1532
  item_list.empty();
1338
1533
  describe= 0;
1339
1534
  found_rows_for_union= 0;
1340
1535
}
1341
1536
 
1342
 
void Select_Lex::init_query()
 
1537
void st_select_lex::init_query()
1343
1538
{
1344
 
  Select_Lex_Node::init_query();
1345
 
  table_list.clear();
1346
 
  top_join_list.clear();
 
1539
  st_select_lex_node::init_query();
 
1540
  table_list.empty();
 
1541
  top_join_list.empty();
1347
1542
  join_list= &top_join_list;
1348
1543
  embedding= leaf_tables= 0;
1349
 
  item_list.clear();
 
1544
  item_list.empty();
1350
1545
  join= 0;
1351
1546
  having= where= 0;
1352
1547
  olap= UNSPECIFIED_OLAP_TYPE;
1365
1560
  parent_lex->push_context(&context);
1366
1561
  cond_count= between_count= with_wild= 0;
1367
1562
  max_equal_elems= 0;
 
1563
  conds_processed_with_permanent_arena= 0;
1368
1564
  ref_pointer_array= 0;
1369
1565
  select_n_where_fields= 0;
1370
1566
  select_n_having_items= 0;
1376
1572
  link_next= 0;
1377
1573
}
1378
1574
 
1379
 
void Select_Lex::init_select()
 
1575
void st_select_lex::init_select()
1380
1576
{
1381
 
  sj_nests.clear();
1382
 
  group_list.clear();
1383
 
  db= 0;
 
1577
  st_select_lex_node::init_select();
 
1578
  sj_nests.empty();
 
1579
  group_list.empty();
 
1580
  type= db= 0;
1384
1581
  having= 0;
 
1582
  table_join_options= 0;
1385
1583
  in_sum_expr= with_wild= 0;
1386
1584
  options= 0;
1387
1585
  braces= 0;
1388
 
  interval_list.clear();
 
1586
  interval_list.empty();
 
1587
  ftfunc_list_alloc.empty();
1389
1588
  inner_sum_func_list= 0;
 
1589
  ftfunc_list= &ftfunc_list_alloc;
1390
1590
  linkage= UNSPECIFIED_TYPE;
1391
1591
  order_list.elements= 0;
1392
1592
  order_list.first= 0;
1395
1595
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1396
1596
  offset_limit= 0;      /* denotes the default offset = 0 */
1397
1597
  with_sum_func= 0;
1398
 
  is_cross= false;
1399
1598
  is_correlated= 0;
1400
1599
  cur_pos_in_select_list= UNDEF_POS;
1401
 
  non_agg_fields.clear();
 
1600
  non_agg_fields.empty();
1402
1601
  cond_value= having_value= Item::COND_UNDEF;
1403
 
  inner_refs_list.clear();
1404
 
  full_group_by_flag.reset();
 
1602
  inner_refs_list.empty();
 
1603
  full_group_by_flag= 0;
1405
1604
}
1406
1605
 
1407
1606
/*
1408
 
  Select_Lex structures linking
 
1607
  st_select_lex structures linking
1409
1608
*/
1410
1609
 
1411
1610
/* include on level down */
1412
 
void Select_Lex_Node::include_down(Select_Lex_Node *upper)
 
1611
void st_select_lex_node::include_down(st_select_lex_node *upper)
1413
1612
{
1414
1613
  if ((next= upper->slave))
1415
1614
    next->prev= &next;
1423
1622
  include on level down (but do not link)
1424
1623
 
1425
1624
  SYNOPSYS
1426
 
    Select_Lex_Node::include_standalone()
 
1625
    st_select_lex_node::include_standalone()
1427
1626
    upper - reference on node underr which this node should be included
1428
1627
    ref - references on reference on this node
1429
1628
*/
1430
 
void Select_Lex_Node::include_standalone(Select_Lex_Node *upper,
1431
 
                                            Select_Lex_Node **ref)
 
1629
void st_select_lex_node::include_standalone(st_select_lex_node *upper,
 
1630
                                            st_select_lex_node **ref)
1432
1631
{
1433
1632
  next= 0;
1434
1633
  prev= ref;
1437
1636
}
1438
1637
 
1439
1638
/* include neighbour (on same level) */
1440
 
void Select_Lex_Node::include_neighbour(Select_Lex_Node *before)
 
1639
void st_select_lex_node::include_neighbour(st_select_lex_node *before)
1441
1640
{
1442
1641
  if ((next= before->next))
1443
1642
    next->prev= &next;
1447
1646
  slave= 0;
1448
1647
}
1449
1648
 
1450
 
/* including in global Select_Lex list */
1451
 
void Select_Lex_Node::include_global(Select_Lex_Node **plink)
 
1649
/* including in global SELECT_LEX list */
 
1650
void st_select_lex_node::include_global(st_select_lex_node **plink)
1452
1651
{
1453
1652
  if ((link_next= *plink))
1454
1653
    link_next->link_prev= &link_next;
1457
1656
}
1458
1657
 
1459
1658
//excluding from global list (internal function)
1460
 
void Select_Lex_Node::fast_exclude()
 
1659
void st_select_lex_node::fast_exclude()
1461
1660
{
1462
1661
  if (link_prev)
1463
1662
  {
1467
1666
  // Remove slave structure
1468
1667
  for (; slave; slave= slave->next)
1469
1668
    slave->fast_exclude();
1470
 
 
 
1669
  
1471
1670
}
1472
1671
 
1473
1672
/*
1474
1673
  excluding select_lex structure (except first (first select can't be
1475
1674
  deleted, because it is most upper select))
1476
1675
*/
1477
 
void Select_Lex_Node::exclude()
 
1676
void st_select_lex_node::exclude()
1478
1677
{
1479
1678
  //exclude from global list
1480
1679
  fast_exclude();
1481
1680
  //exclude from other structures
1482
1681
  if ((*prev= next))
1483
1682
    next->prev= prev;
1484
 
  /*
1485
 
     We do not need following statements, because prev pointer of first
 
1683
  /* 
 
1684
     We do not need following statements, because prev pointer of first 
1486
1685
     list element point to master->slave
1487
1686
     if (master->slave == this)
1488
1687
       master->slave= next;
1494
1693
  Exclude level of current unit from tree of SELECTs
1495
1694
 
1496
1695
  SYNOPSYS
1497
 
    Select_Lex_Unit::exclude_level()
 
1696
    st_select_lex_unit::exclude_level()
1498
1697
 
1499
1698
  NOTE: units which belong to current will be brought up on level of
1500
 
  currernt unit
 
1699
  currernt unit 
1501
1700
*/
1502
 
void Select_Lex_Unit::exclude_level()
 
1701
void st_select_lex_unit::exclude_level()
1503
1702
{
1504
 
  Select_Lex_Unit *units= 0, **units_last= &units;
1505
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1703
  SELECT_LEX_UNIT *units= 0, **units_last= &units;
 
1704
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1506
1705
  {
1507
1706
    // unlink current level from global SELECTs list
1508
1707
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1509
1708
      sl->link_next->link_prev= sl->link_prev;
1510
1709
 
1511
1710
    // bring up underlay levels
1512
 
    Select_Lex_Unit **last= 0;
1513
 
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1711
    SELECT_LEX_UNIT **last= 0;
 
1712
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1514
1713
    {
1515
1714
      u->master= master;
1516
 
      last= (Select_Lex_Unit**)&(u->next);
 
1715
      last= (SELECT_LEX_UNIT**)&(u->next);
1517
1716
    }
1518
1717
    if (last)
1519
1718
    {
1525
1724
  {
1526
1725
    // include brought up levels in place of current
1527
1726
    (*prev)= units;
1528
 
    (*units_last)= (Select_Lex_Unit*)next;
 
1727
    (*units_last)= (SELECT_LEX_UNIT*)next;
1529
1728
    if (next)
1530
 
      next->prev= (Select_Lex_Node**)units_last;
 
1729
      next->prev= (SELECT_LEX_NODE**)units_last;
1531
1730
    units->prev= prev;
1532
1731
  }
1533
1732
  else
1539
1738
  }
1540
1739
}
1541
1740
 
 
1741
 
1542
1742
/*
1543
1743
  Exclude subtree of current unit from tree of SELECTs
 
1744
 
 
1745
  SYNOPSYS
 
1746
    st_select_lex_unit::exclude_tree()
1544
1747
*/
1545
 
void Select_Lex_Unit::exclude_tree()
 
1748
void st_select_lex_unit::exclude_tree()
1546
1749
{
1547
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1750
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1548
1751
  {
1549
1752
    // unlink current level from global SELECTs list
1550
1753
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1551
1754
      sl->link_next->link_prev= sl->link_prev;
1552
1755
 
1553
1756
    // unlink underlay levels
1554
 
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1757
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1555
1758
    {
1556
1759
      u->exclude_level();
1557
1760
    }
1562
1765
    next->prev= prev;
1563
1766
}
1564
1767
 
1565
 
/**
1566
 
 * Mark all Select_Lex struct from this to 'last' as dependent
1567
 
 *
1568
 
 * @param Pointer to last Select_Lex struct, before wich all
1569
 
 *        Select_Lex have to be marked as dependent
1570
 
 * @note 'last' should be reachable from this Select_Lex_Node
1571
 
 */
1572
 
void Select_Lex::mark_as_dependent(Select_Lex *last)
 
1768
 
 
1769
/*
 
1770
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from 
 
1771
  this to 'last' as dependent
 
1772
 
 
1773
  SYNOPSIS
 
1774
    last - pointer to last st_select_lex struct, before wich all 
 
1775
           st_select_lex have to be marked as dependent
 
1776
 
 
1777
  NOTE
 
1778
    'last' should be reachable from this st_select_lex_node
 
1779
*/
 
1780
 
 
1781
void st_select_lex::mark_as_dependent(st_select_lex *last)
1573
1782
{
1574
1783
  /*
1575
1784
    Mark all selects from resolved to 1 before select where was
1576
1785
    found table as depended (of select where was found table)
1577
1786
  */
1578
 
  for (Select_Lex *s= this;
 
1787
  for (SELECT_LEX *s= this;
1579
1788
       s && s != last;
1580
1789
       s= s->outer_select())
1581
1790
  {
1582
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1791
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1583
1792
    {
1584
1793
      // Select is dependent of outer select
1585
 
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1586
 
      s->uncacheable.set(UNCACHEABLE_UNITED);
1587
 
      Select_Lex_Unit *munit= s->master_unit();
1588
 
      munit->uncacheable.set(UNCACHEABLE_UNITED);
1589
 
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1590
 
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
 
1794
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1795
                       UNCACHEABLE_DEPENDENT;
 
1796
      SELECT_LEX_UNIT *munit= s->master_unit();
 
1797
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1798
                       UNCACHEABLE_DEPENDENT;
 
1799
      for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1591
1800
      {
1592
1801
        if (sl != s &&
1593
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1594
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1802
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1803
          sl->uncacheable|= UNCACHEABLE_UNITED;
1595
1804
      }
1596
1805
    }
1597
1806
    s->is_correlated= true;
1601
1810
  }
1602
1811
}
1603
1812
 
1604
 
bool Select_Lex_Node::set_braces(bool)
1605
 
{ return true; }
1606
 
 
1607
 
bool Select_Lex_Node::inc_in_sum_expr()
1608
 
{ return true; }
1609
 
 
1610
 
uint32_t Select_Lex_Node::get_in_sum_expr() 
1611
 
{ return 0; }
1612
 
 
1613
 
TableList* Select_Lex_Node::get_table_list()
1614
 
{ return NULL; }
1615
 
 
1616
 
List<Item>* Select_Lex_Node::get_item_list()
1617
 
{ return NULL; }
1618
 
 
1619
 
TableList *Select_Lex_Node::add_table_to_list(Session *, 
1620
 
                                              Table_ident *, 
1621
 
                                              LEX_STRING *, 
1622
 
                                              const bitset<NUM_OF_TABLE_OPTIONS>&,
1623
 
                                              thr_lock_type, 
1624
 
                                              List<Index_hint> *, 
1625
 
                                              LEX_STRING *)
1626
 
{
1627
 
  return 0;
1628
 
}
1629
 
 
 
1813
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
 
1814
{ return 1; }
 
1815
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
 
1816
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1817
TableList* st_select_lex_node::get_table_list()     { return 0; }
 
1818
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
 
1819
TableList *st_select_lex_node::add_table_to_list (Session *session __attribute__((unused)),
 
1820
                                                   Table_ident *table __attribute__((unused)),
 
1821
                                                  LEX_STRING *alias __attribute__((unused)),
 
1822
                                                  uint32_t table_join_options __attribute__((unused)),
 
1823
                                                  thr_lock_type flags __attribute__((unused)),
 
1824
                                                  List<Index_hint> *hints __attribute__((unused)),
 
1825
                                                  LEX_STRING *option __attribute__((unused)))
 
1826
{
 
1827
  return 0;
 
1828
}
 
1829
uint32_t st_select_lex_node::get_table_join_options()
 
1830
{
 
1831
  return 0;
 
1832
}
1630
1833
 
1631
1834
/*
1632
1835
  prohibit using LIMIT clause
1633
1836
*/
1634
 
bool Select_Lex::test_limit()
 
1837
bool st_select_lex::test_limit()
1635
1838
{
1636
1839
  if (select_limit != 0)
1637
1840
  {
1638
1841
    my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1639
1842
             "LIMIT & IN/ALL/ANY/SOME subquery");
1640
 
    return true;
 
1843
    return(1);
1641
1844
  }
1642
 
  return false;
1643
 
}
1644
 
 
1645
 
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1646
 
{
1647
 
  return this;
1648
 
}
1649
 
 
1650
 
Select_Lex* Select_Lex_Unit::outer_select()
1651
 
{
1652
 
  return (Select_Lex*) master;
1653
 
}
1654
 
 
1655
 
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
 
1845
  return(0);
 
1846
}
 
1847
 
 
1848
 
 
1849
st_select_lex_unit* st_select_lex_unit::master_unit()
 
1850
{
 
1851
    return this;
 
1852
}
 
1853
 
 
1854
 
 
1855
st_select_lex* st_select_lex_unit::outer_select()
 
1856
{
 
1857
  return (st_select_lex*) master;
 
1858
}
 
1859
 
 
1860
 
 
1861
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1656
1862
{
1657
1863
  return add_to_list(session, order_list, item, asc);
1658
1864
}
1659
1865
 
1660
 
bool Select_Lex::add_item_to_list(Session *, Item *item)
 
1866
 
 
1867
bool st_select_lex::add_item_to_list(Session *session __attribute__((unused)),
 
1868
                                     Item *item)
1661
1869
{
1662
1870
  return(item_list.push_back(item));
1663
1871
}
1664
1872
 
1665
 
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
 
1873
 
 
1874
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1666
1875
{
1667
1876
  return add_to_list(session, group_list, item, asc);
1668
1877
}
1669
1878
 
1670
 
Select_Lex_Unit* Select_Lex::master_unit()
1671
 
{
1672
 
  return (Select_Lex_Unit*) master;
1673
 
}
1674
 
 
1675
 
Select_Lex* Select_Lex::outer_select()
1676
 
{
1677
 
  return (Select_Lex*) master->get_master();
1678
 
}
1679
 
 
1680
 
bool Select_Lex::set_braces(bool value)
 
1879
 
 
1880
st_select_lex_unit* st_select_lex::master_unit()
 
1881
{
 
1882
  return (st_select_lex_unit*) master;
 
1883
}
 
1884
 
 
1885
 
 
1886
st_select_lex* st_select_lex::outer_select()
 
1887
{
 
1888
  return (st_select_lex*) master->get_master();
 
1889
}
 
1890
 
 
1891
 
 
1892
bool st_select_lex::set_braces(bool value)
1681
1893
{
1682
1894
  braces= value;
1683
 
  return false;
 
1895
  return 0; 
1684
1896
}
1685
1897
 
1686
 
bool Select_Lex::inc_in_sum_expr()
 
1898
 
 
1899
bool st_select_lex::inc_in_sum_expr()
1687
1900
{
1688
1901
  in_sum_expr++;
1689
 
  return false;
 
1902
  return 0;
1690
1903
}
1691
1904
 
1692
 
uint32_t Select_Lex::get_in_sum_expr()
 
1905
 
 
1906
uint32_t st_select_lex::get_in_sum_expr()
1693
1907
{
1694
1908
  return in_sum_expr;
1695
1909
}
1696
1910
 
1697
 
TableList* Select_Lex::get_table_list()
 
1911
 
 
1912
TableList* st_select_lex::get_table_list()
1698
1913
{
1699
1914
  return (TableList*) table_list.first;
1700
1915
}
1701
1916
 
1702
 
List<Item>* Select_Lex::get_item_list()
 
1917
List<Item>* st_select_lex::get_item_list()
1703
1918
{
1704
1919
  return &item_list;
1705
1920
}
1706
1921
 
1707
 
 
1708
 
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
 
1922
uint32_t st_select_lex::get_table_join_options()
 
1923
{
 
1924
  return table_join_options;
 
1925
}
 
1926
 
 
1927
 
 
1928
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1709
1929
{
1710
1930
  if (ref_pointer_array)
1711
 
    return false;
 
1931
    return 0;
1712
1932
 
1713
1933
  return (ref_pointer_array=
1714
 
          (Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
 
1934
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1715
1935
                                                 item_list.elements +
1716
1936
                                                 select_n_having_items +
1717
1937
                                                 select_n_where_fields +
1718
1938
                                                 order_group_num)*5)) == 0;
1719
1939
}
1720
1940
 
1721
 
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
 
1941
 
 
1942
void st_select_lex_unit::print(String *str, enum_query_type query_type)
1722
1943
{
1723
1944
  bool union_all= !union_distinct;
1724
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1945
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1725
1946
  {
1726
1947
    if (sl != first_select())
1727
1948
    {
1744
1965
      str->append(STRING_WITH_LEN(" order by "));
1745
1966
      fake_select_lex->print_order(
1746
1967
        str,
1747
 
        (Order *) fake_select_lex->order_list.first,
 
1968
        (order_st *) fake_select_lex->order_list.first,
1748
1969
        query_type);
1749
1970
    }
1750
1971
    fake_select_lex->print_limit(session, str, query_type);
1751
1972
  }
1752
1973
}
1753
1974
 
1754
 
void Select_Lex::print_order(String *str,
1755
 
                                Order *order,
 
1975
 
 
1976
void st_select_lex::print_order(String *str,
 
1977
                                order_st *order,
1756
1978
                                enum_query_type query_type)
1757
1979
{
1758
1980
  for (; order; order= order->next)
1771
1993
      str->append(',');
1772
1994
  }
1773
1995
}
 
1996
 
1774
1997
 
1775
 
void Select_Lex::print_limit(Session *, String *str,
 
1998
void st_select_lex::print_limit(Session *session __attribute__((unused)),
 
1999
                                String *str,
1776
2000
                                enum_query_type query_type)
1777
2001
{
1778
 
  Select_Lex_Unit *unit= master_unit();
 
2002
  SELECT_LEX_UNIT *unit= master_unit();
1779
2003
  Item_subselect *item= unit->item;
1780
2004
 
1781
2005
  if (item && unit->global_parameters == this)
1811
2035
  }
1812
2036
}
1813
2037
 
1814
 
LEX::~LEX()
 
2038
/**
 
2039
  @brief Restore the LEX and Session in case of a parse error.
 
2040
 
 
2041
  This is a clean up call that is invoked by the Bison generated
 
2042
  parser before returning an error from DRIZZLEparse. If your
 
2043
  semantic actions manipulate with the global thread state (which
 
2044
  is a very bad practice and should not normally be employed) and
 
2045
  need a clean-up in case of error, and you can not use %destructor
 
2046
  rule in the grammar file itself, this function should be used
 
2047
  to implement the clean up.
 
2048
*/
 
2049
 
 
2050
void LEX::cleanup_lex_after_parse_error(Session *session __attribute__((unused)))
1815
2051
{
1816
 
  delete _create_table;
1817
2052
}
1818
2053
 
1819
2054
/*
1833
2068
    this method to reset state of already initialized Query_tables_list
1834
2069
    so it can be used for processing of new statement.
1835
2070
*/
 
2071
 
1836
2072
void Query_tables_list::reset_query_tables_list(bool init)
1837
2073
{
1838
2074
  if (!init && query_tables)
1848
2084
  query_tables= 0;
1849
2085
  query_tables_last= &query_tables;
1850
2086
  query_tables_own_last= 0;
1851
 
}
 
2087
  if (init)
 
2088
  {
 
2089
    /*
 
2090
      We delay real initialization of hash (and therefore related
 
2091
      memory allocation) until first insertion into this hash.
 
2092
    */
 
2093
    hash_clear(&sroutines);
 
2094
  }
 
2095
  else if (sroutines.records)
 
2096
  {
 
2097
    /* Non-zero sroutines.records means that hash was initialized. */
 
2098
    my_hash_reset(&sroutines);
 
2099
  }
 
2100
  sroutines_list.empty();
 
2101
  sroutines_list_own_last= sroutines_list.next;
 
2102
  sroutines_list_own_elements= 0;
 
2103
  binlog_stmt_flags= 0;
 
2104
}
 
2105
 
 
2106
 
 
2107
/*
 
2108
  Destroy Query_tables_list object with freeing all resources used by it.
 
2109
 
 
2110
  SYNOPSIS
 
2111
    destroy_query_tables_list()
 
2112
*/
 
2113
 
 
2114
void Query_tables_list::destroy_query_tables_list()
 
2115
{
 
2116
  hash_free(&sroutines);
 
2117
}
 
2118
 
1852
2119
 
1853
2120
/*
1854
2121
  Initialize LEX object.
1863
2130
    statement parsing. On should use lex_start() function to prepare LEX
1864
2131
    for this.
1865
2132
*/
1866
 
LEX::LEX() :
1867
 
    result(0), 
1868
 
    yacc_yyss(0), 
1869
 
    yacc_yyvs(0),
1870
 
    session(NULL),
1871
 
    charset(NULL),
1872
 
    var_list(),
1873
 
    sql_command(SQLCOM_END), 
1874
 
    statement(NULL),
1875
 
    option_type(OPT_DEFAULT), 
1876
 
    is_lex_started(0),
1877
 
    cacheable(true),
1878
 
    sum_expr_used(false),
1879
 
    _create_table(NULL),
1880
 
    _create_field(NULL),
1881
 
    _exists(false)
 
2133
 
 
2134
LEX::LEX()
 
2135
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
2136
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1882
2137
{
 
2138
 
 
2139
  my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
 
2140
                         plugins_static_buffer,
 
2141
                         INITIAL_LEX_PLUGIN_LIST_SIZE, 
 
2142
                         INITIAL_LEX_PLUGIN_LIST_SIZE);
1883
2143
  reset_query_tables_list(true);
1884
2144
}
1885
2145
 
 
2146
 
 
2147
/*
 
2148
  Check whether the merging algorithm can be used on this VIEW
 
2149
 
 
2150
  SYNOPSIS
 
2151
    LEX::can_be_merged()
 
2152
 
 
2153
  DESCRIPTION
 
2154
    We can apply merge algorithm if it is single SELECT view  with
 
2155
    subqueries only in WHERE clause (we do not count SELECTs of underlying
 
2156
    views, and second level subqueries) and we have not grpouping, ordering,
 
2157
    HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
 
2158
    several underlying tables.
 
2159
 
 
2160
  RETURN
 
2161
    false - only temporary table algorithm can be used
 
2162
    true  - merge algorithm can be used
 
2163
*/
 
2164
 
 
2165
bool LEX::can_be_merged()
 
2166
{
 
2167
  // TODO: do not forget implement case when select_lex.table_list.elements==0
 
2168
 
 
2169
  /* find non VIEW subqueries/unions */
 
2170
  bool selects_allow_merge= select_lex.next_select() == 0;
 
2171
  if (selects_allow_merge)
 
2172
  {
 
2173
    for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
 
2174
         tmp_unit;
 
2175
         tmp_unit= tmp_unit->next_unit())
 
2176
    {
 
2177
      if (tmp_unit->first_select()->parent_lex == this &&
 
2178
          (tmp_unit->item == 0 ||
 
2179
           (tmp_unit->item->place() != IN_WHERE &&
 
2180
            tmp_unit->item->place() != IN_ON)))
 
2181
      {
 
2182
        selects_allow_merge= 0;
 
2183
        break;
 
2184
      }
 
2185
    }
 
2186
  }
 
2187
 
 
2188
  return (selects_allow_merge &&
 
2189
          select_lex.group_list.elements == 0 &&
 
2190
          select_lex.having == 0 &&
 
2191
          select_lex.with_sum_func == 0 &&
 
2192
          select_lex.table_list.elements >= 1 &&
 
2193
          !(select_lex.options & SELECT_DISTINCT) &&
 
2194
          select_lex.select_limit == 0);
 
2195
}
 
2196
 
 
2197
 
 
2198
/*
 
2199
  check if command can use VIEW with MERGE algorithm (for top VIEWs)
 
2200
 
 
2201
  SYNOPSIS
 
2202
    LEX::can_use_merged()
 
2203
 
 
2204
  DESCRIPTION
 
2205
    Only listed here commands can use merge algorithm in top level
 
2206
    SELECT_LEX (for subqueries will be used merge algorithm if
 
2207
    LEX::can_not_use_merged() is not true).
 
2208
 
 
2209
  RETURN
 
2210
    false - command can't use merged VIEWs
 
2211
    true  - VIEWs with MERGE algorithms can be used
 
2212
*/
 
2213
 
 
2214
bool LEX::can_use_merged()
 
2215
{
 
2216
  switch (sql_command)
 
2217
  {
 
2218
  case SQLCOM_SELECT:
 
2219
  case SQLCOM_CREATE_TABLE:
 
2220
  case SQLCOM_UPDATE:
 
2221
  case SQLCOM_UPDATE_MULTI:
 
2222
  case SQLCOM_DELETE:
 
2223
  case SQLCOM_DELETE_MULTI:
 
2224
  case SQLCOM_INSERT:
 
2225
  case SQLCOM_INSERT_SELECT:
 
2226
  case SQLCOM_REPLACE:
 
2227
  case SQLCOM_REPLACE_SELECT:
 
2228
  case SQLCOM_LOAD:
 
2229
    return true;
 
2230
  default:
 
2231
    return false;
 
2232
  }
 
2233
}
 
2234
 
 
2235
/*
 
2236
  Check if command can't use merged views in any part of command
 
2237
 
 
2238
  SYNOPSIS
 
2239
    LEX::can_not_use_merged()
 
2240
 
 
2241
  DESCRIPTION
 
2242
    Temporary table algorithm will be used on all SELECT levels for queries
 
2243
    listed here (see also LEX::can_use_merged()).
 
2244
 
 
2245
  RETURN
 
2246
    false - command can't use merged VIEWs
 
2247
    true  - VIEWs with MERGE algorithms can be used
 
2248
*/
 
2249
 
 
2250
bool LEX::can_not_use_merged()
 
2251
{
 
2252
  switch (sql_command)
 
2253
  {
 
2254
  /*
 
2255
    SQLCOM_SHOW_FIELDS is necessary to make 
 
2256
    information schema tables working correctly with views.
 
2257
    see get_schema_tables_result function
 
2258
  */
 
2259
  case SQLCOM_SHOW_FIELDS:
 
2260
    return true;
 
2261
  default:
 
2262
    return false;
 
2263
  }
 
2264
}
 
2265
 
 
2266
/*
 
2267
  Detect that we need only table structure of derived table/view
 
2268
 
 
2269
  SYNOPSIS
 
2270
    only_view_structure()
 
2271
 
 
2272
  RETURN
 
2273
    true yes, we need only structure
 
2274
    false no, we need data
 
2275
*/
 
2276
 
 
2277
bool LEX::only_view_structure()
 
2278
{
 
2279
  switch (sql_command) {
 
2280
  case SQLCOM_SHOW_CREATE:
 
2281
  case SQLCOM_SHOW_TABLES:
 
2282
  case SQLCOM_SHOW_FIELDS:
 
2283
    return true;
 
2284
  default:
 
2285
    return false;
 
2286
  }
 
2287
}
 
2288
 
 
2289
 
 
2290
/*
 
2291
  Should Items_ident be printed correctly
 
2292
 
 
2293
  SYNOPSIS
 
2294
    need_correct_ident()
 
2295
 
 
2296
  RETURN
 
2297
    true yes, we need only structure
 
2298
    false no, we need data
 
2299
*/
 
2300
 
 
2301
 
 
2302
bool LEX::need_correct_ident()
 
2303
{
 
2304
  switch(sql_command)
 
2305
  {
 
2306
  case SQLCOM_SHOW_CREATE:
 
2307
  case SQLCOM_SHOW_TABLES:
 
2308
    return true;
 
2309
  default:
 
2310
    return false;
 
2311
  }
 
2312
}
 
2313
 
 
2314
 
1886
2315
/**
1887
2316
  This method should be called only during parsing.
1888
2317
  It is aware of compound statements (stored routine bodies)
1889
2318
  and will initialize the destination with the default
1890
2319
  database of the stored routine, rather than the default
1891
2320
  database of the connection it is parsed in.
1892
 
  E.g. if one has no current database selected, or current database
 
2321
  E.g. if one has no current database selected, or current database 
1893
2322
  set to 'bar' and then issues:
1894
2323
 
1895
2324
  CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
1901
2330
  @return true in case of error (parsing should be aborted, false in
1902
2331
  case of success
1903
2332
*/
1904
 
bool LEX::copy_db_to(char **p_db, size_t *p_db_length) const
 
2333
 
 
2334
bool
 
2335
LEX::copy_db_to(char **p_db, size_t *p_db_length) const
1905
2336
{
1906
2337
  return session->copy_db_to(p_db, p_db_length);
1907
2338
}
1910
2341
  initialize limit counters
1911
2342
 
1912
2343
  SYNOPSIS
1913
 
    Select_Lex_Unit::set_limit()
1914
 
    values      - Select_Lex with initial values for counters
 
2344
    st_select_lex_unit::set_limit()
 
2345
    values      - SELECT_LEX with initial values for counters
1915
2346
*/
1916
 
void Select_Lex_Unit::set_limit(Select_Lex *sl)
 
2347
 
 
2348
void st_select_lex_unit::set_limit(st_select_lex *sl)
1917
2349
{
1918
2350
  ha_rows select_limit_val;
1919
2351
  uint64_t val;
1920
2352
 
1921
2353
  val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
1922
2354
  select_limit_val= (ha_rows)val;
1923
 
  /*
 
2355
  /* 
1924
2356
    Check for overflow : ha_rows can be smaller then uint64_t if
1925
2357
    BIG_TABLES is off.
1926
2358
    */
1933
2365
    select_limit_cnt= HA_POS_ERROR;             // no limit
1934
2366
}
1935
2367
 
 
2368
 
1936
2369
/*
1937
2370
  Unlink the first table from the global table list and the first table from
1938
2371
  outer select (lex->select_lex) local list
1970
2403
    */
1971
2404
    if ((*link_to_local= test(select_lex.table_list.first)))
1972
2405
    {
1973
 
      select_lex.context.table_list=
 
2406
      select_lex.context.table_list= 
1974
2407
        select_lex.context.first_name_resolution_table= first->next_local;
1975
2408
      select_lex.table_list.first= (unsigned char*) (first->next_local);
1976
2409
      select_lex.table_list.elements--; //safety
1985
2418
  return first;
1986
2419
}
1987
2420
 
 
2421
 
1988
2422
/*
1989
2423
  Bring first local table of first most outer select to first place in global
1990
2424
  table list
1994
2428
 
1995
2429
  NOTES
1996
2430
    In many cases (for example, usual INSERT/DELETE/...) the first table of
1997
 
    main Select_Lex have special meaning => check that it is the first table
 
2431
    main SELECT_LEX have special meaning => check that it is the first table
1998
2432
    in global list and re-link to be first in the global list if it is
1999
2433
    necessary.  We need such re-linking only for queries with sub-queries in
2000
2434
    the select list, as only in this case tables of sub-queries will go to
2001
2435
    the global list first.
2002
2436
*/
 
2437
 
2003
2438
void LEX::first_lists_tables_same()
2004
2439
{
2005
2440
  TableList *first_table= (TableList*) select_lex.table_list.first;
2024
2459
  }
2025
2460
}
2026
2461
 
 
2462
 
2027
2463
/*
2028
2464
  Link table back that was unlinked with unlink_first_table()
2029
2465
 
2034
2470
  RETURN
2035
2471
    global list
2036
2472
*/
2037
 
void LEX::link_first_table_back(TableList *first, bool link_to_local)
 
2473
 
 
2474
void LEX::link_first_table_back(TableList *first,
 
2475
                                   bool link_to_local)
2038
2476
{
2039
2477
  if (first)
2040
2478
  {
2054
2492
  }
2055
2493
}
2056
2494
 
 
2495
 
 
2496
 
2057
2497
/*
2058
2498
  cleanup lex for case when we open table by table for processing
2059
2499
 
2065
2505
    derived tables state. To rollback changes in Query_tables_list one has
2066
2506
    to call Query_tables_list::reset_query_tables_list(false).
2067
2507
*/
 
2508
 
2068
2509
void LEX::cleanup_after_one_table_open()
2069
2510
{
2070
2511
  /*
2071
 
    session->getLex()->derived_tables & additional units may be set if we open
2072
 
    a view. It is necessary to clear session->getLex()->derived_tables flag
2073
 
    to prevent processing of derived tables during next openTablesLock
 
2512
    session->lex->derived_tables & additional units may be set if we open
 
2513
    a view. It is necessary to clear session->lex->derived_tables flag
 
2514
    to prevent processing of derived tables during next open_and_lock_tables
2074
2515
    if next table is a real table and cleanup & remove underlying units
2075
 
    NOTE: all units will be connected to session->getLex()->select_lex, because we
 
2516
    NOTE: all units will be connected to session->lex->select_lex, because we
2076
2517
    have not UNION on most upper level.
2077
2518
    */
2078
2519
  if (all_selects_list != &select_lex)
2079
2520
  {
2080
2521
    derived_tables= 0;
2081
2522
    /* cleunup underlying units (units of VIEW) */
2082
 
    for (Select_Lex_Unit *un= select_lex.first_inner_unit();
 
2523
    for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
2083
2524
         un;
2084
2525
         un= un->next_unit())
2085
2526
      un->cleanup();
2090
2531
  }
2091
2532
}
2092
2533
 
2093
 
/*
2094
 
  There are Select_Lex::add_table_to_list &
2095
 
  Select_Lex::set_lock_for_tables are in sql_parse.cc
2096
 
 
2097
 
  Select_Lex::print is in sql_select.cc
2098
 
 
2099
 
  Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
2100
 
  Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
2101
 
  Select_Lex_Unit::change_result
 
2534
 
 
2535
/*
 
2536
  Save current state of Query_tables_list for this LEX, and prepare it
 
2537
  for processing of new statemnt.
 
2538
 
 
2539
  SYNOPSIS
 
2540
    reset_n_backup_query_tables_list()
 
2541
      backup  Pointer to Query_tables_list instance to be used for backup
 
2542
*/
 
2543
 
 
2544
void LEX::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
 
2545
{
 
2546
}
 
2547
 
 
2548
 
 
2549
/*
 
2550
  Restore state of Query_tables_list for this LEX from backup.
 
2551
 
 
2552
  SYNOPSIS
 
2553
    restore_backup_query_tables_list()
 
2554
      backup  Pointer to Query_tables_list instance used for backup
 
2555
*/
 
2556
 
 
2557
void LEX::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
 
2558
{
 
2559
}
 
2560
 
 
2561
 
 
2562
/*
 
2563
  Checks for usage of routines and/or tables in a parsed statement
 
2564
 
 
2565
  SYNOPSIS
 
2566
    st_lex:table_or_sp_used()
 
2567
 
 
2568
  RETURN
 
2569
    false  No routines and tables used
 
2570
    true   Either or both routines and tables are used.
 
2571
*/
 
2572
 
 
2573
bool LEX::table_or_sp_used()
 
2574
{
 
2575
  if (sroutines.records || query_tables)
 
2576
    return(true);
 
2577
 
 
2578
  return(false);
 
2579
}
 
2580
 
 
2581
 
 
2582
/*
 
2583
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
 
2584
 
 
2585
  SYNOPSIS
 
2586
    fix_prepare_info_in_table_list()
 
2587
      session  Thread handle
 
2588
      tbl  List of tables to process
 
2589
 
 
2590
  DESCRIPTION
 
2591
    Perform end-end-of prepare fixup for list of tables, if any of the tables
 
2592
    is a merge-algorithm VIEW, recursively fix up its underlying tables as
 
2593
    well.
 
2594
 
 
2595
*/
 
2596
 
 
2597
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
 
2598
{
 
2599
  for (; tbl; tbl= tbl->next_local)
 
2600
  {
 
2601
    if (tbl->on_expr)
 
2602
    {
 
2603
      tbl->prep_on_expr= tbl->on_expr;
 
2604
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
 
2605
    }
 
2606
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
 
2607
  }
 
2608
}
 
2609
 
 
2610
 
 
2611
/*
 
2612
  There are st_select_lex::add_table_to_list &
 
2613
  st_select_lex::set_lock_for_tables are in sql_parse.cc
 
2614
 
 
2615
  st_select_lex::print is in sql_select.cc
 
2616
 
 
2617
  st_select_lex_unit::prepare, st_select_lex_unit::exec,
 
2618
  st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
 
2619
  st_select_lex_unit::change_result
2102
2620
  are in sql_union.cc
2103
2621
*/
2104
2622
 
2112
2630
 
2113
2631
  DESCRIPTION
2114
2632
    Used in filling up the tagged hints list.
2115
 
    This list is filled by first setting the kind of the hint as a
 
2633
    This list is filled by first setting the kind of the hint as a 
2116
2634
    context variable and then adding hints of the current kind.
2117
2635
    Then the context variable index_hint_type can be reset to the
2118
2636
    next hint type.
2119
2637
*/
2120
 
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
2121
 
{
 
2638
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
 
2639
                                        index_clause_map clause)
 
2640
2122
2641
  current_index_hint_type= type_arg;
2123
2642
  current_index_hint_clause= clause;
2124
2643
}
2125
2644
 
 
2645
 
2126
2646
/*
2127
2647
  Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2128
2648
 
2130
2650
    alloc_index_hints()
2131
2651
      session         current thread.
2132
2652
*/
2133
 
void Select_Lex::alloc_index_hints (Session *session)
2134
 
{
2135
 
  index_hints= new (session->mem_root) List<Index_hint>();
 
2653
 
 
2654
void st_select_lex::alloc_index_hints (Session *session)
 
2655
 
2656
  index_hints= new (session->mem_root) List<Index_hint>(); 
2136
2657
}
2137
2658
 
 
2659
 
 
2660
 
2138
2661
/*
2139
 
  adds an element to the array storing index usage hints
 
2662
  adds an element to the array storing index usage hints 
2140
2663
  (ADD/FORCE/IGNORE INDEX).
2141
2664
 
2142
2665
  SYNOPSIS
2148
2671
  RETURN VALUE
2149
2672
    0 on success, non-zero otherwise
2150
2673
*/
2151
 
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length)
 
2674
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2152
2675
{
2153
 
  return index_hints->push_front (new (session->mem_root)
 
2676
  return index_hints->push_front (new (session->mem_root) 
2154
2677
                                 Index_hint(current_index_hint_type,
2155
2678
                                            current_index_hint_clause,
2156
2679
                                            str, length));
2157
2680
}
2158
 
 
2159
 
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
2160
 
{
2161
 
  if (sql_reserved_words::in_word_set(string.str, string.length))
2162
 
      return true;
2163
 
 
2164
 
  return false;
2165
 
}
2166
 
 
2167
 
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
2168
 
{
2169
 
  if (sql_reserved_words::in_word_set(string.str, string.length))
2170
 
      return true;
2171
 
 
2172
 
  return false;
2173
 
}
2174
 
 
2175
 
 
2176
 
} /* namespace drizzled */