~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

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
 
798
883
      lip->body_utf8_append(lip->m_cpp_text_start);
799
884
 
800
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
885
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
886
                                    lip->m_cpp_text_end);
801
887
 
802
888
      return(result_state);                     // IDENT or IDENT_QUOTED
803
889
 
807
893
      c= lip->yyGet();                  // should be '.'
808
894
      lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
809
895
      if (!ident_map[(uint8_t)lip->yyPeek()])            // Probably ` or "
810
 
        lip->next_state= MY_LEX_START;
 
896
        lip->next_state= MY_LEX_START;
811
897
      return((int) c);
812
898
 
813
899
    case MY_LEX_NUMBER_IDENT:           // number or ident which num-start
846
932
      while (my_isdigit(cs, (c = lip->yyGet()))) ;
847
933
      if (!ident_map[c])
848
934
      {                                 // Can't be identifier
849
 
        state=MY_LEX_INT_OR_REAL;
850
 
        break;
 
935
        state=MY_LEX_INT_OR_REAL;
 
936
        break;
851
937
      }
852
938
      if (c == 'e' || c == 'E')
853
939
      {
854
 
        // The following test is written this way to allow numbers of type 1e1
 
940
        // The following test is written this way to allow numbers of type 1e1
855
941
        if (my_isdigit(cs,lip->yyPeek()) ||
856
942
            (c=(lip->yyGet())) == '+' || c == '-')
857
 
        {                               // Allow 1E+10
 
943
        {                               // Allow 1E+10
858
944
          if (my_isdigit(cs,lip->yyPeek()))     // Number must have digit after sign
859
 
          {
 
945
          {
860
946
            lip->yySkip();
861
947
            while (my_isdigit(cs,lip->yyGet())) ;
862
948
            yylval->lex_str=get_token(lip, 0, lip->yyLength());
863
 
            return(FLOAT_NUM);
864
 
          }
865
 
        }
 
949
            return(FLOAT_NUM);
 
950
          }
 
951
        }
866
952
        lip->yyUnget();
867
953
      }
868
954
      // fall through
869
955
    case MY_LEX_IDENT_START:                    // We come here after '.'
870
956
      result_state= IDENT;
 
957
#if defined(USE_MB) && defined(USE_MB_IDENT)
871
958
      if (use_mb(cs))
872
959
      {
873
 
        result_state= IDENT_QUOTED;
 
960
        result_state= IDENT_QUOTED;
874
961
        while (ident_map[c=lip->yyGet()])
875
962
        {
876
963
          if (my_mbcharlen(cs, c) > 1)
877
964
          {
878
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
879
 
            if (l == 0)
 
965
            int l;
 
966
            if ((l = my_ismbchar(cs,
 
967
                                 lip->get_ptr() -1,
 
968
                                 lip->get_end_of_query())) == 0)
880
969
              break;
881
970
            lip->skip_binary(l-1);
882
971
          }
883
972
        }
884
973
      }
885
974
      else
 
975
#endif
886
976
      {
887
977
        for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
888
978
        /* If there were non-ASCII characters, mark that we must convert */
889
979
        result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
890
980
      }
891
981
      if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
892
 
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
 
982
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
893
983
 
894
984
      yylval->lex_str= get_token(lip, 0, lip->yyLength());
895
985
 
896
986
      lip->body_utf8_append(lip->m_cpp_text_start);
897
987
 
898
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
988
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
989
                                    lip->m_cpp_text_end);
899
990
 
900
991
      return(result_state);
901
992
 
905
996
      char quote_char= c;                       // Used char
906
997
      while ((c=lip->yyGet()))
907
998
      {
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
 
999
        int var_length;
 
1000
        if ((var_length= my_mbcharlen(cs, c)) == 1)
 
1001
        {
 
1002
          if (c == quote_char)
 
1003
          {
 
1004
            if (lip->yyPeek() != quote_char)
 
1005
              break;
 
1006
            c=lip->yyGet();
 
1007
            double_quotes++;
 
1008
            continue;
 
1009
          }
 
1010
        }
 
1011
#ifdef USE_MB
 
1012
        else if (var_length < 1)
 
1013
          break;                                // Error
922
1014
        lip->skip_binary(var_length-1);
 
1015
#endif
923
1016
      }
924
1017
      if (double_quotes)
925
 
              yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
 
1018
        yylval->lex_str=get_quoted_token(lip, 1,
 
1019
                                         lip->yyLength() - double_quotes -1,
 
1020
                                         quote_char);
926
1021
      else
927
1022
        yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
928
1023
      if (c == quote_char)
929
1024
        lip->yySkip();                  // Skip end `
930
1025
      lip->next_state= MY_LEX_START;
 
1026
 
931
1027
      lip->body_utf8_append(lip->m_cpp_text_start);
932
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1028
 
 
1029
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1030
                                    lip->m_cpp_text_end);
 
1031
 
933
1032
      return(IDENT_QUOTED);
934
1033
    }
935
1034
    case MY_LEX_INT_OR_REAL:            // Complete int or incomplete real
936
1035
      if (c != '.')
937
1036
      {                                 // Found complete integer number.
938
1037
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
939
 
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
 
1038
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
940
1039
      }
941
1040
      // fall through
942
1041
    case MY_LEX_REAL:                   // Incomplete real number
945
1044
      if (c == 'e' || c == 'E')
