~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

Merged in changes from Andrey.

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
 
361
361
{
362
362
  if (lex->yacc_yyss)
363
363
  {
364
 
    my_free(lex->yacc_yyss, MYF(0));
365
 
    my_free(lex->yacc_yyvs, MYF(0));
 
364
    free(lex->yacc_yyss);
 
365
    free(lex->yacc_yyvs);
366
366
    lex->yacc_yyss= 0;
367
367
    lex->yacc_yyvs= 0;
368
368
  }
372
372
                     lex->plugins.elements);
373
373
  reset_dynamic(&lex->plugins);
374
374
 
 
375
  delete lex->result;
 
376
  lex->result= 0;
 
377
 
375
378
  return;
376
379
}
377
380
 
378
381
 
379
 
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)
380
383
{
381
384
  const char *tok= lip->get_tok_start();
382
385
 
405
408
    1         name isn't a keyword
406
409
*/
407
410
 
408
 
bool is_keyword(const char *name, uint len)
 
411
bool is_keyword(const char *name, uint32_t len)
409
412
{
410
413
  assert(len != 0);
411
414
  return get_hash_symbol(name,len,0)!=0;
419
422
 
420
423
/* make a copy of token before ptr and set yytoklen */
421
424
 
422
 
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)
423
426
{
424
427
  LEX_STRING tmp;
425
428
  lip->yyUnget();                       // ptr points now after last token char
440
443
*/
441
444
 
442
445
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
443
 
                                   uint skip,
444
 
                                   uint length, char quote)
 
446
                                   uint32_t skip,
 
447
                                   uint32_t length, char quote)
445
448
{
446
449
  LEX_STRING tmp;
447
450
  const char *from, *end;
476
479
 
477
480
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
478
481
{
479
 
  register uchar c,sep;
480
 
  uint found_escape=0;
 
482
  register unsigned char c,sep;
 
483
  uint32_t found_escape=0;
481
484
  const CHARSET_INFO * const cs= lip->m_thd->charset();
482
485
 
483
486
  lip->tok_bitmap= 0;
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
uint32_t st_select_lex_node::get_in_sum_expr()           { return 0; }
1818
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
1821
TableList *st_select_lex_node::add_table_to_list (THD *thd __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
}
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 +
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
    }
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
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
      /*
2494
2490
    {
2495
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
  }
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,