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
932
while (my_isdigit(cs, (c = lip->yyGet()))) ;
847
933
if (!ident_map[c])
848
934
{ // Can't be identifier
849
state=MY_LEX_INT_OR_REAL;
935
state=MY_LEX_INT_OR_REAL;
852
938
if (c == 'e' || c == 'E')
854
// The following test is written this way to allow numbers of type 1e1
940
// The following test is written this way to allow numbers of type 1e1
855
941
if (my_isdigit(cs,lip->yyPeek()) ||
856
942
(c=(lip->yyGet())) == '+' || c == '-')
858
944
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign
861
947
while (my_isdigit(cs,lip->yyGet())) ;
862
948
yylval->lex_str=get_token(lip, 0, lip->yyLength());
869
955
case MY_LEX_IDENT_START: // We come here after '.'
870
956
result_state= IDENT;
957
#if defined(USE_MB) && defined(USE_MB_IDENT)
873
result_state= IDENT_QUOTED;
960
result_state= IDENT_QUOTED;
874
961
while (ident_map[c=lip->yyGet()])
876
963
if (my_mbcharlen(cs, c) > 1)
878
int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
966
if ((l = my_ismbchar(cs,
968
lip->get_end_of_query())) == 0)
881
970
lip->skip_binary(l-1);
887
977
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
888
978
/* If there were non-ASCII characters, mark that we must convert */
889
979
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
891
981
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
892
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
982
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
894
984
yylval->lex_str= get_token(lip, 0, lip->yyLength());
896
986
lip->body_utf8_append(lip->m_cpp_text_start);
898
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
988
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
989
lip->m_cpp_text_end);
900
991
return(result_state);
1253
1367
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1256
lip->next_state=MY_LEX_IDENT_SEP;
1370
lip->next_state=MY_LEX_IDENT_SEP;
1257
1371
length= lip->yyLength();
1258
1372
if (length == 0)
1259
1373
return(ABORT_SYM); // Names must be nonempty.
1260
1374
if ((tokval= find_keyword(lip, length,0)))
1262
1376
lip->yyUnget(); // Put back 'c'
1263
return(tokval); // Was keyword
1377
return(tokval); // Was keyword
1265
1379
yylval->lex_str=get_token(lip, 0, length);
1267
1381
lip->body_utf8_append(lip->m_cpp_text_start);
1269
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1383
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1384
lip->m_cpp_text_end);
1271
1386
return(result_state);
1393
Construct a copy of this object to be used for mysql_alter_table
1394
and mysql_create_table.
1396
Historically, these two functions modify their Alter_info
1397
arguments. This behaviour breaks re-execution of prepared
1398
statements and stored procedures and is compensated by always
1399
supplying a copy of Alter_info to these functions.
1401
@return You need to use check the error in Session for out
1402
of memory condition after calling this function.
1405
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1406
:drop_list(rhs.drop_list, mem_root),
1407
alter_list(rhs.alter_list, mem_root),
1408
key_list(rhs.key_list, mem_root),
1409
create_list(rhs.create_list, mem_root),
1411
keys_onoff(rhs.keys_onoff),
1412
tablespace_op(rhs.tablespace_op),
1413
no_parts(rhs.no_parts),
1414
build_method(rhs.build_method),
1415
datetime_field(rhs.datetime_field),
1416
error_if_not_empty(rhs.error_if_not_empty)
1419
Make deep copies of used objects.
1420
This is not a fully deep copy - clone() implementations
1421
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1422
do not copy string constants. At the same length the only
1423
reason we make a copy currently is that ALTER/CREATE TABLE
1424
code changes input Alter_info definitions, but string
1425
constants never change.
1427
list_copy_and_replace_each_value(drop_list, mem_root);
1428
list_copy_and_replace_each_value(alter_list, mem_root);
1429
list_copy_and_replace_each_value(key_list, mem_root);
1430
list_copy_and_replace_each_value(create_list, mem_root);
1276
1434
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1552
1721
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)
1726
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
1727
this to 'last' as dependent
1730
last - pointer to last st_select_lex struct, before wich all
1731
st_select_lex have to be marked as dependent
1734
'last' should be reachable from this st_select_lex_node
1737
void st_select_lex::mark_as_dependent(st_select_lex *last)
1565
1740
Mark all selects from resolved to 1 before select where was
1566
1741
found table as depended (of select where was found table)
1568
for (Select_Lex *s= this;
1743
for (SELECT_LEX *s= this;
1569
1744
s && s != last;
1570
1745
s= s->outer_select())
1572
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1747
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1574
1749
// 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())
1750
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1751
UNCACHEABLE_DEPENDENT;
1752
SELECT_LEX_UNIT *munit= s->master_unit();
1753
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1754
UNCACHEABLE_DEPENDENT;
1755
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);
1758
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1759
sl->uncacheable|= UNCACHEABLE_UNITED;
1587
1762
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>&,
1769
bool st_select_lex_node::set_braces(bool)
1771
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1772
uint32_t st_select_lex_node::get_in_sum_expr() { return 0; }
1773
TableList* st_select_lex_node::get_table_list() { return 0; }
1774
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1775
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1776
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1780
uint32_t st_select_lex_node::get_table_join_options()
1622
1786
prohibit using LIMIT clause
1624
bool Select_Lex::test_limit()
1788
bool st_select_lex::test_limit()
1626
1790
if (select_limit != 0)
1628
1792
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1629
1793
"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)
1800
st_select_lex_unit* st_select_lex_unit::master_unit()
1806
st_select_lex* st_select_lex_unit::outer_select()
1808
return (st_select_lex*) master;
1812
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1647
1814
return add_to_list(session, order_list, item, asc);
1650
bool Select_Lex::add_item_to_list(Session *, Item *item)
1818
bool st_select_lex::add_item_to_list(Session *, Item *item)
1652
1820
return(item_list.push_back(item));
1655
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1824
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1657
1826
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)
1830
st_select_lex_unit* st_select_lex::master_unit()
1832
return (st_select_lex_unit*) master;
1836
st_select_lex* st_select_lex::outer_select()
1838
return (st_select_lex*) master->get_master();
1842
bool st_select_lex::set_braces(bool value)
1676
bool Select_Lex::inc_in_sum_expr()
1849
bool st_select_lex::inc_in_sum_expr()
1682
uint32_t Select_Lex::get_in_sum_expr()
1856
uint32_t st_select_lex::get_in_sum_expr()
1684
1858
return in_sum_expr;
1687
TableList* Select_Lex::get_table_list()
1862
TableList* st_select_lex::get_table_list()
1689
1864
return (TableList*) table_list.first;
1692
List<Item>* Select_Lex::get_item_list()
1867
List<Item>* st_select_lex::get_item_list()
1694
1869
return &item_list;
1698
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1872
uint32_t st_select_lex::get_table_join_options()
1874
return table_join_options;
1878
bool st_select_lex::setup_ref_array(Session *session, uint32_t order_group_num)
1700
1880
if (ref_pointer_array)
1703
1883
return (ref_pointer_array=
1704
1884
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +