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
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
31
using namespace std;
41
33
/* Stay outside of the namespace because otherwise bison goes nuts */
42
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
34
int DRIZZLElex(void *arg, void *yysession);
47
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
39
static int lex_one_token(void *arg, void *yysession);
50
42
save order by and tables in own lists.
52
44
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
56
if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
47
if (!(order = (order_st *) session->alloc(sizeof(order_st))))
59
49
order->item_ptr= item;
60
50
order->item= &order->item_ptr;
64
54
order->counter_used= 0;
65
list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
55
list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
125
114
(m_buf_length / default_charset_info->mbminlen) *
126
115
my_charset_utf8_bin.mbmaxlen;
128
m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
117
m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
129
118
m_body_utf8_ptr= m_body_utf8;
130
119
*m_body_utf8_ptr= 0;
216
205
Because of this, it's critical to not do too much things here.
217
206
(We already do too much here)
219
void LEX::start(Session *arg)
224
208
void lex_start(Session *session)
226
LEX *lex= session->getLex();
210
LEX *lex= session->lex;
228
212
lex->session= lex->unit.session= session;
230
lex->context_stack.clear();
214
lex->context_stack.empty();
231
215
lex->unit.init_query();
232
216
lex->unit.init_select();
233
217
/* 'parent_lex' is used in init_query() so it must be before it. */
234
218
lex->select_lex.parent_lex= lex;
235
219
lex->select_lex.init_query();
236
lex->value_list.clear();
237
lex->update_list.clear();
238
lex->auxiliary_table_list.clear();
220
lex->value_list.empty();
221
lex->update_list.empty();
222
lex->auxiliary_table_list.empty();
239
223
lex->unit.next= lex->unit.master=
240
224
lex->unit.link_next= lex->unit.return_to= 0;
241
225
lex->unit.prev= lex->unit.link_prev= 0;
247
231
lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
248
232
lex->select_lex.options= 0;
249
233
lex->select_lex.init_order();
250
lex->select_lex.group_list.clear();
234
lex->select_lex.group_list.empty();
251
235
lex->describe= 0;
252
236
lex->derived_tables= 0;
253
237
lex->lock_option= TL_READ;
254
238
lex->leaf_tables_insert= 0;
255
lex->var_list.clear();
256
239
lex->select_lex.select_number= 1;
258
241
lex->select_lex.in_sum_expr=0;
259
lex->select_lex.group_list.clear();
260
lex->select_lex.order_list.clear();
242
lex->select_lex.group_list.empty();
243
lex->select_lex.order_list.empty();
261
244
lex->sql_command= SQLCOM_END;
262
245
lex->duplicates= DUP_ERROR;
361
337
lip->yyUnget(); // ptr points now after last token char
362
338
tmp.length= lip->yytoklen=length;
363
tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
339
tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
364
340
from= lip->get_tok_start() + skip;
388
364
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
366
register unsigned char c,sep;
391
367
bool found_escape= false;
392
368
const CHARSET_INFO * const cs= lip->m_session->charset();
603
579
} /* namespace drizzled */
605
base_sql_lex remember the following states from the following sql_baselex()
581
DRIZZLElex remember the following states from the following DRIZZLElex()
607
583
- MY_LEX_EOQ Found end of query
608
584
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
609
585
(which can't be followed by a signed number)
611
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
587
int DRIZZLElex(void *arg, void *yysession)
589
drizzled::Session *session= (drizzled::Session *)yysession;
613
590
drizzled::Lex_input_stream *lip= session->m_lip;
591
YYSTYPE *yylval=(YYSTYPE*) arg;
616
594
if (lip->lookahead_token != END_OF_INPUT)
637
615
to transform the grammar into a LALR(1) grammar,
638
616
which sql_yacc.yy can process.
640
token= drizzled::lex_one_token(yylval, session);
618
token= drizzled::lex_one_token(arg, yysession);
641
619
if (token == ROLLUP_SYM)
643
621
return WITH_ROLLUP_SYM;
662
640
namespace drizzled
665
int lex_one_token(ParserType *yylval, drizzled::Session *session)
643
int lex_one_token(void *arg, void *yysession)
667
unsigned char c= 0; /* Just set to shutup GCC */
645
register unsigned char c= 0; /* Just set to shutup GCC */
668
646
bool comment_closed;
669
647
int tokval, result_state;
670
648
unsigned int length;
671
649
enum my_lex_states state;
650
Session *session= (Session *)yysession;
672
651
Lex_input_stream *lip= session->m_lip;
673
LEX *lex= session->getLex();
652
LEX *lex= session->lex;
653
YYSTYPE *yylval=(YYSTYPE*) arg;
674
654
const CHARSET_INFO * const cs= session->charset();
675
655
unsigned char *state_map= cs->state_map;
676
656
unsigned char *ident_map= cs->ident_map;
1579
1559
s && s != last;
1580
1560
s= s->outer_select())
1582
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1562
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1584
1564
// Select is dependent of outer select
1585
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1586
s->uncacheable.set(UNCACHEABLE_UNITED);
1565
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1566
UNCACHEABLE_DEPENDENT;
1587
1567
Select_Lex_Unit *munit= s->master_unit();
1588
munit->uncacheable.set(UNCACHEABLE_UNITED);
1589
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1568
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1569
UNCACHEABLE_DEPENDENT;
1590
1570
for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1593
! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1594
sl->uncacheable.set(UNCACHEABLE_UNITED);
1573
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1574
sl->uncacheable|= UNCACHEABLE_UNITED;
1597
1577
s->is_correlated= true;
1616
1596
List<Item>* Select_Lex_Node::get_item_list()
1617
1597
{ return NULL; }
1619
TableList *Select_Lex_Node::add_table_to_list(Session *,
1622
const bitset<NUM_OF_TABLE_OPTIONS>&,
1599
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1600
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1605
uint32_t Select_Lex_Node::get_table_join_options()
1632
1611
prohibit using LIMIT clause
1744
1727
str->append(STRING_WITH_LEN(" order by "));
1745
1728
fake_select_lex->print_order(
1747
(Order *) fake_select_lex->order_list.first,
1730
(order_st *) fake_select_lex->order_list.first,
1750
1733
fake_select_lex->print_limit(session, str, query_type);
1798
@brief Restore the LEX and Session in case of a parse error.
1800
This is a clean up call that is invoked by the Bison generated
1801
parser before returning an error from DRIZZLEparse. If your
1802
semantic actions manipulate with the global thread state (which
1803
is a very bad practice and should not normally be employed) and
1804
need a clean-up in case of error, and you can not use %destructor
1805
rule in the grammar file itself, this function should be used
1806
to implement the clean up.
1808
void LEX::cleanup_lex_after_parse_error(Session *)
1816
delete _create_table;
1863
1856
statement parsing. On should use lex_start() function to prepare LEX
1873
sql_command(SQLCOM_END),
1875
option_type(OPT_DEFAULT),
1878
sum_expr_used(false),
1879
_create_table(NULL),
1880
_create_field(NULL),
1860
:result(0), yacc_yyss(0), yacc_yyvs(0),
1861
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1883
1863
reset_query_tables_list(true);
1868
Detect that we need only table structure of derived table/view
1871
only_view_structure()
1874
true yes, we need only structure
1875
false no, we need data
1877
bool LEX::only_view_structure()
1879
if (sql_command == SQLCOM_SHOW_CREATE)
1886
Should Items_ident be printed correctly
1889
need_correct_ident()
1892
true yes, we need only structure
1893
false no, we need data
1895
bool LEX::need_correct_ident()
1897
if (sql_command== SQLCOM_SHOW_CREATE)
2068
2085
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
2088
session->lex->derived_tables & additional units may be set if we open
2089
a view. It is necessary to clear session->lex->derived_tables flag
2073
2090
to prevent processing of derived tables during next openTablesLock
2074
2091
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
2092
NOTE: all units will be connected to session->lex->select_lex, because we
2076
2093
have not UNION on most upper level.
2078
2095
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
2176
} /* namespace drizzled */