946
1045
      {
947
1046
        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
 
        }
 
1047
        if (c == '-' || c == '+')
 
1048
          c = lip->yyGet();                     // Skip sign
 
1049
        if (!my_isdigit(cs,c))
 
1050
        {                               // No digit after sign
 
1051
          state= MY_LEX_CHAR;
 
1052
          break;
 
1053
        }
955
1054
        while (my_isdigit(cs,lip->yyGet())) ;
956
1055
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
957
 
        return(FLOAT_NUM);
 
1056
        return(FLOAT_NUM);
958
1057
      }
959
1058
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
960
1059
      return(DECIMAL_NUM);
991
1090
        lip->yySkip();
992
1091
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
993
1092
      {
994
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
995
 
        return(tokval);
 
1093
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
1094
        return(tokval);
996
1095
      }
997
1096
      state = MY_LEX_CHAR;              // Something fishy found
998
1097
      break;
1007
1106
      }
1008
1107
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1009
1108
      {
1010
 
        lip->next_state= MY_LEX_START;  // Found long op
1011
 
        return(tokval);
 
1109
        lip->next_state= MY_LEX_START;  // Found long op
 
1110
        return(tokval);
1012
1111
      }
1013
1112
      state = MY_LEX_CHAR;              // Something fishy found
1014
1113
      break;
1016
1115
    case MY_LEX_BOOL:
1017
1116
      if (c != lip->yyPeek())
1018
1117
      {
1019
 
        state=MY_LEX_CHAR;
1020
 
        break;
 
1118
        state=MY_LEX_CHAR;
 
1119
        break;
1021
1120
      }
1022
1121
      lip->yySkip();
1023
1122
      tokval = find_keyword(lip,2,0);   // Is a bool operator
1034
1133
    case MY_LEX_STRING:                 // Incomplete text string
1035
1134
      if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1036
1135
      {
1037
 
        state= MY_LEX_CHAR;             // Read char by char
1038
 
        break;
 
1136
        state= MY_LEX_CHAR;             // Read char by char
 
1137
        break;
1039
1138
      }
1040
1139
      yylval->lex_str.length=lip->yytoklen;
1041
1140
 
1042
1141
      lip->body_utf8_append(lip->m_cpp_text_start);
1043
1142
 
1044
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1143
      lip->body_utf8_append_literal(session, &yylval->lex_str,
 
1144
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
 
1145
        lip->m_cpp_text_end);
 
1146
 
 
1147
      lip->m_underscore_cs= NULL;
1045
1148
 
1046
1149
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1047
1150
      return(TEXT_STRING);
1055
1158
    case MY_LEX_LONG_COMMENT:           /* Long C comment? */
1056
1159
      if (lip->yyPeek() != '*')
1057
1160
      {
1058
 
        state=MY_LEX_CHAR;              // Probable division
1059
 
        break;
 
1161
        state=MY_LEX_CHAR;              // Probable division
 
1162
        break;
1060
1163
      }
1061
1164
      lex->select_lex.options|= OPTION_FOUND_COMMENT;
1062
1165
      /* Reject '/' '*', since we might need to turn off the echo */
1073
1176
 
1074
1177
        /*
1075
1178
          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
 
1179
          '/' '*' '!', followed by exactly
 
1180
          1 digit (major), 2 digits (minor), then 2 digits (dot).
 
1181
          32302 -> 3.23.02
 
1182
          50032 -> 5.0.32
 
1183
          50114 -> 5.1.14
1078
1184
        */
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);
 
1185
        char version_str[6];
 
1186
        version_str[0]= lip->yyPeekn(0);
 
1187
        version_str[1]= lip->yyPeekn(1);
 
1188
        version_str[2]= lip->yyPeekn(2);
 
1189
        version_str[3]= lip->yyPeekn(3);
 
1190
        version_str[4]= lip->yyPeekn(4);
 
1191
        version_str[5]= 0;
 
1192
        if (  my_isdigit(cs, version_str[0])
 
1193
           && my_isdigit(cs, version_str[1])
 
1194
           && my_isdigit(cs, version_str[2])
 
1195
           && my_isdigit(cs, version_str[3])
 
1196
           && my_isdigit(cs, version_str[4])
 
1197
           )
 
