~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
 
#include "config.h"
 
19
#include <config.h>
 
20
 
20
21
#define DRIZZLE_LEX 1
21
 
#include "drizzled/configmake.h"
22
 
#include "drizzled/item/num.h"
23
 
#include "drizzled/error.h"
24
 
#include "drizzled/session.h"
25
 
#include "drizzled/sql_base.h"
26
 
#include "drizzled/lookup_symbol.h"
27
 
#include "drizzled/index_hint.h"
 
22
 
 
23
#include <drizzled/sql_reserved_words.h>
 
24
 
 
25
#include <drizzled/configmake.h>
 
26
#include <drizzled/item/num.h>
 
27
#include <drizzled/error.h>
 
28
#include <drizzled/session.h>
 
29
#include <drizzled/sql_base.h>
 
30
#include <drizzled/lookup_symbol.h>
 
31
#include <drizzled/index_hint.h>
 
32
#include <drizzled/select_result.h>
28
33
 
29
34
#include <cstdio>
30
35
#include <ctype.h>
31
36
 
 
37
union ParserType;
 
38
 
32
39
using namespace std;
33
40
 
34
41
/* Stay outside of the namespace because otherwise bison goes nuts */
35
 
int DRIZZLElex(void *arg, void *yysession);
 
42
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
36
43
 
37
44
namespace drizzled
38
45
{
39
46
 
40
 
static int lex_one_token(void *arg, void *yysession);
 
47
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
41
48
 
42
49
/**
43
50
  save order by and tables in own lists.
45
52
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
46
53
{
47
54
  Order *order;
48
 
  if (!(order = (Order *) session->alloc(sizeof(Order))))
49
 
    return(1);
 
55
 
 
56
  if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
 
57
    return true;
 
58
 
50
59
  order->item_ptr= item;
51
60
  order->item= &order->item_ptr;
52
61
  order->asc = asc;
53
62
  order->free_me=0;
54
63
  order->used=0;
55
64
  order->counter_used= 0;
56
 
  list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
57
 
  return(0);
 
65
  list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
 
66
 
 
67
  return false;
58
68
}
59
69
 
60
70
/**
64
74
 
65
75
Lex_input_stream::Lex_input_stream(Session *session,
66
76
                                   const char* buffer,
67
 
                                   unsigned int length)
68
 
: m_session(session),
 
77
                                   unsigned int length) :
 
78
  m_session(session),
69
79
  yylineno(1),
70
80
  yytoklen(0),
71
81
  yylval(NULL),
88
98
  ignore_space(1),
89
99
  in_comment(NO_COMMENT)
90
100
{
91
 
  m_cpp_buf= (char*) session->alloc(length + 1);
 
101
  m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
92
102
  m_cpp_ptr= m_cpp_buf;
93
103
}
94
104
 
115
125
    (m_buf_length / default_charset_info->mbminlen) *
116
126
    my_charset_utf8_bin.mbmaxlen;
117
127
 
118
 
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
 
128
  m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
119
129
  m_body_utf8_ptr= m_body_utf8;
120
130
  *m_body_utf8_ptr= 0;
121
131
 
213
223
 
214
224
void lex_start(Session *session)
215
225
{
216
 
  LEX *lex= session->lex;
 
226
  LEX *lex= session->getLex();
217
227
 
218
228
  lex->session= lex->unit.session= session;
219
229
 
220
 
  lex->context_stack.empty();
 
230
  lex->context_stack.clear();
221
231
  lex->unit.init_query();
222
232
  lex->unit.init_select();
223
233
  /* 'parent_lex' is used in init_query() so it must be before it. */
224
234
  lex->select_lex.parent_lex= lex;
225
235
  lex->select_lex.init_query();
226
 
  lex->value_list.empty();
227
 
  lex->update_list.empty();
228
 
  lex->auxiliary_table_list.empty();
 
236
  lex->value_list.clear();
 
237
  lex->update_list.clear();
 
238
  lex->auxiliary_table_list.clear();
229
239
  lex->unit.next= lex->unit.master=
230
240
    lex->unit.link_next= lex->unit.return_to= 0;
231
241
  lex->unit.prev= lex->unit.link_prev= 0;
237
247
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
238
248
  lex->select_lex.options= 0;
239
249
  lex->select_lex.init_order();
240
 
  lex->select_lex.group_list.empty();
 
250
  lex->select_lex.group_list.clear();
241
251
  lex->describe= 0;
242
252
  lex->derived_tables= 0;
243
253
  lex->lock_option= TL_READ;
244
254
  lex->leaf_tables_insert= 0;
 
255
  lex->var_list.clear();
245
256
  lex->select_lex.select_number= 1;
246
257
  lex->length=0;
247
258
  lex->select_lex.in_sum_expr=0;
248
 
  lex->select_lex.group_list.empty();
249
 
  lex->select_lex.order_list.empty();
 
259
  lex->select_lex.group_list.clear();
 
260
  lex->select_lex.order_list.clear();
250
261
  lex->sql_command= SQLCOM_END;
251
262
  lex->duplicates= DUP_ERROR;
252
263
  lex->ignore= 0;
261
272
  lex->nest_level=0 ;
262
273
  lex->allow_sum_func= 0;
263
274
  lex->in_sum_func= NULL;
 
275
  lex->type= 0;
264
276
 
265
277
  lex->is_lex_started= true;
266
278
  lex->statement= NULL;
267
279
  
268
280
  lex->is_cross= false;
269
 
 
270
281
  lex->reset();
271
282
}
272
283
 
280
291
    yacc_yyvs= 0;
281
292
  }
282
293
 
283
 
  delete result;
 
294
  safe_delete(result);
 
295
  safe_delete(_create_table);
 
296
  _create_table= NULL;
 
297
  _create_field= NULL;
284
298
 
285
299
  result= 0;
286
300
  setCacheable(true);
287
301
 
288
 
  delete statement;
289
 
  statement= NULL;
 
302
  safe_delete(statement);
290
303
}
291
304
 
292
305
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
347
360
  char *to;
348
361
  lip->yyUnget();                       // ptr points now after last token char
349
362
  tmp.length= lip->yytoklen=length;
350
 
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
 
363
  tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
351
364
  from= lip->get_tok_start() + skip;
352
365
  to= tmp.str;
353
366
  end= to+length;
374
387
*/
375
388
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
376
389
{
377
 
  register unsigned char c,sep;
 
390
  unsigned char c,sep;
378
391
  bool found_escape= false;
379
392
  const CHARSET_INFO * const cs= lip->m_session->charset();
380
393
 
423
436
      end-= post_skip;
424
437
      assert(end >= str);
425
438
 
426
 
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
 
439
      if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
427
440
        return (char*) "";              // memory::SqlAlloc has set error flag
428
441
 
429
442
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
589
602
 
590
603
} /* namespace drizzled */
591
604
/*
592
 
  DRIZZLElex remember the following states from the following DRIZZLElex()
 
605
  base_sql_lex remember the following states from the following sql_baselex()
593
606
 
594
607
  - MY_LEX_EOQ                  Found end of query
595
608
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
596
609
                                (which can't be followed by a signed number)
597
610
*/
598
 
int DRIZZLElex(void *arg, void *yysession)
 
611
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
599
612
{
600
 
  drizzled::Session *session= (drizzled::Session *)yysession;
601
613
  drizzled::Lex_input_stream *lip= session->m_lip;
602
 
  YYSTYPE *yylval=(YYSTYPE*) arg;
603
614
  int token;
604
615
 
605
616
  if (lip->lookahead_token != END_OF_INPUT)
615
626
    return token;
616
627
  }
617
628
 
618
 
  token= drizzled::lex_one_token(arg, yysession);
 
629
  token= drizzled::lex_one_token(yylval, session);
619
630
 
620
631
  switch(token) {
621
632
  case WITH:
626
637
      to transform the grammar into a LALR(1) grammar,
627
638
      which sql_yacc.yy can process.
628
639
    */
629
 
    token= drizzled::lex_one_token(arg, yysession);
 
640
    token= drizzled::lex_one_token(yylval, session);
630
641
    if (token == ROLLUP_SYM)
631
642
    {
632
643
      return WITH_ROLLUP_SYM;
651
662
namespace drizzled
652
663
{
653
664
 
654
 
int lex_one_token(void *arg, void *yysession)
 
665
int lex_one_token(ParserType *yylval, drizzled::Session *session)
655
666
{
656
 
  register unsigned char c= 0; /* Just set to shutup GCC */
 
667
  unsigned char c= 0; /* Just set to shutup GCC */
657
668
  bool comment_closed;
658
669
  int   tokval, result_state;
659
670
  unsigned int length;
660
671
  enum my_lex_states state;
661
 
  Session *session= (Session *)yysession;
662
672
  Lex_input_stream *lip= session->m_lip;
663
 
  LEX *lex= session->lex;
664
 
  YYSTYPE *yylval=(YYSTYPE*) arg;
 
673
  LEX *lex= session->getLex();
665
674
  const CHARSET_INFO * const cs= session->charset();
666
675
  unsigned char *state_map= cs->state_map;
667
676
  unsigned char *ident_map= cs->ident_map;
1325
1334
  table= 0;
1326
1335
  fake_select_lex= 0;
1327
1336
  cleaned= 0;
1328
 
  item_list.empty();
 
1337
  item_list.clear();
1329
1338
  describe= 0;
1330
1339
  found_rows_for_union= 0;
1331
1340
}
1333
1342
void Select_Lex::init_query()
1334
1343
{
1335
1344
  Select_Lex_Node::init_query();
1336
 
  table_list.empty();
1337
 
  top_join_list.empty();
 
1345
  table_list.clear();
 
1346
  top_join_list.clear();
1338
1347
  join_list= &top_join_list;
1339
1348
  embedding= leaf_tables= 0;
1340
 
  item_list.empty();
 
1349
  item_list.clear();
1341
1350
  join= 0;
1342
1351
  having= where= 0;
1343
1352
  olap= UNSPECIFIED_OLAP_TYPE;
1369
1378
 
1370
1379
void Select_Lex::init_select()
1371
1380
{
1372
 
  sj_nests.empty();
1373
 
  group_list.empty();
 
1381
  sj_nests.clear();
 
1382
  group_list.clear();
1374
1383
  db= 0;
1375
1384
  having= 0;
1376
1385
  in_sum_expr= with_wild= 0;
1377
1386
  options= 0;
1378
1387
  braces= 0;
1379
 
  interval_list.empty();
 
1388
  interval_list.clear();
1380
1389
  inner_sum_func_list= 0;
1381
1390
  linkage= UNSPECIFIED_TYPE;
1382
1391
  order_list.elements= 0;
1386
1395
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1387
1396
  offset_limit= 0;      /* denotes the default offset = 0 */
1388
1397
  with_sum_func= 0;
 
1398
  is_cross= false;
1389
1399
  is_correlated= 0;
1390
1400
  cur_pos_in_select_list= UNDEF_POS;
1391
 
  non_agg_fields.empty();
 
1401
  non_agg_fields.clear();
1392
1402
  cond_value= having_value= Item::COND_UNDEF;
1393
 
  inner_refs_list.empty();
 
1403
  inner_refs_list.clear();
1394
1404
  full_group_by_flag.reset();
1395
1405
}
1396
1406
 
1701
1711
    return false;
1702
1712
 
1703
1713
  return (ref_pointer_array=
1704
 
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
 
1714
          (Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
1705
1715
                                                 item_list.elements +
1706
1716
                                                 select_n_having_items +
1707
1717
                                                 select_n_where_fields +
1801
1811
  }
1802
1812
}
1803
1813
 
1804
 
/**
1805
 
  @brief Restore the LEX and Session in case of a parse error.
1806
 
 
1807
 
  This is a clean up call that is invoked by the Bison generated
1808
 
  parser before returning an error from DRIZZLEparse. If your
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
 
*/
1815
 
void LEX::cleanup_lex_after_parse_error(Session *)
 
1814
LEX::~LEX()
1816
1815
{
 
1816
  delete _create_table;
1817
1817
}
1818
1818
 
1819
1819
/*
1863
1863
    statement parsing. On should use lex_start() function to prepare LEX
1864
1864
    for this.
1865
1865
*/
1866
 
LEX::LEX()
1867
 
  :
 
1866
LEX::LEX() :
1868
1867
    result(0), 
1869
1868
    yacc_yyss(0), 
1870
1869
    yacc_yyvs(0),
 
1870
    session(NULL),
1871
1871
    charset(NULL),
 
1872
    var_list(),
1872
1873
    sql_command(SQLCOM_END), 
 
1874
    statement(NULL),
1873
1875
    option_type(OPT_DEFAULT), 
1874
1876
    is_lex_started(0),
1875
1877
    cacheable(true),
1876
 
    sum_expr_used(false)
 
1878
    sum_expr_used(false),
 
1879
    _create_table(NULL),
 
1880
    _create_field(NULL),
 
1881
    _exists(false)
1877
1882
{
1878
1883
  reset_query_tables_list(true);
1879
 
  statement= NULL;
1880
1884
}
1881
1885
 
1882
1886
/**
2064
2068
void LEX::cleanup_after_one_table_open()
2065
2069
{
2066
2070
  /*
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
 
2071
    session->getLex()->derived_tables & additional units may be set if we open
 
2072
    a view. It is necessary to clear session->getLex()->derived_tables flag
2069
2073
    to prevent processing of derived tables during next openTablesLock
2070
2074
    if next table is a real table and cleanup & remove underlying units
2071
 
    NOTE: all units will be connected to session->lex->select_lex, because we
 
2075
    NOTE: all units will be connected to session->getLex()->select_lex, because we
2072
2076
    have not UNION on most upper level.
2073
2077
    */
2074
2078
  if (all_selects_list != &select_lex)
2152
2156
                                            str, length));
2153
2157
}
2154
2158
 
 
2159
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
 
2160
{
 
2161
  if (sql_reserved_words::in_word_set(string.str, string.length))
 
2162
      return true;
 
2163
 
 
2164
  return false;
 
2165
}
 
2166
 
 
2167
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
 
2168
{
 
2169
  if (sql_reserved_words::in_word_set(string.str, string.length))
 
2170
      return true;
 
2171
 
 
2172
  return false;
 
2173
}
 
2174
 
 
2175
 
2155
2176
} /* namespace drizzled */