~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Mark Atwood
  • Date: 2009-03-04 01:02:00 UTC
  • mto: (968.2.20 mordred)
  • mto: This revision was merged to the branch mainline in revision 971.
  • Revision ID: me@mark.atwood.name-20090304010200-t1n4xxdoil2yae9a
add gearman logging plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
 
#include <config.h>
20
 
 
21
19
#define DRIZZLE_LEX 1
22
 
 
23
 
#include <drizzled/sql_reserved_words.h>
24
 
 
25
 
#include <drizzled/configmake.h>
 
20
#include <drizzled/server_includes.h>
26
21
#include <drizzled/item/num.h>
27
22
#include <drizzled/error.h>
28
23
#include <drizzled/session.h>
29
24
#include <drizzled/sql_base.h>
30
25
#include <drizzled/lookup_symbol.h>
31
 
#include <drizzled/index_hint.h>
32
 
#include <drizzled/select_result.h>
33
26
 
34
 
#include <cstdio>
35
27
#include <ctype.h>
36
28
 
37
 
union ParserType;
38
 
 
39
29
using namespace std;
40
30
 
41
 
/* Stay outside of the namespace because otherwise bison goes nuts */
42
 
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
43
 
 
44
 
namespace drizzled
45
 
{
46
 
 
47
 
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
48
 
 
49
 
/**
50
 
  save order by and tables in own lists.
 
31
 
 
32
static int lex_one_token(void *arg, void *yysession);
 
33
 
 
34
 
 
35
/*
 
36
  We are using pointer to this variable for distinguishing between assignment
 
37
  to NEW row field (when parsing trigger definition) and structured variable.
51
38
*/
52
 
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
53
 
{
54
 
  Order *order;
55
 
 
56
 
  if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
57
 
    return true;
58
 
 
59
 
  order->item_ptr= item;
60
 
  order->item= &order->item_ptr;
61
 
  order->asc = asc;
62
 
  order->free_me=0;
63
 
  order->used=0;
64
 
  order->counter_used= 0;
65
 
  list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
66
 
 
67
 
  return false;
68
 
}
 
39
 
 
40
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
69
41
 
70
42
/**
71
43
  LEX_STRING constant for null-string to be used in parser and other places.
72
44
*/
73
45
const LEX_STRING null_lex_str= {NULL, 0};
74
46
 
 
47
 
 
48
/*
 
49
  Names of the index hints (for error messages). Keep in sync with
 
50
  index_hint_type
 
51
*/
 
52
 
 
53
const char * index_hint_type_name[] =
 
54
{
 
55
  "IGNORE INDEX",
 
56
  "USE INDEX",
 
57
  "FORCE INDEX"
 
58
};
 
59
 
 
60
 
 
61
 
 
62
void
 
63
st_parsing_options::reset()
 
64
{
 
65
  allows_select_procedure= true;
 
66
}
 
67
 
75
68
Lex_input_stream::Lex_input_stream(Session *session,
76
69
                                   const char* buffer,
77
 
                                   unsigned int length) :
78
 
  m_session(session),
 
70
                                   unsigned int length)
 
71
: m_session(session),
79
72
  yylineno(1),
80
73
  yytoklen(0),
81
74
  yylval(NULL),
95
88
  m_body_utf8(NULL),
96
89
  m_cpp_utf8_processed_ptr(NULL),
97
90
  next_state(MY_LEX_START),
 
91
  found_semicolon(NULL),
98
92
  ignore_space(1),
99
 
  in_comment(NO_COMMENT)
 
93
  in_comment(NO_COMMENT),
 
94
  m_underscore_cs(NULL)
100
95
{
101
 
  m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
 
96
  m_cpp_buf= (char*) session->alloc(length + 1);
102
97
  m_cpp_ptr= m_cpp_buf;
103
98
}
104
99
 
116
111
  @param begin_ptr  Pointer to the start of the body in the pre-processed
117
112
                    buffer.
118
113
*/
 
114
 
119
115
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
120
116
{
121
117
  assert(begin_ptr);
125
121
    (m_buf_length / default_charset_info->mbminlen) *
126
122
    my_charset_utf8_bin.mbmaxlen;
127
123
 
128
 
  m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
 
124
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
129
125
  m_body_utf8_ptr= m_body_utf8;
130
126
  *m_body_utf8_ptr= 0;
131
127
 
152
148
                  m_cpp_utf8_processed_ptr will be set in the end of the
153
149
                  operation.
154
150
*/
 
151
 
155
152
void Lex_input_stream::body_utf8_append(const char *ptr,
156
153
                                        const char *end_ptr)
157
154
{
180
177
  @param ptr  Pointer in the pre-processed buffer, which specifies the end
181
178
              of the chunk, which should be appended to the utf8 body.
182
179
*/
 
180
 
183
181
void Lex_input_stream::body_utf8_append(const char *ptr)
184
182
{
185
183
  body_utf8_append(ptr, ptr);
196
194
                  m_cpp_utf8_processed_ptr will be set in the end of the
197
195
                  operation.
198
196
*/
199
 
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
 
197
 
 
198
void Lex_input_stream::body_utf8_append_literal(Session *session,
 
199
                                                const LEX_STRING *txt,
 
200
                                                const CHARSET_INFO * const txt_cs,
200
201
                                                const char *end_ptr)
201
202
{
202
203
  if (!m_cpp_utf8_processed_ptr)
203
204
    return;
204
205
 
 
206
  LEX_STRING utf_txt;
 
207
 
 
208
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
 
209
  {
 
210
    session->convert_string(&utf_txt,
 
211
                        &my_charset_utf8_general_ci,
 
212
                        txt->str, txt->length,
 
213
                        txt_cs);
 
214
  }
 
215
  else
 
216
  {
 
217
    utf_txt.str= txt->str;
 
218
    utf_txt.length= txt->length;
 
219
  }
 
220
 
205
221
  /* NOTE: utf_txt.length is in bytes, not in symbols. */
206
222
 
207
 
  memcpy(m_body_utf8_ptr, txt->str, txt->length);
208
 
  m_body_utf8_ptr += txt->length;
 
223
  memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
 
224
  m_body_utf8_ptr += utf_txt.length;
209
225
  *m_body_utf8_ptr= 0;
210
226
 
211
227
  m_cpp_utf8_processed_ptr= end_ptr;
212
228
}
213
229
 
 
230
 
214
231
/*
215
232
  This is called before every query that is to be parsed.
216
233
  Because of this, it's critical to not do too much things here.
217
234
  (We already do too much here)
218
235
*/
219
 
void LEX::start(Session *arg)
220
 
{
221
 
  lex_start(arg);
222
 
}
223
236
 
224
237
void lex_start(Session *session)
225
238
{
226
 
  LEX *lex= session->getLex();
 
239
  LEX *lex= session->lex;
227
240
 
228
241
  lex->session= lex->unit.session= session;
229
242
 
230
 
  lex->context_stack.clear();
 
243
  lex->context_stack.empty();
231
244
  lex->unit.init_query();
232
245
  lex->unit.init_select();
233
246
  /* 'parent_lex' is used in init_query() so it must be before it. */
234
247
  lex->select_lex.parent_lex= lex;
235
248
  lex->select_lex.init_query();
236
 
  lex->value_list.clear();
237
 
  lex->update_list.clear();
238
 
  lex->auxiliary_table_list.clear();
 
249
  lex->value_list.empty();
 
250
  lex->update_list.empty();
 
251
  lex->param_list.empty();
 
252
  lex->auxiliary_table_list.empty();
239
253
  lex->unit.next= lex->unit.master=
240
254
    lex->unit.link_next= lex->unit.return_to= 0;
241
255
  lex->unit.prev= lex->unit.link_prev= 0;
247
261
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
248
262
  lex->select_lex.options= 0;
249
263
  lex->select_lex.init_order();
250
 
  lex->select_lex.group_list.clear();
 
264
  lex->select_lex.group_list.empty();
251
265
  lex->describe= 0;
 
266
  lex->subqueries= false;
252
267
  lex->derived_tables= 0;
253
268
  lex->lock_option= TL_READ;
254
269
  lex->leaf_tables_insert= 0;
255
 
  lex->var_list.clear();
 
270
  lex->parsing_options.reset();
256
271
  lex->select_lex.select_number= 1;
257
272
  lex->length=0;
258
273
  lex->select_lex.in_sum_expr=0;
259
 
  lex->select_lex.group_list.clear();
260
 
  lex->select_lex.order_list.clear();
 
274
  lex->select_lex.ftfunc_list_alloc.empty();
 
275
  lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
 
276
  lex->select_lex.group_list.empty();
 
277
  lex->select_lex.order_list.empty();
261
278
  lex->sql_command= SQLCOM_END;
262
279
  lex->duplicates= DUP_ERROR;
263
280
  lex->ignore= 0;
 
281
  lex->proc_list.first= 0;
264
282
  lex->escape_used= false;
265
283
  lex->query_tables= 0;
266
284
  lex->reset_query_tables_list(false);
267
285
  lex->expr_allows_subselect= true;
268
286
  lex->use_only_table_context= false;
 
287
  lex->parse_vcol_expr= false;
269
288
 
270
289
  lex->name.str= 0;
271
290
  lex->name.length= 0;
272
291
  lex->nest_level=0 ;
273
292
  lex->allow_sum_func= 0;
274
293
  lex->in_sum_func= NULL;
275
 
  lex->type= 0;
276
294
 
277
295
  lex->is_lex_started= true;
278
 
  lex->statement= NULL;
279
 
  
280
 
  lex->is_cross= false;
281
 
  lex->reset();
282
296
}
283
297
 
284
 
void LEX::end()
 
298
void lex_end(LEX *lex)
285
299
{
286
 
  if (yacc_yyss)
 
300
  if (lex->yacc_yyss)
287
301
  {
288
 
    free(yacc_yyss);
289
 
    free(yacc_yyvs);
290
 
    yacc_yyss= 0;
291
 
    yacc_yyvs= 0;
 
302
    free(lex->yacc_yyss);
 
303
    free(lex->yacc_yyvs);
 
304
    lex->yacc_yyss= 0;
 
305
    lex->yacc_yyvs= 0;
292
306
  }
293
307
 
294
 
  safe_delete(result);
295
 
  safe_delete(_create_table);
296
 
  _create_table= NULL;
297
 
  _create_field= NULL;
298
 
 
299
 
  result= 0;
300
 
  setCacheable(true);
301
 
 
302
 
  safe_delete(statement);
 
308
  delete lex->result;
 
309
  lex->result= 0;
303
310
}
304
311
 
 
312
 
305
313
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
306
314
{
307
315
  /* Plenty of memory for the largest lex symbol we have */
325
333
  return 0;
326
334
}
327
335
 
 
336
 
328
337
bool is_lex_native_function(const LEX_STRING *name)
329
338
{
330
339
  assert(name != NULL);
332
341
}
333
342
 
334
343
/* make a copy of token before ptr and set yytoklen */
 
344
 
335
345
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
336
346
{
337
347
  LEX_STRING tmp;
351
361
   get_quoted_token yet. But it should be fixed in the
352
362
   future to operate multichar strings (like ucs2)
353
363
*/
 
364
 
354
365
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
355
366
                                   uint32_t skip,
356
367
                                   uint32_t length, char quote)
360
371
  char *to;
361
372
  lip->yyUnget();                       // ptr points now after last token char
362
373
  tmp.length= lip->yytoklen=length;
363
 
  tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
 
374
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
364
375
  from= lip->get_tok_start() + skip;
365
376
  to= tmp.str;
366
377
  end= to+length;
385
396
  Return an unescaped text literal without quotes
386
397
  Fix sometimes to do only one scan of the string
387
398
*/
 
399
 
388
400
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
389
401
{
390
 
  unsigned char c,sep;
391
 
  bool found_escape= false;
 
402
  register unsigned char c,sep;
 
403
  uint32_t found_escape=0;
392
404
  const CHARSET_INFO * const cs= lip->m_session->charset();
393
405
 
394
406
  lip->tok_bitmap= 0;
397
409
  {
398
410
    c= lip->yyGet();
399
411
    lip->tok_bitmap|= c;
 
412
#ifdef USE_MB
400
413
    {
401
 
      if (use_mb(cs))
402
 
      {
403
 
        int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
404
 
        if (l != 0) 
405
 
        {
406
 
          lip->skip_binary(l-1);
407
 
          continue;
408
 
        }
 
414
      int l;
 
415
      if (use_mb(cs) &&
 
416
          (l = my_ismbchar(cs,
 
417
                           lip->get_ptr() -1,
 
418
                           lip->get_end_of_query()))) {
 
419
        lip->skip_binary(l-1);
 
420
        continue;
409
421
      }
410
422
    }
 
423
#endif
411
424
    if (c == '\\')
412
425
    {                                   // Escaped character
413
 
      found_escape= true;
 
426
      found_escape=1;
414
427
      if (lip->eof())
415
 
        return 0;
 
428
        return 0;
416
429
      lip->yySkip();
417
430
    }
418
431
    else if (c == sep)
419
432
    {
420
433
      if (c == lip->yyGet())            // Check if two separators in a row
421
434
      {
422
 
        found_escape= true;                 // duplicate. Remember for delete
423
 
        continue;
 
435
        found_escape=1;                 // duplicate. Remember for delete
 
436
        continue;
424
437
      }
425
438
      else
426
439
        lip->yyUnget();
432
445
      str= lip->get_tok_start();
433
446
      end= lip->get_ptr();
434
447
      /* Extract the text from the token */
435
 
      str+= pre_skip;
436
 
      end-= post_skip;
 
448
      str += pre_skip;
 
449
      end -= post_skip;
437
450
      assert(end >= str);
438
451
 
439
 
      if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
440
 
        return (char*) "";              // memory::SqlAlloc has set error flag
 
452
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
 
453
        return (char*) "";              // Sql_alloc has set error flag
441
454
 
442
455
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
443
456
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
444
457
 
445
 
      if (! found_escape)
 
458
      if (!found_escape)
446
459
      {
447
 
        lip->yytoklen= (uint32_t) (end-str);
448
 
        memcpy(start, str, lip->yytoklen);
449
 
        start[lip->yytoklen]= 0;
 
460
        lip->yytoklen=(uint32_t) (end-str);
 
461
        memcpy(start,str,lip->yytoklen);
 
462
        start[lip->yytoklen]=0;
450
463
      }
451
464
      else
452
465
      {
453
466
        char *to;
454
467
 
455
 
        for (to= start; str != end; str++)
456
 
        {
457
 
          if (use_mb(cs))
458
 
          {
459
 
            int l= my_ismbchar(cs, str, end);
460
 
            if (l != 0)
461
 
            {
462
 
              while (l--)
463
 
                *to++= *str++;
464
 
              str--;
465
 
              continue;
466
 
            }
467
 
          }
468
 
          if (*str == '\\' && (str + 1) != end)
469
 
          {
470
 
            switch (*++str) {
471
 
            case 'n':
472
 
              *to++= '\n';
473
 
              break;
474
 
            case 't':
475
 
              *to++= '\t';
476
 
              break;
477
 
            case 'r':
478
 
              *to++= '\r';
479
 
              break;
480
 
            case 'b':
481
 
              *to++= '\b';
482
 
              break;
483
 
            case '0':
484
 
              *to++= 0;                 // Ascii null
485
 
              break;
486
 
            case 'Z':                   // ^Z must be escaped on Win32
487
 
              *to++= '\032';
488
 
              break;
489
 
            case '_':
490
 
            case '%':
491
 
              *to++= '\\';              // remember prefix for wildcard
492
 
              /* Fall through */
493
 
            default:
 
468
        for (to=start ; str != end ; str++)
 
469
        {
 
470
#ifdef USE_MB
 
471
          int l;
 
472
          if (use_mb(cs) &&
 
473
              (l = my_ismbchar(cs, str, end))) {
 
474
              while (l--)
 
475
                  *to++ = *str++;
 
476
              str--;
 
477
              continue;
 
478
          }
 
479
#endif
 
480
          if (*str == '\\' && str+1 != end)
 
481
          {
 
482
            switch(*++str) {
 
483
            case 'n':
 
484
              *to++='\n';
 
485
              break;
 
486
            case 't':
 
487
              *to++= '\t';
 
488
              break;
 
489
            case 'r':
 
490
              *to++ = '\r';
 
491
              break;
 
492
            case 'b':
 
493
              *to++ = '\b';
 
494
              break;
 
495
            case '0':
 
496
              *to++= 0;                 // Ascii null
 
497
              break;
 
498
            case 'Z':                   // ^Z must be escaped on Win32
 
499
              *to++='\032';
 
500
              break;
 
501
            case '_':
 
502
            case '%':
 
503
              *to++= '\\';              // remember prefix for wildcard
 
504
              /* Fall through */
 
505
            default:
494
506
              *to++= *str;
495
 
              break;
496
 
            }
497
 
          }
498
 
          else if (*str == sep)
499
 
            *to++= *str++;              // Two ' or "
500
 
          else
501
 
            *to++ = *str;
502
 
        }
503
 
        *to= 0;
504
 
        lip->yytoklen= (uint32_t) (to - start);
 
507
              break;
 
508
            }
 
509
          }
 
510
          else if (*str == sep)
 
511
            *to++= *str++;              // Two ' or "
 
512
          else
 
513
            *to++ = *str;
 
514
        }
 
515
        *to=0;
 
516
        lip->yytoklen=(uint32_t) (to-start);
505
517
      }
506
518
      return start;
507
519
    }
518
530
** is done with int64_t or double.
519
531
*/
520
532
 
521
 
static const char *long_str= "2147483647";
522
 
static const uint32_t long_len= 10;
523
 
static const char *signed_long_str= "-2147483648";
524
 
static const char *int64_t_str= "9223372036854775807";
525
 
static const uint32_t int64_t_len= 19;
526
 
static const char *signed_int64_t_str= "-9223372036854775808";
527
 
static const uint32_t signed_int64_t_len= 19;
528
 
static const char *unsigned_int64_t_str= "18446744073709551615";
529
 
static const uint32_t unsigned_int64_t_len= 20;
 
533
static const char *long_str="2147483647";
 
534
static const uint32_t long_len=10;
 
535
static const char *signed_long_str="-2147483648";
 
536
static const char *int64_t_str="9223372036854775807";
 
537
static const uint32_t int64_t_len=19;
 
538
static const char *signed_int64_t_str="-9223372036854775808";
 
539
static const uint32_t signed_int64_t_len=19;
 
540
static const char *unsigned_int64_t_str="18446744073709551615";
 
541
static const uint32_t unsigned_int64_t_len=20;
530
542
 
531
543
static inline uint32_t int_token(const char *str,uint32_t length)
532
544
{
600
612
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
601
613
}
602
614
 
603
 
} /* namespace drizzled */
 
615
 
604
616
/*
605
 
  base_sql_lex remember the following states from the following sql_baselex()
 
617
  DRIZZLElex remember the following states from the following DRIZZLElex()
606
618
 
607
619
  - MY_LEX_EOQ                  Found end of query
608
620
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
609
621
                                (which can't be followed by a signed number)
610
622
*/
611
 
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
 
623
 
 
624
int DRIZZLElex(void *arg, void *yysession)
612
625
{
613
 
  drizzled::Lex_input_stream *lip= session->m_lip;
 
626
  Session *session= (Session *)yysession;
 
627
  Lex_input_stream *lip= session->m_lip;
 
628
  YYSTYPE *yylval=(YYSTYPE*) arg;
614
629
  int token;
615
630
 
616
631
  if (lip->lookahead_token != END_OF_INPUT)
626
641
    return token;
627
642
  }
628
643
 
629
 
  token= drizzled::lex_one_token(yylval, session);
 
644
  token= lex_one_token(arg, yysession);
630
645
 
631
646
  switch(token) {
632
647
  case WITH:
637
652
      to transform the grammar into a LALR(1) grammar,
638
653
      which sql_yacc.yy can process.
639
654
    */
640
 
    token= drizzled::lex_one_token(yylval, session);
 
655
    token= lex_one_token(arg, yysession);
641
656
    if (token == ROLLUP_SYM)
642
657
    {
643
658
      return WITH_ROLLUP_SYM;
659
674
  return token;
660
675
}
661
676
 
662
 
namespace drizzled
663
 
{
664
 
 
665
 
int lex_one_token(ParserType *yylval, drizzled::Session *session)
666
 
{
667
 
  unsigned char c= 0; /* Just set to shutup GCC */
 
677
int lex_one_token(void *arg, void *yysession)
 
678
{
 
679
  register unsigned char c= 0; /* Just set to shutup GCC */
668
680
  bool comment_closed;
669
681
  int   tokval, result_state;
670
682
  unsigned int length;
671
683
  enum my_lex_states state;
 
684
  Session *session= (Session *)yysession;
672
685
  Lex_input_stream *lip= session->m_lip;
673
 
  LEX *lex= session->getLex();
 
686
  LEX *lex= session->lex;
 
687
  YYSTYPE *yylval=(YYSTYPE*) arg;
674
688
  const CHARSET_INFO * const cs= session->charset();
675
689
  unsigned char *state_map= cs->state_map;
676
690
  unsigned char *ident_map= cs->ident_map;
688
702
      // Skip starting whitespace
689
703
      while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
690
704
      {
691
 
        if (c == '\n')
692
 
          lip->yylineno++;
 
705
        if (c == '\n')
 
706
          lip->yylineno++;
693
707
 
694
708
        lip->yySkip();
695
709
      }
702
716
    case MY_LEX_ESCAPE:
703
717
      if (lip->yyGet() == 'N')
704
718
      {                                 // Allow \N as shortcut for NULL
705
 
        yylval->lex_str.str=(char*) "\\N";
706
 
        yylval->lex_str.length=2;
707
 
        return NULL_SYM;
 
719
        yylval->lex_str.str=(char*) "\\N";
 
720
        yylval->lex_str.length=2;
 
721
        return NULL_SYM;
708
722
      }
709
723
    case MY_LEX_CHAR:                   // Unknown or single char token
710
724
    case MY_LEX_SKIP:                   // This should not happen
717
731
      }
718
732
 
719
733
      if (c != ')')
720
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
734
        lip->next_state= MY_LEX_START;  // Allow signed numbers
721
735
 
722
736
      if (c == ',')
723
737
      {
738
752
    case MY_LEX_IDENT_OR_HEX:
739
753
      if (lip->yyPeek() == '\'')
740
754
      {                                 // Found x'hex-number'
741
 
        state= MY_LEX_HEX_NUMBER;
742
 
        break;
 
755
        state= MY_LEX_HEX_NUMBER;
 
756
        break;
743
757
      }
744
758
    case MY_LEX_IDENT_OR_BIN:
745
759
      if (lip->yyPeek() == '\'')
749
763
      }
750
764
    case MY_LEX_IDENT:
751
765
      const char *start;
 
766
#if defined(USE_MB) && defined(USE_MB_IDENT)
752
767
      if (use_mb(cs))
753
768
      {
754
 
        result_state= IDENT_QUOTED;
 
769
        result_state= IDENT_QUOTED;
755
770
        if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
756
771
        {
757
772
          int l = my_ismbchar(cs,
767
782
        {
768
783
          if (my_mbcharlen(cs, c) > 1)
769
784
          {
770
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
771
 
            if (l == 0)
 
785
            int l;
 
786
            if ((l = my_ismbchar(cs,
 
787
                                 lip->get_ptr() -1,
 
788
                                 lip->get_end_of_query())) == 0)
772
789
              break;
773
790
            lip->skip_binary(l-1);
774
791
          }
775
792
        }
776
793
      }
777
794
      else
 
795
#endif
778
796
      {
779
797
        for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {};
780
798
        /* If there were non-ASCII characters, mark that we must convert */
791
809
        for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
792
810
      }
793
811
      if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
794
 
              lip->next_state=MY_LEX_IDENT_SEP;
 
812
        lip->next_state=MY_LEX_IDENT_SEP;
795
813
      else
796
814
      {                                 // '(' must follow directly if function
797
815
        lip->yyUnget();
798
 
        if ((tokval = find_keyword(lip, length, c == '(')))
799
 
        {
800
 
          lip->next_state= MY_LEX_START;        // Allow signed numbers
801
 
          return(tokval);               // Was keyword
802
 
        }
 
816
        if ((tokval = find_keyword(lip, length, c == '(')))
 
817
        {
 
818
          lip->next_state= MY_LEX_START;        // Allow signed numbers
 
819
          return(tokval);               // Was keyword
 
820
        }
803
821
        lip->yySkip();                  // next state does a unget
804
822
      }
805
823
      yylval->lex_str=get_token(lip, 0, length);
806
824
 
807
825
      lip->body_utf8_append(lip->m_cpp_text_start);
808
826
 
809
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
827
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
828
                                    lip->m_cpp_text_end);
810
829
 
811
830
      return(result_state);                     // IDENT or IDENT_QUOTED
812
831
 
816
835
      c= lip->yyGet();                  // should be '.'
817
836
      lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
818
837
      if (!ident_map[(uint8_t)lip->yyPeek()])            // Probably ` or "
819
 
        lip->next_state= MY_LEX_START;
 
838
        lip->next_state= MY_LEX_START;
820
839
      return((int) c);
821
840
 
822
841
    case MY_LEX_NUMBER_IDENT:           // number or ident which num-start
855
874
      while (my_isdigit(cs, (c = lip->yyGet()))) ;
856
875
      if (!ident_map[c])
857
876
      {                                 // Can't be identifier
858
 
        state=MY_LEX_INT_OR_REAL;
859
 
        break;
 
877
        state=MY_LEX_INT_OR_REAL;
 
878
        break;
860
879
      }
861
880
      if (c == 'e' || c == 'E')
862
881
      {
863
 
        // The following test is written this way to allow numbers of type 1e1
 
882
        // The following test is written this way to allow numbers of type 1e1
864
883
        if (my_isdigit(cs,lip->yyPeek()) ||
865
884
            (c=(lip->yyGet())) == '+' || c == '-')
866
 
        {                               // Allow 1E+10
 
885
        {                               // Allow 1E+10
867
886
          if (my_isdigit(cs,lip->yyPeek()))     // Number must have digit after sign
868
 
          {
 
887
          {
869
888
            lip->yySkip();
870
889
            while (my_isdigit(cs,lip->yyGet())) ;
871
890
            yylval->lex_str=get_token(lip, 0, lip->yyLength());
872
 
            return(FLOAT_NUM);
873
 
          }
874
 
        }
 
891
            return(FLOAT_NUM);
 
892
          }
 
893
        }
875
894
        lip->yyUnget();
876
895
      }
877
896
      // fall through
878
897
    case MY_LEX_IDENT_START:                    // We come here after '.'
879
898
      result_state= IDENT;
 
899
#if defined(USE_MB) && defined(USE_MB_IDENT)
880
900
      if (use_mb(cs))
881
901
      {
882
 
        result_state= IDENT_QUOTED;
 
902
        result_state= IDENT_QUOTED;
883
903
        while (ident_map[c=lip->yyGet()])
884
904
        {
885
905
          if (my_mbcharlen(cs, c) > 1)
886
906
          {
887
 
            int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
888
 
            if (l == 0)
 
907
            int l;
 
908
            if ((l = my_ismbchar(cs,
 
909
                                 lip->get_ptr() -1,
 
910
                                 lip->get_end_of_query())) == 0)
889
911
              break;
890
912
            lip->skip_binary(l-1);
891
913
          }
892
914
        }
893
915
      }
894
916
      else
 
917
#endif
895
918
      {
896
919
        for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
897
920
        /* If there were non-ASCII characters, mark that we must convert */
898
921
        result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
899
922
      }
900
923
      if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
901
 
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
 
924
        lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
902
925
 
903
926
      yylval->lex_str= get_token(lip, 0, lip->yyLength());
904
927
 
905
928
      lip->body_utf8_append(lip->m_cpp_text_start);
906
929
 
907
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
930
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
931
                                    lip->m_cpp_text_end);
908
932
 
909
933
      return(result_state);
910
934
 
914
938
      char quote_char= c;                       // Used char
915
939
      while ((c=lip->yyGet()))
916
940
      {
917
 
        int var_length;
918
 
        if ((var_length= my_mbcharlen(cs, c)) == 1)
919
 
        {
920
 
          if (c == quote_char)
921
 
          {
922
 
                  if (lip->yyPeek() != quote_char)
923
 
              break;
924
 
                  c=lip->yyGet();
925
 
            double_quotes++;
926
 
            continue;
927
 
          }
928
 
        }
929
 
        else if (var_length < 1)
930
 
          break;                                // Error
 
941
        int var_length;
 
942
        if ((var_length= my_mbcharlen(cs, c)) == 1)
 
943
        {
 
944
          if (c == quote_char)
 
945
          {
 
946
            if (lip->yyPeek() != quote_char)
 
947
              break;
 
948
            c=lip->yyGet();
 
949
            double_quotes++;
 
950
            continue;
 
951
          }
 
952
        }
 
953
#ifdef USE_MB
 
954
        else if (var_length < 1)
 
955
          break;                                // Error
931
956
        lip->skip_binary(var_length-1);
 
957
#endif
932
958
      }
933
959
      if (double_quotes)
934
 
              yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
 
960
        yylval->lex_str=get_quoted_token(lip, 1,
 
961
                                         lip->yyLength() - double_quotes -1,
 
962
                                         quote_char);
935
963
      else
936
964
        yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
937
965
      if (c == quote_char)
938
966
        lip->yySkip();                  // Skip end `
939
967
      lip->next_state= MY_LEX_START;
 
968
 
940
969
      lip->body_utf8_append(lip->m_cpp_text_start);
941
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
970
 
 
971
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
972
                                    lip->m_cpp_text_end);
 
973
 
942
974
      return(IDENT_QUOTED);
943
975
    }
944
976
    case MY_LEX_INT_OR_REAL:            // Complete int or incomplete real
945
977
      if (c != '.')
946
978
      {                                 // Found complete integer number.
947
979
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
948
 
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
 
980
        return int_token(yylval->lex_str.str,yylval->lex_str.length);
949
981
      }
950
982
      // fall through
951
983
    case MY_LEX_REAL:                   // Incomplete real number
954
986
      if (c == 'e' || c == 'E')
955
987
      {
956
988
        c = lip->yyGet();
957
 
        if (c == '-' || c == '+')
958
 
                c = lip->yyGet();                     // Skip sign
959
 
        if (!my_isdigit(cs,c))
960
 
        {                               // No digit after sign
961
 
          state= MY_LEX_CHAR;
962
 
          break;
963
 
        }
 
989
        if (c == '-' || c == '+')
 
990
          c = lip->yyGet();                     // Skip sign
 
991
        if (!my_isdigit(cs,c))
 
992
        {                               // No digit after sign
 
993
          state= MY_LEX_CHAR;
 
994
          break;
 
995
        }
964
996
        while (my_isdigit(cs,lip->yyGet())) ;
965
997
        yylval->lex_str=get_token(lip, 0, lip->yyLength());
966
 
        return(FLOAT_NUM);
 
998
        return(FLOAT_NUM);
967
999
      }
968
1000
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
969
1001
      return(DECIMAL_NUM);
1000
1032
        lip->yySkip();
1001
1033
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1002
1034
      {
1003
 
        lip->next_state= MY_LEX_START;  // Allow signed numbers
1004
 
        return(tokval);
 
1035
        lip->next_state= MY_LEX_START;  // Allow signed numbers
 
1036
        return(tokval);
1005
1037
      }
1006
1038
      state = MY_LEX_CHAR;              // Something fishy found
1007
1039
      break;
1016
1048
      }
1017
1049
      if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1018
1050
      {
1019
 
        lip->next_state= MY_LEX_START;  // Found long op
1020
 
        return(tokval);
 
1051
        lip->next_state= MY_LEX_START;  // Found long op
 
1052
        return(tokval);
1021
1053
      }
1022
1054
      state = MY_LEX_CHAR;              // Something fishy found
1023
1055
      break;
1025
1057
    case MY_LEX_BOOL:
1026
1058
      if (c != lip->yyPeek())
1027
1059
      {
1028
 
        state=MY_LEX_CHAR;
1029
 
        break;
 
1060
        state=MY_LEX_CHAR;
 
1061
        break;
1030
1062
      }
1031
1063
      lip->yySkip();
1032
1064
      tokval = find_keyword(lip,2,0);   // Is a bool operator
1043
1075
    case MY_LEX_STRING:                 // Incomplete text string
1044
1076
      if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1045
1077
      {
1046
 
        state= MY_LEX_CHAR;             // Read char by char
1047
 
        break;
 
1078
        state= MY_LEX_CHAR;             // Read char by char
 
1079
        break;
1048
1080
      }
1049
1081
      yylval->lex_str.length=lip->yytoklen;
1050
1082
 
1051
1083
      lip->body_utf8_append(lip->m_cpp_text_start);
1052
1084
 
1053
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1085
      lip->body_utf8_append_literal(session, &yylval->lex_str,
 
1086
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
 
1087
        lip->m_cpp_text_end);
 
1088
 
 
1089
      lip->m_underscore_cs= NULL;
1054
1090
 
1055
1091
      lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1056
1092
      return(TEXT_STRING);
1064
1100
    case MY_LEX_LONG_COMMENT:           /* Long C comment? */
1065
1101
      if (lip->yyPeek() != '*')
1066
1102
      {
1067
 
        state=MY_LEX_CHAR;              // Probable division
1068
 
        break;
 
1103
        state=MY_LEX_CHAR;              // Probable division
 
1104
        break;
1069
1105
      }
1070
1106
      lex->select_lex.options|= OPTION_FOUND_COMMENT;
1071
1107
      /* Reject '/' '*', since we might need to turn off the echo */
1172
1208
        state=MY_LEX_START;
1173
1209
      }
1174
1210
      else
1175
 
        state=MY_LEX_CHAR;              // Return '*'
 
1211
        state=MY_LEX_CHAR;              // Return '*'
1176
1212
      break;
1177
1213
    case MY_LEX_SET_VAR:                // Check if ':='
1178
1214
      if (lip->yyPeek() != '=')
1179
1215
      {
1180
 
        state=MY_LEX_CHAR;              // Return ':'
1181
 
        break;
 
1216
        state=MY_LEX_CHAR;              // Return ':'
 
1217
        break;
1182
1218
      }
1183
1219
      lip->yySkip();
1184
1220
      return (SET_VAR);
1185
1221
    case MY_LEX_SEMICOLON:                      // optional line terminator
1186
1222
      if (lip->yyPeek())
1187
1223
      {
 
1224
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1225
        {
 
1226
          lip->found_semicolon= lip->get_ptr();
 
1227
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1228
          lip->next_state= MY_LEX_END;
 
1229
          lip->set_echo(true);
 
1230
          return (END_OF_INPUT);
 
1231
        }
1188
1232
        state= MY_LEX_CHAR;             // Return ';'
1189
 
        break;
 
1233
        break;
1190
1234
      }
1191
1235
      lip->next_state=MY_LEX_END;       // Mark for next loop
1192
1236
      return(END_OF_INPUT);
1207
1251
      break;
1208
1252
    case MY_LEX_END:
1209
1253
      lip->next_state=MY_LEX_END;
1210
 
      return false;                     // We found end of input last time
 
1254
      return(0);                        // We found end of input last time
1211
1255
 
1212
1256
      /* Actually real shouldn't start with . but allow them anyhow */
1213
1257
    case MY_LEX_REAL_OR_POINT:
1214
1258
      if (my_isdigit(cs,lip->yyPeek()))
1215
 
        state= MY_LEX_REAL;             // Real
 
1259
        state = MY_LEX_REAL;            // Real
1216
1260
      else
1217
1261
      {
1218
 
        state= MY_LEX_IDENT_SEP;        // return '.'
 
1262
        state= MY_LEX_IDENT_SEP;        // return '.'
1219
1263
        lip->yyUnget();                 // Put back '.'
1220
1264
      }
1221
1265
      break;
1224
1268
      case MY_LEX_STRING:
1225
1269
      case MY_LEX_USER_VARIABLE_DELIMITER:
1226
1270
      case MY_LEX_STRING_OR_DELIMITER:
1227
 
        break;
 
1271
        break;
1228
1272
      case MY_LEX_USER_END:
1229
 
        lip->next_state=MY_LEX_SYSTEM_VAR;
1230
 
        break;
 
1273
        lip->next_state=MY_LEX_SYSTEM_VAR;
 
1274
        break;
1231
1275
      default:
1232
 
        lip->next_state=MY_LEX_HOSTNAME;
1233
 
        break;
 
1276
        lip->next_state=MY_LEX_HOSTNAME;
 
1277
        break;
1234
1278
      }
1235
1279
      yylval->lex_str.str=(char*) lip->get_ptr();
1236
1280
      yylval->lex_str.length=1;
1237
1281
      return((int) '@');
1238
1282
    case MY_LEX_HOSTNAME:               // end '@' of user@hostname
1239
1283
      for (c=lip->yyGet() ;
1240
 
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
 
1284
           my_isalnum(cs,c) || c == '.' || c == '_' ||  c == '$';
1241
1285
           c= lip->yyGet()) ;
1242
1286
      yylval->lex_str=get_token(lip, 0, lip->yyLength());
1243
1287
      return(LEX_HOSTNAME);
1252
1296
      return((int) '@');
1253
1297
    case MY_LEX_IDENT_OR_KEYWORD:
1254
1298
      /*
1255
 
        We come here when we have found two '@' in a row.
1256
 
        We should now be able to handle:
1257
 
        [(global | local | session) .]variable_name
 
1299
        We come here when we have found two '@' in a row.
 
1300
        We should now be able to handle:
 
1301
        [(global | local | session) .]variable_name
1258
1302
      */
1259
1303
 
1260
1304
      for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1262
1306
      result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1263
1307
 
1264
1308
      if (c == '.')
1265
 
        lip->next_state=MY_LEX_IDENT_SEP;
 
1309
        lip->next_state=MY_LEX_IDENT_SEP;
1266
1310
      length= lip->yyLength();
1267
1311
      if (length == 0)
1268
1312
        return(ABORT_SYM);              // Names must be nonempty.
1269
1313
      if ((tokval= find_keyword(lip, length,0)))
1270
1314
      {
1271
1315
        lip->yyUnget();                         // Put back 'c'
1272
 
        return(tokval);                         // Was keyword
 
1316
        return(tokval);                         // Was keyword
1273
1317
      }
1274
1318
      yylval->lex_str=get_token(lip, 0, length);
1275
1319
 
1276
1320
      lip->body_utf8_append(lip->m_cpp_text_start);
1277
1321
 
1278
 
      lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
 
1322
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
 
1323
                                    lip->m_cpp_text_end);
1279
1324
 
1280
1325
      return(result_state);
1281
1326
    }
1282
1327
  }
