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 */
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
20
19
#define DRIZZLE_LEX 1
21
#include "drizzled/configmake.h"
22
#include "drizzled/item/num.h"
23
#include "drizzled/error.h"
24
#include "drizzled/session.h"
25
#include "drizzled/sql_base.h"
26
#include "drizzled/lookup_symbol.h"
27
#include "drizzled/index_hint.h"
34
/* Stay outside of the namespace because otherwise bison goes nuts */
35
int DRIZZLElex(void *arg, void *yysession);
20
#include <drizzled/server_includes.h>
21
#include <drizzled/item/num.h>
22
#include <drizzled/error.h>
23
#include <drizzled/session.h>
24
#include <drizzled/sql_base.h>
40
26
static int lex_one_token(void *arg, void *yysession);
43
save order by and tables in own lists.
29
We are using pointer to this variable for distinguishing between assignment
30
to NEW row field (when parsing trigger definition) and structured variable.
45
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
48
if (!(order = (Order *) session->alloc(sizeof(Order))))
50
order->item_ptr= item;
51
order->item= &order->item_ptr;
55
order->counter_used= 0;
56
list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
33
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
61
36
LEX_STRING constant for null-string to be used in parser and other places.
63
38
const LEX_STRING null_lex_str= {NULL, 0};
42
The following data is based on the latin1 character set, and is only
43
used when comparing keywords
46
static unsigned char to_upper_lex[]=
48
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
49
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
50
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
51
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
52
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
53
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
54
96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
55
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
56
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
57
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
58
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
59
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
60
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
61
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
62
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
63
208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
67
Names of the index hints (for error messages). Keep in sync with
71
const char * index_hint_type_name[] =
78
int lex_casecmp(const char *s, const char *t, uint32_t len)
81
to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
85
/* EVIL EVIL - this is included here so that it will have to_upper_lex */
86
#include <drizzled/lex_hash.h>
92
for (i=0 ; i < array_elements(symbols) ; i++)
93
symbols[i].length=(unsigned char) strlen(symbols[i].name);
94
for (i=0 ; i < array_elements(sql_functions) ; i++)
95
sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
102
{ // Call this when daemon ends
108
st_parsing_options::reset()
110
allows_select_procedure= true;
65
113
Lex_input_stream::Lex_input_stream(Session *session,
66
114
const char* buffer,
67
115
unsigned int length)
846
954
while (my_isdigit(cs, (c = lip->yyGet()))) ;
847
955
if (!ident_map[c])
848
956
{ // Can't be identifier
849
state=MY_LEX_INT_OR_REAL;
957
state=MY_LEX_INT_OR_REAL;
852
960
if (c == 'e' || c == 'E')
854
// The following test is written this way to allow numbers of type 1e1
962
// The following test is written this way to allow numbers of type 1e1
855
963
if (my_isdigit(cs,lip->yyPeek()) ||
856
964
(c=(lip->yyGet())) == '+' || c == '-')
858
966
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign
861
969
while (my_isdigit(cs,lip->yyGet())) ;
862
970
yylval->lex_str=get_token(lip, 0, lip->yyLength());
869
977
case MY_LEX_IDENT_START: // We come here after '.'
870
978
result_state= IDENT;
979
#if defined(USE_MB) && defined(USE_MB_IDENT)
873
result_state= IDENT_QUOTED;
982
result_state= IDENT_QUOTED;
874
983
while (ident_map[c=lip->yyGet()])
876
985
if (my_mbcharlen(cs, c) > 1)
878
int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
988
if ((l = my_ismbchar(cs,
990
lip->get_end_of_query())) == 0)
881
992
lip->skip_binary(l-1);
887
999
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
888
1000
/* If there were non-ASCII characters, mark that we must convert */
889
1001
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
891
1003
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
892
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
1004
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
894
1006
yylval->lex_str= get_token(lip, 0, lip->yyLength());
896
1008
lip->body_utf8_append(lip->m_cpp_text_start);
898
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1010
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1011
lip->m_cpp_text_end);
900
1013
return(result_state);
1253
1389
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1256
lip->next_state=MY_LEX_IDENT_SEP;
1392
lip->next_state=MY_LEX_IDENT_SEP;
1257
1393
length= lip->yyLength();
1258
1394
if (length == 0)
1259
1395
return(ABORT_SYM); // Names must be nonempty.
1260
1396
if ((tokval= find_keyword(lip, length,0)))
1262
1398
lip->yyUnget(); // Put back 'c'
1263
return(tokval); // Was keyword
1399
return(tokval); // Was keyword
1265
1401
yylval->lex_str=get_token(lip, 0, length);
1267
1403
lip->body_utf8_append(lip->m_cpp_text_start);
1269
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1405
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1406
lip->m_cpp_text_end);
1271
1408
return(result_state);
1415
Construct a copy of this object to be used for mysql_alter_table
1416
and mysql_create_table.
1418
Historically, these two functions modify their Alter_info
1419
arguments. This behaviour breaks re-execution of prepared
1420
statements and stored procedures and is compensated by always
1421
supplying a copy of Alter_info to these functions.
1423
@return You need to use check the error in Session for out
1424
of memory condition after calling this function.
1427
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1428
:drop_list(rhs.drop_list, mem_root),
1429
alter_list(rhs.alter_list, mem_root),
1430
key_list(rhs.key_list, mem_root),
1431
create_list(rhs.create_list, mem_root),
1433
keys_onoff(rhs.keys_onoff),
1434
tablespace_op(rhs.tablespace_op),
1435
no_parts(rhs.no_parts),
1436
build_method(rhs.build_method),
1437
datetime_field(rhs.datetime_field),
1438
error_if_not_empty(rhs.error_if_not_empty)
1441
Make deep copies of used objects.
1442
This is not a fully deep copy - clone() implementations
1443
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1444
do not copy string constants. At the same length the only
1445
reason we make a copy currently is that ALTER/CREATE TABLE
1446
code changes input Alter_info definitions, but string
1447
constants never change.
1449
list_copy_and_replace_each_value(drop_list, mem_root);
1450
list_copy_and_replace_each_value(alter_list, mem_root);
1451
list_copy_and_replace_each_value(key_list, mem_root);
1452
list_copy_and_replace_each_value(create_list, mem_root);
1276
1456
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1552
1743
next->prev= prev;
1556
* Mark all Select_Lex struct from this to 'last' as dependent
1558
* @param Pointer to last Select_Lex struct, before wich all
1559
* Select_Lex have to be marked as dependent
1560
* @note 'last' should be reachable from this Select_Lex_Node
1562
void Select_Lex::mark_as_dependent(Select_Lex *last)
1748
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
1749
this to 'last' as dependent
1752
last - pointer to last st_select_lex struct, before wich all
1753
st_select_lex have to be marked as dependent
1756
'last' should be reachable from this st_select_lex_node
1759
void st_select_lex::mark_as_dependent(st_select_lex *last)
1565
1762
Mark all selects from resolved to 1 before select where was
1566
1763
found table as depended (of select where was found table)
1568
for (Select_Lex *s= this;
1765
for (SELECT_LEX *s= this;
1569
1766
s && s != last;
1570
1767
s= s->outer_select())
1572
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1769
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1574
1771
// Select is dependent of outer select
1575
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1576
s->uncacheable.set(UNCACHEABLE_UNITED);
1577
Select_Lex_Unit *munit= s->master_unit();
1578
munit->uncacheable.set(UNCACHEABLE_UNITED);
1579
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1580
for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1772
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1773
UNCACHEABLE_DEPENDENT;
1774
SELECT_LEX_UNIT *munit= s->master_unit();
1775
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1776
UNCACHEABLE_DEPENDENT;
1777
for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1583
! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1584
sl->uncacheable.set(UNCACHEABLE_UNITED);
1780
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1781
sl->uncacheable|= UNCACHEABLE_UNITED;
1587
1784
s->is_correlated= true;
1594
bool Select_Lex_Node::set_braces(bool)
1597
bool Select_Lex_Node::inc_in_sum_expr()
1600
uint32_t Select_Lex_Node::get_in_sum_expr()
1603
TableList* Select_Lex_Node::get_table_list()
1606
List<Item>* Select_Lex_Node::get_item_list()
1609
TableList *Select_Lex_Node::add_table_to_list(Session *,
1612
const bitset<NUM_OF_TABLE_OPTIONS>&,
1791
bool st_select_lex_node::set_braces(bool)
1793
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1794
uint32_t st_select_lex_node::get_in_sum_expr() { return 0; }
1795
TableList* st_select_lex_node::get_table_list() { return 0; }
1796
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1797
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1798
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1802
uint32_t st_select_lex_node::get_table_join_options()
1622
1808
prohibit using LIMIT clause
1624
bool Select_Lex::test_limit()
1810
bool st_select_lex::test_limit()
1626
1812
if (select_limit != 0)
1628
1814
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1629
1815
"LIMIT & IN/ALL/ANY/SOME subquery");
1635
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1640
Select_Lex* Select_Lex_Unit::outer_select()
1642
return (Select_Lex*) master;
1645
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1822
st_select_lex_unit* st_select_lex_unit::master_unit()
1828
st_select_lex* st_select_lex_unit::outer_select()
1830
return (st_select_lex*) master;
1834
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1647
1836
return add_to_list(session, order_list, item, asc);
1650
bool Select_Lex::add_item_to_list(Session *, Item *item)
1840
bool st_select_lex::add_item_to_list(Session *, Item *item)
1652
1842
return(item_list.push_back(item));
1655
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1846
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1657
1848
return add_to_list(session, group_list, item, asc);
1660
Select_Lex_Unit* Select_Lex::master_unit()
1662
return (Select_Lex_Unit*) master;
1665
Select_Lex* Select_Lex::outer_select()
1667
return (Select_Lex*) master->get_master();
1670
bool Select_Lex::set_braces(bool value)
1852
st_select_lex_unit* st_select_lex::master_unit()
1854
return (st_select_lex_unit*) master;
1858
st_select_lex* st_select_lex::outer_select()
1860
return (st_select_lex*) master->get_master();
1864
bool st_select_lex::set_braces(bool value)
1676
bool Select_Lex::inc_in_sum_expr()
1871
bool st_select_lex::inc_in_sum_expr()
1682
uint32_t Select_Lex::get_in_sum_expr()
1878
uint32_t st_select_lex::get_in_sum_expr()
1684
1880
return in_sum_expr;
1687
TableList* Select_Lex::get_table_list()
1884
TableList* st_select_lex::get_table_list()
1689
1886
return (TableList*) table_list.first;
1692
List<Item>* Select_Lex::get_item_list()
1889
List<Item>* st_select_lex::get_item_list()
1694
1891
return &item_list;
1698
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1894
uint32_t st_select_lex::get_table_join_options()
1896
return table_join_options;
1900
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1700
1902
if (ref_pointer_array)
1703
1905
return (ref_pointer_array=
1704
1906
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +