~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Brian Aker
  • Date: 2011-02-04 09:29:39 UTC
  • mfrom: (2139.3.6 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: brian@tangent.org-20110204092939-nlwrimamw0fxxhgl
Main bit of this patch is that Inno now just uses the identifier so we only
have one spot to make changes for paths.

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
21
#define DRIZZLE_LEX 1
22
22
 
23
 
#include <drizzled/sql_reserved_words.h>
 
23
#include "drizzled/sql_reserved_words.h"
24
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>
 
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"
33
32
 
34
33
#include <cstdio>
35
34
#include <ctype.h>
36
35
 
37
 
union ParserType;
38
 
 
39
36
using namespace std;
40
37
 
41
38
/* Stay outside of the namespace because otherwise bison goes nuts */
42
 
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
 
39
int DRIZZLElex(void *arg, void *yysession);
43
40
 
44
41
namespace drizzled
45
42
{
46
43
 
47
 
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
 
44
static int lex_one_token(void *arg, void *yysession);
48
45
 
49
46
/**
50
47
  save order by and tables in own lists.
53
50
{
54
51
  Order *order;
55
52
 
56
 
  if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
 
53
  if (!(order = (Order *) session->alloc(sizeof(Order))))
57
54
    return true;
58
55
 
59
56
  order->item_ptr= item;
98
95
  ignore_space(1),
99
96
  in_comment(NO_COMMENT)
100
97
{
101
 
  m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
 
98
  m_cpp_buf= (char*) session->alloc(length + 1);
102
99
  m_cpp_ptr= m_cpp_buf;
103
100
}
104
101
 
125
122
    (m_buf_length / default_charset_info->mbminlen) *
126
123
    my_charset_utf8_bin.mbmaxlen;
127
124
 
128
 
  m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
 
125
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
129
126
  m_body_utf8_ptr= m_body_utf8;
130
127
  *m_body_utf8_ptr= 0;
131
128
 
223
220
 
224
221
void lex_start(Session *session)
225
222
{
226
 
  LEX *lex= session->getLex();
 
223
  LEX *lex= session->lex;
227
224
 
228
225
  lex->session= lex->unit.session= session;
229
226
 
230
 
  lex->context_stack.clear();
 
227
  lex->context_stack.empty();
231
228
  lex->unit.init_query();
232
229
  lex->unit.init_select();
233
230
  /* 'parent_lex' is used in init_query() so it must be before it. */
234
231
  lex->select_lex.parent_lex= lex;
235
232
  lex->select_lex.init_query();
236
 
  lex->value_list.clear();
237
 
  lex->update_list.clear();
238
 
  lex->auxiliary_table_list.clear();
 
233
  lex->value_list.empty();
 
234
  lex->update_list.empty();
 
235
  lex->auxiliary_table_list.empty();
239
236
  lex->unit.next= lex->unit.master=
240
237
    lex->unit.link_next= lex->unit.return_to= 0;
241
238
  lex->unit.prev= lex->unit.link_prev= 0;
247
244
  lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
248
245
  lex->select_lex.options= 0;
249
246
  lex->select_lex.init_order();
250
 
  lex->select_lex.group_list.clear();
 
247
  lex->select_lex.group_list.empty();
251
248
  lex->describe= 0;
252
249
  lex->derived_tables= 0;
253
250
  lex->lock_option= TL_READ;
256
253
  lex->select_lex.select_number= 1;
257
254
  lex->length=0;
258
255
  lex->select_lex.in_sum_expr=0;
259
 
  lex->select_lex.group_list.clear();
260
 
  lex->select_lex.order_list.clear();
 
256
  lex->select_lex.group_list.empty();
 
257
  lex->select_lex.order_list.empty();
261
258
  lex->sql_command= SQLCOM_END;
262
259
  lex->duplicates= DUP_ERROR;
263
260
  lex->ignore= 0;
291
288
    yacc_yyvs= 0;
292
289
  }
293
290
 
294
 
  safe_delete(result);
295
 
  safe_delete(_create_table);
 
291
  delete result;
 
292
  delete _create_table;
296
293
  _create_table= NULL;
297
294
  _create_field= NULL;
298
295
 
299
296
  result= 0;
300
297
  setCacheable(true);
301
298
 
302
 
  safe_delete(statement);
 
299
  delete statement;
 
300
  statement= NULL;
303
301
}
304
302
 
305
303
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
360
358
  char *to;
361
359
  lip->yyUnget();                       // ptr points now after last token char
362
360
  tmp.length= lip->yytoklen=length;
363
 
  tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
 
361
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
364
362
  from= lip->get_tok_start() + skip;
365
363
  to= tmp.str;
366
364
  end= to+length;
387
385
*/
388
386
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
389
387
{
390
 
  unsigned char c,sep;
 
388
  register unsigned char c,sep;
391
389
  bool found_escape= false;
392
390
  const CHARSET_INFO * const cs= lip->m_session->charset();
393
391
 
436
434
      end-= post_skip;
437
435
      assert(end >= str);
438
436
 
439
 
      if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
 
437
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
440
438
        return (char*) "";              // memory::SqlAlloc has set error flag
441
439
 
442
440
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
602
600
 
603
601
} /* namespace drizzled */
604
602
/*
605
 
  base_sql_lex remember the following states from the following sql_baselex()
 
603
  DRIZZLElex remember the following states from the following DRIZZLElex()
606
604
 
607
605
  - MY_LEX_EOQ                  Found end of query
608
606
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
609
607
                                (which can't be followed by a signed number)
610
608
*/
611
 
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
 
609
int DRIZZLElex(void *arg, void *yysession)
612
610
{
 
611
  drizzled::Session *session= (drizzled::Session *)yysession;
613
612
  drizzled::Lex_input_stream *lip= session->m_lip;
 
613
  YYSTYPE *yylval=(YYSTYPE*) arg;
614
614
  int token;
615
615
 
616
616
  if (lip->lookahead_token != END_OF_INPUT)
626
626
    return token;
627
627
  }
628
628
 
629
 
  token= drizzled::lex_one_token(yylval, session);
 
629
  token= drizzled::lex_one_token(arg, yysession);
630
630
 
631
631
  switch(token) {
632
632
  case WITH:
637
637
      to transform the grammar into a LALR(1) grammar,
638
638
      which sql_yacc.yy can process.
639
639
    */
640
 
    token= drizzled::lex_one_token(yylval, session);
 
640
    token= drizzled::lex_one_token(arg, yysession);
641
641
    if (token == ROLLUP_SYM)
642
642
    {
643
643
      return WITH_ROLLUP_SYM;
662
662
namespace drizzled
663
663
{
664
664
 
665
 
int lex_one_token(ParserType *yylval, drizzled::Session *session)
 
665
int lex_one_token(void *arg, void *yysession)
666
666
{
667
 
  unsigned char c= 0; /* Just set to shutup GCC */
 
667
  register unsigned char c= 0; /* Just set to shutup GCC */
668
668
  bool comment_closed;
669
669
  int   tokval, result_state;
670
670
  unsigned int length;
671
671
  enum my_lex_states state;
 
672
  Session *session= (Session *)yysession;
672
673
  Lex_input_stream *lip= session->m_lip;
673
 
  LEX *lex= session->getLex();
 
674
  LEX *lex= session->lex;
 
675
  YYSTYPE *yylval=(YYSTYPE*) arg;
674
676
  const CHARSET_INFO * const cs= session->charset();
675
677
  unsigned char *state_map= cs->state_map;
676
678
  unsigned char *ident_map= cs->ident_map;
1334
1336
  table= 0;
1335
1337
  fake_select_lex= 0;
1336
1338
  cleaned= 0;
1337
 
  item_list.clear();
 
1339
  item_list.empty();
1338
1340
  describe= 0;
1339
1341
  found_rows_for_union= 0;
1340
1342
}
1342
1344
void Select_Lex::init_query()
1343
1345
{
1344
1346
  Select_Lex_Node::init_query();
1345
 
  table_list.clear();
1346
 
  top_join_list.clear();
 
1347
  table_list.empty();
 
1348
  top_join_list.empty();
1347
1349
  join_list= &top_join_list;
1348
1350
  embedding= leaf_tables= 0;
1349
 
  item_list.clear();
 
1351
  item_list.empty();
1350
1352
  join= 0;
1351
1353
  having= where= 0;
1352
1354
  olap= UNSPECIFIED_OLAP_TYPE;
1378
1380
 
1379
1381
void Select_Lex::init_select()
1380
1382
{
1381
 
  sj_nests.clear();
1382
 
  group_list.clear();
 
1383
  sj_nests.empty();
 
1384
  group_list.empty();
1383
1385
  db= 0;
1384
1386
  having= 0;
1385
1387
  in_sum_expr= with_wild= 0;
1386
1388
  options= 0;
1387
1389
  braces= 0;
1388
 
  interval_list.clear();
 
1390
  interval_list.empty();
1389
1391
  inner_sum_func_list= 0;
1390
1392
  linkage= UNSPECIFIED_TYPE;
1391
1393
  order_list.elements= 0;
1395
1397
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1396
1398
  offset_limit= 0;      /* denotes the default offset = 0 */
1397
1399
  with_sum_func= 0;
1398
 
  is_cross= false;
1399
1400
  is_correlated= 0;
1400
1401
  cur_pos_in_select_list= UNDEF_POS;
1401
 
  non_agg_fields.clear();
 
1402
  non_agg_fields.empty();
1402
1403
  cond_value= having_value= Item::COND_UNDEF;
1403
 
  inner_refs_list.clear();
 
1404
  inner_refs_list.empty();
1404
1405
  full_group_by_flag.reset();
1405
1406
}
1406
1407
 
1711
1712
    return false;
1712
1713
 
1713
1714
  return (ref_pointer_array=
1714
 
          (Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
 
1715
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1715
1716
                                                 item_list.elements +
1716
1717
                                                 select_n_having_items +
1717
1718
                                                 select_n_where_fields +
2068
2069
void LEX::cleanup_after_one_table_open()
2069
2070
{
2070
2071
  /*
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
 
2072
    session->lex->derived_tables & additional units may be set if we open
 
2073
    a view. It is necessary to clear session->lex->derived_tables flag
2073
2074
    to prevent processing of derived tables during next openTablesLock
2074
2075
    if next table is a real table and cleanup & remove underlying units
2075
 
    NOTE: all units will be connected to session->getLex()->select_lex, because we
 
2076
    NOTE: all units will be connected to session->lex->select_lex, because we
2076
2077
    have not UNION on most upper level.
2077
2078
    */
2078
2079
  if (all_selects_list != &select_lex)