~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
  used when comparing keywords
43
43
*/
44
44
 
45
 
static uchar to_upper_lex[]=
 
45
static unsigned char to_upper_lex[]=
46
46
{
47
47
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
48
48
   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
74
74
  "FORCE INDEX"
75
75
};
76
76
 
77
 
inline int lex_casecmp(const char *s, const char *t, uint len)
 
77
inline int lex_casecmp(const char *s, const char *t, uint32_t len)
78
78
{
79
79
  while (len-- != 0 &&
80
 
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
 
80
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
81
81
  return (int) len+1;
82
82
}
83
83
 
86
86
 
87
87
void lex_init(void)
88
88
{
89
 
  uint i;
 
89
  uint32_t i;
90
90
  for (i=0 ; i < array_elements(symbols) ; i++)
91
 
    symbols[i].length=(uchar) strlen(symbols[i].name);
 
91
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
92
92
  for (i=0 ; i < array_elements(sql_functions) ; i++)
93
 
    sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
 
93
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
94
94
 
95
95
  return;
96
96
}
163
163
  assert(begin_ptr);
164
164
  assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
165
165
 
166
 
  uint body_utf8_length=
 
166
  uint32_t body_utf8_length=
167
167
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
168
168
    my_charset_utf8_bin.mbmaxlen;
169
169
 
331
331
  lex->reset_query_tables_list(false);
332
332
  lex->expr_allows_subselect= true;
333
333
  lex->use_only_table_context= false;
 
334
  lex->parse_vcol_expr= false;
334
335
 
335
336
  lex->name.str= 0;
336
337
  lex->name.length= 0;
360
361
{
361
362
  if (lex->yacc_yyss)
362
363
  {
363
 
    my_free(lex->yacc_yyss, MYF(0));
364
 
    my_free(lex->yacc_yyvs, MYF(0));
 
364
    free(lex->yacc_yyss);
 
365
    free(lex->yacc_yyvs);
365
366
    lex->yacc_yyss= 0;
366
367
    lex->yacc_yyvs= 0;
367
368
  }
371
372
                     lex->plugins.elements);
372
373
  reset_dynamic(&lex->plugins);
373
374
 
 
375
  delete lex->result;
 
376
  lex->result= 0;
 
377
 
374
378
  return;
375
379
}
376
380
 
377
381
 
378
 
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
 
382
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
379
383
{
380
384
  const char *tok= lip->get_tok_start();
381
385
 
404
408
    1         name isn't a keyword
405
409
*/
406
410
 
407
 
bool is_keyword(const char *name, uint len)
 
411
bool is_keyword(const char *name, uint32_t len)
408
412
{
409
413
  assert(len != 0);
410
414
  return get_hash_symbol(name,len,0)!=0;
418
422
 
419
423
/* make a copy of token before ptr and set yytoklen */
420
424
 
421
 
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
 
425
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
422
426
{
423
427
  LEX_STRING tmp;
424
428
  lip->yyUnget();                       // ptr points now after last token char
439
443
*/
440
444
 
441
445
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
442
 
                                   uint skip,
443
 
                                   uint length, char quote)
 
446
                                   uint32_t skip,
 
447
                                   uint32_t length, char quote)
444
448
{
445
449
  LEX_STRING tmp;
446
450
  const char *from, *end;
475
479
 
476
480
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
477
481
{
478
 
  register uchar c,sep;
479
 
  uint found_escape=0;
 
482
  register unsigned char c,sep;
 
483
  uint32_t found_escape=0;
480
484
  const CHARSET_INFO * const cs= lip->m_thd->charset();
481
485
 
482
486
  lip->tok_bitmap= 0;
553
557
              continue;
554
558
          }
555
559
#endif
556
 
          if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
557
 
              *str == '\\' && str+1 != end)
 
560
          if (*str == '\\' && str+1 != end)
558
561
          {
559
562
            switch(*++str) {
560
563
            case 'n':
602
605
/*
603
606
** Calc type of integer; long integer, int64_t integer or real.
604
607
** Returns smallest type that match the string.
605
 
** When using unsigned long long values the result is converted to a real
 
608
** When using uint64_t values the result is converted to a real
606
609
** because else they will be unexpected sign changes because all calculation
607
610
** is done with int64_t or double.
608
611
*/
609
612
 
610
613
static const char *long_str="2147483647";
611
 
static const uint long_len=10;
 
614
static const uint32_t long_len=10;
612
615
static const char *signed_long_str="-2147483648";
613
616
static const char *int64_t_str="9223372036854775807";
614
 
static const uint int64_t_len=19;
 
617
static const uint32_t int64_t_len=19;
615
618
static const char *signed_int64_t_str="-9223372036854775808";
616
 
static const uint signed_int64_t_len=19;
 
619
static const uint32_t signed_int64_t_len=19;
617
620
static const char *unsigned_int64_t_str="18446744073709551615";
618
 
static const uint unsigned_int64_t_len=20;
 
621
static const uint32_t unsigned_int64_t_len=20;
619
622
 
620
 
static inline uint int_token(const char *str,uint length)
 
623
static inline uint32_t int_token(const char *str,uint32_t length)
621
624
{
622
625
  if (length < long_len)                        // quick normal case
623
626
    return NUM;
639
642
  if (length < long_len)
640
643
    return NUM;
641
644
 
642
 
  uint smaller,bigger;
 
645
  uint32_t smaller,bigger;
643
646
  const char *cmp;
644
647
  if (neg)
645
648
  {
686
689
    }
687
690
  }
688
691
  while (*cmp && *cmp++ == *str++) ;
689
 
  return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
 
692
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
690
693
}
691
694
 
692
695
 
723
726
  switch(token) {
724
727
  case WITH:
725
728
    /*
726
 
      Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
 
729
      Parsing 'WITH' 'ROLLUP' requires 2 look ups,
727
730
      which makes the grammar LALR(2).
728
731
      Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
729
732
      to transform the grammar into a LALR(1) grammar,
730
733
      which sql_yacc.yy can process.
731
734
    */
732
735
    token= lex_one_token(arg, yythd);
733
 
    switch(token) {
734
 
    case CUBE_SYM:
735
 
      return WITH_CUBE_SYM;
736
 
    case ROLLUP_SYM:
 
736
    if (token == ROLLUP_SYM)
 
737
    {
737
738
      return WITH_ROLLUP_SYM;
738
 
    default:
 
739
    }
 
740
    else
 
741
    {
739
742
      /*
740
743
        Save the token following 'WITH'
741
744
      */
764
767
  LEX *lex= thd->lex;
765
768
  YYSTYPE *yylval=(YYSTYPE*) arg;
766
769
  const CHARSET_INFO * const cs= thd->charset();
767
 
  uchar *state_map= cs->state_map;
768
 
  uchar *ident_map= cs->ident_map;
 
770
  unsigned char *state_map= cs->state_map;
 
771
  unsigned char *ident_map= cs->ident_map;
769
772
 
770
773
  lip->yylval=yylval;                   // The global state
771
774
 
1034
1037
 
1035
1038
    case MY_LEX_USER_VARIABLE_DELIMITER:        // Found quote char
1036
1039
    {
1037
 
      uint double_quotes= 0;
 
1040
      uint32_t double_quotes= 0;
1038
1041
      char quote_char= c;                       // Used char
1039
1042
      while ((c=lip->yyGet()))
1040
1043
      {
1565
1568
  select_n_having_items= 0;
1566
1569
  subquery_in_having= explicit_limit= 0;
1567
1570
  is_item_list_lookup= 0;
1568
 
  first_execution= 1;
1569
 
  first_cond_optimization= 1;
1570
1571
  parsing_place= NO_MATTER;
1571
1572
  exclude_from_table_unique_test= false;
1572
1573
  nest_level= 0;
1591
1592
  linkage= UNSPECIFIED_TYPE;
1592
1593
  order_list.elements= 0;
1593
1594
  order_list.first= 0;
1594
 
  order_list.next= (uchar**) &order_list.first;
 
1595
  order_list.next= (unsigned char**) &order_list.first;
1595
1596
  /* Set limit and offset to default values */
1596
1597
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1597
1598
  offset_limit= 0;      /* denotes the default offset = 0 */
1814
1815
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1815
1816
{ return 1; }
1816
1817
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
1817
 
uint st_select_lex_node::get_in_sum_expr()           { return 0; }
1818
 
TABLE_LIST* st_select_lex_node::get_table_list()     { return 0; }
 
1818
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1819
TableList* st_select_lex_node::get_table_list()     { return 0; }
1819
1820
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
1820
 
TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
 
1821
TableList *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1821
1822
                                                   Table_ident *table __attribute__((unused)),
1822
1823
                                                  LEX_STRING *alias __attribute__((unused)),
1823
1824
                                                  uint32_t table_join_options __attribute__((unused)),
1904
1905
}
1905
1906
 
1906
1907
 
1907
 
uint st_select_lex::get_in_sum_expr()
 
1908
uint32_t st_select_lex::get_in_sum_expr()
1908
1909
{
1909
1910
  return in_sum_expr;
1910
1911
}
1911
1912
 
1912
1913
 
1913
 
TABLE_LIST* st_select_lex::get_table_list()
 
1914
TableList* st_select_lex::get_table_list()
1914
1915
{
1915
 
  return (TABLE_LIST*) table_list.first;
 
1916
  return (TableList*) table_list.first;
1916
1917
}
1917
1918
 
1918
1919
List<Item>* st_select_lex::get_item_list()
1926
1927
}
1927
1928
 
1928
1929
 
1929
 
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
 
1930
bool st_select_lex::setup_ref_array(THD *thd, uint32_t order_group_num)
1930
1931
{
1931
1932
  if (ref_pointer_array)
1932
1933
    return 0;
1933
1934
 
1934
 
  /*
1935
 
    We have to create array in prepared statement memory if it is
1936
 
    prepared statement
1937
 
  */
1938
 
  Query_arena *arena= thd->stmt_arena;
1939
1935
  return (ref_pointer_array=
1940
 
          (Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
 
1936
          (Item **)thd->alloc(sizeof(Item*) * (n_child_sum_items +
1941
1937
                                                 item_list.elements +
1942
1938
                                                 select_n_having_items +
1943
1939
                                                 select_n_where_fields +
1971
1967
      str->append(STRING_WITH_LEN(" order by "));
1972
1968
      fake_select_lex->print_order(
1973
1969
        str,
1974
 
        (ORDER *) fake_select_lex->order_list.first,
 
1970
        (order_st *) fake_select_lex->order_list.first,
1975
1971
        query_type);
1976
1972
    }
1977
1973
    fake_select_lex->print_limit(thd, str, query_type);
1980
1976
 
1981
1977
 
1982
1978
void st_select_lex::print_order(String *str,
1983
 
                                ORDER *order,
 
1979
                                order_st *order,
1984
1980
                                enum_query_type query_type)
1985
1981
{
1986
1982
  for (; order; order= order->next)
1988
1984
    if (order->counter_used)
1989
1985
    {
1990
1986
      char buffer[20];
1991
 
      uint length= snprintf(buffer, 20, "%d", order->counter);
 
1987
      uint32_t length= snprintf(buffer, 20, "%d", order->counter);
1992
1988
      str->append(buffer, length);
1993
1989
    }
1994
1990
    else
2024
2020
                    ((Item_in_subselect*)item)->exec_method ==
2025
2021
                    Item_in_subselect::MATERIALIZATION) ?
2026
2022
                   true :
2027
 
                   (select_limit->val_int() == 1LL) &&
 
2023
                   (select_limit->val_int() == 1L) &&
2028
2024
                   offset_limit == 0));
2029
2025
      return;
2030
2026
    }
2079
2075
{
2080
2076
  if (!init && query_tables)
2081
2077
  {
2082
 
    TABLE_LIST *table= query_tables;
 
2078
    TableList *table= query_tables;
2083
2079
    for (;;)
2084
2080
    {
2085
2081
      if (query_tables_last == &table->next_global ||
2367
2363
    select_limit_val= HA_POS_ERROR;
2368
2364
#endif
2369
2365
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2370
 
                                                 0ULL);
 
2366
                                                 0UL);
2371
2367
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2372
2368
  if (select_limit_cnt < select_limit_val)
2373
2369
    select_limit_cnt= HA_POS_ERROR;             // no limit
2392
2388
      In this case link_to_local is set.
2393
2389
 
2394
2390
*/
2395
 
TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local)
 
2391
TableList *st_lex::unlink_first_table(bool *link_to_local)
2396
2392
{
2397
 
  TABLE_LIST *first;
 
2393
  TableList *first;
2398
2394
  if ((first= query_tables))
2399
2395
  {
2400
2396
    /*
2413
2409
    {
2414
2410
      select_lex.context.table_list= 
2415
2411
        select_lex.context.first_name_resolution_table= first->next_local;
2416
 
      select_lex.table_list.first= (uchar*) (first->next_local);
 
2412
      select_lex.table_list.first= (unsigned char*) (first->next_local);
2417
2413
      select_lex.table_list.elements--; //safety
2418
2414
      first->next_local= 0;
2419
2415
      /*
2445
2441
 
2446
2442
void st_lex::first_lists_tables_same()
2447
2443
{
2448
 
  TABLE_LIST *first_table= (TABLE_LIST*) select_lex.table_list.first;
 
2444
  TableList *first_table= (TableList*) select_lex.table_list.first;
2449
2445
  if (query_tables != first_table && first_table != 0)
2450
2446
  {
2451
 
    TABLE_LIST *next;
 
2447
    TableList *next;
2452
2448
    if (query_tables_last == &first_table->next_global)
2453
2449
      query_tables_last= first_table->prev_global;
2454
2450
 
2479
2475
    global list
2480
2476
*/
2481
2477
 
2482
 
void st_lex::link_first_table_back(TABLE_LIST *first,
 
2478
void st_lex::link_first_table_back(TableList *first,
2483
2479
                                   bool link_to_local)
2484
2480
{
2485
2481
  if (first)
2492
2488
 
2493
2489
    if (link_to_local)
2494
2490
    {
2495
 
      first->next_local= (TABLE_LIST*) select_lex.table_list.first;
 
2491
      first->next_local= (TableList*) select_lex.table_list.first;
2496
2492
      select_lex.context.table_list= first;
2497
 
      select_lex.table_list.first= (uchar*) first;
 
2493
      select_lex.table_list.first= (unsigned char*) first;
2498
2494
      select_lex.table_list.elements++; //safety
2499
2495
    }
2500
2496
  }
2602
2598
 
2603
2599
*/
2604
2600
 
2605
 
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
 
2601
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
2606
2602
{
2607
2603
  for (; tbl; tbl= tbl->next_local)
2608
2604
  {
2679
2675
  RETURN VALUE
2680
2676
    0 on success, non-zero otherwise
2681
2677
*/
2682
 
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
 
2678
bool st_select_lex::add_index_hint (THD *thd, char *str, uint32_t length)
2683
2679
{
2684
2680
  return index_hints->push_front (new (thd->mem_root) 
2685
2681
                                 Index_hint(current_index_hint_type,