1283
1328
}
1284
1329
 
 
1330
 
 
1331
/**
 
1332
  Construct a copy of this object to be used for mysql_alter_table
 
1333
  and mysql_create_table.
 
1334
 
 
1335
  Historically, these two functions modify their Alter_info
 
1336
  arguments. This behaviour breaks re-execution of prepared
 
1337
  statements and stored procedures and is compensated by always
 
1338
  supplying a copy of Alter_info to these functions.
 
1339
 
 
1340
  @return You need to use check the error in Session for out
 
1341
  of memory condition after calling this function.
 
1342
*/
 
1343
 
 
1344
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
 
1345
  :drop_list(rhs.drop_list, mem_root),
 
1346
  alter_list(rhs.alter_list, mem_root),
 
1347
  key_list(rhs.key_list, mem_root),
 
1348
  create_list(rhs.create_list, mem_root),
 
1349
  flags(rhs.flags),
 
1350
  keys_onoff(rhs.keys_onoff),
 
1351
  tablespace_op(rhs.tablespace_op),
 
1352
  no_parts(rhs.no_parts),
 
1353
  build_method(rhs.build_method),
 
1354
  datetime_field(rhs.datetime_field),
 
1355
  error_if_not_empty(rhs.error_if_not_empty)
 
1356
{
 
1357
  /*
 
1358
    Make deep copies of used objects.
 
1359
    This is not a fully deep copy - clone() implementations
 
1360
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
 
1361
    do not copy string constants. At the same length the only
 
1362
    reason we make a copy currently is that ALTER/CREATE TABLE
 
1363
    code changes input Alter_info definitions, but string
 
1364
    constants never change.
 
1365
  */
 
1366
  list_copy_and_replace_each_value(drop_list, mem_root);
 
1367
  list_copy_and_replace_each_value(alter_list, mem_root);
 
1368
  list_copy_and_replace_each_value(key_list, mem_root);
 
1369
  list_copy_and_replace_each_value(create_list, mem_root);
 
1370
}
 
1371
 
 
1372
 
1285
1373
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1286
1374
{
1287
1375
  /*
1289
1377
    This code assumes that there are no multi-bytes characters
1290
1378
    that can be considered white-space.
1291
1379
  */
 
1380
 
1292
1381
  while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1293
1382
  {
1294
 
    str->length--;
1295
 
    str->str++;
 
1383
    str->length --;
 
1384
    str->str ++;
1296
1385
  }
1297
1386
 
1298
1387
  /*
1301
1390
  */
1302
1391
  while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1303
1392
  {
1304
 
    str->length--;
 
1393
    str->length --;
1305
1394
  }
1306
1395
}
1307
1396
 
 
1397
 
1308
1398
/*
1309
1399
  Select_Lex structures initialisations
1310
1400
*/
 
1401
 
1311
1402
void Select_Lex_Node::init_query()
1312
1403
{
1313
1404
  options= 0;
1314
1405
  linkage= UNSPECIFIED_TYPE;
1315
1406
  no_error= no_table_names_allowed= 0;
1316
 
  uncacheable.reset();
 
1407
  uncacheable= 0;
1317
1408
}
1318
1409
 
1319
1410
void Select_Lex_Node::init_select()
1334
1425
  table= 0;
1335
1426
  fake_select_lex= 0;