1198
        {
 
1199
          ulong version;
 
1200
          version=strtol(version_str, NULL, 10);
1095
1201
 
1096
1202
          /* Accept 'M' 'm' 'm' 'd' 'd' */
1097
 
          lip->yySkipn(pos-1);
 
1203
          lip->yySkipn(5);
1098
1204
 
1099
1205
          if (version <= DRIZZLE_VERSION_ID)
1100
1206
          {
1163
1269
        state=MY_LEX_START;
1164
1270
      }
1165
1271
      else
1166
 
        state=MY_LEX_CHAR;              // Return '*'
 
1272
        state=MY_LEX_CHAR;              // Return '*'
1167
1273
      break;
1168
1274
    case MY_LEX_SET_VAR:                // Check if ':='
1169
1275
      if (lip->yyPeek() != '=')
1170
1276
      {
1171
 
        state=MY_LEX_CHAR;              // Return ':'
1172
 
        break;
 
1277
        state=MY_LEX_CHAR;              // Return ':'
 
1278
        break;
1173
1279
      }
1174
1280
      lip->yySkip();
1175
1281
      return (SET_VAR);
1176
1282
    case MY_LEX_SEMICOLON:                      // optional line terminator
1177
1283
      if (lip->yyPeek())
1178
1284
      {
 
1285
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1286
        {
 
1287
          lip->found_semicolon= lip->get_ptr();
 
1288
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1289
          lip->next_state= MY_LEX_END;
 
1290
          lip->set_echo(true);
 
1291
          return (END_OF_INPUT);
 
1292
        }
1179
1293
        state= MY_LEX_CHAR;             // Return ';'
1180
 
        break;
 
1294
        break;
1181
1295
      }
1182
1296
      lip->next_state=MY_LEX_END;       // Mark for next loop
1183
1297
      return(END_OF_INPUT);
1198
1312
      break;
1199
1313
    case MY_LEX_END:
1200
1314
      lip->next_state=MY_LEX_END;
1201
 
      return false;                     // We found end of input last time
 
1315
      return(0);                        // We found end of input last time
1202
1316
 
1203
1317
      /* Actually real shouldn't start with . but allow them anyhow */
1204
1318
    case MY_LEX_REAL_OR_POINT:
1205
1319
      if (my_isdigit(cs,lip->yyPeek()))
1206
 
        state= MY_LEX_REAL;             // Real
 
1320
        state = MY_LEX_REAL;            // Real
1207
1321
      else
1208
1322
      {
1209
 
        state= MY_LEX_IDENT_SEP;        // return '.'
 
1323
        state= MY_LEX_IDENT_SEP;        // return '.'
1210
1324
        lip->yyUnget();                 // Put back '.'
1211
1325
      }
1212
1326
      break;
1215
1329
      case MY_LEX_STRING:
1216
1330
      case MY_LEX_USER_VARIABLE_DELIMITER:
1217
1331
      case MY_LEX_STRING_OR_DELIMITER:
1218
 
        break;
 
1332
        break;
1219
1333
      case MY_LEX_USER_END:
1220
 
        lip->next_state=MY_LEX_SYSTEM_VAR;
1221
 
        break;
 
1334
        lip->next_state=MY_LEX_SYSTEM_VAR;
 
1335
        break;
1222
1336
      default:
1223
 
        lip->next_state=MY_LEX_HOSTNAME;
1224
 
        break;
 
1337
        lip->next_state=MY_LEX_HOSTNAME;
 
1338
        break;
1225
1339
      }
1226
1340
      yylval->lex_str.str=(char*) lip->get_ptr();
1227
1341
      yylval->lex_str.length=1;
1228
1342
      return((int) '@');
1229
1343
    case MY_LEX_HOSTNAME:               // end '@' of user@hostname
1230
1344
      for (c=lip->yyGet() ;
1231
 
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
 
1345
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
1232
1346
           c= lip->yyGet()) ;
1233
1347
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1234
1348
      return(LEX_HOSTNAME);
1243
1357
      return((int) '@');
1244
1358
    case MY_LEX_IDENT_OR_KEYWORD:
1245
1359
      /*
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
 
1360
        We come here when we have found two '@' in a row.
 
1361
        We should now be able to handle:
 
1362
        [(global | local | session) .]variable_name
1249
1363
      */
1250
1364
 
1251
1365
      for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1253
1367
      result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1254
1368
 
1255
1369
      if (c == '.')
1256
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
1370
        lip->next_state=MY_LEX_IDENT_SEP;
1257
1371
      length= lip->yyLength();
1258
1372
      if (length == 0)
1259
1373
        return(ABORT_SYM);              // Names must be nonempty.
1260
1374
      if ((tokval= find_keyword(lip, length,0)))
1261
1375
      {
1262
1376
        lip->yyUnget();                         // Put back 'c'
1263
 
        return(tokval);                         // Was keyword
 
1377
        return(tokval);                         // Was keyword
1264
1378
      }
1265
1379
      yylval->lex_str=get_token(lip, 0, length);
1266
1380
 
1267
1381
      lip->body_utf8_append(lip->m_cpp_text_start);
1268
1382
 
1269
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1383
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1384
                                    lip->m_cpp_text_end);
1270
1385
 
1271
1386
      return(result_state);
1272
1387
    }
1273
1388
  }
1274
1389
}
1275
1390
 
 
1391
 
 
1392
/**
 
1393
  Construct a copy of this object to be used for mysql_alter_table
 
1394
  and mysql_create_table.
 
1395
 
 
1396
  Historically, these two functions modify their Alter_info
 
1397
  arguments. This behaviour breaks re-execution of prepared
 
1398
  statements and stored procedures and is compensated by always
 
1399
  supplying a copy of Alter_info to these functions.
 
1400
 
 
1401
  @return You need to use check the error in Session for out
 
1402
  of memory condition after calling this function.
 
1403
*/
 
1404
 
 
1405
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
 
1406
  :drop_list(rhs.drop_list, mem_root),
 
1407
  alter_list(rhs.alter_list, mem_root),
 
1408
  key_list(rhs.key_list, mem_root),
 
1409
  create_list(rhs.create_list, mem_root),
 
1410
  flags(rhs.flags),
 
1411
  keys_onoff(rhs.keys_onoff),
 
1412
  tablespace_op(rhs.tablespace_op),
 
1413
  no_parts(rhs.no_parts),
 
1414
  build_method(rhs.build_method),
 
1415
  datetime_field(rhs.datetime_field),
 
1416
  error_if_not_empty(rhs.error_if_not_empty)
 
