~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

Removed protocol field flags.

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
 
/**
43
 
  save order by and tables in own lists.
 
35
/*
 
36
  We are using pointer to this variable for distinguishing between assignment
 
37
  to NEW row field (when parsing trigger definition) and structured variable.
44
38
*/
45
 
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
46
 
{
47
 
  Order *order;
48
 
  if (!(order = (Order *) session->alloc(sizeof(Order))))
49
 
    return(1);
50
 
  order->item_ptr= item;
51
 
  order->item= &order->item_ptr;
52
 
  order->asc = asc;
53
 
  order->free_me=0;
54
 
  order->used=0;
55
 
  order->counter_used= 0;
56
 
  list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
57
 
  return(0);
58
 
}
 
39
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
59
40
 
60
41
/**
61
42
  LEX_STRING constant for null-string to be used in parser and other places.
85
66
  m_body_utf8(NULL),
86
67
  m_cpp_utf8_processed_ptr(NULL),
87
68
  next_state(MY_LEX_START),
 
69
  found_semicolon(NULL),
88
70
  ignore_space(1),
89
71
  in_comment(NO_COMMENT)
90
72
{
206
188
  Because of this, it's critical to not do too much things here.
207
189
  (We already do too much here)
208
190
*/
209
 
void LEX::start(Session *arg)
210
 
{
211
 
  lex_start(arg);
212
 
}
213
 
 
214
191
void lex_start(Session *session)
215
192
{
216
193
  LEX *lex= session->lex;
225
202
  lex->select_lex.init_query();
226
203
  lex->value_list.empty();
227
204
  lex->update_list.empty();
 
205
  lex->param_list.empty();
228
206
  lex->auxiliary_table_list.empty();
229
207
  lex->unit.next= lex->unit.master=
230
208
    lex->unit.link_next= lex->unit.return_to= 0;
263
241
  lex->in_sum_func= NULL;
264
242
 
265
243
  lex->is_lex_started= true;
266
 
  lex->statement= NULL;
267
 
  
268
 
  lex->is_cross= false;
269
 
 
270
 
  lex->reset();
 
244
  lex->create_table_proto= NULL;
271
245
}
272
246
 
273
 
void LEX::end()
 
247
void lex_end(LEX *lex)
274
248
{
275
 
  if (yacc_yyss)
 
249
  if (lex->yacc_yyss)
276
250
  {
277
 
    free(yacc_yyss);
278
 
    free(yacc_yyvs);
279
 
    yacc_yyss= 0;
280
 
    yacc_yyvs= 0;
 
251
    free(lex->yacc_yyss);
 
252
    free(lex->yacc_yyvs);
 
253
    lex->yacc_yyss= 0;
 
254
    lex->yacc_yyvs= 0;
281
255
  }
282
256
 
283
 
  delete result;
284
 
 
285
 
  result= 0;
286
 
  setCacheable(true);
287
 
 
288
 
  delete statement;
289
 
  statement= NULL;
 
257
  delete lex->result;
 
258
 
 
259
  if(lex->create_table_proto)
 
260
    delete lex->create_table_proto;
 
261
  lex->result= 0;
290
262
}
291
263
 
292
264
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
424
396
      assert(end >= str);
425
397
 
426
398
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
427
 
        return (char*) "";              // memory::SqlAlloc has set error flag
 
399
        return (char*) "";              // Sql_alloc has set error flag
428
400
 
429
401
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
430
402
      lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
587
559
  return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
588
560
}
589
561
 
590
 
} /* namespace drizzled */
591
562
/*
592
563
  DRIZZLElex remember the following states from the following DRIZZLElex()
593
564
 
597
568
*/
598
569
int DRIZZLElex(void *arg, void *yysession)
599
570
{
600
 
  drizzled::Session *session= (drizzled::Session *)yysession;
601
 
  drizzled::Lex_input_stream *lip= session->m_lip;
 
571
  Session *session= (Session *)yysession;
 
572
  Lex_input_stream *lip= session->m_lip;
602
573
  YYSTYPE *yylval=(YYSTYPE*) arg;
603
574
  int token;
604
575
 
615
586
    return token;
616
587
  }
617
588
 
618
 
  token= drizzled::lex_one_token(arg, yysession);
 
589
  token= lex_one_token(arg, yysession);
619
590
 
620
591
  switch(token) {
621
592
  case WITH:
626
597
      to transform the grammar into a LALR(1) grammar,
627
598
      which sql_yacc.yy can process.
628
599
    */
629
 
    token= drizzled::lex_one_token(arg, yysession);
 
600
    token= lex_one_token(arg, yysession);
630
601
    if (token == ROLLUP_SYM)
631
602
    {
632
603
      return WITH_ROLLUP_SYM;
648
619
  return token;
649
620
}
650
621
 
651
 
namespace drizzled
652
 
{
653
 
 
654
622
int lex_one_token(void *arg, void *yysession)
655
623
{
656
624
  register unsigned char c= 0; /* Just set to shutup GCC */
1273
1241
  }
1274
1242
}
1275
1243
 
 
1244
/**
 
1245
  Construct a copy of this object to be used for mysql_alter_table
 
1246
  and mysql_create_table.
 
1247
 
 
1248
  Historically, these two functions modify their Alter_info
 
1249
  arguments. This behaviour breaks re-execution of prepared
 
1250
  statements and stored procedures and is compensated by always
 
1251
  supplying a copy of Alter_info to these functions.
 
1252
 
 
1253
  @return You need to use check the error in Session for out
 
1254
  of memory condition after calling this function.
 
1255
*/
 
1256
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
 
1257
  :drop_list(rhs.drop_list, mem_root),
 
1258
  alter_list(rhs.alter_list, mem_root),
 
1259
  key_list(rhs.key_list, mem_root),
 
1260
  create_list(rhs.create_list, mem_root),
 
1261
  flags(rhs.flags),
 
1262
  keys_onoff(rhs.keys_onoff),
 
1263
  tablespace_op(rhs.tablespace_op),
 
1264
  no_parts(rhs.no_parts),
 
1265
  build_method(rhs.build_method),
 
1266
  datetime_field(rhs.datetime_field),
 
1267
  error_if_not_empty(rhs.error_if_not_empty)
 
1268
{
 
1269
  /*
 
1270
    Make deep copies of used objects.
 
1271
    This is not a fully deep copy - clone() implementations
 
1272
    of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
 
1273
    do not copy string constants. At the same length the only
 
1274
    reason we make a copy currently is that ALTER/CREATE TABLE
 
1275
    code changes input Alter_info definitions, but string
 
1276
    constants never change.
 
1277
  */
 
1278
  list_copy_and_replace_each_value(drop_list, mem_root);
 
1279
  list_copy_and_replace_each_value(alter_list, mem_root);
 
1280
  list_copy_and_replace_each_value(key_list, mem_root);
 
1281
  list_copy_and_replace_each_value(create_list, mem_root);
 
1282
}
 
1283
 
1276
1284
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1277
1285
{
1278
1286
  /*
1304
1312
  options= 0;
1305
1313
  linkage= UNSPECIFIED_TYPE;
1306
1314
  no_error= no_table_names_allowed= 0;
1307
 
  uncacheable.reset();
 
1315
  uncacheable= 0;
1308
1316
}
1309
1317
 
1310
1318
void Select_Lex_Node::init_select()
1371
1379
{
1372
1380
  sj_nests.empty();
1373
1381
  group_list.empty();
1374
 
  db= 0;
 
1382
  type= db= 0;
1375
1383
  having= 0;
 
1384
  table_join_options= 0;
1376
1385
  in_sum_expr= with_wild= 0;
1377
1386
  options= 0;
1378
1387
  braces= 0;
1569
1578
       s && s != last;
1570
1579
       s= s->outer_select())
1571
1580
  {
1572
 
    if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
 
1581
    if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1573
1582
    {
1574
1583
      // Select is dependent of outer select
1575
 
      s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1576
 
      s->uncacheable.set(UNCACHEABLE_UNITED);
 
1584
      s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
 
1585
                       UNCACHEABLE_DEPENDENT;
1577
1586
      Select_Lex_Unit *munit= s->master_unit();
1578
 
      munit->uncacheable.set(UNCACHEABLE_UNITED);
1579
 
      munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
 
1587
      munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
 
1588
                       UNCACHEABLE_DEPENDENT;
1580
1589
      for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1581
1590
      {
1582
1591
        if (sl != s &&
1583
 
            ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1584
 
          sl->uncacheable.set(UNCACHEABLE_UNITED);
 
1592
            !(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
 
1593
          sl->uncacheable|= UNCACHEABLE_UNITED;
1585
1594
      }
1586
1595
    }
1587
1596
    s->is_correlated= true;
1606
1615
List<Item>* Select_Lex_Node::get_item_list()
1607
1616
{ return NULL; }
1608
1617
 
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 *)
 
1618
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
 
1619
                                                  thr_lock_type, List<Index_hint> *, LEX_STRING *)
1616
1620
{
1617
1621
  return 0;
1618
1622
}
1619
1623
 
 
1624
uint32_t Select_Lex_Node::get_table_join_options()
 
1625
{
 
1626
  return 0;
 
1627
}
1620
1628
 
1621
1629
/*
1622
1630
  prohibit using LIMIT clause
1694
1702
  return &item_list;
1695
1703
}
1696
1704
 
 
1705
uint32_t Select_Lex::get_table_join_options()
 
1706
{
 
1707
  return table_join_options;
 
1708
}
1697
1709
 
1698
1710
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1699
1711
{
1734
1746
      str->append(STRING_WITH_LEN(" order by "));
1735
1747
      fake_select_lex->print_order(
1736
1748
        str,
1737
 
        (Order *) fake_select_lex->order_list.first,
 
1749
        (order_st *) fake_select_lex->order_list.first,
1738
1750
        query_type);
1739
1751
    }
1740
1752
    fake_select_lex->print_limit(session, str, query_type);
1742
1754
}
1743
1755
 
1744
1756
void Select_Lex::print_order(String *str,
1745
 
                                Order *order,
 
1757
                                order_st *order,
1746
1758
                                enum_query_type query_type)
1747
1759
{
1748
1760
  for (; order; order= order->next)
1864
1876
    for this.
1865
1877
*/
1866
1878
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)
 
1879
  :result(0), yacc_yyss(0), yacc_yyvs(0),
 
1880
   sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1877
1881
{
1878
1882
  reset_query_tables_list(true);
1879
 
  statement= NULL;
 
1883
  create_table_proto= NULL;
 
1884
}
 
1885
 
 
1886
/*
 
1887
  Detect that we need only table structure of derived table/view
 
1888
 
 
1889
  SYNOPSIS
 
1890
    only_view_structure()
 
1891
 
 
1892
  RETURN
 
1893
    true yes, we need only structure
 
1894
    false no, we need data
 
1895
*/
 
1896
bool LEX::only_view_structure()
 
1897
{
 
1898
  switch (sql_command) {
 
1899
  case SQLCOM_SHOW_CREATE:
 
1900
  case SQLCOM_SHOW_TABLES:
 
1901
  case SQLCOM_SHOW_FIELDS:
 
1902
    return true;
 
1903
  default:
 
1904
    return false;
 
1905
  }
 
1906
}
 
1907
 
 
1908
/*
 
1909
  Should Items_ident be printed correctly
 
1910
 
 
1911
  SYNOPSIS
 
1912
    need_correct_ident()
 
1913
 
 
1914
  RETURN
 
1915
    true yes, we need only structure
 
1916
    false no, we need data
 
1917
*/
 
1918
bool LEX::need_correct_ident()
 
1919
{
 
1920
  switch(sql_command)
 
1921
  {
 
1922
  case SQLCOM_SHOW_CREATE:
 
1923
  case SQLCOM_SHOW_TABLES:
 
1924
    return true;
 
1925
  default:
 
1926
    return false;
 
1927
  }
1880
1928
}
1881
1929
 
1882
1930
/**
2066
2114
  /*
2067
2115
    session->lex->derived_tables & additional units may be set if we open
2068
2116
    a view. It is necessary to clear session->lex->derived_tables flag
2069
 
    to prevent processing of derived tables during next openTablesLock
 
2117
    to prevent processing of derived tables during next open_and_lock_tables
2070
2118
    if next table is a real table and cleanup & remove underlying units
2071
2119
    NOTE: all units will be connected to session->lex->select_lex, because we
2072
2120
    have not UNION on most upper level.
2151
2199
                                            current_index_hint_clause,
2152
2200
                                            str, length));
2153
2201
}
2154
 
 
2155
 
} /* namespace drizzled */