~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Brian Aker
  • Date: 2009-01-07 21:26:58 UTC
  • Revision ID: brian@tangent.org-20090107212658-2fh0s2uwh10w68y2
Committing fix lock_multi

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
19
#define DRIZZLE_LEX 1
21
 
#include "drizzled/configmake.h"
22
 
#include "drizzled/item/num.h"
23
 
#include "drizzled/error.h"
24
 
#include "drizzled/session.h"
25
 
#include "drizzled/sql_base.h"
26
 
#include "drizzled/lookup_symbol.h"
27
 
#include "drizzled/index_hint.h"
28
 
 
29
 
#include <cstdio>
30
 
#include <ctype.h>
31
 
 
32
 
using namespace std;
33
 
 
34
 
/* Stay outside of the namespace because otherwise bison goes nuts */
35
 
int DRIZZLElex(void *arg, void *yysession);
36
 
 
37
 
namespace drizzled
38
 
{
 
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>
39
25
 
40
26
static int lex_one_token(void *arg, void *yysession);
41
27
 
42
 
/**
43
 
  save order by and tables in own lists.
 
28
/*
 
29
  We are using pointer to this variable for distinguishing between assignment
 
30
  to NEW row field (when parsing trigger definition) and structured variable.
44
31
*/
45
 
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
46
 
{
47
 
  Order *order;
48
 
  if (!(order = (Order *) session->alloc(sizeof(Order))))
49
 
    return(1);
50
 
  order->item_ptr= item;
51
 
  order->item= &order->item_ptr;
52
 
  order->asc = asc;
53
 
  order->free_me=0;
54
 
  order->used=0;
55
 
  order->counter_used= 0;
56
 
  list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
57
 
  return(0);
58
 
}
 
32
 
 
33
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
59
34
 
60
35
/**
61
36
  LEX_STRING constant for null-string to be used in parser and other places.
62
37
*/
63
38
const LEX_STRING null_lex_str= {NULL, 0};
64
39
 
 
40
 
 
41
/*
 
42
  The following data is based on the latin1 character set, and is only
 
43
  used when comparing keywords
 
44
*/
 
45
 
 
46
static unsigned char to_upper_lex[]=
 
47
{
 
48
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
 
49
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
 
50
   32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
 
51
   48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
 
52
   64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
 
53
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
 
54
   96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
 
55
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
 
56
  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
 
57
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
 
58
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
 
59
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
 
60
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
 
61
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
 
62
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
 
63
  208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
 
64
};
 
65
 
 
66
/*
 
67
  Names of the index hints (for error messages). Keep in sync with
 
68
  index_hint_type
 
69
*/
 
70
 
 
71
const char * index_hint_type_name[] =
 
72
{
 
73
  "IGNORE INDEX",
 
74
  "USE INDEX",
 
75
  "FORCE INDEX"
 
76
};
 
77
 
 
78
int lex_casecmp(const char *s, const char *t, uint32_t len)
 
79
{
 
80
  while (len-- != 0 &&
 
81
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
 
82
  return (int) len+1;
 
83
}
 
84
 
 
85
/* EVIL EVIL - this is included here so that it will have to_upper_lex */
 
86
#include <drizzled/lex_hash.h>
 
87
 
 
88
 
 
89
void lex_init(void)
 
90
{
 
91
  uint32_t i;
 
92
  for (i=0 ; i < array_elements(symbols) ; i++)
 
93
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
 
94
  for (i=0 ; i < array_elements(sql_functions) ; i++)
 
95
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
 
96
 
 
97
  return;
 
98
}
 
99
 
 
100
 
 
101
void lex_free(void)
 
102
{                                       // Call this when daemon ends
 
103
  return;
 
104
}
 
105
 
 
106
 
 
107
void
 
108
st_parsing_options::reset()
 
109
{
 
110
  allows_select_procedure= true;
 
111
}
 
112
 
65
113
Lex_input_stream::Lex_input_stream(Session *session,
66
114
                                   const char* buffer,
67
115
                                   unsigned int length)
85
133
  m_body_utf8(NULL),
86
134
  m_cpp_utf8_processed_ptr(NULL),
87
135
  next_state(MY_LEX_START),
 
136
  found_semicolon(NULL),
88
137
  ignore_space(1),
89
 
  in_comment(NO_COMMENT)
 
138
  in_comment(NO_COMMENT),
 
139
  m_underscore_cs(NULL)
90
140
{
91
141
  m_cpp_buf= (char*) session->alloc(length + 1);
92
142
  m_cpp_ptr= m_cpp_buf;
106
156
  @param begin_ptr  Pointer to the start of the body in the pre-processed
107
157
                    buffer.
108
158
*/
 
159
 
109
160
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
110
161
{
111
162
  assert(begin_ptr);
142
193
                  m_cpp_utf8_processed_ptr will be set in the end of the
143
194
                  operation.
144
195
*/
 
196
 
145
197
void Lex_input_stream::body_utf8_append(const char *ptr,
146
198
                                        const char *end_ptr)
147
199
{
170
222
  @param ptr  Pointer in the pre-processed buffer, which specifies the end
171
223
              of the chunk, which should be appended to the utf8 body.
172
224
*/
 
225
 
173
226
void Lex_input_stream::body_utf8_append(const char *ptr)
174
227
{
175
228
  body_utf8_append(ptr, ptr);
186
239
                  m_cpp_utf8_processed_ptr will be set in the end of the
187
240
                  operation.
188
241
*/
189
 
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
 
242
 
 
243
void Lex_input_stream::body_utf8_append_literal(Session *session,
 
244
                                                const LEX_STRING *txt,
 
245
                                                const CHARSET_INFO * const txt_cs,
190
246
                                                const char *end_ptr)
191
247
{
192
248
  if (!m_cpp_utf8_processed_ptr)
193
249
    return;
194
250
 
 
251
  LEX_STRING utf_txt;
 
252
 
 
253
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
 
254
  {
 
255
    session->convert_string(&utf_txt,
 
256
                        &my_charset_utf8_general_ci,
 
257
                        txt->str, txt->length,
 
258
                        txt_cs);
 
259
  }
 
260
  else
 
261
  {
 
262
    utf_txt.str= txt->str;
 
263
    utf_txt.length= txt->length;
 
264
  }
 
265
 
195
266
  /* NOTE: utf_txt.length is in bytes, not in symbols. */
196
267
 
197
 
  memcpy(m_body_utf8_ptr, txt->str, txt->length);
198
 
  m_body_utf8_ptr += txt->length;
 
268
  memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
 
269
  m_body_utf8_ptr += utf_txt.length;
199
270
  *m_body_utf8_ptr= 0;
200
271
 
201
272
  m_cpp_utf8_processed_ptr= end_ptr;
202
273
}
203
274
 
 
275
 
204
276
/*
205
277
  This is called before every query that is to be parsed.
206
278
  Because of this, it's critical to not do too much things here.
207
279
  (We already do too much here)
208
280
*/
209
 
void LEX::start(Session *arg)
210
 
{
211
 
  lex_start(arg);
212
 
}
213
281
 
214
282
void lex_start(Session *session)
215
283
{
225
293
  lex->select_lex.init_query();
226
294
  lex->value_list.empty();
227
295
  lex->update_list.empty();
 
296
  lex->param_list.empty();
228
297
  lex->auxiliary_table_list.empty();
229
298
  lex->unit.next= lex->unit.master=
230
299
    lex->unit.link_next= lex->unit.return_to= 0;
234
303
  lex->select_lex.master= &lex->unit;
235
304
  lex->select_lex.prev= &lex->unit.slave;
236
305
  lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
237
 
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
 
306
  lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
238
307
  lex->select_lex.options= 0;
239
308
  lex->select_lex.init_order();
240
309
  lex->select_lex.group_list.empty();
241
310
  lex->describe= 0;
 
311
  lex->subqueries= false;
242
312
  lex->derived_tables= 0;
243
313
  lex->lock_option= TL_READ;
244
314
  lex->leaf_tables_insert= 0;
 
315
  lex->parsing_options.reset();
245
316
  lex->select_lex.select_number= 1;
246
317
  lex->length=0;
247
318
  lex->select_lex.in_sum_expr=0;
 
319
  lex->select_lex.ftfunc_list_alloc.empty();
 
320
  lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
248
321
  lex->select_lex.group_list.empty();
249
322
  lex->select_lex.order_list.empty();
250
323
  lex->sql_command= SQLCOM_END;
251
324
  lex->duplicates= DUP_ERROR;
252
325
  lex->ignore= 0;
 
326
  lex->proc_list.first= 0;
253
327
  lex->escape_used= false;
254
328
  lex->query_tables= 0;
255
329
  lex->reset_query_tables_list(false);
256
330
  lex->expr_allows_subselect= true;
257
331
  lex->use_only_table_context= false;
 
332
  lex->parse_vcol_expr= false;
258
333
 
259
334
  lex->name.str= 0;
260
335
  lex->name.length= 0;
263
338
  lex->in_sum_func= NULL;
264
339
 
265
340
  lex->is_lex_started= true;
266
 
  lex->statement= NULL;
267
 
  
268
 
  lex->is_cross= false;
269
 
 
270
 
  lex->reset();
271
341
}
272
342
 
273
 
void LEX::end()
 
343
void lex_end(LEX *lex)
274
344
{
275
 
  if (yacc_yyss)
 
345
  if (lex->yacc_yyss)
276
346
  {
277
 
    free(yacc_yyss);
278
 
    free(yacc_yyvs);
279
 
    yacc_yyss= 0;
280
 
    yacc_yyvs= 0;
 
347
    free(lex->yacc_yyss);
 
348
    free(lex->yacc_yyvs);
 
349
    lex->yacc_yyss= 0;
 
350
    lex->yacc_yyvs= 0;
281
351
  }
282
352
 
283
 
  delete result;
284
 
 
285
 
  result= 0;
286
 
  setCacheable(true);
287
 
 
288
 
  delete statement;
289
 
  statement= NULL;
 
353
  delete lex->result;
 
354
  lex->result= 0;
290
355
}
291
356
 
 
357
 
292
358
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
293
359
{
294
 
  /* Plenty of memory for the largest lex symbol we have */
295
 
  char tok_upper[64];
296
360
  const char *tok= lip->get_tok_start();
297
 
  uint32_t tok_pos= 0;
298
 
  for (;tok_pos<len && tok_pos<63;tok_pos++)
299
 
    tok_upper[tok_pos]=my_toupper(system_charset_info, tok[tok_pos]);
300
 
  tok_upper[tok_pos]=0;
301
361
 
302
 
  const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
 
362
  SYMBOL *symbol= get_hash_symbol(tok, len, function);
303
363
  if (symbol)
304
364
  {
305
365
    lip->yylval->symbol.symbol=symbol;
312
372
  return 0;
313
373
}
314
374
 
 
375
/*
 
376
  Check if name is a keyword
 
377
 
 
378
  SYNOPSIS
 
379
    is_keyword()
 
380
    name      checked name (must not be empty)
 
381
    len       length of checked name
 
382
 
 
383
  RETURN VALUES
 
384
    0         name is a keyword
 
385
    1         name isn't a keyword
 
386
*/
 
387
 
 
388
bool is_keyword(const char *name, uint32_t len)
 
389
{
 
390
  assert(len != 0);
 
391
  return get_hash_symbol(name,len,0)!=0;
 
392
}
 
393
 
315
394
bool is_lex_native_function(const LEX_STRING *name)
316
395
{
317
396
  assert(name != NULL);
318
 
  return (lookup_symbol(name->str, name->length, 1) != 0);
 
397
  return (get_hash_symbol(name->str, name->length, 1) != 0);
319
398
}
320
399
 
321
400
/* make a copy of token before ptr and set yytoklen */
 
401
 
322
402
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
323
403
{
324
404
  LEX_STRING tmp;
338
418
   get_quoted_token yet. But it should be fixed in the
339
419
   future to operate multichar strings (like ucs2)
340
420
*/
 
421
 
341
422
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
342
423
                                   uint32_t skip,
343
424
                                   uint32_t length, char quote)
372
453
  Return an unescaped text literal without quotes
373
454
  Fix sometimes to do only one scan of the string
374
455
*/
 
456
 
375
457
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
376
458
{
377
459
  register unsigned char c,sep;
378
 
  bool found_escape= false;
 
460
  uint32_t found_escape=0;
379
461
  const CHARSET_INFO * const cs= lip->m_session->charset();
380
462
 
381
463
  lip->tok_bitmap= 0;
384
466
  {
385
467
    c= lip->yyGet();
386
468
    lip->tok_bitmap|= c;
 
469
#ifdef USE_MB
387
470
    {
388
 
      if (use_mb(cs))
389
 
      {
390
 
        int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
391
 
        if (l != 0) 
392
 
        {
393
 
          lip->skip_binary(l-1);
394
 
          continue;
395
 
        }
 
471
      int l;
 
472
      if (use_mb(cs) &&
 
473
          (l = my_ismbchar(cs,
 
474
                           lip->get_ptr() -1,
 
475
                           lip->get_end_of_query()))) {
 
476
        lip->skip_binary(l-1);
 
477
        continue;
396
478
      }
397
479
    }
 
480
#endif
398
481
    if (c == '\\')
399
482
    {                                   // Escaped character
400
 
      found_escape= true;
 
483
      found_escape=1;
401
484
      if (lip->eof())
402
 
        return 0;
 
485
        return 0;
403
486
      lip->yySkip();
404
487
    }
405
488
    else if (c == sep)
406
489
    {
407
490
      if (c == lip->yyGet())            // Check if two separators in a row
408
491
      {
409
 
        found_escape= true;                 // duplicate. Remember for delete
410
 
        continue;
 
492
        found_escape=1;                 // duplicate. Remember for delete
 
493
        continue;
411
494
      }
412
495
      else
413
496
        lip->yyUnget();
419
502
      str= lip->get_tok_start();
420
503
      end= lip->get_ptr();
421
504
      /* Extract the text from the token */
422
 
      str+= pre_skip;
423
 
      end-= post_skip;
 
505
      str += pre_skip;
 
506
      end -= post_skip;
424
507
      assert(end >= str);
425
508
 
426
 
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
427
 
        return (char*) "";              // memory::SqlAlloc has set error flag
 
509
      if (!(start= (char*) lip->m_session->alloc((uint) (end-str)+1)))
 
510
        return (char*) "";              // Sql_alloc has set error flag
428
511
 
429
512
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
430
513
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
431
514
 
432
 
      if (! found_escape)
 
515
      if (!found_escape)
433
516
      {
434
 
        lip->yytoklen= (uint32_t) (end-str);
435
 
        memcpy(start, str, lip->yytoklen);
436
 
        start[lip->yytoklen]= 0;
 
517
        lip->yytoklen=(uint) (end-str);
 
518
        memcpy(start,str,lip->yytoklen);
 
519
        start[lip->yytoklen]=0;
437
520
      }
438
521
      else
439
522
      {
440
523
        char *to;
441
524
 
442
 
        for (to= start; str != end; str++)
443
 
        {
444
 
          if (use_mb(cs))
445
 
          {
446
 
            int l= my_ismbchar(cs, str, end);
447
 
            if (l != 0)
448
 
            {
449
 
              while (l--)
450
 
                *to++= *str++;
451
 
              str--;
452
 
              continue;
453
 
            }
454
 
          }
455
 
          if (*str == '\\' && (str + 1) != end)
456
 
          {
457
 
            switch (*++str) {
458
 
            case 'n':
459
 
              *to++= '\n';
460
 
              break;
461
 
            case 't':
462
 
              *to++= '\t';
463
 
              break;
464
 
            case 'r':
465
 
              *to++= '\r';
466
 
              break;
467
 
            case 'b':
468
 
              *to++= '\b';
469
 
              break;
470
 
            case '0':
471
 
              *to++= 0;                 // Ascii null
472
 
              break;
473
 
            case 'Z':                   // ^Z must be escaped on Win32
474
 
              *to++= '\032';
475
 
              break;
476
 
            case '_':
477
 
            case '%':
478
 
              *to++= '\\';              // remember prefix for wildcard
479
 
              /* Fall through */
480
 
            default:
 
525
        for (to=start ; str != end ; str++)
 
526
        {
 
527
#ifdef USE_MB
 
528
          int l;
 
529
          if (use_mb(cs) &&
 
530
              (l = my_ismbchar(cs, str, end))) {
 
531
              while (l--)
 
532
                  *to++ = *str++;
 
533
              str--;
 
534
              continue;
 
535
          }
 
536
#endif
 
537
          if (*str == '\\' && str+1 != end)
 
538
          {
 
539
            switch(*++str) {
 
540
            case 'n':
 
541
              *to++='\n';
 
542
              break;
 
543
            case 't':
 
544
              *to++= '\t';
 
545
              break;
 
546
            case 'r':
 
547
              *to++ = '\r';
 
548
              break;
 
549
            case 'b':
 
550
              *to++ = '\b';
 
551
              break;
 
552
            case '0':
 
553
              *to++= 0;                 // Ascii null
 
554
              break;
 
555
            case 'Z':                   // ^Z must be escaped on Win32
 
556
              *to++='\032';
 
557
              break;
 
558
            case '_':
 
559
            case '%':
 
560
              *to++= '\\';              // remember prefix for wildcard
 
561
              /* Fall through */
 
562
            default:
481
563
              *to++= *str;
482
 
              break;
483
 
            }
484
 
          }
485
 
          else if (*str == sep)
486
 
            *to++= *str++;              // Two ' or "
487
 
          else
488
 
            *to++ = *str;
489
 
        }
490
 
        *to= 0;
491
 
        lip->yytoklen= (uint32_t) (to - start);
 
564
              break;
 
565
            }
 
566
          }
 
567
          else if (*str == sep)
 
568
            *to++= *str++;              // Two ' or "
 
569
          else
 
570
            *to++ = *str;
 
571
        }
 
572
        *to=0;
 
573
        lip->yytoklen=(uint) (to-start);
492
574
      }
493
575
      return start;
494
576
    }
505
587
** is done with int64_t or double.
506
588
*/
507
589
 
508
 
static const char *long_str= "2147483647";
509
 
static const uint32_t long_len= 10;
510
 
static const char *signed_long_str= "-2147483648";
511
 
static const char *int64_t_str= "9223372036854775807";
512
 
static const uint32_t int64_t_len= 19;
513
 
static const char *signed_int64_t_str= "-9223372036854775808";
514
 
static const uint32_t signed_int64_t_len= 19;
515
 
static const char *unsigned_int64_t_str= "18446744073709551615";
516
 
static const uint32_t unsigned_int64_t_len= 20;
 
590
static const char *long_str="2147483647";
 
591
static const uint32_t long_len=10;
 
592
static const char *signed_long_str="-2147483648";
 
593
static const char *int64_t_str="9223372036854775807";
 
594
static const uint32_t int64_t_len=19;
 
595
static const char *signed_int64_t_str="-9223372036854775808";
 
596
static const uint32_t signed_int64_t_len=19;
 
597
static const char *unsigned_int64_t_str="18446744073709551615";
 
598
static const uint32_t unsigned_int64_t_len=20;
517
599
 
518
600
static inline uint32_t int_token(const char *str,uint32_t length)
519
601
{
587
669
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
588
670
}
589
671
 
590
 
} /* namespace drizzled */
 
672
 
591
673
/*
592
674
  DRIZZLElex remember the following states from the following DRIZZLElex()
593
675
 
595
677
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
596
678
                                (which can't be followed by a signed number)
597
679
*/
 
680
 
598
681
int DRIZZLElex(void *arg, void *yysession)
599
682
{
600
 
  drizzled::Session *session= (drizzled::Session *)yysession;
601
 
  drizzled::Lex_input_stream *lip= session->m_lip;
 
683
  Session *session= (Session *)yysession;
 
684
  Lex_input_stream *lip= session->m_lip;
602
685
  YYSTYPE *yylval=(YYSTYPE*) arg;
603
686
  int token;
604
687
 
615
698
    return token;
616
699
  }
617
700
 
618
 
  token= drizzled::lex_one_token(arg, yysession);
 
701
  token= lex_one_token(arg, yysession);
619
702
 
620
703
  switch(token) {
621
704
  case WITH:
626
709
      to transform the grammar into a LALR(1) grammar,
627
710
      which sql_yacc.yy can process.
628
711
    */
629
 
    token= drizzled::lex_one_token(arg, yysession);
 
712
    token= lex_one_token(arg, yysession);
630
713
    if (token == ROLLUP_SYM)
631
714
    {
632
715
      return WITH_ROLLUP_SYM;
641
724
      lip->lookahead_token= token;
642
725
      return WITH;
643
726
    }
 
727
    break;
644
728
  default:
645
729
    break;
646
730
  }
648
732
  return token;
649
733
}
650
734
 
651
 
namespace drizzled
652
 
{
653
 
 
654
735
int lex_one_token(void *arg, void *yysession)
655
736
{
656
737
  register unsigned char c= 0; /* Just set to shutup GCC */
679
760
      // Skip starting whitespace
680
761
      while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
681
762
      {
682
 
        if (c == '\n')
683
 
          lip->yylineno++;
 
763
        if (c == '\n')
 
764
          lip->yylineno++;
684
765
 
685
766
        lip->yySkip();
686
767
      }
693
774
    case MY_LEX_ESCAPE:
694
775
      if (lip->yyGet() == 'N')
695
776
      {                                 // Allow \N as shortcut for NULL
696
 
        yylval->lex_str.str=(char*) "\\N";
697
 
        yylval->lex_str.length=2;
698
 
        return NULL_SYM;
 
777
        yylval->lex_str.str=(char*) "\\N";
 
778
        yylval->lex_str.length=2;
 
779
        return NULL_SYM;
699
780
      }
700
781
    case MY_LEX_CHAR:                   // Unknown or single char token
701
782
    case MY_LEX_SKIP:                   // This should not happen
708
789
      }
709
790
 
710
791
      if (c != ')')
711
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
792
        lip->next_state= MY_LEX_START;  // Allow signed numbers
712
793
 
713
794
      if (c == ',')
714
795
      {
729
810
    case MY_LEX_IDENT_OR_HEX:
730
811
      if (lip->yyPeek() == '\'')
731
812
      {                                 // Found x'hex-number'
732
 
        state= MY_LEX_HEX_NUMBER;
733
 
        break;
 
813
        state= MY_LEX_HEX_NUMBER;
 
814
        break;
734
815
      }
735
816
    case MY_LEX_IDENT_OR_BIN:
736
817
      if (lip->yyPeek() == '\'')
740
821
      }
741
822
    case MY_LEX_IDENT:
742
823
      const char *start;
 
824
#if defined(USE_MB) && defined(USE_MB_IDENT)
743
825
      if (use_mb(cs))
744
826
      {
745
 
        result_state= IDENT_QUOTED;
 
827
        result_state= IDENT_QUOTED;
746
828
        if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
747
829
        {
748
830
          int l = my_ismbchar(cs,
758
840
        {
759
841
          if (my_mbcharlen(cs, c) > 1)
760
842
          {
761
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
762
 
            if (l == 0)
 
843
            int l;
 
844
            if ((l = my_ismbchar(cs,
 
845
                                 lip->get_ptr() -1,
 
846
                                 lip->get_end_of_query())) == 0)
763
847
              break;
764
848
            lip->skip_binary(l-1);
765
849
          }
766
850
        }
767
851
      }
768
852
      else
 
853
#endif
769
854
      {
770
855
        for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {};
771
856
        /* If there were non-ASCII characters, mark that we must convert */
782
867
        for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
783
868
      }
784
869
      if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
785
 
              lip->next_state=MY_LEX_IDENT_SEP;
 
870
        lip->next_state=MY_LEX_IDENT_SEP;
786
871
      else
787
872
      {                                 // '(' must follow directly if function
788
873
        lip->yyUnget();
789
 
        if ((tokval = find_keyword(lip, length, c == '(')))
790
 
        {
791
 
          lip->next_state= MY_LEX_START;        // Allow signed numbers
792
 
          return(tokval);               // Was keyword
793
 
        }
 
874
        if ((tokval = find_keyword(lip, length, c == '(')))
 
875
        {
 
876
          lip->next_state= MY_LEX_START;        // Allow signed numbers
 
877
          return(tokval);               // Was keyword
 
878
        }
794
879
        lip->yySkip();                  // next state does a unget
795
880
      }
796
881
      yylval->lex_str=get_token(lip, 0, length);
797
882
 
 
883
      /*
 
884
         Note: "SELECT _bla AS 'alias'"
 
885
         _bla should be considered as a IDENT if charset haven't been found.
 
886
         So we don't use MYF(MY_WME) with get_charset_by_csname to avoid
 
887
         producing an error.
 
888
      */
 
889
 
 
890
      if (yylval->lex_str.str[0] == '_')
 
891
      {
 
892
        const CHARSET_INFO * const cs= get_charset_by_csname(yylval->lex_str.str + 1,
 
893
                                                             MY_CS_PRIMARY, MYF(0));
 
894
        if (cs)
 
895
        {
 
896
          yylval->charset= cs;
 
897
          lip->m_underscore_cs= cs;
 
898
 
 
899
          lip->body_utf8_append(lip->m_cpp_text_start,
 
900
                                lip->get_cpp_tok_start() + length);
 
901
          return(UNDERSCORE_CHARSET);
 
902
        }
 
903
      }
 
904
 
798
905
      lip->body_utf8_append(lip->m_cpp_text_start);
799
906
 
800
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
907
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
908
                                    lip->m_cpp_text_end);
801
909
 
802
910
      return(result_state);                     // IDENT or IDENT_QUOTED
803
911
 
807
915
      c= lip->yyGet();                  // should be '.'
808
916
      lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
809
917
      if (!ident_map[(uint8_t)lip->yyPeek()])            // Probably ` or "
810
 
        lip->next_state= MY_LEX_START;
 
918
        lip->next_state= MY_LEX_START;
811
919
      return((int) c);
812
920
 
813
921
    case MY_LEX_NUMBER_IDENT:           // number or ident which num-start
846
954
      while (my_isdigit(cs, (c = lip->yyGet()))) ;
847
955
      if (!ident_map[c])
848
956
      {                                 // Can't be identifier
849
 
        state=MY_LEX_INT_OR_REAL;
850
 
        break;
 
957
        state=MY_LEX_INT_OR_REAL;
 
958
        break;
851
959
      }
852
960
      if (c == 'e' || c == 'E')
853
961
      {
854
 
        // The following test is written this way to allow numbers of type 1e1
 
962
        // The following test is written this way to allow numbers of type 1e1
855
963
        if (my_isdigit(cs,lip->yyPeek()) ||
856
964
            (c=(lip->yyGet())) == '+' || c == '-')
857
 
        {                               // Allow 1E+10
 
965
        {                               // Allow 1E+10
858
966
          if (my_isdigit(cs,lip->yyPeek()))     // Number must have digit after sign
859
 
          {
 
967
          {
860
968
            lip->yySkip();
861
969
            while (my_isdigit(cs,lip->yyGet())) ;
862
970
            yylval->lex_str=get_token(lip, 0, lip->yyLength());
863
 
            return(FLOAT_NUM);
864
 
          }
865
 
        }
 
971
            return(FLOAT_NUM);
 
972
          }
 
973
        }
866
974
        lip->yyUnget();
867
975
      }
868
976
      // fall through
869
977
    case MY_LEX_IDENT_START:                    // We come here after '.'
870
978
      result_state= IDENT;
 
979
#if defined(USE_MB) && defined(USE_MB_IDENT)
871
980
      if (use_mb(cs))
872
981
      {
873
 
        result_state= IDENT_QUOTED;
 
982
        result_state= IDENT_QUOTED;
874
983
        while (ident_map[c=lip->yyGet()])
875
984
        {
876
985
          if (my_mbcharlen(cs, c) > 1)
877
986
          {
878
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
879
 
            if (l == 0)
 
987
            int l;
 
988
            if ((l = my_ismbchar(cs,
 
989
                                 lip->get_ptr() -1,
 
990
                                 lip->get_end_of_query())) == 0)
880
991
              break;
881
992
            lip->skip_binary(l-1);
882
993
          }
883
994
        }
884
995
      }
885
996
      else
 
997
#endif
886
998
      {
887
999
        for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
888
1000
        /* If there were non-ASCII characters, mark that we must convert */
889
1001
        result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
890
1002
      }
891
1003
      if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
892
 
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
 
1004
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
893
1005
 
894
1006
      yylval->lex_str= get_token(lip, 0, lip->yyLength());
895
1007
 
896
1008
      lip->body_utf8_append(lip->m_cpp_text_start);
897
1009
 
898
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1010
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1011
                                    lip->m_cpp_text_end);
899
1012
 
900
1013
      return(result_state);
901
1014
 
905
1018
      char quote_char= c;                       // Used char
906
1019
      while ((c=lip->yyGet()))
907
1020
      {
908
 
        int var_length;
909
 
        if ((var_length= my_mbcharlen(cs, c)) == 1)
910
 
        {
911
 
          if (c == quote_char)
912
 
          {
913
 
                  if (lip->yyPeek() != quote_char)
914
 
              break;
915
 
                  c=lip->yyGet();
916
 
            double_quotes++;
917
 
            continue;
918
 
          }
919
 
        }
920
 
        else if (var_length < 1)
921
 
          break;                                // Error
 
1021
        int var_length;
 
1022
        if ((var_length= my_mbcharlen(cs, c)) == 1)
 
1023
        {
 
1024
          if (c == quote_char)
 
1025
          {
 
1026
            if (lip->yyPeek() != quote_char)
 
1027
              break;
 
1028
            c=lip->yyGet();
 
1029
            double_quotes++;
 
1030
            continue;
 
1031
          }
 
1032
        }
 
1033
#ifdef USE_MB
 
1034
        else if (var_length < 1)
 
1035
          break;                                // Error
922
1036
        lip->skip_binary(var_length-1);
 
1037
#endif
923
1038
      }
924
1039
      if (double_quotes)
925
 
              yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
 
1040
        yylval->lex_str=get_quoted_token(lip, 1,
 
1041
                                         lip->yyLength() - double_quotes -1,
 
1042
                                         quote_char);
926
1043
      else
927
1044
        yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
928
1045
      if (c == quote_char)
929
1046
        lip->yySkip();                  // Skip end `
930
1047
      lip->next_state= MY_LEX_START;
 
1048
 
931
1049
      lip->body_utf8_append(lip->m_cpp_text_start);
932
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1050
 
 
1051
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1052
                                    lip->m_cpp_text_end);
 
1053
 
933
1054
      return(IDENT_QUOTED);
934
1055
    }
935
1056
    case MY_LEX_INT_OR_REAL:            // Complete int or incomplete real
936
1057
      if (c != '.')
937
1058
      {                                 // Found complete integer number.
938
1059
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
939
 
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
 
1060
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
940
1061
      }
941
1062
      // fall through
942
1063
    case MY_LEX_REAL:                   // Incomplete real number
945
1066
      if (c == 'e' || c == 'E')
946
1067
      {
947
1068
        c = lip->yyGet();
948
 
        if (c == '-' || c == '+')
949
 
                c = lip->yyGet();                     // Skip sign
950
 
        if (!my_isdigit(cs,c))
951
 
        {                               // No digit after sign
952
 
          state= MY_LEX_CHAR;
953
 
          break;
954
 
        }
 
1069
        if (c == '-' || c == '+')
 
1070
          c = lip->yyGet();                     // Skip sign
 
1071
        if (!my_isdigit(cs,c))
 
1072
        {                               // No digit after sign
 
1073
          state= MY_LEX_CHAR;
 
1074
          break;
 
1075
        }
955
1076
        while (my_isdigit(cs,lip->yyGet())) ;
956
1077
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
957
 
        return(FLOAT_NUM);
 
1078
        return(FLOAT_NUM);
958
1079
      }
959
1080
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
960
1081
      return(DECIMAL_NUM);
991
1112
        lip->yySkip();
992
1113
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
993
1114
      {
994
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
995
 
        return(tokval);
 
1115
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
1116
        return(tokval);
996
1117
      }
997
1118
      state = MY_LEX_CHAR;              // Something fishy found
998
1119
      break;
1007
1128
      }
1008
1129
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1009
1130
      {
1010
 
        lip->next_state= MY_LEX_START;  // Found long op
1011
 
        return(tokval);
 
1131
        lip->next_state= MY_LEX_START;  // Found long op
 
1132
        return(tokval);
1012
1133
      }
1013
1134
      state = MY_LEX_CHAR;              // Something fishy found
1014
1135
      break;
1016
1137
    case MY_LEX_BOOL:
1017
1138
      if (c != lip->yyPeek())
1018
1139
      {
1019
 
        state=MY_LEX_CHAR;
1020
 
        break;
 
1140
        state=MY_LEX_CHAR;
 
1141
        break;
1021
1142
      }
1022
1143
      lip->yySkip();
1023
1144
      tokval = find_keyword(lip,2,0);   // Is a bool operator
1034
1155
    case MY_LEX_STRING:                 // Incomplete text string
1035
1156
      if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1036
1157
      {
1037
 
        state= MY_LEX_CHAR;             // Read char by char
1038
 
        break;
 
1158
        state= MY_LEX_CHAR;             // Read char by char
 
1159
        break;
1039
1160
      }
1040
1161
      yylval->lex_str.length=lip->yytoklen;
1041
1162
 
1042
1163
      lip->body_utf8_append(lip->m_cpp_text_start);
1043
1164
 
1044
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1165
      lip->body_utf8_append_literal(session, &yylval->lex_str,
 
1166
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
 
1167
        lip->m_cpp_text_end);
 
1168
 
 
1169
      lip->m_underscore_cs= NULL;
1045
1170
 
1046
1171
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1047
1172
      return(TEXT_STRING);
1055
1180
    case MY_LEX_LONG_COMMENT:           /* Long C comment? */
1056
1181
      if (lip->yyPeek() != '*')
1057
1182
      {
1058
 
        state=MY_LEX_CHAR;              // Probable division
1059
 
        break;
 
1183
        state=MY_LEX_CHAR;              // Probable division
 
1184
        break;
1060
1185
      }
1061
1186
      lex->select_lex.options|= OPTION_FOUND_COMMENT;
1062
1187
      /* Reject '/' '*', since we might need to turn off the echo */
1073
1198
 
1074
1199
        /*
1075
1200
          The special comment format is very strict:
1076
 
          '/' '*' '!', followed by digits ended by a non-digit.
1077
 
          There must be at least 5 digits for it to count
 
1201
          '/' '*' '!', followed by exactly
 
1202
          1 digit (major), 2 digits (minor), then 2 digits (dot).
 
1203
          32302 -> 3.23.02
 
1204
          50032 -> 5.0.32
 
1205
          50114 -> 5.1.14
1078
1206
        */
1079
 
        const int MAX_VERSION_SIZE= 16;
1080
 
        char version_str[MAX_VERSION_SIZE];
1081
 
 
1082
 
        int pos= 0;
1083
 
        do
1084
 
        {
1085
 
          version_str[pos]= lip->yyPeekn(pos);
1086
 
          pos++;
1087
 
        } while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1088
 
        version_str[pos]= 0;
1089
 
 
1090
 
        /* To keep some semblance of compatibility, we impose a 5 digit floor */
1091
 
        if (pos > 4)
1092
 
        {
1093
 
          uint64_t version;
1094
 
          version=strtoll(version_str, NULL, 10);
 
1207
        char version_str[6];
 
1208
        version_str[0]= lip->yyPeekn(0);
 
1209
        version_str[1]= lip->yyPeekn(1);
 
1210
        version_str[2]= lip->yyPeekn(2);
 
1211
        version_str[3]= lip->yyPeekn(3);
 
1212
        version_str[4]= lip->yyPeekn(4);
 
1213
        version_str[5]= 0;
 
1214
        if (  my_isdigit(cs, version_str[0])
 
1215
           && my_isdigit(cs, version_str[1])
 
1216
           && my_isdigit(cs, version_str[2])
 
1217
           && my_isdigit(cs, version_str[3])
 
1218
           && my_isdigit(cs, version_str[4])
 
1219
           )
 
1220
        {
 
1221
          ulong version;
 
1222
          version=strtol(version_str, NULL, 10);
1095
1223
 
1096
1224
          /* Accept 'M' 'm' 'm' 'd' 'd' */
1097
 
          lip->yySkipn(pos-1);
 
1225
          lip->yySkipn(5);
1098
1226
 
1099
1227
          if (version <= DRIZZLE_VERSION_ID)
1100
1228
          {
1163
1291
        state=MY_LEX_START;
1164
1292
      }
1165
1293
      else
1166
 
        state=MY_LEX_CHAR;              // Return '*'
 
1294
        state=MY_LEX_CHAR;              // Return '*'
1167
1295
      break;
1168
1296
    case MY_LEX_SET_VAR:                // Check if ':='
1169
1297
      if (lip->yyPeek() != '=')
1170
1298
      {
1171
 
        state=MY_LEX_CHAR;              // Return ':'
1172
 
        break;
 
1299
        state=MY_LEX_CHAR;              // Return ':'
 
1300
        break;
1173
1301
      }
1174
1302
      lip->yySkip();
1175
1303
      return (SET_VAR);
1176
1304
    case MY_LEX_SEMICOLON:                      // optional line terminator
1177
1305
      if (lip->yyPeek())
1178
1306
      {
 
1307
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1308
        {
 
1309
          lip->found_semicolon= lip->get_ptr();
 
1310
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1311
          lip->next_state= MY_LEX_END;
 
1312
          lip->set_echo(true);
 
1313
          return (END_OF_INPUT);
 
1314
        }
1179
1315
        state= MY_LEX_CHAR;             // Return ';'
1180
 
        break;
 
1316
        break;
1181
1317
      }
1182
1318
      lip->next_state=MY_LEX_END;       // Mark for next loop
1183
1319
      return(END_OF_INPUT);
1198
1334
      break;
1199
1335
    case MY_LEX_END:
1200
1336
      lip->next_state=MY_LEX_END;
1201
 
      return false;                     // We found end of input last time
 
1337
      return(0);                        // We found end of input last time
1202
1338
 
1203
1339
      /* Actually real shouldn't start with . but allow them anyhow */
1204
1340
    case MY_LEX_REAL_OR_POINT:
1205
1341
      if (my_isdigit(cs,lip->yyPeek()))
1206
 
        state= MY_LEX_REAL;             // Real
 
1342
        state = MY_LEX_REAL;            // Real
1207
1343
      else
1208
1344
      {
1209
 
        state= MY_LEX_IDENT_SEP;        // return '.'
 
1345
        state= MY_LEX_IDENT_SEP;        // return '.'
1210
1346
        lip->yyUnget();                 // Put back '.'
1211
1347
      }
1212
1348
      break;
1215
1351
      case MY_LEX_STRING:
1216
1352
      case MY_LEX_USER_VARIABLE_DELIMITER:
1217
1353
      case MY_LEX_STRING_OR_DELIMITER:
1218
 
        break;
 
1354
        break;
1219
1355
      case MY_LEX_USER_END:
1220
 
        lip->next_state=MY_LEX_SYSTEM_VAR;
1221
 
        break;
 
1356
        lip->next_state=MY_LEX_SYSTEM_VAR;
 
1357
        break;
1222
1358
      default:
1223
 
        lip->next_state=MY_LEX_HOSTNAME;
1224
 
        break;
 
1359
        lip->next_state=MY_LEX_HOSTNAME;
 
1360
        break;
1225
1361
      }
1226
1362
      yylval->lex_str.str=(char*) lip->get_ptr();
1227
1363
      yylval->lex_str.length=1;
1228
1364
      return((int) '@');
1229
1365
    case MY_LEX_HOSTNAME:               // end '@' of user@hostname
1230
1366
      for (c=lip->yyGet() ;
1231
 
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
 
1367
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
1232
1368
           c= lip->yyGet()) ;
1233
1369
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1234
1370
      return(LEX_HOSTNAME);
1243
1379
      return((int) '@');
1244
1380
    case MY_LEX_IDENT_OR_KEYWORD:
1245
1381
      /*
1246
 
        We come here when we have found two '@' in a row.
1247
 
        We should now be able to handle:
1248
 
        [(global | local | session) .]variable_name
 
1382
        We come here when we have found two '@' in a row.
 
1383
        We should now be able to handle:
 
1384
        [(global | local | session) .]variable_name
1249
1385
      */
1250
1386
 
1251
1387
      for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1253
1389
      result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1254
1390
 
1255
1391
      if (c == '.')
1256
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
1392
        lip->next_state=MY_LEX_IDENT_SEP;
1257
1393
      length= lip->yyLength();
1258
1394
      if (length == 0)
1259
1395
        return(ABORT_SYM);              // Names must be nonempty.
1260
1396
      if ((tokval= find_keyword(lip, length,0)))
1261
1397
      {
1262
1398
        lip->yyUnget();                         // Put back 'c'
1263
 
        return(tokval);                         // Was keyword
 
1399
        return(tokval);                         // Was keyword
1264
1400
      }
1265
1401
      yylval->lex_str=get_token(lip, 0, length);
1266
1402
 
1267
1403
      lip->body_utf8_append(lip->m_cpp_text_start);
1268
1404
 
1269
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1405
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1406
                                    lip->m_cpp_text_end);
1270
1407
 
1271
1408
      return(result_state);
1272
1409
    }
1273
1410
  }
1274
1411
}
1275
1412
 
 
1413
 
 
1414
/**
 
1415
  Construct a copy of this object to be used for mysql_alter_table
 
1416
  and mysql_create_table.
 
1417
 
 
1418
  Historically, these two functions modify their Alter_info
 
1419
  arguments. This behaviour breaks re-execution of prepared
 
1420
  statements and stored procedures and is compensated by always
 
1421
  supplying a copy of Alter_info to these functions.
 
1422
 
 
1423
  @return You need to use check the error in Session for out
 
1424
  of memory condition after calling this function.
 
1425
*/
 
1426
 
 
1427
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
 
1428
  :drop_list(rhs.drop_list, mem_root),
 
1429
  alter_list(rhs.alter_list, mem_root),
 
1430
  key_list(rhs.key_list, mem_root),
 
1431
  create_list(rhs.create_list, mem_root),
 
1432
  flags(rhs.flags),
 
1433
  keys_onoff(rhs.keys_onoff),
 
1434
  tablespace_op(rhs.tablespace_op),
 
1435
  no_parts(rhs.no_parts),
 
1436
  build_method(rhs.build_method),
 
1437
  datetime_field(rhs.datetime_field),
 
1438
  error_if_not_empty(rhs.error_if_not_empty)
 
1439
{
 
1440
  /*
 
1441
    Make deep copies of used objects.
 
1442
    This is not a fully deep copy - clone() implementations
 
1443
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
 
1444
    do not copy string constants. At the same length the only
 
1445
    reason we make a copy currently is that ALTER/CREATE TABLE
 
1446
    code changes input Alter_info definitions, but string
 
1447
    constants never change.
 
1448
  */
 
1449
  list_copy_and_replace_each_value(drop_list, mem_root);
 
1450
  list_copy_and_replace_each_value(alter_list, mem_root);
 
1451
  list_copy_and_replace_each_value(key_list, mem_root);
 
1452
  list_copy_and_replace_each_value(create_list, mem_root);
 
1453
}
 
1454
 
 
1455
 
1276
1456
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1277
1457
{
1278
1458
  /*
1280
1460
    This code assumes that there are no multi-bytes characters
1281
1461
    that can be considered white-space.
1282
1462
  */
 
1463
 
1283
1464
  while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1284
1465
  {
1285
 
    str->length--;
1286
 
    str->str++;
 
1466
    str->length --;
 
1467
    str->str ++;
1287
1468
  }
1288
1469
 
1289
1470
  /*
1292
1473
  */
1293
1474
  while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1294
1475
  {
1295
 
    str->length--;
 
1476
    str->length --;
1296
1477
  }
1297
1478
}
1298
1479
 
 
1480
 
1299
1481
/*
1300
 
  Select_Lex structures initialisations
 
1482
  st_select_lex structures initialisations
1301
1483
*/
1302
 
void Select_Lex_Node::init_query()
 
1484
 
 
1485
void st_select_lex_node::init_query()
1303
1486
{
1304
1487
  options= 0;
1305
1488
  linkage= UNSPECIFIED_TYPE;
1306
1489
  no_error= no_table_names_allowed= 0;
1307
 
  uncacheable.reset();
1308
 
}
1309
 
 
1310
 
void Select_Lex_Node::init_select()
1311
 
{
1312
 
}
1313
 
 
1314
 
void Select_Lex_Unit::init_query()
1315
 
{
1316
 
  Select_Lex_Node::init_query();
 
1490
  uncacheable= 0;
 
1491
}
 
1492
 
 
1493
void st_select_lex_node::init_select()
 
1494
{
 
1495
}
 
1496
 
 
1497
void st_select_lex_unit::init_query()
 
1498
{
 
1499
  st_select_lex_node::init_query();
1317
1500
  linkage= GLOBAL_OPTIONS_TYPE;
1318
1501
  global_parameters= first_select();
1319
1502
  select_limit_cnt= HA_POS_ERROR;
1330
1513
  found_rows_for_union= 0;
1331
1514
}
1332
1515
 
1333
 
void Select_Lex::init_query()
 
1516
void st_select_lex::init_query()
1334
1517
{
1335
 
  Select_Lex_Node::init_query();
 
1518
  st_select_lex_node::init_query();
1336
1519
  table_list.empty();
1337
1520
  top_join_list.empty();
1338
1521
  join_list= &top_join_list;
1367
1550
  link_next= 0;
1368
1551
}
1369
1552
 
1370
 
void Select_Lex::init_select()
 
1553
void st_select_lex::init_select()
1371
1554
{
 
1555
  st_select_lex_node::init_select();
1372
1556
  sj_nests.empty();
1373
1557
  group_list.empty();
1374
 
  db= 0;
 
1558
  type= db= 0;
1375
1559
  having= 0;
 
1560
  table_join_options= 0;
1376
1561
  in_sum_expr= with_wild= 0;
1377
1562
  options= 0;
1378
1563
  braces= 0;
1379
1564
  interval_list.empty();
 
1565
  ftfunc_list_alloc.empty();
1380
1566
  inner_sum_func_list= 0;
 
1567
  ftfunc_list= &ftfunc_list_alloc;
1381
1568
  linkage= UNSPECIFIED_TYPE;
1382
1569
  order_list.elements= 0;
1383
1570
  order_list.first= 0;
1391
1578
  non_agg_fields.empty();
1392
1579
  cond_value= having_value= Item::COND_UNDEF;
1393
1580
  inner_refs_list.empty();
1394
 
  full_group_by_flag.reset();
 
1581
  full_group_by_flag= 0;
1395
1582
}
1396
1583
 
1397
1584
/*
1398
 
  Select_Lex structures linking
 
1585
  st_select_lex structures linking
1399
1586
*/
1400
1587
 
1401
1588
/* include on level down */
1402
 
void Select_Lex_Node::include_down(Select_Lex_Node *upper)
 
1589
void st_select_lex_node::include_down(st_select_lex_node *upper)
1403
1590
{
1404
1591
  if ((next= upper->slave))
1405
1592
    next->prev= &next;
1413
1600
  include on level down (but do not link)
1414
1601
 
1415
1602
  SYNOPSYS
1416
 
    Select_Lex_Node::include_standalone()
 
1603
    st_select_lex_node::include_standalone()
1417
1604
    upper - reference on node underr which this node should be included
1418
1605
    ref - references on reference on this node
1419
1606
*/
1420
 
void Select_Lex_Node::include_standalone(Select_Lex_Node *upper,
1421
 
                                            Select_Lex_Node **ref)
 
1607
void st_select_lex_node::include_standalone(st_select_lex_node *upper,
 
1608
                                            st_select_lex_node **ref)
1422
1609
{
1423
1610
  next= 0;
1424
1611
  prev= ref;
1427
1614
}
1428
1615
 
1429
1616
/* include neighbour (on same level) */
1430
 
void Select_Lex_Node::include_neighbour(Select_Lex_Node *before)
 
1617
void st_select_lex_node::include_neighbour(st_select_lex_node *before)
1431
1618
{
1432
1619
  if ((next= before->next))
1433
1620
    next->prev= &next;
1437
1624
  slave= 0;
1438
1625
}
1439
1626
 
1440
 
/* including in global Select_Lex list */
1441
 
void Select_Lex_Node::include_global(Select_Lex_Node **plink)
 
1627
/* including in global SELECT_LEX list */
 
1628
void st_select_lex_node::include_global(st_select_lex_node **plink)
1442
1629
{
1443
1630
  if ((link_next= *plink))
1444
1631
    link_next->link_prev= &link_next;
1447
1634
}
1448
1635
 
1449
1636
//excluding from global list (internal function)
1450
 
void Select_Lex_Node::fast_exclude()
 
1637
void st_select_lex_node::fast_exclude()
1451
1638
{
1452
1639
  if (link_prev)
1453
1640
  {
1464
1651
  excluding select_lex structure (except first (first select can't be
1465
1652
  deleted, because it is most upper select))
1466
1653
*/
1467
 
void Select_Lex_Node::exclude()
 
1654
void st_select_lex_node::exclude()
1468
1655
{
1469
1656
  //exclude from global list
1470
1657
  fast_exclude();
1484
1671
  Exclude level of current unit from tree of SELECTs
1485
1672
 
1486
1673
  SYNOPSYS
1487
 
    Select_Lex_Unit::exclude_level()
 
1674
    st_select_lex_unit::exclude_level()
1488
1675
 
1489
1676
  NOTE: units which belong to current will be brought up on level of
1490
1677
  currernt unit
1491
1678
*/
1492
 
void Select_Lex_Unit::exclude_level()
 
1679
void st_select_lex_unit::exclude_level()
1493
1680
{
1494
 
  Select_Lex_Unit *units= 0, **units_last= &units;
1495
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1681
  SELECT_LEX_UNIT *units= 0, **units_last= &units;
 
1682
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1496
1683
  {
1497
1684
    // unlink current level from global SELECTs list
1498
1685
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1499
1686
      sl->link_next->link_prev= sl->link_prev;
1500
1687
 
1501
1688
    // bring up underlay levels
1502
 
    Select_Lex_Unit **last= 0;
1503
 
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1689
    SELECT_LEX_UNIT **last= 0;
 
1690
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1504
1691
    {
1505
1692
      u->master= master;
1506
 
      last= (Select_Lex_Unit**)&(u->next);
 
1693
      last= (SELECT_LEX_UNIT**)&(u->next);
1507
1694
    }
1508
1695
    if (last)
1509
1696
    {
1515
1702
  {
1516
1703
    // include brought up levels in place of current
1517
1704
    (*prev)= units;
1518
 
    (*units_last)= (Select_Lex_Unit*)next;
 
1705
    (*units_last)= (SELECT_LEX_UNIT*)next;
1519
1706
    if (next)
1520
 
      next->prev= (Select_Lex_Node**)units_last;
 
1707
      next->prev= (SELECT_LEX_NODE**)units_last;
1521
1708
    units->prev= prev;
1522
1709
  }
1523
1710
  else
1529
1716
  }
1530
1717
}
1531
1718
 
 
1719
 
1532
1720
/*
1533
1721
  Exclude subtree of current unit from tree of SELECTs
 
1722
 
 
1723
  SYNOPSYS
 
1724
    st_select_lex_unit::exclude_tree()
1534
1725
*/
1535
 
void Select_Lex_Unit::exclude_tree()
 
1726
void st_select_lex_unit::exclude_tree()
1536
1727
{
1537
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1728
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1538
1729
  {
1539
1730
    // unlink current level from global SELECTs list
1540
1731
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1541
1732
      sl->link_next->link_prev= sl->link_prev;
1542
1733
 
1543
1734
    // unlink underlay levels
1544
 
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1735
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1545
1736
    {
1546
1737
      u->exclude_level();
1547
1738
    }
1552
1743
    next->prev= prev;
1553
1744
}
1554
1745
 
1555
 
/**
1556
 
 * Mark all Select_Lex struct from this to 'last' as dependent
1557
 
 *
1558
 
 * @param Pointer to last Select_Lex struct, before wich all
1559
 
 *        Select_Lex have to be marked as dependent
1560
 
 * @note 'last' should be reachable from this Select_Lex_Node
1561
 
 */
1562
 
void Select_Lex::mark_as_dependent(Select_Lex *last)
 
1746
 
 
1747
/*
 
1748
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
 
1749
  this to 'last' as dependent
 
1750
 
 
1751
  SYNOPSIS
 
1752
    last - pointer to last st_select_lex struct, before wich all
 
1753
           st_select_lex have to be marked as dependent
 
1754
 
 
1755
  NOTE
 
1756
    'last' should be reachable from this st_select_lex_node
 
1757
*/
 
1758
 
 
1759
void st_select_lex::mark_as_dependent(st_select_lex *last)
1563
1760
{
1564
1761
  /*
1565
1762
    Mark all selects from resolved to 1 before select where was
1566
1763
    found table as depended (of select where was found table)
1567
1764
  */
1568
 
  for (Select_Lex *s= this;
 
1765
  for (SELECT_LEX *s= this;
1569
1766
       s && s != last;
1570
1767
       s= s->outer_select())
1571
1768
  {
1572
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1769
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1573
1770
    {
1574
1771
      // Select is dependent of outer select
1575
 
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1576
 
      s->uncacheable.set(UNCACHEABLE_UNITED);
1577
 
      Select_Lex_Unit *munit= s->master_unit();
1578
 
      munit->uncacheable.set(UNCACHEABLE_UNITED);
1579
 
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1580
 
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
 
1772
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1773
                       UNCACHEABLE_DEPENDENT;
 
1774
      SELECT_LEX_UNIT *munit= s->master_unit();
 
1775
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1776
                       UNCACHEABLE_DEPENDENT;
 
1777
      for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1581
1778
      {
1582
1779
        if (sl != s &&
1583
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1584
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1780
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1781
          sl->uncacheable|= UNCACHEABLE_UNITED;
1585
1782
      }
1586
1783
    }
1587
1784
    s->is_correlated= true;
1591
1788
  }
1592
1789
}
1593
1790
 
1594
 
bool Select_Lex_Node::set_braces(bool)
1595
 
{ return true; }
1596
 
 
1597
 
bool Select_Lex_Node::inc_in_sum_expr()
1598
 
{ return true; }
1599
 
 
1600
 
uint32_t Select_Lex_Node::get_in_sum_expr() 
1601
 
{ return 0; }
1602
 
 
1603
 
TableList* Select_Lex_Node::get_table_list()
1604
 
{ return NULL; }
1605
 
 
1606
 
List<Item>* Select_Lex_Node::get_item_list()
1607
 
{ return NULL; }
1608
 
 
1609
 
TableList *Select_Lex_Node::add_table_to_list(Session *, 
1610
 
                                              Table_ident *, 
1611
 
                                              LEX_STRING *, 
1612
 
                                              const bitset<NUM_OF_TABLE_OPTIONS>&,
1613
 
                                              thr_lock_type, 
1614
 
                                              List<Index_hint> *, 
1615
 
                                              LEX_STRING *)
1616
 
{
1617
 
  return 0;
1618
 
}
1619
 
 
 
1791
bool st_select_lex_node::set_braces(bool)
 
1792
{ return 1; }
 
1793
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
 
1794
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1795
TableList* st_select_lex_node::get_table_list()     { return 0; }
 
1796
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
 
1797
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1798
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
 
1799
{
 
1800
  return 0;
 
1801
}
 
1802
uint32_t st_select_lex_node::get_table_join_options()
 
1803
{
 
1804
  return 0;
 
1805
}
1620
1806
 
1621
1807
/*
1622
1808
  prohibit using LIMIT clause
1623
1809
*/
1624
 
bool Select_Lex::test_limit()
 
1810
bool st_select_lex::test_limit()
1625
1811
{
1626
1812
  if (select_limit != 0)
1627
1813
  {
1628
1814
    my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1629
1815
             "LIMIT & IN/ALL/ANY/SOME subquery");
1630
 
    return true;
 
1816
    return(1);
1631
1817
  }
1632
 
  return false;
1633
 
}
1634
 
 
1635
 
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1636
 
{
1637
 
  return this;
1638
 
}
1639
 
 
1640
 
Select_Lex* Select_Lex_Unit::outer_select()
1641
 
{
1642
 
  return (Select_Lex*) master;
1643
 
}
1644
 
 
1645
 
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
 
1818
  return(0);
 
1819
}
 
1820
 
 
1821
 
 
1822
st_select_lex_unit* st_select_lex_unit::master_unit()
 
1823
{
 
1824
    return this;
 
1825
}
 
1826
 
 
1827
 
 
1828
st_select_lex* st_select_lex_unit::outer_select()
 
1829
{
 
1830
  return (st_select_lex*) master;
 
1831
}
 
1832
 
 
1833
 
 
1834
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1646
1835
{
1647
1836
  return add_to_list(session, order_list, item, asc);
1648
1837
}
1649
1838
 
1650
 
bool Select_Lex::add_item_to_list(Session *, Item *item)
 
1839
 
 
1840
bool st_select_lex::add_item_to_list(Session *, Item *item)
1651
1841
{
1652
1842
  return(item_list.push_back(item));
1653
1843
}
1654
1844
 
1655
 
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
 
1845
 
 
1846
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1656
1847
{
1657
1848
  return add_to_list(session, group_list, item, asc);
1658
1849
}
1659
1850
 
1660
 
Select_Lex_Unit* Select_Lex::master_unit()
1661
 
{
1662
 
  return (Select_Lex_Unit*) master;
1663
 
}
1664
 
 
1665
 
Select_Lex* Select_Lex::outer_select()
1666
 
{
1667
 
  return (Select_Lex*) master->get_master();
1668
 
}
1669
 
 
1670
 
bool Select_Lex::set_braces(bool value)
 
1851
 
 
1852
st_select_lex_unit* st_select_lex::master_unit()
 
1853
{
 
1854
  return (st_select_lex_unit*) master;
 
1855
}
 
1856
 
 
1857
 
 
1858
st_select_lex* st_select_lex::outer_select()
 
1859
{
 
1860
  return (st_select_lex*) master->get_master();
 
1861
}
 
1862
 
 
1863
 
 
1864
bool st_select_lex::set_braces(bool value)
1671
1865
{
1672
1866
  braces= value;
1673
 
  return false;
 
1867
  return 0;
1674
1868
}
1675
1869
 
1676
 
bool Select_Lex::inc_in_sum_expr()
 
1870
 
 
1871
bool st_select_lex::inc_in_sum_expr()
1677
1872
{
1678
1873
  in_sum_expr++;
1679
 
  return false;
 
1874
  return 0;
1680
1875
}
1681
1876
 
1682
 
uint32_t Select_Lex::get_in_sum_expr()
 
1877
 
 
1878
uint32_t st_select_lex::get_in_sum_expr()
1683
1879
{
1684
1880
  return in_sum_expr;
1685
1881
}
1686
1882
 
1687
 
TableList* Select_Lex::get_table_list()
 
1883
 
 
1884
TableList* st_select_lex::get_table_list()
1688
1885
{
1689
1886
  return (TableList*) table_list.first;
1690
1887
}
1691
1888
 
1692
 
List<Item>* Select_Lex::get_item_list()
 
1889
List<Item>* st_select_lex::get_item_list()
1693
1890
{
1694
1891
  return &item_list;
1695
1892
}
1696
1893
 
1697
 
 
1698
 
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
 
1894
uint32_t st_select_lex::get_table_join_options()
 
1895
{
 
1896
  return table_join_options;
 
1897
}
 
1898
 
 
1899
 
 
1900
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1699
1901
{
1700
1902
  if (ref_pointer_array)
1701
 
    return false;
 
1903
    return 0;
1702
1904
 
1703
1905
  return (ref_pointer_array=
1704
1906
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1708
1910
                                                 order_group_num)*5)) == 0;
1709
1911
}
1710
1912
 
1711
 
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
 
1913
 
 
1914
void st_select_lex_unit::print(String *str, enum_query_type query_type)
1712
1915
{
1713
1916
  bool union_all= !union_distinct;
1714
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1917
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1715
1918
  {
1716
1919
    if (sl != first_select())
1717
1920
    {
1734
1937
      str->append(STRING_WITH_LEN(" order by "));
1735
1938
      fake_select_lex->print_order(
1736
1939
        str,
1737
 
        (Order *) fake_select_lex->order_list.first,
 
1940
        (order_st *) fake_select_lex->order_list.first,
1738
1941
        query_type);
1739
1942
    }
1740
1943
    fake_select_lex->print_limit(session, str, query_type);
1741
1944
  }
1742
1945
}
1743
1946
 
1744
 
void Select_Lex::print_order(String *str,
1745
 
                                Order *order,
 
1947
 
 
1948
void st_select_lex::print_order(String *str,
 
1949
                                order_st *order,
1746
1950
                                enum_query_type query_type)
1747
1951
{
1748
1952
  for (; order; order= order->next)
1762
1966
  }
1763
1967
}
1764
1968
 
1765
 
void Select_Lex::print_limit(Session *, String *str,
 
1969
 
 
1970
void st_select_lex::print_limit(Session *, String *str,
1766
1971
                                enum_query_type query_type)
1767
1972
{
1768
 
  Select_Lex_Unit *unit= master_unit();
 
1973
  SELECT_LEX_UNIT *unit= master_unit();
1769
1974
  Item_subselect *item= unit->item;
1770
1975
 
1771
1976
  if (item && unit->global_parameters == this)
1812
2017
  rule in the grammar file itself, this function should be used
1813
2018
  to implement the clean up.
1814
2019
*/
 
2020
 
1815
2021
void LEX::cleanup_lex_after_parse_error(Session *)
1816
2022
{
1817
2023
}
1833
2039
    this method to reset state of already initialized Query_tables_list
1834
2040
    so it can be used for processing of new statement.
1835
2041
*/
 
2042
 
1836
2043
void Query_tables_list::reset_query_tables_list(bool init)
1837
2044
{
1838
2045
  if (!init && query_tables)
1850
2057
  query_tables_own_last= 0;
1851
2058
}
1852
2059
 
 
2060
 
 
2061
/*
 
2062
  Destroy Query_tables_list object with freeing all resources used by it.
 
2063
 
 
2064
  SYNOPSIS
 
2065
    destroy_query_tables_list()
 
2066
*/
 
2067
 
 
2068
void Query_tables_list::destroy_query_tables_list()
 
2069
{
 
2070
}
 
2071
 
 
2072
 
1853
2073
/*
1854
2074
  Initialize LEX object.
1855
2075
 
1863
2083
    statement parsing. On should use lex_start() function to prepare LEX
1864
2084
    for this.
1865
2085
*/
 
2086
 
1866
2087
LEX::LEX()
1867
 
  :
1868
 
    result(0), 
1869
 
    yacc_yyss(0), 
1870
 
    yacc_yyvs(0),
1871
 
    charset(NULL),
1872
 
    sql_command(SQLCOM_END), 
1873
 
    option_type(OPT_DEFAULT), 
1874
 
    is_lex_started(0),
1875
 
    cacheable(true),
1876
 
    sum_expr_used(false)
 
2088
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
2089
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1877
2090
{
 
2091
 
1878
2092
  reset_query_tables_list(true);
1879
 
  statement= NULL;
1880
 
}
 
2093
}
 
2094
 
 
2095
/*
 
2096
  Detect that we need only table structure of derived table/view
 
2097
 
 
2098
  SYNOPSIS
 
2099
    only_view_structure()
 
2100
 
 
2101
  RETURN
 
2102
    true yes, we need only structure
 
2103
    false no, we need data
 
2104
*/
 
2105
 
 
2106
bool LEX::only_view_structure()
 
2107
{
 
2108
  switch (sql_command) {
 
2109
  case SQLCOM_SHOW_CREATE:
 
2110
  case SQLCOM_SHOW_TABLES:
 
2111
  case SQLCOM_SHOW_FIELDS:
 
2112
    return true;
 
2113
  default:
 
2114
    return false;
 
2115
  }
 
2116
}
 
2117
 
 
2118
 
 
2119
/*
 
2120
  Should Items_ident be printed correctly
 
2121
 
 
2122
  SYNOPSIS
 
2123
    need_correct_ident()
 
2124
 
 
2125
  RETURN
 
2126
    true yes, we need only structure
 
2127
    false no, we need data
 
2128
*/
 
2129
 
 
2130
 
 
2131
bool LEX::need_correct_ident()
 
2132
{
 
2133
  switch(sql_command)
 
2134
  {
 
2135
  case SQLCOM_SHOW_CREATE:
 
2136
  case SQLCOM_SHOW_TABLES:
 
2137
    return true;
 
2138
  default:
 
2139
    return false;
 
2140
  }
 
2141
}
 
2142
 
1881
2143
 
1882
2144
/**
1883
2145
  This method should be called only during parsing.
1897
2159
  @return true in case of error (parsing should be aborted, false in
1898
2160
  case of success
1899
2161
*/
1900
 
bool LEX::copy_db_to(char **p_db, size_t *p_db_length) const
 
2162
 
 
2163
bool
 
2164
LEX::copy_db_to(char **p_db, size_t *p_db_length) const
1901
2165
{
1902
2166
  return session->copy_db_to(p_db, p_db_length);
1903
2167
}
1906
2170
  initialize limit counters
1907
2171
 
1908
2172
  SYNOPSIS
1909
 
    Select_Lex_Unit::set_limit()
1910
 
    values      - Select_Lex with initial values for counters
 
2173
    st_select_lex_unit::set_limit()
 
2174
    values      - SELECT_LEX with initial values for counters
1911
2175
*/
1912
 
void Select_Lex_Unit::set_limit(Select_Lex *sl)
 
2176
 
 
2177
void st_select_lex_unit::set_limit(st_select_lex *sl)
1913
2178
{
1914
2179
  ha_rows select_limit_val;
1915
2180
  uint64_t val;
1929
2194
    select_limit_cnt= HA_POS_ERROR;             // no limit
1930
2195
}
1931
2196
 
 
2197
 
1932
2198
/*
1933
2199
  Unlink the first table from the global table list and the first table from
1934
2200
  outer select (lex->select_lex) local list
1981
2247
  return first;
1982
2248
}
1983
2249
 
 
2250
 
1984
2251
/*
1985
2252
  Bring first local table of first most outer select to first place in global
1986
2253
  table list
1990
2257
 
1991
2258
  NOTES
1992
2259
    In many cases (for example, usual INSERT/DELETE/...) the first table of
1993
 
    main Select_Lex have special meaning => check that it is the first table
 
2260
    main SELECT_LEX have special meaning => check that it is the first table
1994
2261
    in global list and re-link to be first in the global list if it is
1995
2262
    necessary.  We need such re-linking only for queries with sub-queries in
1996
2263
    the select list, as only in this case tables of sub-queries will go to
1997
2264
    the global list first.
1998
2265
*/
 
2266
 
1999
2267
void LEX::first_lists_tables_same()
2000
2268
{
2001
2269
  TableList *first_table= (TableList*) select_lex.table_list.first;
2020
2288
  }
2021
2289
}
2022
2290
 
 
2291
 
2023
2292
/*
2024
2293
  Link table back that was unlinked with unlink_first_table()
2025
2294
 
2030
2299
  RETURN
2031
2300
    global list
2032
2301
*/
2033
 
void LEX::link_first_table_back(TableList *first, bool link_to_local)
 
2302
 
 
2303
void LEX::link_first_table_back(TableList *first,
 
2304
                                   bool link_to_local)
2034
2305
{
2035
2306
  if (first)
2036
2307
  {
2050
2321
  }
2051
2322
}
2052
2323
 
 
2324
 
 
2325
 
2053
2326
/*
2054
2327
  cleanup lex for case when we open table by table for processing
2055
2328
 
2061
2334
    derived tables state. To rollback changes in Query_tables_list one has
2062
2335
    to call Query_tables_list::reset_query_tables_list(false).
2063
2336
*/
 
2337
 
2064
2338
void LEX::cleanup_after_one_table_open()
2065
2339
{
2066
2340
  /*
2067
2341
    session->lex->derived_tables & additional units may be set if we open
2068
2342
    a view. It is necessary to clear session->lex->derived_tables flag
2069
 
    to prevent processing of derived tables during next openTablesLock
 
2343
    to prevent processing of derived tables during next open_and_lock_tables
2070
2344
    if next table is a real table and cleanup & remove underlying units
2071
2345
    NOTE: all units will be connected to session->lex->select_lex, because we
2072
2346
    have not UNION on most upper level.
2075
2349
  {
2076
2350
    derived_tables= 0;
2077
2351
    /* cleunup underlying units (units of VIEW) */
2078
 
    for (Select_Lex_Unit *un= select_lex.first_inner_unit();
 
2352
    for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
2079
2353
         un;
2080
2354
         un= un->next_unit())
2081
2355
      un->cleanup();
2086
2360
  }
2087
2361
}
2088
2362
 
2089
 
/*
2090
 
  There are Select_Lex::add_table_to_list &
2091
 
  Select_Lex::set_lock_for_tables are in sql_parse.cc
2092
 
 
2093
 
  Select_Lex::print is in sql_select.cc
2094
 
 
2095
 
  Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
2096
 
  Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
2097
 
  Select_Lex_Unit::change_result
 
2363
 
 
2364
/*
 
2365
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
 
2366
 
 
2367
  SYNOPSIS
 
2368
    fix_prepare_info_in_table_list()
 
2369
      session  Thread handle
 
2370
      tbl  List of tables to process
 
2371
 
 
2372
  DESCRIPTION
 
2373
    Perform end-end-of prepare fixup for list of tables, if any of the tables
 
2374
    is a merge-algorithm VIEW, recursively fix up its underlying tables as
 
2375
    well.
 
2376
 
 
2377
*/
 
2378
 
 
2379
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
 
2380
{
 
2381
  for (; tbl; tbl= tbl->next_local)
 
2382
  {
 
2383
    if (tbl->on_expr)
 
2384
    {
 
2385
      tbl->prep_on_expr= tbl->on_expr;
 
2386
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
 
2387
    }
 
2388
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
 
2389
  }
 
2390
}
 
2391
 
 
2392
 
 
2393
/*
 
2394
  There are st_select_lex::add_table_to_list &
 
2395
  st_select_lex::set_lock_for_tables are in sql_parse.cc
 
2396
 
 
2397
  st_select_lex::print is in sql_select.cc
 
2398
 
 
2399
  st_select_lex_unit::prepare, st_select_lex_unit::exec,
 
2400
  st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
 
2401
  st_select_lex_unit::change_result
2098
2402
  are in sql_union.cc
2099
2403
*/
2100
2404
 
2113
2417
    Then the context variable index_hint_type can be reset to the
2114
2418
    next hint type.
2115
2419
*/
2116
 
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
 
2420
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
 
2421
                                        index_clause_map clause)
2117
2422
{
2118
2423
  current_index_hint_type= type_arg;
2119
2424
  current_index_hint_clause= clause;
2120
2425
}
2121
2426
 
 
2427
 
2122
2428
/*
2123
2429
  Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2124
2430
 
2126
2432
    alloc_index_hints()
2127
2433
      session         current thread.
2128
2434
*/
2129
 
void Select_Lex::alloc_index_hints (Session *session)
 
2435
 
 
2436
void st_select_lex::alloc_index_hints (Session *session)
2130
2437
{
2131
2438
  index_hints= new (session->mem_root) List<Index_hint>();
2132
2439
}
2133
2440
 
 
2441
 
 
2442
 
2134
2443
/*
2135
2444
  adds an element to the array storing index usage hints
2136
2445
  (ADD/FORCE/IGNORE INDEX).
2144
2453
  RETURN VALUE
2145
2454
    0 on success, non-zero otherwise
2146
2455
*/
2147
 
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length)
 
2456
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2148
2457
{
2149
2458
  return index_hints->push_front (new (session->mem_root)
2150
2459
                                 Index_hint(current_index_hint_type,
2151
2460
                                            current_index_hint_clause,
2152
2461
                                            str, length));
2153
2462
}
2154
 
 
2155
 
} /* namespace drizzled */