~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Stewart Smith
  • Date: 2008-09-25 10:04:06 UTC
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080925100406-hld92f4dr4nuar3a
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
  used when comparing keywords
43
43
*/
44
44
 
45
 
static unsigned char to_upper_lex[]=
 
45
static uchar 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, uint32_t len)
 
77
inline int lex_casecmp(const char *s, const char *t, uint len)
78
78
{
79
79
  while (len-- != 0 &&
80
 
         to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
 
80
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
81
81
  return (int) len+1;
82
82
}
83
83
 
86
86
 
87
87
void lex_init(void)
88
88
{
89
 
  uint32_t i;
 
89
  uint i;
90
90
  for (i=0 ; i < array_elements(symbols) ; i++)
91
 
    symbols[i].length=(unsigned char) strlen(symbols[i].name);
 
91
    symbols[i].length=(uchar) strlen(symbols[i].name);
92
92
  for (i=0 ; i < array_elements(sql_functions) ; i++)
93
 
    sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
 
93
    sql_functions[i].length=(uchar) 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
 
  uint32_t body_utf8_length=
 
166
  uint body_utf8_length=
167
167
    (m_buf_length / thd->variables.character_set_client->mbminlen) *
168
168
    my_charset_utf8_bin.mbmaxlen;
169
169
 
360
360
{
361
361
  if (lex->yacc_yyss)
362
362
  {
363
 
    free(lex->yacc_yyss);
364
 
    free(lex->yacc_yyvs);
 
363
    my_free(lex->yacc_yyss, MYF(0));
 
364
    my_free(lex->yacc_yyvs, MYF(0));
365
365
    lex->yacc_yyss= 0;
366
366
    lex->yacc_yyvs= 0;
367
367
  }
371
371
                     lex->plugins.elements);
372
372
  reset_dynamic(&lex->plugins);
373
373
 
374
 
  delete lex->result;
375
 
  lex->result= 0;
376
 
 
377
374
  return;
378
375
}
379
376
 
380
377
 
381
 
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
 
378
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
382
379
{
383
380
  const char *tok= lip->get_tok_start();
384
381
 
407
404
    1         name isn't a keyword
408
405
*/
409
406
 
410
 
bool is_keyword(const char *name, uint32_t len)
 
407
bool is_keyword(const char *name, uint len)
411
408
{
412
409
  assert(len != 0);
413
410
  return get_hash_symbol(name,len,0)!=0;
421
418
 
422
419
/* make a copy of token before ptr and set yytoklen */
423
420
 
424
 
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
 
421
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
425
422
{
426
423
  LEX_STRING tmp;
427
424
  lip->yyUnget();                       // ptr points now after last token char
442
439
*/
443
440
 
444
441
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
445
 
                                   uint32_t skip,
446
 
                                   uint32_t length, char quote)
 
442
                                   uint skip,
 
443
                                   uint length, char quote)
447
444
{
448
445
  LEX_STRING tmp;
449
446
  const char *from, *end;
478
475
 
479
476
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
480
477
{
481
 
  register unsigned char c,sep;
482
 
  uint32_t found_escape=0;
 
478
  register uchar c,sep;
 
479
  uint found_escape=0;
483
480
  const CHARSET_INFO * const cs= lip->m_thd->charset();
484
481
 
485
482
  lip->tok_bitmap= 0;
610
607
*/
611
608
 
612
609
static const char *long_str="2147483647";
613
 
static const uint32_t long_len=10;
 
610
static const uint long_len=10;
614
611
static const char *signed_long_str="-2147483648";
615
612
static const char *int64_t_str="9223372036854775807";
616
 
static const uint32_t int64_t_len=19;
 
613
static const uint int64_t_len=19;
617
614
static const char *signed_int64_t_str="-9223372036854775808";
618
 
static const uint32_t signed_int64_t_len=19;
 
615
static const uint signed_int64_t_len=19;
619
616
static const char *unsigned_int64_t_str="18446744073709551615";
620
 
static const uint32_t unsigned_int64_t_len=20;
 
617
static const uint unsigned_int64_t_len=20;
621
618
 
622
 
static inline uint32_t int_token(const char *str,uint32_t length)
 
619
static inline uint int_token(const char *str,uint length)
623
620
{
624
621
  if (length < long_len)                        // quick normal case
625
622
    return NUM;
641
638
  if (length < long_len)
642
639
    return NUM;
643
640
 
644
 
  uint32_t smaller,bigger;
 
641
  uint smaller,bigger;
645
642
  const char *cmp;
646
643
  if (neg)
647
644
  {
688
685
    }
689
686
  }
690
687
  while (*cmp && *cmp++ == *str++) ;
691
 
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
 
688
  return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
692
689
}
693
690
 
694
691
 
725
722
  switch(token) {
726
723
  case WITH:
727
724
    /*
728
 
      Parsing 'WITH' 'ROLLUP' requires 2 look ups,
 
725
      Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
729
726
      which makes the grammar LALR(2).
730
727
      Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
731
728
      to transform the grammar into a LALR(1) grammar,
732
729
      which sql_yacc.yy can process.
733
730
    */
734
731
    token= lex_one_token(arg, yythd);
735
 
    if (token == ROLLUP_SYM)
736
 
    {
 
732
    switch(token) {
 
733
    case CUBE_SYM:
 
734
      return WITH_CUBE_SYM;
 
735
    case ROLLUP_SYM:
737
736
      return WITH_ROLLUP_SYM;
738
 
    }
739
 
    else
740
 
    {
 
737
    default:
741
738
      /*
742
739
        Save the token following 'WITH'
743
740
      */
766
763
  LEX *lex= thd->lex;
767
764
  YYSTYPE *yylval=(YYSTYPE*) arg;
768
765
  const CHARSET_INFO * const cs= thd->charset();
769
 
  unsigned char *state_map= cs->state_map;
770
 
  unsigned char *ident_map= cs->ident_map;
 
766
  uchar *state_map= cs->state_map;
 
767
  uchar *ident_map= cs->ident_map;
771
768
 
772
769
  lip->yylval=yylval;                   // The global state
773
770
 
1036
1033
 
1037
1034
    case MY_LEX_USER_VARIABLE_DELIMITER:        // Found quote char
1038
1035
    {
1039
 
      uint32_t double_quotes= 0;
 
1036
      uint double_quotes= 0;
1040
1037
      char quote_char= c;                       // Used char
1041
1038
      while ((c=lip->yyGet()))
1042
1039
      {
1567
1564
  select_n_having_items= 0;
1568
1565
  subquery_in_having= explicit_limit= 0;
1569
1566
  is_item_list_lookup= 0;
 
1567
  first_execution= 1;
 
1568
  first_cond_optimization= 1;
1570
1569
  parsing_place= NO_MATTER;
1571
1570
  exclude_from_table_unique_test= false;
1572
1571
  nest_level= 0;
1591
1590
  linkage= UNSPECIFIED_TYPE;
1592
1591
  order_list.elements= 0;
1593
1592
  order_list.first= 0;
1594
 
  order_list.next= (unsigned char**) &order_list.first;
 
1593
  order_list.next= (uchar**) &order_list.first;
1595
1594
  /* Set limit and offset to default values */
1596
1595
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1597
1596
  offset_limit= 0;      /* denotes the default offset = 0 */
1814
1813
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1815
1814
{ return 1; }
1816
1815
bool st_select_lex_node::inc_in_sum_expr()           { return 1; }
1817
 
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
 
1816
uint st_select_lex_node::get_in_sum_expr()           { return 0; }
1818
1817
TableList* st_select_lex_node::get_table_list()     { return 0; }
1819
1818
List<Item>* st_select_lex_node::get_item_list()      { return 0; }
1820
1819
TableList *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1904
1903
}
1905
1904
 
1906
1905
 
1907
 
uint32_t st_select_lex::get_in_sum_expr()
 
1906
uint st_select_lex::get_in_sum_expr()
1908
1907
{
1909
1908
  return in_sum_expr;
1910
1909
}
1926
1925
}
1927
1926
 
1928
1927
 
1929
 
bool st_select_lex::setup_ref_array(THD *thd, uint32_t order_group_num)
 
1928
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1930
1929
{
1931
1930
  if (ref_pointer_array)
1932
1931
    return 0;
1933
1932
 
 
1933
  /*
 
1934
    We have to create array in prepared statement memory if it is
 
1935
    prepared statement
 
1936
  */
 
1937
  Query_arena *arena= thd->stmt_arena;
1934
1938
  return (ref_pointer_array=
1935
 
          (Item **)thd->alloc(sizeof(Item*) * (n_child_sum_items +
 
1939
          (Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1936
1940
                                                 item_list.elements +
1937
1941
                                                 select_n_having_items +
1938
1942
                                                 select_n_where_fields +
1983
1987
    if (order->counter_used)
1984
1988
    {
1985
1989
      char buffer[20];
1986
 
      uint32_t length= snprintf(buffer, 20, "%d", order->counter);
 
1990
      uint length= snprintf(buffer, 20, "%d", order->counter);
1987
1991
      str->append(buffer, length);
1988
1992
    }
1989
1993
    else
2019
2023
                    ((Item_in_subselect*)item)->exec_method ==
2020
2024
                    Item_in_subselect::MATERIALIZATION) ?
2021
2025
                   true :
2022
 
                   (select_limit->val_int() == 1L) &&
 
2026
                   (select_limit->val_int() == 1LL) &&
2023
2027
                   offset_limit == 0));
2024
2028
      return;
2025
2029
    }
2362
2366
    select_limit_val= HA_POS_ERROR;
2363
2367
#endif
2364
2368
  offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2365
 
                                                 0UL);
 
2369
                                                 0ULL);
2366
2370
  select_limit_cnt= select_limit_val + offset_limit_cnt;
2367
2371
  if (select_limit_cnt < select_limit_val)
2368
2372
    select_limit_cnt= HA_POS_ERROR;             // no limit
2408
2412
    {
2409
2413
      select_lex.context.table_list= 
2410
2414
        select_lex.context.first_name_resolution_table= first->next_local;
2411
 
      select_lex.table_list.first= (unsigned char*) (first->next_local);
 
2415
      select_lex.table_list.first= (uchar*) (first->next_local);
2412
2416
      select_lex.table_list.elements--; //safety
2413
2417
      first->next_local= 0;
2414
2418
      /*
2489
2493
    {
2490
2494
      first->next_local= (TableList*) select_lex.table_list.first;
2491
2495
      select_lex.context.table_list= first;
2492
 
      select_lex.table_list.first= (unsigned char*) first;
 
2496
      select_lex.table_list.first= (uchar*) first;
2493
2497
      select_lex.table_list.elements++; //safety
2494
2498
    }
2495
2499
  }
2674
2678
  RETURN VALUE
2675
2679
    0 on success, non-zero otherwise
2676
2680
*/
2677
 
bool st_select_lex::add_index_hint (THD *thd, char *str, uint32_t length)
 
2681
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2678
2682
{
2679
2683
  return index_hints->push_front (new (thd->mem_root) 
2680
2684
                                 Index_hint(current_index_hint_type,