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"
20
#include "drizzled/server_includes.h"
22
21
#include "drizzled/item/num.h"
23
22
#include "drizzled/error.h"
24
23
#include "drizzled/session.h"
26
25
#include "drizzled/lookup_symbol.h"
27
26
#include "drizzled/index_hint.h"
32
30
using namespace std;
34
/* Stay outside of the namespace because otherwise bison goes nuts */
35
int DRIZZLElex(void *arg, void *yysession);
40
32
static int lex_one_token(void *arg, void *yysession);
43
save order by and tables in own lists.
35
We are using pointer to this variable for distinguishing between assignment
36
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);
38
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
61
41
LEX_STRING constant for null-string to be used in parser and other places.
186
168
m_cpp_utf8_processed_ptr will be set in the end of the
189
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
171
void Lex_input_stream::body_utf8_append_literal(Session *session,
172
const LEX_STRING *txt,
173
const CHARSET_INFO * const txt_cs,
190
174
const char *end_ptr)
192
176
if (!m_cpp_utf8_processed_ptr)
181
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
183
session->convert_string(&utf_txt,
184
&my_charset_utf8_general_ci,
185
txt->str, txt->length,
190
utf_txt.str= txt->str;
191
utf_txt.length= txt->length;
195
194
/* NOTE: utf_txt.length is in bytes, not in symbols. */
197
memcpy(m_body_utf8_ptr, txt->str, txt->length);
198
m_body_utf8_ptr += txt->length;
196
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
197
m_body_utf8_ptr += utf_txt.length;
199
198
*m_body_utf8_ptr= 0;
201
200
m_cpp_utf8_processed_ptr= end_ptr;
263
258
lex->in_sum_func= NULL;
265
260
lex->is_lex_started= true;
266
lex->statement= NULL;
268
lex->is_cross= false;
261
lex->create_table_proto= NULL;
264
void lex_end(LEX *lex)
268
free(lex->yacc_yyss);
269
free(lex->yacc_yyvs);
276
if(lex->create_table_proto)
277
delete lex->create_table_proto;
292
281
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
598
590
int DRIZZLElex(void *arg, void *yysession)
600
drizzled::Session *session= (drizzled::Session *)yysession;
601
drizzled::Lex_input_stream *lip= session->m_lip;
592
Session *session= (Session *)yysession;
593
Lex_input_stream *lip= session->m_lip;
602
594
YYSTYPE *yylval=(YYSTYPE*) arg;
798
789
lip->body_utf8_append(lip->m_cpp_text_start);
800
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
791
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
792
lip->m_cpp_text_end);
802
794
return(result_state); // IDENT or IDENT_QUOTED
929
926
lip->yySkip(); // Skip end `
930
927
lip->next_state= MY_LEX_START;
931
928
lip->body_utf8_append(lip->m_cpp_text_start);
932
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
929
lip->body_utf8_append_literal(session, &yylval->lex_str, cs, lip->m_cpp_text_end);
933
930
return(IDENT_QUOTED);
935
932
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
1042
1039
lip->body_utf8_append(lip->m_cpp_text_start);
1044
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1041
lip->body_utf8_append_literal(session, &yylval->lex_str,
1042
lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1043
lip->m_cpp_text_end);
1045
lip->m_underscore_cs= NULL;
1046
1047
lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1047
1048
return(TEXT_STRING);
1176
1177
case MY_LEX_SEMICOLON: // optional line terminator
1177
1178
if (lip->yyPeek())
1180
if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
1182
lip->found_semicolon= lip->get_ptr();
1183
session->server_status|= SERVER_MORE_RESULTS_EXISTS;
1184
lip->next_state= MY_LEX_END;
1185
lip->set_echo(true);
1186
return (END_OF_INPUT);
1179
1188
state= MY_LEX_CHAR; // Return ';'
1267
1276
lip->body_utf8_append(lip->m_cpp_text_start);
1269
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1278
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1279
lip->m_cpp_text_end);
1271
1281
return(result_state);
1287
Construct a copy of this object to be used for mysql_alter_table
1288
and mysql_create_table.
1290
Historically, these two functions modify their Alter_info
1291
arguments. This behaviour breaks re-execution of prepared
1292
statements and stored procedures and is compensated by always
1293
supplying a copy of Alter_info to these functions.
1295
@return You need to use check the error in Session for out
1296
of memory condition after calling this function.
1298
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1299
:drop_list(rhs.drop_list, mem_root),
1300
alter_list(rhs.alter_list, mem_root),
1301
key_list(rhs.key_list, mem_root),
1302
create_list(rhs.create_list, mem_root),
1304
keys_onoff(rhs.keys_onoff),
1305
tablespace_op(rhs.tablespace_op),
1306
no_parts(rhs.no_parts),
1307
build_method(rhs.build_method),
1308
datetime_field(rhs.datetime_field),
1309
error_if_not_empty(rhs.error_if_not_empty)
1312
Make deep copies of used objects.
1313
This is not a fully deep copy - clone() implementations
1314
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1315
do not copy string constants. At the same length the only
1316
reason we make a copy currently is that ALTER/CREATE TABLE
1317
code changes input Alter_info definitions, but string
1318
constants never change.
1320
list_copy_and_replace_each_value(drop_list, mem_root);
1321
list_copy_and_replace_each_value(alter_list, mem_root);
1322
list_copy_and_replace_each_value(key_list, mem_root);
1323
list_copy_and_replace_each_value(create_list, mem_root);
1276
1326
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1569
1620
s && s != last;
1570
1621
s= s->outer_select())
1572
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1623
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1574
1625
// Select is dependent of outer select
1575
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1576
s->uncacheable.set(UNCACHEABLE_UNITED);
1626
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1627
UNCACHEABLE_DEPENDENT;
1577
1628
Select_Lex_Unit *munit= s->master_unit();
1578
munit->uncacheable.set(UNCACHEABLE_UNITED);
1579
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1629
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1630
UNCACHEABLE_DEPENDENT;
1580
1631
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);
1634
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1635
sl->uncacheable|= UNCACHEABLE_UNITED;
1587
1638
s->is_correlated= true;
1606
1657
List<Item>* Select_Lex_Node::get_item_list()
1607
1658
{ return NULL; }
1609
TableList *Select_Lex_Node::add_table_to_list(Session *,
1612
const bitset<NUM_OF_TABLE_OPTIONS>&,
1660
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1661
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1666
uint32_t Select_Lex_Node::get_table_join_options()
1622
1672
prohibit using LIMIT clause
1734
1788
str->append(STRING_WITH_LEN(" order by "));
1735
1789
fake_select_lex->print_order(
1737
(Order *) fake_select_lex->order_list.first,
1791
(order_st *) fake_select_lex->order_list.first,
1740
1794
fake_select_lex->print_limit(session, str, query_type);
1872
sql_command(SQLCOM_END),
1873
option_type(OPT_DEFAULT),
1876
sum_expr_used(false)
1921
:result(0), yacc_yyss(0), yacc_yyvs(0),
1922
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1878
1924
reset_query_tables_list(true);
1925
create_table_proto= NULL;
1929
Detect that we need only table structure of derived table/view
1932
only_view_structure()
1935
true yes, we need only structure
1936
false no, we need data
1938
bool LEX::only_view_structure()
1940
switch (sql_command) {
1941
case SQLCOM_SHOW_CREATE:
1942
case SQLCOM_SHOW_TABLES:
1943
case SQLCOM_SHOW_FIELDS:
1951
Should Items_ident be printed correctly
1954
need_correct_ident()
1957
true yes, we need only structure
1958
false no, we need data
1960
bool LEX::need_correct_ident()
1964
case SQLCOM_SHOW_CREATE:
1965
case SQLCOM_SHOW_TABLES:
2067
2157
session->lex->derived_tables & additional units may be set if we open
2068
2158
a view. It is necessary to clear session->lex->derived_tables flag
2069
to prevent processing of derived tables during next openTablesLock
2159
to prevent processing of derived tables during next open_and_lock_tables
2070
2160
if next table is a real table and cleanup & remove underlying units
2071
2161
NOTE: all units will be connected to session->lex->select_lex, because we
2072
2162
have not UNION on most upper level.