~drizzle-trunk/drizzle/development

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