1417
{
 
1418
  /*
 
1419
    Make deep copies of used objects.
 
1420
    This is not a fully deep copy - clone() implementations
 
1421
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
 
1422
    do not copy string constants. At the same length the only
 
1423
    reason we make a copy currently is that ALTER/CREATE TABLE
 
1424
    code changes input Alter_info definitions, but string
 
1425
    constants never change.
 
1426
  */
 
1427
  list_copy_and_replace_each_value(drop_list, mem_root);
 
1428
  list_copy_and_replace_each_value(alter_list, mem_root);
 
1429
  list_copy_and_replace_each_value(key_list, mem_root);
 
1430
  list_copy_and_replace_each_value(create_list, mem_root);
 
1431
}
 
1432
 
 
1433
 
1276
1434
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1277
1435
{
1278
1436
  /*
1280
1438
    This code assumes that there are no multi-bytes characters
1281
1439
    that can be considered white-space.
1282
1440
  */
 
1441
 
1283
1442
  while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1284
1443
  {
1285
 
    str->length--;
1286
 
    str->str++;
 
1444
    str->length --;
 
1445
    str->str ++;
1287
1446
  }
1288
1447
 
1289
1448
  /*
1292
1451
  */
1293
1452
  while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1294
1453
  {
1295
 
    str->length--;
 
1454
    str->length --;
1296
1455
  }
1297
1456
}
1298
1457
 
 
1458
 
1299
1459
/*
1300
 
  Select_Lex structures initialisations
 
1460
  st_select_lex structures initialisations
1301
1461
*/
1302
 
void Select_Lex_Node::init_query()
 
1462
 
 
1463
void st_select_lex_node::init_query()
1303
1464
{
1304
1465
  options= 0;
1305
1466
  linkage= UNSPECIFIED_TYPE;
1306
1467
  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();
 
1468
  uncacheable= 0;
 
1469
}
 
1470
 
 
1471
void st_select_lex_node::init_select()
 
1472
{
 
1473
}
 
1474
 
 
1475
void st_select_lex_unit::init_query()
 
1476
{
 
1477
  st_select_lex_node::init_query();
1317
1478
  linkage= GLOBAL_OPTIONS_TYPE;
1318
1479
  global_parameters= first_select();
1319
1480
  select_limit_cnt= HA_POS_ERROR;
1330
1491
  found_rows_for_union= 0;
1331
1492
}
1332
1493
 
1333
 
void Select_Lex::init_query()
 
1494
void st_select_lex::init_query()
1334
1495
{
1335
 
  Select_Lex_Node::init_query();
 
1496
  st_select_lex_node::init_query();
1336
1497
  table_list.empty();
1337
1498
  top_join_list.empty();
1338
1499
  join_list= &top_join_list;
1367
1528
  link_next= 0;
1368
1529
}
1369
1530
 
1370
 
void Select_Lex::init_select()
 
1531
void st_select_lex::init_select()
1371
1532
{
 
1533
  st_select_lex_node::init_select();
1372
1534
  sj_nests.empty();
1373
1535
  group_list.empty();
1374
 
  db= 0;
 
1536
  type= db= 0;
1375
1537
  having= 0;
 
1538
  table_join_options= 0;
1376
1539
  in_sum_expr= with_wild= 0;
1377
1540
  options= 0;
1378
1541
  braces= 0;
1379
1542
  interval_list.empty();
 
1543
  ftfunc_list_alloc.empty();
1380
1544
  inner_sum_func_list= 0;
 
1545
  ftfunc_list= &ftfunc_list_alloc;
1381
1546
  linkage= UNSPECIFIED_TYPE;
1382
1547
  order_list.elements= 0;
1383
1548
  order_list.first= 0;
1391
1556
  non_agg_fields.empty();
1392
1557
  cond_value= having_value= Item::COND_UNDEF;
1393
1558
  inner_refs_list.empty();
1394
 
  full_group_by_flag.reset();
 
1559
  full_group_by_flag= 0;
1395
1560
}
1396
1561
 
1397
1562
/*
1398
 
  Select_Lex structures linking
 
1563
  st_select_lex structures linking
1399
1564
*/
1400
1565
 
1401
1566
/* include on level down */
1402
 
void Select_Lex_Node::include_down(Select_Lex_Node *upper)
 