1336
1427
  cleaned= 0;
1337
 
  item_list.clear();
 
1428
  item_list.empty();
1338
1429
  describe= 0;
1339
1430
  found_rows_for_union= 0;
1340
1431
}
1342
1433
void Select_Lex::init_query()
1343
1434
{
1344
1435
  Select_Lex_Node::init_query();
1345
 
  table_list.clear();
1346
 
  top_join_list.clear();
 
1436
  table_list.empty();
 
1437
  top_join_list.empty();
1347
1438
  join_list= &top_join_list;
1348
1439
  embedding= leaf_tables= 0;
1349
 
  item_list.clear();
 
1440
  item_list.empty();
1350
1441
  join= 0;
1351
1442
  having= where= 0;
1352
1443
  olap= UNSPECIFIED_OLAP_TYPE;
1378
1469
 
1379
1470
void Select_Lex::init_select()
1380
1471
{
1381
 
  sj_nests.clear();
1382
 
  group_list.clear();
1383
 
  db= 0;
 
1472
  Select_Lex_Node::init_select();
 
1473
  sj_nests.empty();
 
1474
  group_list.empty();
 
1475
  type= db= 0;
1384
1476
  having= 0;
 
1477
  table_join_options= 0;
1385
1478
  in_sum_expr= with_wild= 0;
1386
1479
  options= 0;
1387
1480
  braces= 0;
1388
 
  interval_list.clear();
 
1481
  interval_list.empty();
 
1482
  ftfunc_list_alloc.empty();
1389
1483
  inner_sum_func_list= 0;
 
1484
  ftfunc_list= &ftfunc_list_alloc;
1390
1485
  linkage= UNSPECIFIED_TYPE;
1391
1486
  order_list.elements= 0;
1392
1487
  order_list.first= 0;
1395
1490
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1396
1491
  offset_limit= 0;      /* denotes the default offset = 0 */
1397
1492
  with_sum_func= 0;
1398
 
  is_cross= false;
1399
1493
  is_correlated= 0;
1400
1494
  cur_pos_in_select_list= UNDEF_POS;
1401
 
  non_agg_fields.clear();
 
1495
  non_agg_fields.empty();
1402
1496
  cond_value= having_value= Item::COND_UNDEF;
1403
 
  inner_refs_list.clear();
1404
 
  full_group_by_flag.reset();
 
1497
  inner_refs_list.empty();
 
1498
  full_group_by_flag= 0;
1405
1499
}
1406
1500
 
1407
1501
/*
1539
1633
  }
1540
1634
}
1541
1635
 
 
1636
 
1542
1637
/*
1543
1638
  Exclude subtree of current unit from tree of SELECTs
 
1639
 
 
1640
  SYNOPSYS
 
1641
    Select_Lex_Unit::exclude_tree()
1544
1642
*/
1545
1643
void Select_Lex_Unit::exclude_tree()
1546
1644
{
1562
1660
    next->prev= prev;
1563
1661
}
1564
1662
 
1565
 
/**
1566
 
 * Mark all Select_Lex struct from this to 'last' as dependent
1567
 
 *
1568
 
 * @param Pointer to last Select_Lex struct, before wich all
1569
 
 *        Select_Lex have to be marked as dependent
1570
 
 * @note 'last' should be reachable from this Select_Lex_Node
1571
 
 */
 
1663
 
 
1664
/*
 
1665
  Select_Lex_Node::mark_as_dependent mark all Select_Lex struct from
 
1666
  this to 'last' as dependent
 
1667
 
 
1668
  SYNOPSIS
 
1669
    last - pointer to last Select_Lex struct, before wich all
 
1670
           Select_Lex have to be marked as dependent
 
1671
 
 
1672
  NOTE
 
1673
    'last' should be reachable from this Select_Lex_Node
 
1674
*/
 
1675
 
1572
1676
void Select_Lex::mark_as_dependent(Select_Lex *last)
1573
1677
{
1574
1678
  /*
1579
1683
       s && s != last;
1580
1684
       s= s->outer_select())
1581
1685
  {
1582
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1686
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1583
1687
    {
1584
1688
      // Select is dependent of outer select
1585
 
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1586
 
      s->uncacheable.set(UNCACHEABLE_UNITED);
 
1689
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1690
                       UNCACHEABLE_DEPENDENT;
1587
1691
      Select_Lex_Unit *munit= s->master_unit();
1588
 
      munit->uncacheable.set(UNCACHEABLE_UNITED);
1589
 
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
 
1692
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1693
                       UNCACHEABLE_DEPENDENT;
1590
1694
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1591
1695
      {
1592
1696
        if (sl != s &&
1593
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1594
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1697
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1698
          sl->uncacheable|= UNCACHEABLE_UNITED;
1595
1699
      }
1596
1700
    }
1597
1701
    s->is_correlated= true;
1602
1706
}
1603
1707
 
1604
1708
bool Select_Lex_Node::set_braces(bool)
1605
 
{ return true; }
1606
 
 
1607
 
bool Select_Lex_Node::inc_in_sum_expr()
1608
 
{ return true; }
1609
 
 
1610
 
uint32_t Select_Lex_Node::get_in_sum_expr() 
1611
 
{ return 0; }
1612
 
 
1613
 
TableList* Select_Lex_Node::get_table_list()
1614
 
{ return NULL; }
1615
 
 
1616
 
List<Item>* Select_Lex_Node::get_item_list()
1617
 
{ return NULL; }
1618
 
 
1619
 
TableList *Select_Lex_Node::add_table_to_list(Session *, 
1620
 
                                              Table_ident *, 
1621
 
                                              LEX_STRING *, 
1622
 
                                              const bitset<NUM_OF_TABLE_OPTIONS>&,
1623
 
                                              thr_lock_type, 
1624
 
                                              List<Index_hint> *, 
1625
 
                                              LEX_STRING *)
1626
 
{
1627
 
  return 0;
1628
 
}
1629
 
 
 
1709
{ return 1; }
 
1710
bool Select_Lex_Node::inc_in_sum_expr()           { return 1; }
 
1711
uint32_t Select_Lex_Node::get_in_sum_expr()           { return 0; }
 
1712
TableList* Select_Lex_Node::get_table_list()     { return 0; }
 
1713
List<Item>* Select_Lex_Node::get_item_list()      { return 0; }
 
1714
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1715
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
 
1716
{
 
1717
  return 0;
 
1718
}
 
1719
uint32_t Select_Lex_Node::get_table_join_options()
 
1720
{
 
1721
  return 0;
 
1722
}
1630
1723
 
1631
1724
/*
1632
1725
  prohibit using LIMIT clause
1637
1730
  {
1638
1731
    my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1639
1732
             "LIMIT & IN/ALL/ANY/SOME subquery");
1640
 
    return true;
 
1733
    return(1);
1641
1734
  }
1642
 
  return false;
 
1735
  return(0);
1643
1736
}
1644
1737
 
 
1738
 
1645
1739
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1646
1740
{
1647
 
  return this;
 
1741
    return this;
1648
1742
}
1649
1743
 
 
1744
 
1650
1745
Select_Lex* Select_Lex_Unit::outer_select()
1651
1746
{
1652
1747
  return (Select_Lex*) master;
1653
1748
}
1654
1749
 
 
1750
 
1655
1751
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1656
1752
{
1657
1753
  return add_to_list(session, order_list, item, asc);
1658
1754
}
1659
1755
 
 
1756
 
1660
1757
bool Select_Lex::add_item_to_list(Session *, Item *item)
1661
1758
{
1662
1759
  return(item_list.push_back(item));
1663
1760
}
1664
1761
 
 
1762
 
1665
1763
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1666
1764
{
1667
1765
  return add_to_list(session, group_list, item, asc);
1668
1766
}
1669
1767
 
 
1768
 
1670
1769
Select_Lex_Unit* Select_Lex::master_unit()
1671
1770
{
1672
1771
  return (Select_Lex_Unit*) master;
1673
1772
}
1674
1773
 
 
1774
 
1675
1775
Select_Lex* Select_Lex::outer_select()
1676
1776
{
1677
1777
  return (Select_Lex*) master->get_master();
1678
1778
}
1679
1779
 
 
1780
 
1680
1781
bool Select_Lex::set_braces(bool value)
1681
1782
{
1682
1783
  braces= value;
1683
 
  return false;
 
1784
  return 0;
1684
1785
}
1685
1786
 
 
1787
 
1686
1788
bool Select_Lex::inc_in_sum_expr()
1687
1789
{
1688
1790
  in_sum_expr++;
1689
 
  return false;
 
1791
  return 0;
1690
1792
}
1691
1793
 
 
1794
 
1692
1795
uint32_t Select_Lex::get_in_sum_expr()
1693
1796
{
1694
1797
  return in_sum_expr;
1695
1798
}
1696
1799
 
 
1800
 
1697
1801
TableList* Select_Lex::get_table_list()
1698
1802
{
1699
1803
  return (TableList*) table_list.first;
1704
1808
  return &item_list;
1705
1809
}
1706
1810
 
 
1811
uint32_t Select_Lex::get_table_join_options()
 
1812
{
 
1813
  return table_join_options;
 
1814
}
 
1815
 
1707
1816
 
1708
1817
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1709
1818
{
1710
1819
  if (ref_pointer_array)
1711
 
    return false;
 
1820
    return 0;
1712
1821
 
1713
1822
  return (ref_pointer_array=
1714
 
          (Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
 
1823
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1715
1824
                                                 item_list.elements +
1716
1825
                                                 select_n_having_items +
1717
1826
                                                 select_n_where_fields +
1718
1827
                                                 order_group_num)*5)) == 0;
1719
1828
}
1720
1829
 
 
1830
 
1721
1831
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
1722
1832
{
1723
1833
  bool union_all= !union_distinct;
1744
1854
      str->append(STRING_WITH_LEN(" order by "));
1745
1855
      fake_select_lex->print_order(
1746
1856
        str,
1747
 
        (Order *) fake_select_lex->order_list.first,
 
1857
        (order_st *) fake_select_lex->order_list.first,
1748
1858
        query_type);
1749
1859
    }
1750
1860
    fake_select_lex->print_limit(session, str, query_type);
1751
1861
  }
1752
1862
}
1753
1863
 
 
1864
 
1754
1865
void Select_Lex::print_order(String *str,
1755
 
                                Order *order,
 
1866
                                order_st *order,
1756
1867
                                enum_query_type query_type)
1757
1868
{
1758
1869
  for (; order; order= order->next)
1772
1883
  }
1773
1884
}
1774
1885
 
 
1886
 
1775
1887
void Select_Lex::print_limit(Session *, String *str,
1776
1888
                                enum_query_type query_type)
1777
1889
{
1811
1923
  }
1812
1924
}
1813
1925
 
1814
 
LEX::~LEX()
 
1926
/**
 
1927
  @brief Restore the LEX and Session in case of a parse error.
 
1928
 
 
1929
  This is a clean up call that is invoked by the Bison generated
 
1930
  parser before returning an error from DRIZZLEparse. If your
 
1931
  semantic actions manipulate with the global thread state (which
 
1932
  is a very bad practice and should not normally be employed) and
 
1933
  need a clean-up in case of error, and you can not use %destructor
 
1934
  rule in the grammar file itself, this function should be used
 
1935
  to implement the clean up.
 
1936
*/
 
1937
 
 
1938
void LEX::cleanup_lex_after_parse_error(Session *)
1815
1939
{
1816
 
  delete _create_table;
1817
1940
}
1818
1941
 
1819
1942
/*
1833
1956
    this method to reset state of already initialized Query_tables_list
1834
1957
    so it can be used for processing of new statement.
1835
1958
*/
 
1959
 
1836
1960
void Query_tables_list::reset_query_tables_list(bool init)
1837
1961
{
1838
1962
  if (!init && query_tables)
1850
1974
  query_tables_own_last= 0;
1851
1975
}
1852
1976
 
 
1977
 
 
1978
/*
 
1979
  Destroy Query_tables_list object with freeing all resources used by it.
 
1980
 
 
1981
  SYNOPSIS
 
1982
    destroy_query_tables_list()
 
1983
*/
 
1984
 
 
1985
void Query_tables_list::destroy_query_tables_list()
 
1986
{
 
1987
}
 
1988
 
 
1989
 
1853
1990
/*
1854
1991
  Initialize LEX object.
1855
1992
 
1863
2000
    statement parsing. On should use lex_start() function to prepare LEX
1864
2001
    for this.
1865
2002
*/
1866
 
LEX::LEX() :
1867
 
    result(0), 
1868
 
    yacc_yyss(0), 
1869
 
    yacc_yyvs(0),
1870
 
    session(NULL),
1871
 
    charset(NULL),
1872
 
    var_list(),
1873
 
    sql_command(SQLCOM_END), 
1874
 
    statement(NULL),
1875
 
    option_type(OPT_DEFAULT), 
1876
 
    is_lex_started(0),
1877
 
    cacheable(true),
1878
 
    sum_expr_used(false),
1879
 
    _create_table(NULL),
1880
 
    _create_field(NULL),
1881
 
    _exists(false)
 
2003
 
 
2004
LEX::LEX()
 
2005
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
2006
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1882
2007
{
 
2008
 
1883
2009
  reset_query_tables_list(true);
1884
2010
}
1885
2011
 
 
2012
/*
 
2013
  Detect that we need only table structure of derived table/view
 
2014
 
 
2015
  SYNOPSIS
 
2016
    only_view_structure()
 
2017
 
 
2018
  RETURN
 
2019
    true yes, we need only structure
 
2020
    false no, we need data
 
2021
*/
 
2022
 
 
2023
bool LEX::only_view_structure()
 
2024
{
 
2025
  switch (sql_command) {
 
2026
  case SQLCOM_SHOW_CREATE:
 
2027
  case SQLCOM_SHOW_TABLES:
 
2028
  case SQLCOM_SHOW_FIELDS:
 
2029
    return true;
 
2030
  default:
 
2031
    return false;
 
2032
  }
 
2033
}
 
2034
 
 
2035
 
 
2036
/*
 
2037
  Should Items_ident be printed correctly
 
2038
 
 
2039
  SYNOPSIS
 
2040
    need_correct_ident()
 
2041
 
 
2042
  RETURN
 
2043
    true yes, we need only structure
 
2044
    false no, we need data
 
2045
*/
 
2046
 
 
2047
 
 
2048
bool LEX::need_correct_ident()
 
2049
{
 
2050
  switch(sql_command)
 
2051
  {
 
2052
  case SQLCOM_SHOW_CREATE:
 
2053
  case SQLCOM_SHOW_TABLES:
 
2054
    return true;
 
2055
  default:
 
2056
    return false;
 
2057
  }
 
2058
}
 
2059
 
 
2060
 
1886
2061
/**
1887
2062
  This method should be called only during parsing.
1888
2063
  It is aware of compound statements (stored routine bodies)
1901
2076
  @return true in case of error (parsing should be aborted, false in
1902
2077
  case of success
1903
2078
*/
1904
 
bool LEX::copy_db_to(char **p_db, size_t *p_db_length) const
 
2079
 
 
2080
bool
 
2081
LEX::copy_db_to(char **p_db, size_t *p_db_length) const
1905
2082
{
1906
2083
  return session->copy_db_to(p_db, p_db_length);
1907
2084
}
1913
2090
    Select_Lex_Unit::set_limit()
1914
2091
    values      - Select_Lex with initial values for counters
1915
2092
*/
 
2093
 
1916
2094
void Select_Lex_Unit::set_limit(Select_Lex *sl)
1917
2095
{
1918
2096
  ha_rows select_limit_val;
1933
2111
    select_limit_cnt= HA_POS_ERROR;             // no limit
1934
2112
}
1935
2113
 
 
2114
 
1936
2115
/*
1937
2116
  Unlink the first table from the global table list and the first table from
1938
2117
  outer select (lex->select_lex) local list
1985
2164
  return first;
1986
2165
}
1987
2166
 
 
2167
 
1988
2168
/*
1989
2169
  Bring first local table of first most outer select to first place in global
1990
2170
  table list
2000
2180
    the select list, as only in this case tables of sub-queries will go to
2001
2181
    the global list first.
2002
2182
*/
 
2183
 
2003
2184
void LEX::first_lists_tables_same()
2004
2185
{
2005
2186
  TableList *first_table= (TableList*) select_lex.table_list.first;
2024
2205
  }
2025
2206
}
2026
2207
 
 
2208
 
2027
2209
/*
2028
2210
  Link table back that was unlinked with unlink_first_table()
2029
2211
 
2034
2216
  RETURN
2035
2217
    global list
2036
2218
*/
2037
 
void LEX::link_first_table_back(TableList *first, bool link_to_local)
 
2219
 
 
2220
void LEX::link_first_table_back(TableList *first,
 
2221
                                   bool link_to_local)
2038
2222
{
2039
2223
  if (first)
2040
2224
  {
2054
2238
  }
2055
2239
}
2056
2240
 
 
2241
 
 
2242
 
2057
2243
/*
2058
2244
  cleanup lex for case when we open table by table for processing
2059
2245
 
2065
2251
    derived tables state. To rollback changes in Query_tables_list one has
2066
2252
    to call Query_tables_list::reset_query_tables_list(false).
2067
2253
*/
 
2254
 
2068
2255
void LEX::cleanup_after_one_table_open()
2069
2256
{
2070
2257
  /*
2071
 
    session->getLex()->derived_tables & additional units may be set if we open
2072
 
    a view. It is necessary to clear session->getLex()->derived_tables flag
2073
 
    to prevent processing of derived tables during next openTablesLock
 
2258
    session->lex->derived_tables & additional units may be set if we open
 
2259
    a view. It is necessary to clear session->lex->derived_tables flag
 
2260
    to prevent processing of derived tables during next open_and_lock_tables
2074
2261
    if next table is a real table and cleanup & remove underlying units
2075
 
    NOTE: all units will be connected to session->getLex()->select_lex, because we
 
2262
    NOTE: all units will be connected to session->lex->select_lex, because we
2076
2263
    have not UNION on most upper level.
2077
2264
    */
2078
2265
  if (all_selects_list != &select_lex)
2090
2277
  }
2091
2278
}
2092
2279
 
 
2280
 
 
2281
/*
 
2282
  Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
 
2283
 
 
2284
  SYNOPSIS
 
2285
    fix_prepare_info_in_table_list()
 
2286
      session  Thread handle
 
2287
      tbl  List of tables to process
 
2288
 
 
2289
  DESCRIPTION
 
2290
    Perform end-end-of prepare fixup for list of tables, if any of the tables
 
2291
    is a merge-algorithm VIEW, recursively fix up its underlying tables as
 
2292
    well.
 
2293
 
 
2294
*/
 
