13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
18
#define DRIZZLE_LEX 1
20
#include <drizzled/item/num.h>
21
#include <drizzled/abort_exception.h>
20
22
#include <drizzled/my_hash.h>
21
23
#include <drizzled/error.h>
22
24
#include <drizzled/nested_join.h>
23
25
#include <drizzled/query_id.h>
24
#include "drizzled/transaction_services.h"
26
#include <drizzled/transaction_services.h>
25
27
#include <drizzled/sql_parse.h>
26
28
#include <drizzled/data_home.h>
27
29
#include <drizzled/sql_base.h>
28
30
#include <drizzled/show.h>
29
#include <drizzled/db.h>
30
31
#include <drizzled/function/time/unix_timestamp.h>
31
32
#include <drizzled/function/get_system_var.h>
32
33
#include <drizzled/item/cmpfunc.h>
33
34
#include <drizzled/item/null.h>
34
35
#include <drizzled/session.h>
36
#include <drizzled/session/cache.h>
35
37
#include <drizzled/sql_load.h>
36
38
#include <drizzled/lock.h>
37
39
#include <drizzled/select_send.h>
38
40
#include <drizzled/plugin/client.h>
39
41
#include <drizzled/statement.h>
40
42
#include <drizzled/statement/alter_table.h>
41
#include "drizzled/probes.h"
42
#include "drizzled/session/cache.h"
43
#include "drizzled/global_charset_info.h"
45
#include "drizzled/plugin/logging.h"
46
#include "drizzled/plugin/query_rewrite.h"
47
#include "drizzled/plugin/query_cache.h"
48
#include "drizzled/plugin/authorization.h"
49
#include "drizzled/optimizer/explain_plan.h"
50
#include "drizzled/pthread_globals.h"
51
#include "drizzled/plugin/event_observer.h"
43
#include <drizzled/probes.h>
44
#include <drizzled/global_charset_info.h>
46
#include <drizzled/plugin/logging.h>
47
#include <drizzled/plugin/query_rewrite.h>
48
#include <drizzled/plugin/query_cache.h>
49
#include <drizzled/plugin/authorization.h>
50
#include <drizzled/optimizer/explain_plan.h>
51
#include <drizzled/pthread_globals.h>
52
#include <drizzled/plugin/event_observer.h>
53
#include <drizzled/visibility.h>
55
#include <drizzled/schema.h>
53
57
#include <limits.h>
56
60
#include <algorithm>
57
61
#include <boost/date_time.hpp>
58
#include "drizzled/internal/my_sys.h"
62
#include <drizzled/internal/my_sys.h>
60
64
using namespace std;
62
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
66
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
68
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
72
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
69
73
static bool parse_sql(Session *session, Lex_input_stream *lip);
70
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
74
void parse(Session *session, const char *inBuf, uint32_t length);
73
77
@defgroup Runtime_Environment Runtime Environment
77
81
extern size_t my_thread_stack_size;
78
82
extern const CHARSET_INFO *character_set_filesystem;
80
const LEX_STRING command_name[COM_END+1]={
81
{ C_STRING_WITH_LEN("Sleep") },
82
{ C_STRING_WITH_LEN("Quit") },
83
{ C_STRING_WITH_LEN("Init DB") },
84
{ C_STRING_WITH_LEN("Query") },
85
{ C_STRING_WITH_LEN("Shutdown") },
86
{ C_STRING_WITH_LEN("Connect") },
87
{ C_STRING_WITH_LEN("Ping") },
88
{ C_STRING_WITH_LEN("Error") } // Last command number
87
static const std::string command_name[COM_END+1]={
95
"Error" // Last command number
91
100
const char *xa_state_names[]={
92
101
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
283
297
case Diagnostics_area::DA_ERROR:
284
298
/* The query failed, send error to log and abort bootstrap. */
285
session->client->sendError(session->main_da.sql_errno(),
299
session->getClient()->sendError(session->main_da.sql_errno(),
286
300
session->main_da.message());
289
303
case Diagnostics_area::DA_EOF:
290
session->client->sendEOF();
304
session->getClient()->sendEOF();
293
307
case Diagnostics_area::DA_OK:
294
session->client->sendOK();
308
session->getClient()->sendOK();
297
311
case Diagnostics_area::DA_DISABLED:
453
468
assert(first_table == all_tables);
454
469
assert(first_table == all_tables && first_table != 0);
456
lex->first_lists_tables_same();
471
session->getLex()->first_lists_tables_same();
457
473
/* should be assigned after making first tables same */
458
all_tables= lex->query_tables;
474
all_tables= session->getLex()->query_tables;
459
476
/* set context for commands which do not use setup_tables */
461
context.resolve_in_table_list_only((TableList*)select_lex->
477
select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
465
480
Reset warning count for each query that uses tables
468
483
variables, but for now this is probably good enough.
469
484
Don't reset warnings when executing a stored routine.
471
if (all_tables || ! lex->is_single_level_stmt())
486
if (all_tables || ! session->getLex()->is_single_level_stmt())
473
488
drizzle_reset_errors(session, 0);
476
491
assert(session->transaction.stmt.hasModifiedNonTransData() == false);
493
if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
494
&& ! session->inTransaction()
495
&& session->getLex()->statement->isTransactional())
497
if (session->startTransaction() == false)
499
my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
478
504
/* now we are ready to execute the statement */
479
res= lex->statement->execute();
505
res= session->getLex()->statement->execute();
480
506
session->set_proc_info("query end");
482
508
The return value for ROW_COUNT() is "implementation dependent" if the
518
557
session->send_explain_fields(result);
519
558
optimizer::ExplainPlan planner;
520
res= planner.explainUnion(session, &session->lex->unit, result);
559
res= planner.explainUnion(session, &session->getLex()->unit, result);
521
560
if (lex->describe & DESCRIBE_EXTENDED)
524
563
String str(buff,(uint32_t) sizeof(buff), system_charset_info);
526
session->lex->unit.print(&str, QT_ORDINARY);
565
session->getLex()->unit.print(&str, QT_ORDINARY);
527
566
str.append('\0');
528
567
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
529
568
ER_YES, str.ptr());
604
mysql_new_select(LEX *lex, bool move_down)
644
new_select(LEX *lex, bool move_down)
606
646
Select_Lex *select_lex;
607
647
Session *session= lex->session;
609
649
if (!(select_lex= new (session->mem_root) Select_Lex()))
611
652
select_lex->select_number= ++session->select_number;
612
653
select_lex->parent_lex= lex; /* Used in init_query. */
613
654
select_lex->init_query();
614
655
select_lex->init_select();
615
656
lex->nest_level++;
616
658
if (lex->nest_level > (int) MAX_SELECT_NESTING)
618
660
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
621
664
select_lex->nest_level= lex->nest_level;
645
688
if (lex->current_select->order_list.first && !lex->current_select->braces)
647
690
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
650
694
select_lex->include_neighbour(lex->current_select);
651
695
Select_Lex_Unit *unit= select_lex->master_unit();
652
if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
697
if (not unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
654
700
select_lex->context.outer_context=
655
701
unit->first_select()->context.outer_context;
676
723
@param var_name Variable name
679
void create_select_for_variable(const char *var_name)
726
void create_select_for_variable(Session *session, const char *var_name)
683
729
LEX_STRING tmp, null_lex_string;
685
731
char buff[MAX_SYS_VAR_LENGTH*2+4+8];
688
session= current_session;
690
mysql_init_select(lex);
734
lex= session->getLex();
691
736
lex->sql_command= SQLCOM_SELECT;
692
737
tmp.str= (char*) var_name;
693
738
tmp.length=strlen(var_name);
714
758
@param length Length of the query text
717
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
761
void parse(Session *session, const char *inBuf, uint32_t length)
719
boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
720
session->lex->start(session);
763
session->getLex()->start(session);
722
765
session->reset_for_next_command();
723
766
/* Check if the Query is Cached if and return true if yes
899
933
TableList *Select_Lex::add_table_to_list(Session *session,
902
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
903
thr_lock_type lock_type,
904
List<Index_hint> *index_hints_arg,
936
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
937
thr_lock_type lock_type,
938
List<Index_hint> *index_hints_arg,
905
939
LEX_STRING *option)
908
942
TableList *previous_table_ref; /* The table preceding the current one. */
910
LEX *lex= session->lex;
944
LEX *lex= session->getLex();
913
947
return NULL; // End of memory
977
1011
tables=tables->next_local)
979
if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
980
!strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1013
if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1014
not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
982
1016
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1117
1151
TableList *Select_Lex::nest_last_join(Session *session)
1119
1153
TableList *ptr;
1120
nested_join_st *nested_join;
1154
NestedJoin *nested_join;
1121
1155
List<TableList> *embedded_list;
1123
1157
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1124
sizeof(nested_join_st))))
1158
sizeof(NestedJoin))))
1126
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1160
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1127
1161
nested_join= ptr->getNestedJoin();
1128
1162
ptr->setEmbedding(embedding);
1129
1163
ptr->setJoinList(join_list);
1130
1164
ptr->alias= (char*) "(nest_last_join)";
1131
1165
embedded_list= &nested_join->join_list;
1132
embedded_list->empty();
1166
embedded_list->clear();
1134
1168
for (uint32_t i=0; i < 2; i++)
1487
1519
bool update_precheck(Session *session, TableList *)
1489
1521
const char *msg= 0;
1490
LEX *lex= session->lex;
1491
Select_Lex *select_lex= &lex->select_lex;
1522
Select_Lex *select_lex= &session->getLex()->select_lex;
1493
if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
1524
if (session->getLex()->select_lex.item_list.elements != session->getLex()->value_list.elements)
1495
1526
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1499
if (session->lex->select_lex.table_list.elements > 1)
1530
if (session->getLex()->select_lex.table_list.elements > 1)
1501
1532
if (select_lex->order_list.elements)
1502
1533
msg= "ORDER BY";
1675
1705
/* Parse the query. */
1677
bool mysql_parse_status= DRIZZLEparse(session) != 0;
1707
bool parse_status= base_sql_parse(session) != 0;
1679
1709
/* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1681
assert(!mysql_parse_status || session->is_error());
1711
assert(!parse_status || session->is_error());
1683
1713
/* Reset Lex_input_stream. */
1685
1715
session->m_lip= NULL;
1687
DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
1717
DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
1689
1719
/* That's it. */
1691
return mysql_parse_status || session->is_fatal_error;
1721
return parse_status || session->is_fatal_error;