1567
void st_select_lex_node::include_down(st_select_lex_node *upper)
1403
1568
{
1404
1569
  if ((next= upper->slave))
1405
1570
    next->prev= &next;
1413
1578
  include on level down (but do not link)
1414
1579
 
1415
1580
  SYNOPSYS
1416
 
    Select_Lex_Node::include_standalone()
 
1581
    st_select_lex_node::include_standalone()
1417
1582
    upper - reference on node underr which this node should be included
1418
1583
    ref - references on reference on this node
1419
1584
*/
1420
 
void Select_Lex_Node::include_standalone(Select_Lex_Node *upper,
1421
 
                                            Select_Lex_Node **ref)
 
1585
void st_select_lex_node::include_standalone(st_select_lex_node *upper,
 
1586
                                            st_select_lex_node **ref)
1422
1587
{
1423
1588
  next= 0;
1424
1589
  prev= ref;
1427
1592
}
1428
1593
 
1429
1594
/* include neighbour (on same level) */
1430
 
void Select_Lex_Node::include_neighbour(Select_Lex_Node *before)
 
1595
void st_select_lex_node::include_neighbour(st_select_lex_node *before)
1431
1596
{
1432
1597
  if ((next= before->next))
1433
1598
    next->prev= &next;
1437
1602
  slave= 0;
1438
1603
}
1439
1604
 
1440
 
/* including in global Select_Lex list */
1441
 
void Select_Lex_Node::include_global(Select_Lex_Node **plink)
 
1605
/* including in global SELECT_LEX list */
 
1606
void st_select_lex_node::include_global(st_select_lex_node **plink)
1442
1607
{
1443
1608
  if ((link_next= *plink))
1444
1609
    link_next->link_prev= &link_next;
1447
1612
}
1448
1613
 
1449
1614
//excluding from global list (internal function)
1450
 
void Select_Lex_Node::fast_exclude()
 
1615
void st_select_lex_node::fast_exclude()
1451
1616
{
1452
1617
  if (link_prev)
1453
1618
  {
1464
1629
  excluding select_lex structure (except first (first select can't be
1465
1630
  deleted, because it is most upper select))
1466
1631
*/
1467
 
void Select_Lex_Node::exclude()
 
1632
void st_select_lex_node::exclude()
1468
1633
{
1469
1634
  //exclude from global list
1470
1635
  fast_exclude();
1484
1649
  Exclude level of current unit from tree of SELECTs
1485
1650
 
1486
1651
  SYNOPSYS
1487
 
    Select_Lex_Unit::exclude_level()
 
1652
    st_select_lex_unit::exclude_level()
1488
1653
 
1489
1654
  NOTE: units which belong to current will be brought up on level of
1490
1655
  currernt unit
1491
1656
*/
1492
 
void Select_Lex_Unit::exclude_level()
 
1657
void st_select_lex_unit::exclude_level()
1493
1658
{
1494
 
  Select_Lex_Unit *units= 0, **units_last= &units;
1495
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1659
  SELECT_LEX_UNIT *units= 0, **units_last= &units;
 
1660
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1496
1661
  {
1497
1662
    // unlink current level from global SELECTs list
1498
1663
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1499
1664
      sl->link_next->link_prev= sl->link_prev;
1500
1665
 
1501
1666
    // 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())
 
1667
    SELECT_LEX_UNIT **last= 0;
 
1668
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1504
1669
    {
1505
1670
      u->master= master;
1506
 
      last= (Select_Lex_Unit**)&(u->next);
 
1671
      last= (SELECT_LEX_UNIT**)&(u->next);
1507
1672
    }
1508
1673
    if (last)
1509
1674
    {
1515
1680
  {
1516
1681
    // include brought up levels in place of current
1517
1682
    (*prev)= units;
1518
 
    (*units_last)= (Select_Lex_Unit*)next;
 
1683
    (*units_last)= (SELECT_LEX_UNIT*)next;
1519
1684
    if (next)
1520
 
      next->prev= (Select_Lex_Node**)units_last;
 
1685
      next->prev= (SELECT_LEX_NODE**)units_last;
1521
1686
    units->prev= prev;
1522
1687
  }
1523
1688
  else
1529
1694
  }
1530
1695
}
1531
1696
 
 
1697
 
1532
1698
/*
1533
1699
  Exclude subtree of current unit from tree of SELECTs
 
1700
 
 
1701
  SYNOPSYS
 
1702
    st_select_lex_unit::exclude_tree()
1534
1703
*/
1535
 
void Select_Lex_Unit::exclude_tree()
 
1704
void st_select_lex_unit::exclude_tree()
1536
1705
{
1537
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1706
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1538
1707
  {
1539
1708
    // unlink current level from global SELECTs list
1540
1709
    if (sl->link_prev && (*sl->link_prev= sl->link_next))
1541
1710
      sl->link_next->link_prev= sl->link_prev;
1542
1711
 
1543
1712
    // unlink underlay levels
1544
 
    for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
 
1713
    for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1545
1714
    {
1546
1715
      u->exclude_level();
1547
1716
    }
1552
1721
    next->prev= prev;
1553
1722
}
1554
1723
 
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)
 
1724
 
 
1725
/*
 
1726
  st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
 
1727
  this to 'last' as dependent
 
1728
 
 
1729
  SYNOPSIS
 
1730
    last - pointer to last st_select_lex struct, before wich all
 
1731
           st_select_lex have to be marked as dependent
 
1732
 
 
1733
  NOTE
 
1734
    'last' should be reachable from this st_select_lex_node
 
1735
*/
 
1736
 
 
1737
void st_select_lex::mark_as_dependent(st_select_lex *last)
1563
1738
{
1564
1739
  /*
1565
1740
    Mark all selects from resolved to 1 before select where was
1566
1741
    found table as depended (of select where was found table)
1567
1742
  */
1568
 
  for (Select_Lex *s= this;
 
1743
  for (SELECT_LEX *s= this;
1569
1744
       s && s != last;
1570
1745
       s= s->outer_select())
1571
1746
  {
1572
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1747
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1573
1748
    {
1574
1749
      // 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())
 
1750
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1751
                       UNCACHEABLE_DEPENDENT;
 
1752
      SELECT_LEX_UNIT *munit= s->master_unit();
 
1753
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1754
                       UNCACHEABLE_DEPENDENT;
 
1755
      for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1581
1756
      {
1582
1757
        if (sl != s &&
1583
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1584
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1758
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1759
          sl->uncacheable|= UNCACHEABLE_UNITED;
1585
1760
      }
1586
1761
    }
1587
1762
    s->is_correlated= true;
1591
1766
  }
1592
1767
}
1593
1768
 
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
 
 
 
1769
bool st_select_lex_node::set_braces(bool)
 
1770
{ return 1; }
 
1771
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
 
1772
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1773
TableList* st_select_lex_node::get_table_list()     { return 0; }
 
1774
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
 
1775
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1776
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
 
1777
{
 
1778
  return 0;
 
1779
}
 
1780
uint32_t st_select_lex_node::get_table_join_options()
 
1781
{
 
1782
  return 0;
 
1783
}
1620
1784
 
1621
1785
/*
1622
1786
  prohibit using LIMIT clause
1623
1787
*/
1624
 
bool Select_Lex::test_limit()
 
1788
bool st_select_lex::test_limit()
1625
1789
{
1626
1790
  if (select_limit != 0)
1627
1791
  {
1628
1792
    my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1629
1793
             "LIMIT & IN/ALL/ANY/SOME subquery");
1630
 
    return true;
 
1794
    return(1);
1631
1795
  }
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)
 
1796
  return(0);
 
1797
}
 
1798
 
 
1799
 
 
1800
st_select_lex_unit* st_select_lex_unit::master_unit()
 
1801
{
 
1802
    return this;
 
1803
}
 
1804
 
 
1805
 
 
1806
st_select_lex* st_select_lex_unit::outer_select()
 
1807
{
 
1808
  return (st_select_lex*) master;
 
1809
}
 
1810
 
 
1811
 
 
1812
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1646
1813
{
1647
1814
  return add_to_list(session, order_list, item, asc);
1648
1815
}
1649
1816
 
1650
 
bool Select_Lex::add_item_to_list(Session *, Item *item)
 
1817
 
 
1818
bool st_select_lex::add_item_to_list(Session *, Item *item)
1651
1819
{
1652
1820
  return(item_list.push_back(item));
1653
1821
}
1654
1822
 
1655
 
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
 
1823
 
 
1824
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1656
1825
{
1657
1826
  return add_to_list(session, group_list, item, asc);
1658
1827
}
1659
1828
 
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)
 
1829
 
 
1830
st_select_lex_unit* st_select_lex::master_unit()
 
1831
{
 
1832
  return (st_select_lex_unit*) master;
 
1833
}
 
1834
 
 
1835
 
 
1836
st_select_lex* st_select_lex::outer_select()
 
1837
{
 
1838
  return (st_select_lex*) master->get_master();
 
1839
}
 
1840
 
 
1841
 
 
1842
bool st_select_lex::set_braces(bool value)
1671
1843
{
1672
1844
  braces= value;
1673
 
  return false;
 
1845
  return 0;
1674
1846
}
1675
1847
 
1676
 
bool Select_Lex::inc_in_sum_expr()
 
1848
 
 
1849
bool st_select_lex::inc_in_sum_expr()
1677
1850
{
1678
1851
  in_sum_expr++;
1679
 
  return false;
 
1852
  return 0;
1680
1853
}
1681
1854
 
1682
 
uint32_t Select_Lex::get_in_sum_expr()
 
1855
 
 
1856
uint32_t st_select_lex::get_in_sum_expr()
1683
1857
{
1684
1858
  return in_sum_expr;
1685
1859
}
1686
1860
 
1687
 
TableList* Select_Lex::get_table_list()
 
1861
 
 
1862
TableList* st_select_lex::get_table_list()
1688
1863
{
1689
1864
  return (TableList*) table_list.first;
1690
1865
}
1691
1866
 
1692
 
List<Item>* Select_Lex::get_item_list()
 
1867
List<Item>* st_select_lex::get_item_list()
1693
1868
{
1694
1869
  return &item_list;
1695
1870
}
1696
1871
 
1697
 
 
1698
 
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
 
1872
uint32_t st_select_lex::get_table_join_options()
 
1873
{
 
1874
  return table_join_options;
 
1875
}
 
1876
 
 
1877
 
 
1878
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1699
1879
{
1700
1880
  if (ref_pointer_array)
1701
 
    return false;
 
1881
    return 0;
1702
1882
 
1703
1883
  return (ref_pointer_array=
1704
1884
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1708
1888
                                                 order_group_num)*5)) == 0;
1709
1889
}
1710
1890
 
1711
 
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
 
1891
 
 
1892
void st_select_lex_unit::print(String *str, enum_query_type query_type)
1712
1893
{
1713
1894
  bool union_all= !union_distinct;
1714
 
  for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
 
1895
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1715
1896
  {
1716
1897
    if (sl != first_select())
1717
1898
    {
1734
1915
      str->append(STRING_WITH_LEN(" order by "));
1735
1916
      fake_select_lex->print_order(
1736
1917
        str,
1737
 
        (Order *) fake_select_lex->order_list.first,
 
1918
        (order_st *) fake_select_lex->order_list.first,
1738
1919
        query_type);
1739
1920
    }
1740
1921
    fake_select_lex->print_limit(session, str, query_type);
1741
1922
  }
1742
1923
}
1743
1924
 
1744
 
void Select_Lex::print_order(String *str,
1745
 
                                Order *order,
 
1925
 
 
1926
void st_select_lex::print_order(String *str,
 
1927
                                order_st *order,
1746
1928
                                enum_query_type query_type)
1747
1929
{
1748
1930
  for (; order; order= order->next)
1762
1944
  }
1763
1945
}
1764
1946
 
1765
 
void Select_Lex::print_limit(Session *, String *str,
 
1947
 
 
1948
void st_select_lex::print_limit(Session *, String *str,
1766
1949
                                enum_query_type query_type)
1767
1950
{
1768
 
  Select_Lex_Unit *unit= master_unit();
 
1951
  SELECT_LEX_UNIT *unit= master_unit();
1769
1952
  Item_subselect *item= unit->item;
1770
1953
 
1771
1954
  if (item && unit->global_parameters == this)
1812
1995
  rule in the grammar file itself, this function should be used
1813
1996
  to implement the clean up.
1814
1997
*/
 
1998
 
1815
1999
void LEX::cleanup_lex_after_parse_error(Session *)
1816
2000
{
1817
2001
}
1833
2017
    this method to reset state of already initialized Query_tables_list
1834
2018
    so it can be used for processing of new statement.
1835
2019
*/
 
2020
 
1836
2021
void Query_tables_list::reset_query_tables_list(bool init)
1837
2022
{
1838
2023
  if (!init && query_tables)
1850
2035
  query_tables_own_last= 0;
1851
2036
}
1852
2037
 
 
2038
 
 
2039
/*
 
2040
  Destroy Query_tables_list object with freeing all resources used by it.
 
2041
 
 
2042
  SYNOPSIS
 
2043
    destroy_query_tables_list()
 
2044
*/
 
2045
 
 
2046
void Query_tables_list::destroy_query_tables_list()
 
2047
{
 
2048
}
 
2049
 
 
2050
 
1853
2051
/*
1854
2052
  Initialize LEX object.
1855
2053
 
1863
2061
    statement parsing. On should use lex_start() function to prepare LEX
1864
2062
    for this.
1865
2063
*/
 
2064
 
1866
2065
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)
 
2066
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
2067
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1877
2068
{
 
2069
 
1878
2070
  reset_query_tables_list(true);
1879
 
  statement= NULL;
1880
 
}
 
2071
}
 
2072
 
 
2073
/*
 
2074
  Detect that we need only table structure of derived table/view
 
2075
 
 
2076
  SYNOPSIS
 
2077
    only_view_structure()
 
2078
 
 
2079
  RETURN
 
2080
    true yes, we need only structure
 
2081
    false no, we need data
 
2082
*/
 
2083
 
 
2084
bool LEX::only_view_structure()
 
2085
{
 
2086
  switch (sql_command) {
 
2087
  case SQLCOM_SHOW_CREATE:
 
2088
  case SQLCOM_SHOW_TABLES:
 
2089
  case SQLCOM_SHOW_FIELDS:
 
2090
    return true;
 
2091
  default:
 
2092
    return false;
 
2093
  }
 
2094
}
 
2095
 
 
2096
 
 
2097
/*
 
2098
  Should Items_ident be printed correctly
 
2099
 
 
2100
  SYNOPSIS
 
2101
    need_correct_ident()
 
2102
 
 
2103
  RETURN
 
2104
    true yes, we need only structure
 
2105
    false no, we need data
 
2106
*/
 
2107
 
 
2108
 
 
2109
bool LEX::need_correct_ident()
 
2110
{
 
2111
  switch(sql_command)
 
2112
  {
 
2113
  case SQLCOM_SHOW_CREATE:
 
2114
  case SQLCOM_SHOW_TABLES:
 
2115
    return true;
 
2116
  default:
 
2117
    return false;
 
2118
  }
 
2119
}
 
2120
 
1881
2121
 
1882
2122
/**
1883
2123
  This method should be called only during parsing.
1897
2137
  @return true in case of error (parsing should be aborted, false in
1898
2138
  case of success
1899
2139
*/
1900
 
bool LEX::copy_db_to(char **p_db, size_t *p_db_length) const
 
2140
 
 
2141
bool
 
2142
LEX::copy_db_to(char **p_db, size_t *p_db_length) const
1901
2143
{
1902
2144
  return session->copy_db_to(p_db, p_db_length);
1903
2145
}
1906
2148
  initialize limit counters
1907
2149
 
1908
2150
  SYNOPSIS
1909
 
    Select_Lex_Unit::set_limit()
1910
 
    values      - Select_Lex with initial values for counters
 
2151
    st_select_lex_unit::set_limit()
 
2152
    values      - SELECT_LEX with initial values for counters
1911
2153
*/
1912
 
void Select_Lex_Unit::set_limit(Select_Lex *sl)
 
2154
 
 
2155
void st_select_lex_unit::set_limit(st_select_lex *sl)
1913
2156
{
1914
2157
  ha_rows select_limit_val;
1915
2158
  uint64_t val;
1929
2172
    select_limit_cnt= HA_POS_ERROR;             // no limit
1930
2173
}
1931
2174
 
 
2175
 
1932
2176
/*
1933
2177
  Unlink the first table from the global table list and the first table from
1934
2178
  outer select (lex->select_lex) local list
1981
2225
  return first;
1982
2226
}
1983
2227
 
 
2228
 
1984
2229
/*
1985
2230
  Bring first local table of first most outer select to first place in global
1986
2231
  table list
1990
2235
 
1991
2236
  NOTES
1992
2237
    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
 
2238
    main SELECT_LEX have special meaning => check that it is the first table
1994
2239
    in global list and re-link to be first in the global list if it is
1995
2240
    necessary.  We need such re-linking only for queries with sub-queries in
1996
2241
    the select list, as only in this case tables of sub-queries will go to
1997
2242
    the global list first.
1998
2243
*/
 
2244
 
1999
2245
void LEX::first_lists_tables_same()
2000
2246
{
2001
2247
  TableList *first_table= (TableList*) select_lex.table_list.first;
2020
2266
  }
2021
2267
}
2022
2268
 
 
2269
 
2023
2270
/*
2024
2271
  Link table back that was unlinked with unlink_first_table()
2025
2272
 
2030
2277
  RETURN
2031
2278
    global list
2032
2279
*/
2033
 
void LEX::link_first_table_back(TableList *first, bool link_to_local)
 
2280
 
 
2281
void LEX::link_first_table_back(TableList *first,
 
2282
                                   bool link_to_local)
2034
2283
{
2035
2284
  if (first)
2036
2285
  {
2050
2299
  }
2051
2300
}
2052
2301
 
 
2302
 
 
2303
 
2053
2304
/*
2054
2305
  cleanup lex for case when we open table by table for processing
2055
2306
 
2061
2312
    derived tables state. To rollback changes in Query_tables_list one has
2062
2313
    to call Query_tables_list::reset_query_tables_list(false).
2063
2314
*/
 
2315
 
2064
2316
void LEX::cleanup_after_one_table_open()
2065
2317
{
2066
2318
  /*
2067
2319
    session->lex->derived_tables & additional units may be set if we open
2068
2320
    a view. It is necessary to clear session->lex->derived_tables flag
2069
 
    to prevent processing of derived tables during next openTablesLock
 
2321
    to prevent processing of derived tables during next open_and_lock_tables
2070
2322
    if next table is a real table and cleanup & remove underlying units
2071
2323
    NOTE: all units will be connected to session->lex->select_lex, because we
2072
2324
    have not UNION on most upper level.
2075
2327
  {
2076
2328
    derived_tables= 0;
2077
2329
    /* cleunup underlying units (units of VIEW) */
2078
 
    for (Select_Lex_Unit *un= select_lex.first_inner_unit();
 
2330
    for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
2079
2331
         un;
2080
2332
         un= un->next_unit())
2081
2333
      un->cleanup();
2086
2338
  }
2087
2339
}
2088
2340
 
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
 
2341
 
 
2342
/*
 
2343
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
 
2344
 
 
2345
  SYNOPSIS
 
2346
    fix_prepare_info_in_table_list()
 
2347
      session  Thread handle
 
2348
      tbl  List of tables to process
 
2349
 
 
2350
  DESCRIPTION
 
2351
    Perform end-end-of prepare fixup for list of tables, if any of the tables
 
2352
    is a merge-algorithm VIEW, recursively fix up its underlying tables as
 
2353
    well.
 
2354
 
 
2355
*/
 
2356
 
 
2357
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
 
2358
{
 
2359
  for (; tbl; tbl= tbl->next_local)
 
2360
  {
 
2361
    if (tbl->on_expr)
 
2362
    {
 
2363
      tbl->prep_on_expr= tbl->on_expr;
 
2364
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
 
2365
    }
 
2366
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
 
2367
  }
 
2368
}
 
2369
 
 
2370
 
 
2371
/*
 
2372
  There are st_select_lex::add_table_to_list &
 
2373
  st_select_lex::set_lock_for_tables are in sql_parse.cc
 
2374
 
 
2375
  st_select_lex::print is in sql_select.cc
 
2376
 
 
2377
  st_select_lex_unit::prepare, st_select_lex_unit::exec,
 
2378
  st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
 
2379
  st_select_lex_unit::change_result
2098
2380
  are in sql_union.cc
2099
2381
*/
2100
2382
 
