~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#define DRIZZLE_LEX 1
20
20
#include <drizzled/server_includes.h>
21
21
 
22
 
static int lex_one_token(void *arg, void *yythd);
 
22
static int lex_one_token(void *arg, void *yysession);
23
23
 
24
24
/*
25
25
  We are using pointer to this variable for distinguishing between assignment
108
108
  allows_derived= true;
109
109
}
110
110
 
111
 
Lex_input_stream::Lex_input_stream(THD *thd,
 
111
Lex_input_stream::Lex_input_stream(Session *session,
112
112
                                   const char* buffer,
113
113
                                   unsigned int length)
114
 
: m_thd(thd),
 
114
: m_session(session),
115
115
  yylineno(1),
116
116
  yytoklen(0),
117
117
  yylval(NULL),
136
136
  in_comment(NO_COMMENT),
137
137
  m_underscore_cs(NULL)
138
138
{
139
 
  m_cpp_buf= (char*) thd->alloc(length + 1);
 
139
  m_cpp_buf= (char*) session->alloc(length + 1);
140
140
  m_cpp_ptr= m_cpp_buf;
141
141
}
142
142
 
150
150
     statement;
151
151
  2) Determine the beginning of the body.
152
152
 
153
 
  @param thd        Thread context.
 
153
  @param session        Thread context.
154
154
  @param begin_ptr  Pointer to the start of the body in the pre-processed
155
155
                    buffer.
156
156
*/
157
157
 
158
 
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
 