2295
 
 
2296
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
 
2297
{
 
2298
  for (; tbl; tbl= tbl->next_local)
 
2299
  {
 
2300
    if (tbl->on_expr)
 
2301
    {
 
2302
      tbl->prep_on_expr= tbl->on_expr;
 
2303
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
 
2304
    }
 
2305
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
 
2306
  }
 
2307
}
 
2308
 
 
2309
 
2093
2310
/*
2094
2311
  There are Select_Lex::add_table_to_list &
2095
2312
  Select_Lex::set_lock_for_tables are in sql_parse.cc
2117
2334
    Then the context variable index_hint_type can be reset to the
2118
2335
    next hint type.
2119
2336
*/
2120
 
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
 
2337
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg,
 
2338
                                        index_clause_map clause)
2121
2339
{
2122
2340
  current_index_hint_type= type_arg;
2123
2341
  current_index_hint_clause= clause;
2124
2342
}
2125
2343
 
 
2344
 
2126
2345
/*
2127
2346
  Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2128
2347
 
2130
2349
    alloc_index_hints()
2131
2350
      session         current thread.
2132
2351
*/
 
2352
 
2133
2353
void Select_Lex::alloc_index_hints (Session *session)
2134
2354
{
2135
2355
  index_hints= new (session->mem_root) List<Index_hint>();
2136
2356
}
2137
2357
 
 
2358
 
 
2359
 
2138
2360
/*
2139
2361
  adds an element to the array storing index usage hints
2140
2362
  (ADD/FORCE/IGNORE INDEX).
2155
2377
                                            current_index_hint_clause,
2156
2378
                                            str, length));
2157
2379
}
2158
 
 
2159
 
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
2160
 
{
2161
 
  if (sql_reserved_words::in_word_set(string.str, string.length))
2162
 
      return true;
2163
 
 
2164
 
  return false;
2165
 
}
2166
 
 
2167
 
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
2168
 
{
2169
 
  if (sql_reserved_words::in_word_set(string.str, string.length))
2170
 
      return true;
2171
 
 
2172
 
  return false;
2173
 
}
2174
 
 
2175
 
 
2176
 
} /* namespace drizzled */