2113
2395
    Then the context variable index_hint_type can be reset to the
2114
2396
    next hint type.
2115
2397
*/
2116
 
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
 
2398
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
 
2399
                                        index_clause_map clause)
2117
2400
{
2118
2401
  current_index_hint_type= type_arg;
2119
2402
  current_index_hint_clause= clause;
2120
2403
}
2121
2404
 
 
2405
 
2122
2406
/*
2123
2407
  Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2124
2408
 
2126
2410
    alloc_index_hints()
2127
2411
      session         current thread.
2128
2412
*/
2129
 
void Select_Lex::alloc_index_hints (Session *session)
 
2413
 
 
2414
void st_select_lex::alloc_index_hints (Session *session)
2130
2415
{
2131
2416
  index_hints= new (session->mem_root) List<Index_hint>();
2132
2417
}
2133
2418
 
 
2419
 
 
2420
 
2134
2421
/*
2135
2422
  adds an element to the array storing index usage hints
2136
2423
  (ADD/FORCE/IGNORE INDEX).
2144
2431
  RETURN VALUE
2145
2432
    0 on success, non-zero otherwise
2146
2433
*/
2147
 
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length)
 
2434
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2148
2435
{
2149
2436
  return index_hints->push_front (new (session->mem_root)
2150
2437
                                 Index_hint(current_index_hint_type,
2151
2438
                                            current_index_hint_clause,
2152
2439
                                            str, length));
2153
2440
}
2154
 
 
2155
 
} /* namespace drizzled */