17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
21
20
#define DRIZZLE_LEX 1
23
#include <drizzled/sql_reserved_words.h>
25
#include <drizzled/configmake.h>
26
#include <drizzled/item/num.h>
27
#include <drizzled/error.h>
28
#include <drizzled/session.h>
29
#include <drizzled/sql_base.h>
30
#include <drizzled/lookup_symbol.h>
31
#include <drizzled/index_hint.h>
32
#include <drizzled/select_result.h>
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"
39
32
using namespace std;
41
34
/* Stay outside of the namespace because otherwise bison goes nuts */
42
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
35
int DRIZZLElex(void *arg, void *yysession);
47
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
40
static int lex_one_token(void *arg, void *yysession);
50
43
save order by and tables in own lists.
52
45
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
56
if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
48
if (!(order = (order_st *) session->alloc(sizeof(order_st))))
59
50
order->item_ptr= item;
60
51
order->item= &order->item_ptr;
64
55
order->counter_used= 0;
65
list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
56
list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
125
115
(m_buf_length / default_charset_info->mbminlen) *
126
116
my_charset_utf8_bin.mbmaxlen;
128
m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
118
m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
129
119
m_body_utf8_ptr= m_body_utf8;
130
120
*m_body_utf8_ptr= 0;
216
206
Because of this, it's critical to not do too much things here.
217
207
(We already do too much here)
219
void LEX::start(Session *arg)
224
209
void lex_start(Session *session)
226
LEX *lex= session->getLex();
211
LEX *lex= session->lex;
228
213
lex->session= lex->unit.session= session;
230
lex->context_stack.clear();
215
lex->context_stack.empty();
231
216
lex->unit.init_query();
232
217
lex->unit.init_select();
233
218
/* 'parent_lex' is used in init_query() so it must be before it. */
234
219
lex->select_lex.parent_lex= lex;
235
220
lex->select_lex.init_query();
236
lex->value_list.clear();
237
lex->update_list.clear();
238
lex->auxiliary_table_list.clear();
221
lex->value_list.empty();
222
lex->update_list.empty();
223
lex->auxiliary_table_list.empty();
239
224
lex->unit.next= lex->unit.master=
240
225
lex->unit.link_next= lex->unit.return_to= 0;
241
226
lex->unit.prev= lex->unit.link_prev= 0;
247
232
lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
248
233
lex->select_lex.options= 0;
249
234
lex->select_lex.init_order();
250
lex->select_lex.group_list.clear();
235
lex->select_lex.group_list.empty();
251
236
lex->describe= 0;
252
237
lex->derived_tables= 0;
253
238
lex->lock_option= TL_READ;
254
239
lex->leaf_tables_insert= 0;
255
lex->var_list.clear();
256
240
lex->select_lex.select_number= 1;
258
242
lex->select_lex.in_sum_expr=0;
259
lex->select_lex.group_list.clear();
260
lex->select_lex.order_list.clear();
243
lex->select_lex.group_list.empty();
244
lex->select_lex.order_list.empty();
261
245
lex->sql_command= SQLCOM_END;
262
246
lex->duplicates= DUP_ERROR;
361
346
lip->yyUnget(); // ptr points now after last token char
362
347
tmp.length= lip->yytoklen=length;
363
tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
348
tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
364
349
from= lip->get_tok_start() + skip;
388
373
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
375
register unsigned char c,sep;
391
376
bool found_escape= false;
392
377
const CHARSET_INFO * const cs= lip->m_session->charset();
437
422
assert(end >= str);
439
if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
424
if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
440
425
return (char*) ""; // memory::SqlAlloc has set error flag
442
427
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
603
588
} /* namespace drizzled */
605
base_sql_lex remember the following states from the following sql_baselex()
590
DRIZZLElex remember the following states from the following DRIZZLElex()
607
592
- MY_LEX_EOQ Found end of query
608
593
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
609
594
(which can't be followed by a signed number)
611
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
596
int DRIZZLElex(void *arg, void *yysession)
598
drizzled::Session *session= (drizzled::Session *)yysession;
613
599
drizzled::Lex_input_stream *lip= session->m_lip;
600
YYSTYPE *yylval=(YYSTYPE*) arg;
616
603
if (lip->lookahead_token != END_OF_INPUT)
637
624
to transform the grammar into a LALR(1) grammar,
638
625
which sql_yacc.yy can process.
640
token= drizzled::lex_one_token(yylval, session);
627
token= drizzled::lex_one_token(arg, yysession);
641
628
if (token == ROLLUP_SYM)
643
630
return WITH_ROLLUP_SYM;
662
649
namespace drizzled
665
int lex_one_token(ParserType *yylval, drizzled::Session *session)
652
int lex_one_token(void *arg, void *yysession)
667
unsigned char c= 0; /* Just set to shutup GCC */
654
register unsigned char c= 0; /* Just set to shutup GCC */
668
655
bool comment_closed;
669
656
int tokval, result_state;
670
657
unsigned int length;
671
658
enum my_lex_states state;
659
Session *session= (Session *)yysession;
672
660
Lex_input_stream *lip= session->m_lip;
673
LEX *lex= session->getLex();
661
LEX *lex= session->lex;
662
YYSTYPE *yylval=(YYSTYPE*) arg;
674
663
const CHARSET_INFO * const cs= session->charset();
675
664
unsigned char *state_map= cs->state_map;
676
665
unsigned char *ident_map= cs->ident_map;
1342
1331
void Select_Lex::init_query()
1344
1333
Select_Lex_Node::init_query();
1346
top_join_list.clear();
1335
top_join_list.empty();
1347
1336
join_list= &top_join_list;
1348
1337
embedding= leaf_tables= 0;
1351
1340
having= where= 0;
1352
1341
olap= UNSPECIFIED_OLAP_TYPE;
1395
1384
select_limit= 0; /* denotes the default limit = HA_POS_ERROR */
1396
1385
offset_limit= 0; /* denotes the default offset = 0 */
1397
1386
with_sum_func= 0;
1399
1387
is_correlated= 0;
1400
1388
cur_pos_in_select_list= UNDEF_POS;
1401
non_agg_fields.clear();
1389
non_agg_fields.empty();
1402
1390
cond_value= having_value= Item::COND_UNDEF;
1403
inner_refs_list.clear();
1391
inner_refs_list.empty();
1404
1392
full_group_by_flag.reset();
1744
1732
str->append(STRING_WITH_LEN(" order by "));
1745
1733
fake_select_lex->print_order(
1747
(Order *) fake_select_lex->order_list.first,
1735
(order_st *) fake_select_lex->order_list.first,
1750
1738
fake_select_lex->print_limit(session, str, query_type);
1803
@brief Restore the LEX and Session in case of a parse error.
1805
This is a clean up call that is invoked by the Bison generated
1806
parser before returning an error from DRIZZLEparse. If your
1807
semantic actions manipulate with the global thread state (which
1808
is a very bad practice and should not normally be employed) and
1809
need a clean-up in case of error, and you can not use %destructor
1810
rule in the grammar file itself, this function should be used
1811
to implement the clean up.
1813
void LEX::cleanup_lex_after_parse_error(Session *)
1816
delete _create_table;
2068
2062
void LEX::cleanup_after_one_table_open()
2071
session->getLex()->derived_tables & additional units may be set if we open
2072
a view. It is necessary to clear session->getLex()->derived_tables flag
2065
session->lex->derived_tables & additional units may be set if we open
2066
a view. It is necessary to clear session->lex->derived_tables flag
2073
2067
to prevent processing of derived tables during next openTablesLock
2074
2068
if next table is a real table and cleanup & remove underlying units
2075
NOTE: all units will be connected to session->getLex()->select_lex, because we
2069
NOTE: all units will be connected to session->lex->select_lex, because we
2076
2070
have not UNION on most upper level.
2078
2072
if (all_selects_list != &select_lex)
2159
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
2161
if (sql_reserved_words::in_word_set(string.str, string.length))
2167
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
2169
if (sql_reserved_words::in_word_set(string.str, string.length))
2176
2153
} /* namespace drizzled */