158
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
159
159
{
160
160
  assert(begin_ptr);
161
161
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
162
162
 
163
163
  uint32_t body_utf8_length=
164
 
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
 
164
    (m_buf_length / session->variables.character_set_client->mbminlen) *
165
165
    my_charset_utf8_bin.mbmaxlen;
166
166
 
167
 
  m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
 
167
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
168
168
  m_body_utf8_ptr= m_body_utf8;
169
169
  *m_body_utf8_ptr= 0;
170
170
 
230
230
  The operation converts the specified text literal to the utf8 and appends
231
231
  the result to the utf8-body.
232
232
 
233
 
  @param thd      Thread context.
 
233
  @param session      Thread context.
234
234
  @param txt      Text literal.
235
235
  @param txt_cs   Character set of the text literal.
236
236
  @param end_ptr  Pointer in the pre-processed buffer, to which
238
238
                  operation.
239
239
*/
240
240
 
241
 
void Lex_input_stream::body_utf8_append_literal(THD *thd,
 
241
void Lex_input_stream::body_utf8_append_literal(Session *session,
242
242
                                                const LEX_STRING *txt,
243
243
                                                const CHARSET_INFO * const txt_cs,
244
244
                                                const char *end_ptr)
250
250
 
251
251
  if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
252
252
  {
253
 
    thd->convert_string(&utf_txt,
 
253
    session->convert_string(&utf_txt,
254
254
                        &my_charset_utf8_general_ci,
255
255
                        txt->str, txt->length,
256
256
                        txt_cs);
277
277
  (We already do too much here)
278
278
*/
279
279
 
280
 
void lex_start(THD *thd)
 
280
void lex_start(Session *session)
281
281
{
282
 
  LEX *lex= thd->lex;
 
282
  LEX *lex= session->lex;
283
283
 
284
 
  lex->thd= lex->unit.thd= thd;
 
284
  lex->session= lex->unit.session= session;
285
285
 
286
286
  lex->context_stack.empty();
287
287
  lex->unit.init_query();
424
424
  LEX_STRING tmp;
425
425
  lip->yyUnget();                       // ptr points now after last token char
426
426
  tmp.length=lip->yytoklen=length;
427
 
  tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
 
427
  tmp.str= lip->m_session->strmake(lip->get_tok_start() + skip, tmp.length);
428
428
 
429
429
  lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
430
430
  lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
448
448
  char *to;
449
449
  lip->yyUnget();                       // ptr points now after last token char
450
450
  tmp.length= lip->yytoklen=length;
451
 
  tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
 
451
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
452
452
  from= lip->get_tok_start() + skip;
453
453
  to= tmp.str;
454
454
  end= to+length;
478
478
{
479
479
  register unsigned char c,sep;
480
480
  uint32_t found_escape=0;
481
 
  const CHARSET_INFO * const cs= lip->m_thd->charset();
 
481
  const CHARSET_INFO * const cs= lip->m_session->charset();
482
482
 
483
483
  lip->tok_bitmap= 0;
484
484
  sep= lip->yyGetLast();                        // String should end with this
526
526
      end -= post_skip;
527
527
      assert(end >= str);
528
528
 
529
 
      if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
 
529
      if (!(start= (char*) lip->m_session->alloc((uint) (end-str)+1)))
530
530
        return (char*) "";              // Sql_alloc has set error flag
531
531
 
532
532
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
698
698
                                (which can't be followed by a signed number)
699
699
*/
700
700
 
701
 
int MYSQLlex(void *arg, void *yythd)
 
701
int MYSQLlex(void *arg, void *yysession)
702
702
{
703
 
  THD *thd= (THD *)yythd;
704
 
  Lex_input_stream *lip= thd->m_lip;
 
703
  Session *session= (Session *)yysession;
 
704
  Lex_input_stream *lip= session->m_lip;
705
705
  YYSTYPE *yylval=(YYSTYPE*) arg;
706
706
  int token;
707
707
 
718
718
    return token;
719
719
  }
720
720
 
721
 
  token= lex_one_token(arg, yythd);
 
721
  token= lex_one_token(arg, yysession);
722
722
 
723
723
  switch(token) {
724
724
  case WITH:
729
729
      to transform the grammar into a LALR(1) grammar,
730
730
      which sql_yacc.yy can process.
731
731
    */
732
 
    token= lex_one_token(arg, yythd);
 
732
    token= lex_one_token(arg, yysession);
733
733
    if (token == ROLLUP_SYM)
734
734
    {
735
735
      return WITH_ROLLUP_SYM;
752
752
  return token;
753
753
}
754
754
 
755
 
int lex_one_token(void *arg, void *yythd)
 
755
int lex_one_token(void *arg, void *yysession)
756
756
{
757
757
  register unsigned char c= 0; /* Just set to shutup GCC */
758
758
  bool comment_closed;
759
759
  int   tokval, result_state;
760
760
  unsigned int length;
761
761
  enum my_lex_states state;
762
 
  THD *thd= (THD *)yythd;
763
 
  Lex_input_stream *lip= thd->m_lip;
764
 
  LEX *lex= thd->lex;
 
762
  Session *session= (Session *)yysession;
 
763
  Lex_input_stream *lip= session->m_lip;
 
764
  LEX *lex= session->lex;
765
765
  YYSTYPE *yylval=(YYSTYPE*) arg;
766
 
  const CHARSET_INFO * const cs= thd->charset();
 
766
  const CHARSET_INFO * const cs= session->charset();
767
767
  unsigned char *state_map= cs->state_map;
768
768
  unsigned char *ident_map= cs->ident_map;
769
769
 
924
924
 
925
925
      lip->body_utf8_append(lip->m_cpp_text_start);
926
926
 
927
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
927
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
928
928
                                    lip->m_cpp_text_end);
929
929
 
930
930
      return(result_state);                     // IDENT or IDENT_QUOTED
1027
1027
 
1028
1028
      lip->body_utf8_append(lip->m_cpp_text_start);
1029
1029
 
1030
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1030
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1031
1031
                                    lip->m_cpp_text_end);
1032
1032
 
1033
1033
      return(result_state);
1068
1068
 
1069
1069
      lip->body_utf8_append(lip->m_cpp_text_start);
1070
1070
 
1071
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1071
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1072
1072
                                    lip->m_cpp_text_end);
1073
1073
 
1074
1074
      return(IDENT_QUOTED);
1182
1182
 
1183
1183
      lip->body_utf8_append(lip->m_cpp_text_start);
1184
1184
 
1185
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str,
 
1185
      lip->body_utf8_append_literal(session, &yylval->lex_str,
1186
1186
        lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1187
1187
        lip->m_cpp_text_end);
1188
1188
 
1324
1324
    case MY_LEX_SEMICOLON:                      // optional line terminator
1325
1325
      if (lip->yyPeek())
1326
1326
      {
1327
 
        if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS))
 
1327
        if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
1328
1328
        {
1329
1329
          lip->found_semicolon= lip->get_ptr();
1330
 
          thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
 
1330
          session->server_status|= SERVER_MORE_RESULTS_EXISTS;
1331
1331
          lip->next_state= MY_LEX_END;
1332
1332
          lip->set_echo(true);
1333
1333
          return (END_OF_INPUT);
1422
1422
 
1423
1423
      lip->body_utf8_append(lip->m_cpp_text_start);
1424
1424
 
1425
 
      lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
 
1425
      lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1426
1426
                                    lip->m_cpp_text_end);
1427
1427
 
1428
1428
      return(result_state);
1440
1440
  statements and stored procedures and is compensated by always
1441
1441
  supplying a copy of Alter_info to these functions.
1442
1442
 
1443
 
  @return You need to use check the error in THD for out
 
1443
  @return You need to use check the error in Session for out
1444
1444
  of memory condition after calling this function.
1445
1445
*/
1446
1446
 
1815
1815
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
1816
1816
TableList* st_select_lex_node::get_table_list()     { return 0; }
1817
1817
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
1818
 
TableList *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
 
1818
TableList *st_select_lex_node::add_table_to_list (Session *session __attribute__((unused)),
1819
1819
                                                   Table_ident *table __attribute__((unused)),
1820
1820
                                                  LEX_STRING *alias __attribute__((unused)),
1821
1821
                                                  uint32_t table_join_options __attribute__((unused)),
1857
1857
}
1858
1858
 
1859
1859
 
1860
 
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
 
1860
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1861
1861
{
1862
 
  return add_to_list(thd, order_list, item, asc);
 
1862
  return add_to_list(session, order_list, item, asc);
1863
1863
}
1864
1864
 
1865
1865
 
1866
 
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
 
1866
bool st_select_lex::add_item_to_list(Session *session __attribute__((unused)),
1867
1867
                                     Item *item)
1868
1868
{
1869
1869
  return(item_list.push_back(item));
1870
1870
}
1871
1871
 
1872
1872
 
1873
 
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
 
1873
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1874
1874
{
1875
 
  return add_to_list(thd, group_list, item, asc);
 
1875
  return add_to_list(session, group_list, item, asc);
1876
1876
}
1877
1877
 
1878
1878
 
1924
1924
}
1925
1925
 
1926
1926
 
1927
 
bool st_select_lex::setup_ref_array(THD *thd, uint32_t order_group_num)
 
1927
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1928
1928
{
1929
1929
  if (ref_pointer_array)
1930
1930
    return 0;
1931
1931
 
1932
1932
  return (ref_pointer_array=
1933
 
          (Item **)thd->alloc(sizeof(Item*) * (n_child_sum_items +
 
1933
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1934
1934
                                                 item_list.elements +
1935
1935
                                                 select_n_having_items +
1936
1936
                                                 select_n_where_fields +
1953
1953
    }
1954
1954
    if (sl->braces)
1955
1955
      str->append('(');
1956
 
    sl->print(thd, str, query_type);
 
1956
    sl->print(session, str, query_type);
1957
1957
    if (sl->braces)
1958
1958
      str->append(')');
1959
1959
  }
1967
1967
        (order_st *) fake_select_lex->order_list.first,
1968
1968
        query_type);
1969
1969
    }
1970
 
    fake_select_lex->print_limit(thd, str, query_type);
 
1970
    fake_select_lex->print_limit(session, str, query_type);
1971
1971
  }
1972
1972
}
1973
1973
 
1994
1994
}
1995
1995
 
1996
1996
 
1997
 
void st_select_lex::print_limit(THD *thd __attribute__((unused)),
 
1997
void st_select_lex::print_limit(Session *session __attribute__((unused)),
1998
1998
                                String *str,
1999
1999
                                enum_query_type query_type)
2000
2000
{
2035
2035
}
2036
2036
 
2037
2037
/**
2038
 
  @brief Restore the LEX and THD in case of a parse error.
 
2038
  @brief Restore the LEX and Session in case of a parse error.
2039
2039
 
2040
2040
  This is a clean up call that is invoked by the Bison generated
2041
2041
  parser before returning an error from MYSQLparse. If your
2046
2046
  to implement the clean up.
2047
2047
*/
2048
2048
 
2049
 
void st_lex::cleanup_lex_after_parse_error(THD *thd __attribute__((unused)))
 
2049
void st_lex::cleanup_lex_after_parse_error(Session *session __attribute__((unused)))
2050
2050
{
2051
2051
}
2052
2052
 
2124
2124
 
2125
2125
  NOTE
2126
2126
    LEX object initialized with this constructor can be used as part of
2127
 
    THD object for which one can safely call open_tables(), lock_tables()
 
2127
    Session object for which one can safely call open_tables(), lock_tables()
2128
2128
    and close_thread_tables() functions. But it is not yet ready for
2129
2129
    statement parsing. On should use lex_start() function to prepare LEX
2130
2130
    for this.
2333
2333
bool
2334
2334
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
2335
2335
{
2336
 
  return thd->copy_db_to(p_db, p_db_length);
 
2336
  return session->copy_db_to(p_db, p_db_length);
2337
2337
}
2338
2338
 
2339
2339
/*
2351
2351
 
2352
2352
  val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2353
2353
  select_limit_val= (ha_rows)val;
2354
 
#ifndef BIG_TABLES
2355
2354
  /* 
2356
2355
    Check for overflow : ha_rows can be smaller then uint64_t if
2357
2356
    BIG_TABLES is off.
2358
2357
    */
2359
2358
  if (val != (uint64_t)select_limit_val)
2360
2359
    select_limit_val= HA_POS_ERROR;
2361
 
#endif
2362
2360
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2363
2361
                                                 0UL);
2364
2362
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2510
2508
void st_lex::cleanup_after_one_table_open()
2511
2509
{
2512
2510
  /*
2513
 
    thd->lex->derived_tables & additional units may be set if we open
2514
 
    a view. It is necessary to clear thd->lex->derived_tables flag
 
2511
    session->lex->derived_tables & additional units may be set if we open
 
2512
    a view. It is necessary to clear session->lex->derived_tables flag
2515
2513
    to prevent processing of derived tables during next open_and_lock_tables
2516
2514
    if next table is a real table and cleanup & remove underlying units
2517
 
    NOTE: all units will be connected to thd->lex->select_lex, because we
 
2515
    NOTE: all units will be connected to session->lex->select_lex, because we
2518
2516
    have not UNION on most upper level.
2519
2517
    */
2520
2518
  if (all_selects_list != &select_lex)
2585
2583
 
2586
2584
  SYNOPSIS
2587
2585
    fix_prepare_info_in_table_list()
2588
 
      thd  Thread handle
 
2586
      session  Thread handle
2589
2587
      tbl  List of tables to process
2590
2588
 
2591
2589
  DESCRIPTION
2595
2593
 
2596
2594
*/
2597
2595
 
2598
 
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
 
2596
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
2599
2597
{
2600
2598
  for (; tbl; tbl= tbl->next_local)
2601
2599
  {
2602
2600
    if (tbl->on_expr)
2603
2601
    {
2604
2602
      tbl->prep_on_expr= tbl->on_expr;
2605
 
      tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
 
2603
      tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
2606
2604
    }
2607
 
    fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
 
2605
    fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
2608
2606
  }
2609
2607
}
2610
2608
 
2649
2647
 
2650
2648
  SYNOPSIS
2651
2649
    alloc_index_hints()
2652
 
      thd         current thread.
 
2650
      session         current thread.
2653
2651
*/
2654
2652
 
2655
 
void st_select_lex::alloc_index_hints (THD *thd)
 
2653
void st_select_lex::alloc_index_hints (Session *session)
2656
2654
2657
 
  index_hints= new (thd->mem_root) List<Index_hint>(); 
 
2655
  index_hints= new (session->mem_root) List<Index_hint>(); 
2658
2656
}
2659
2657
 
2660
2658
 
2665
2663
 
2666
2664
  SYNOPSIS
2667
2665
    add_index_hint()
2668
 
      thd         current thread.
 
2666
      session         current thread.
2669
2667
      str         name of the index.
2670
2668
      length      number of characters in str.
2671
2669
 
2672
2670
  RETURN VALUE
2673
2671
    0 on success, non-zero otherwise
2674
2672
*/
2675
 
bool st_select_lex::add_index_hint (THD *thd, char *str, uint32_t length)
 
2673
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2676
2674
{
2677
 
  return index_hints->push_front (new (thd->mem_root) 
 
2675
  return index_hints->push_front (new (session->mem_root) 
2678
2676
                                 Index_hint(current_index_hint_type,
2679
2677
                                            current_index_hint_clause,
2680
2678
                                            str, length));