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 */
21
19
#define DRIZZLE_LEX 1
23
#include "drizzled/sql_reserved_words.h"
25
#include "drizzled/configmake.h"
20
#include "drizzled/server_includes.h"
26
21
#include "drizzled/item/num.h"
27
22
#include "drizzled/error.h"
28
23
#include "drizzled/session.h"
30
25
#include "drizzled/lookup_symbol.h"
31
26
#include "drizzled/index_hint.h"
36
30
using namespace std;
38
/* Stay outside of the namespace because otherwise bison goes nuts */
32
static int lex_one_token(void *arg, void *yysession);
39
33
int DRIZZLElex(void *arg, void *yysession);
44
static int lex_one_token(void *arg, void *yysession);
47
36
save order by and tables in own lists.
49
38
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
53
if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
41
if (!(order = (order_st *) session->alloc(sizeof(order_st))))
56
43
order->item_ptr= item;
57
44
order->item= &order->item_ptr;
61
48
order->counter_used= 0;
62
list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
49
list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
56
We are using pointer to this variable for distinguishing between assignment
57
to NEW row field (when parsing trigger definition) and structured variable.
59
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
68
62
LEX_STRING constant for null-string to be used in parser and other places.
93
87
m_cpp_utf8_processed_ptr(NULL),
94
88
next_state(MY_LEX_START),
89
found_semicolon(NULL),
96
91
in_comment(NO_COMMENT)
98
m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
93
m_cpp_buf= (char*) session->alloc(length + 1);
99
94
m_cpp_ptr= m_cpp_buf;
122
117
(m_buf_length / default_charset_info->mbminlen) *
123
118
my_charset_utf8_bin.mbmaxlen;
125
m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
120
m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
126
121
m_body_utf8_ptr= m_body_utf8;
127
122
*m_body_utf8_ptr= 0;
232
222
lex->select_lex.init_query();
233
223
lex->value_list.empty();
234
224
lex->update_list.empty();
225
lex->param_list.empty();
235
226
lex->auxiliary_table_list.empty();
236
227
lex->unit.next= lex->unit.master=
237
228
lex->unit.link_next= lex->unit.return_to= 0;
269
259
lex->nest_level=0 ;
270
260
lex->allow_sum_func= 0;
271
261
lex->in_sum_func= NULL;
274
263
lex->is_lex_started= true;
264
lex->create_table_proto= NULL;
275
265
lex->statement= NULL;
277
lex->is_cross= false;
268
void lex_end(LEX *lex)
272
free(lex->yacc_yyss);
273
free(lex->yacc_yyvs);
292
delete _create_table;
280
if(lex->create_table_proto)
281
delete lex->create_table_proto;
285
delete lex->statement;
303
288
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
359
344
lip->yyUnget(); // ptr points now after last token char
360
345
tmp.length= lip->yytoklen=length;
361
tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
346
tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
362
347
from= lip->get_tok_start() + skip;
435
420
assert(end >= str);
437
if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
438
return (char*) ""; // memory::SqlAlloc has set error flag
422
if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
423
return (char*) ""; // Sql_alloc has set error flag
440
425
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
441
426
lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
609
593
int DRIZZLElex(void *arg, void *yysession)
611
drizzled::Session *session= (drizzled::Session *)yysession;
612
drizzled::Lex_input_stream *lip= session->m_lip;
595
Session *session= (Session *)yysession;
596
Lex_input_stream *lip= session->m_lip;
613
597
YYSTYPE *yylval=(YYSTYPE*) arg;
637
621
to transform the grammar into a LALR(1) grammar,
638
622
which sql_yacc.yy can process.
640
token= drizzled::lex_one_token(arg, yysession);
624
token= lex_one_token(arg, yysession);
641
625
if (token == ROLLUP_SYM)
643
627
return WITH_ROLLUP_SYM;
1269
Construct a copy of this object to be used for mysql_alter_table
1270
and mysql_create_table.
1272
Historically, these two functions modify their Alter_info
1273
arguments. This behaviour breaks re-execution of prepared
1274
statements and stored procedures and is compensated by always
1275
supplying a copy of Alter_info to these functions.
1277
@return You need to use check the error in Session for out
1278
of memory condition after calling this function.
1280
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1281
:drop_list(rhs.drop_list, mem_root),
1282
alter_list(rhs.alter_list, mem_root),
1283
key_list(rhs.key_list, mem_root),
1284
create_list(rhs.create_list, mem_root),
1286
keys_onoff(rhs.keys_onoff),
1287
tablespace_op(rhs.tablespace_op),
1288
no_parts(rhs.no_parts),
1289
build_method(rhs.build_method),
1290
datetime_field(rhs.datetime_field),
1291
error_if_not_empty(rhs.error_if_not_empty)
1294
Make deep copies of used objects.
1295
This is not a fully deep copy - clone() implementations
1296
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1297
do not copy string constants. At the same length the only
1298
reason we make a copy currently is that ALTER/CREATE TABLE
1299
code changes input Alter_info definitions, but string
1300
constants never change.
1302
list_copy_and_replace_each_value(drop_list, mem_root);
1303
list_copy_and_replace_each_value(alter_list, mem_root);
1304
list_copy_and_replace_each_value(key_list, mem_root);
1305
list_copy_and_replace_each_value(create_list, mem_root);
1287
1308
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1581
1602
s && s != last;
1582
1603
s= s->outer_select())
1584
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1605
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1586
1607
// Select is dependent of outer select
1587
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1588
s->uncacheable.set(UNCACHEABLE_UNITED);
1608
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1609
UNCACHEABLE_DEPENDENT;
1589
1610
Select_Lex_Unit *munit= s->master_unit();
1590
munit->uncacheable.set(UNCACHEABLE_UNITED);
1591
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1611
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1612
UNCACHEABLE_DEPENDENT;
1592
1613
for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1595
! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1596
sl->uncacheable.set(UNCACHEABLE_UNITED);
1616
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1617
sl->uncacheable|= UNCACHEABLE_UNITED;
1599
1620
s->is_correlated= true;
1618
1639
List<Item>* Select_Lex_Node::get_item_list()
1619
1640
{ return NULL; }
1621
TableList *Select_Lex_Node::add_table_to_list(Session *,
1624
const bitset<NUM_OF_TABLE_OPTIONS>&,
1642
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1643
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1648
uint32_t Select_Lex_Node::get_table_join_options()
1634
1654
prohibit using LIMIT clause
1746
1770
str->append(STRING_WITH_LEN(" order by "));
1747
1771
fake_select_lex->print_order(
1749
(Order *) fake_select_lex->order_list.first,
1773
(order_st *) fake_select_lex->order_list.first,
1752
1776
fake_select_lex->print_limit(session, str, query_type);
1841
@brief Restore the LEX and Session in case of a parse error.
1843
This is a clean up call that is invoked by the Bison generated
1844
parser before returning an error from DRIZZLEparse. If your
1845
semantic actions manipulate with the global thread state (which
1846
is a very bad practice and should not normally be employed) and
1847
need a clean-up in case of error, and you can not use %destructor
1848
rule in the grammar file itself, this function should be used
1849
to implement the clean up.
1851
void LEX::cleanup_lex_after_parse_error(Session *)
1818
delete _create_table;
1865
1899
statement parsing. On should use lex_start() function to prepare LEX
1875
sql_command(SQLCOM_END),
1877
option_type(OPT_DEFAULT),
1880
sum_expr_used(false),
1881
_create_table(NULL),
1882
_create_field(NULL),
1903
:result(0), yacc_yyss(0), yacc_yyvs(0),
1904
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1885
1906
reset_query_tables_list(true);
1907
create_table_proto= NULL;
1912
Detect that we need only table structure of derived table/view
1915
only_view_structure()
1918
true yes, we need only structure
1919
false no, we need data
1921
bool LEX::only_view_structure()
1923
switch (sql_command) {
1924
case SQLCOM_SHOW_CREATE:
1925
case SQLCOM_SHOW_TABLES:
1926
case SQLCOM_SHOW_FIELDS:
1934
Should Items_ident be printed correctly
1937
need_correct_ident()
1940
true yes, we need only structure
1941
false no, we need data
1943
bool LEX::need_correct_ident()
1947
case SQLCOM_SHOW_CREATE:
1948
case SQLCOM_SHOW_TABLES:
2157
2224
current_index_hint_clause,
2161
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
2163
if (sql_reserved_words::in_word_set(string.str, string.length))
2169
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
2171
if (sql_reserved_words::in_word_set(string.str, string.length))
2178
} /* namespace drizzled */