~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Stewart Smith
  • Date: 2009-10-08 13:49:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: stewart@flamingspork.com-20091008134911-72y6d480660udl83
remove unused tree_search() from mysys/my_tree.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
 
#include "config.h"
20
19
#define DRIZZLE_LEX 1
21
 
#include "drizzled/configmake.h"
 
20
#include "drizzled/server_includes.h"
22
21
#include "drizzled/item/num.h"
23
22
#include "drizzled/error.h"
24
23
#include "drizzled/session.h"
26
25
#include "drizzled/lookup_symbol.h"
27
26
#include "drizzled/index_hint.h"
28
27
 
29
 
#include <cstdio>
30
28
#include <ctype.h>
31
29
 
32
30
using namespace std;
33
31
 
34
 
/* Stay outside of the namespace because otherwise bison goes nuts */
 
32
static int lex_one_token(void *arg, void *yysession);
35
33
int DRIZZLElex(void *arg, void *yysession);
36
34
 
37
 
namespace drizzled
38
 
{
39
 
 
40
 
static int lex_one_token(void *arg, void *yysession);
41
 
 
42
35
/**
43
36
  save order by and tables in own lists.
44
37
*/
45
38
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
46
39
{
47
 
  Order *order;
48
 
  if (!(order = (Order *) session->alloc(sizeof(Order))))
 
40
  order_st *order;
 
41
  if (!(order = (order_st *) session->alloc(sizeof(order_st))))
49
42
    return(1);
50
43
  order->item_ptr= item;
51
44
  order->item= &order->item_ptr;
85
78
  m_body_utf8(NULL),
86
79
  m_cpp_utf8_processed_ptr(NULL),
87
80
  next_state(MY_LEX_START),
 
81
  found_semicolon(NULL),
88
82
  ignore_space(1),
89
83
  in_comment(NO_COMMENT)
90
84
{
206
200
  Because of this, it's critical to not do too much things here.
207
201
  (We already do too much here)
208
202
*/
209
 
void LEX::start(Session *arg)
210
 
{
211
 
  lex_start(arg);
212
 
}
213
 
 
214
203
void lex_start(Session *session)
215
204
{
216
205
  LEX *lex= session->lex;
264
253
 
265
254
  lex->is_lex_started= true;
266
255
  lex->statement= NULL;
267
 
  
268
 
  lex->is_cross= false;
269
 
 
270
 
  lex->reset();
271
256
}
272
257
 
273
 
void LEX::end()
 
258
void lex_end(LEX *lex)
274
259
{
275
 
  if (yacc_yyss)
 
260
  if (lex->yacc_yyss)
276
261
  {
277
 
    free(yacc_yyss);
278
 
    free(yacc_yyvs);
279
 
    yacc_yyss= 0;
280
 
    yacc_yyvs= 0;
 
262
    free(lex->yacc_yyss);
 
263
    free(lex->yacc_yyvs);
 
264
    lex->yacc_yyss= 0;
 
265
    lex->yacc_yyvs= 0;
281
266
  }
282
267
 
283
 
  delete result;
284
 
 
285
 
  result= 0;
286
 
  setCacheable(true);
287
 
 
288
 
  delete statement;
289
 
  statement= NULL;
 
268
  delete lex->result;
 
269
 
 
270
  lex->result= 0;
 
271
 
 
272
  if (lex->statement) 
 
273
    delete lex->statement;
290
274
}
291
275
 
292
276
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
424
408
      assert(end >= str);
425
409
 
426
410
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
427
 
        return (char*) "";              // memory::SqlAlloc has set error flag
 
411
        return (char*) "";              // Sql_alloc has set error flag
428
412
 
429
413
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
430
414
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
587
571
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
588
572
}
589
573
 
590
 
} /* namespace drizzled */
591
574
/*
592
575
  DRIZZLElex remember the following states from the following DRIZZLElex()
593
576
 
597
580
*/
598
581
int DRIZZLElex(void *arg, void *yysession)
599
582
{
600
 
  drizzled::Session *session= (drizzled::Session *)yysession;
601
 
  drizzled::Lex_input_stream *lip= session->m_lip;
 
583
  Session *session= (Session *)yysession;
 
584
  Lex_input_stream *lip= session->m_lip;
602
585
  YYSTYPE *yylval=(YYSTYPE*) arg;
603
586
  int token;
604
587
 
615
598
    return token;
616
599
  }
617
600
 
618
 
  token= drizzled::lex_one_token(arg, yysession);
 
601
  token= lex_one_token(arg, yysession);
619
602
 
620
603
  switch(token) {
621
604
  case WITH:
626
609
      to transform the grammar into a LALR(1) grammar,
627
610
      which sql_yacc.yy can process.
628
611
    */
629
 
    token= drizzled::lex_one_token(arg, yysession);
 
612
    token= lex_one_token(arg, yysession);
630
613
    if (token == ROLLUP_SYM)
631
614
    {
632
615
      return WITH_ROLLUP_SYM;
648
631
  return token;
649
632
}
650
633
 
651
 
namespace drizzled
652
 
{
653
 
 
654
634
int lex_one_token(void *arg, void *yysession)
655
635
{
656
636
  register unsigned char c= 0; /* Just set to shutup GCC */
1304
1284
  options= 0;
1305
1285
  linkage= UNSPECIFIED_TYPE;
1306
1286
  no_error= no_table_names_allowed= 0;
1307
 
  uncacheable.reset();
 
1287
  uncacheable= 0;
1308
1288
}
1309
1289
 
1310
1290
void Select_Lex_Node::init_select()
1371
1351
{
1372
1352
  sj_nests.empty();
1373
1353
  group_list.empty();
1374
 
  db= 0;
 
1354
  type= db= 0;
1375
1355
  having= 0;
 
1356
  table_join_options= 0;
1376
1357
  in_sum_expr= with_wild= 0;
1377
1358
  options= 0;
1378
1359
  braces= 0;
1569
1550
       s && s != last;
1570
1551
       s= s->outer_select())
1571
1552
  {
1572
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1553
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1573
1554
    {
1574
1555
      // Select is dependent of outer select
1575
 
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1576
 
      s->uncacheable.set(UNCACHEABLE_UNITED);
 
1556
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1557
                       UNCACHEABLE_DEPENDENT;
1577
1558
      Select_Lex_Unit *munit= s->master_unit();
1578
 
      munit->uncacheable.set(UNCACHEABLE_UNITED);
1579
 
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
 
1559
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1560
                       UNCACHEABLE_DEPENDENT;
1580
1561
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1581
1562
      {
1582
1563
        if (sl != s &&
1583
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1584
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1564
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1565
          sl->uncacheable|= UNCACHEABLE_UNITED;
1585
1566
      }
1586
1567
    }
1587
1568
    s->is_correlated= true;
1606
1587
List<Item>* Select_Lex_Node::get_item_list()
1607
1588
{ return NULL; }
1608
1589
 
1609
 
TableList *Select_Lex_Node::add_table_to_list(Session *, 
1610
 
                                              Table_ident *, 
1611
 
                                              LEX_STRING *, 
1612
 
                                              const bitset<NUM_OF_TABLE_OPTIONS>&,
1613
 
                                              thr_lock_type, 
1614
 
                                              List<Index_hint> *, 
1615
 
                                              LEX_STRING *)
 
1590
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1591
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
1616
1592
{
1617
1593
  return 0;
1618
1594
}
1619
1595
 
 
1596
uint32_t Select_Lex_Node::get_table_join_options()
 
1597
{
 
1598
  return 0;
 
1599
}
1620
1600
 
1621
1601
/*
1622
1602
  prohibit using LIMIT clause
1694
1674
  return &item_list;
1695
1675
}
1696
1676
 
 
1677
uint32_t Select_Lex::get_table_join_options()
 
1678
{
 
1679
  return table_join_options;
 
1680
}
1697
1681
 
1698
1682
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1699
1683
{
1734
1718
      str->append(STRING_WITH_LEN(" order by "));
1735
1719
      fake_select_lex->print_order(
1736
1720
        str,
1737
 
        (Order *) fake_select_lex->order_list.first,
 
1721
        (order_st *) fake_select_lex->order_list.first,
1738
1722
        query_type);
1739
1723
    }
1740
1724
    fake_select_lex->print_limit(session, str, query_type);
1742
1726
}
1743
1727
 
1744
1728
void Select_Lex::print_order(String *str,
1745
 
                                Order *order,
 
1729
                                order_st *order,
1746
1730
                                enum_query_type query_type)
1747
1731
{
1748
1732
  for (; order; order= order->next)
1864
1848
    for this.
1865
1849
*/
1866
1850
LEX::LEX()
1867
 
  :
1868
 
    result(0), 
1869
 
    yacc_yyss(0), 
1870
 
    yacc_yyvs(0),
1871
 
    charset(NULL),
1872
 
    sql_command(SQLCOM_END), 
1873
 
    option_type(OPT_DEFAULT), 
1874
 
    is_lex_started(0),
1875
 
    cacheable(true),
1876
 
    sum_expr_used(false)
 
1851
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
1852
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1877
1853
{
1878
1854
  reset_query_tables_list(true);
1879
1855
  statement= NULL;
1880
1856
}
1881
1857
 
 
1858
/*
 
1859
  Detect that we need only table structure of derived table/view
 
1860
 
 
1861
  SYNOPSIS
 
1862
    only_view_structure()
 
1863
 
 
1864
  RETURN
 
1865
    true yes, we need only structure
 
1866
    false no, we need data
 
1867
*/
 
1868
bool LEX::only_view_structure()
 
1869
{
 
1870
  switch (sql_command) {
 
1871
  case SQLCOM_SHOW_CREATE:
 
1872
  case SQLCOM_SHOW_TABLES:
 
1873
  case SQLCOM_SHOW_FIELDS:
 
1874
    return true;
 
1875
  default:
 
1876
    return false;
 
1877
  }
 
1878
}
 
1879
 
 
1880
/*
 
1881
  Should Items_ident be printed correctly
 
1882
 
 
1883
  SYNOPSIS
 
1884
    need_correct_ident()
 
1885
 
 
1886
  RETURN
 
1887
    true yes, we need only structure
 
1888
    false no, we need data
 
1889
*/
 
1890
bool LEX::need_correct_ident()
 
1891
{
 
1892
  switch(sql_command)
 
1893
  {
 
1894
  case SQLCOM_SHOW_CREATE:
 
1895
  case SQLCOM_SHOW_TABLES:
 
1896
    return true;
 
1897
  default:
 
1898
    return false;
 
1899
  }
 
1900
}
 
1901
 
1882
1902
/**
1883
1903
  This method should be called only during parsing.
1884
1904
  It is aware of compound statements (stored routine bodies)
2151
2171
                                            current_index_hint_clause,
2152
2172
                                            str, length));
2153
2173
}
2154
 
 
2155
 
} /* namespace drizzled */