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
#include "drizzled/abort_exception.h"
22
21
#include <drizzled/my_hash.h>
23
22
#include <drizzled/error.h>
24
23
#include <drizzled/nested_join.h>
25
24
#include <drizzled/query_id.h>
26
#include <drizzled/transaction_services.h>
25
#include "drizzled/transaction_services.h"
27
26
#include <drizzled/sql_parse.h>
28
27
#include <drizzled/data_home.h>
29
28
#include <drizzled/sql_base.h>
30
29
#include <drizzled/show.h>
30
#include <drizzled/db.h>
31
31
#include <drizzled/function/time/unix_timestamp.h>
32
32
#include <drizzled/function/get_system_var.h>
33
33
#include <drizzled/item/cmpfunc.h>
34
34
#include <drizzled/item/null.h>
35
35
#include <drizzled/session.h>
36
#include <drizzled/session/cache.h>
37
36
#include <drizzled/sql_load.h>
38
37
#include <drizzled/lock.h>
39
38
#include <drizzled/select_send.h>
40
39
#include <drizzled/plugin/client.h>
41
40
#include <drizzled/statement.h>
42
41
#include <drizzled/statement/alter_table.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>
42
#include "drizzled/probes.h"
43
#include "drizzled/session/cache.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"
57
54
#include <limits.h>
60
57
#include <algorithm>
61
58
#include <boost/date_time.hpp>
62
#include <drizzled/internal/my_sys.h>
59
#include "drizzled/internal/my_sys.h"
64
61
using namespace std;
66
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
63
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
72
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
69
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
73
70
static bool parse_sql(Session *session, Lex_input_stream *lip);
74
71
void parse(Session *session, const char *inBuf, uint32_t length);
81
78
extern size_t my_thread_stack_size;
82
79
extern const CHARSET_INFO *character_set_filesystem;
87
static const std::string command_name[COM_END+1]={
95
"Error" // Last command number
81
const LEX_STRING command_name[COM_END+1]={
82
{ C_STRING_WITH_LEN("Sleep") },
83
{ C_STRING_WITH_LEN("Quit") },
84
{ C_STRING_WITH_LEN("Init DB") },
85
{ C_STRING_WITH_LEN("Query") },
86
{ C_STRING_WITH_LEN("Shutdown") },
87
{ C_STRING_WITH_LEN("Connect") },
88
{ C_STRING_WITH_LEN("Ping") },
89
{ C_STRING_WITH_LEN("Error") } // Last command number
100
92
const char *xa_state_names[]={
101
93
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
468
454
assert(first_table == all_tables);
469
455
assert(first_table == all_tables && first_table != 0);
471
session->getLex()->first_lists_tables_same();
457
lex->first_lists_tables_same();
473
458
/* should be assigned after making first tables same */
474
all_tables= session->getLex()->query_tables;
459
all_tables= lex->query_tables;
476
460
/* set context for commands which do not use setup_tables */
477
select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
462
context.resolve_in_table_list_only((TableList*)select_lex->
480
466
Reset warning count for each query that uses tables
483
469
variables, but for now this is probably good enough.
484
470
Don't reset warnings when executing a stored routine.
486
if (all_tables || ! session->getLex()->is_single_level_stmt())
472
if (all_tables || ! lex->is_single_level_stmt())
488
474
drizzle_reset_errors(session, 0);
491
477
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));
504
479
/* now we are ready to execute the statement */
505
res= session->getLex()->statement->execute();
480
res= lex->statement->execute();
506
481
session->set_proc_info("query end");
508
483
The return value for ROW_COUNT() is "implementation dependent" if the
557
519
session->send_explain_fields(result);
558
520
optimizer::ExplainPlan planner;
559
res= planner.explainUnion(session, &session->getLex()->unit, result);
521
res= planner.explainUnion(session, &session->lex->unit, result);
560
522
if (lex->describe & DESCRIBE_EXTENDED)
563
525
String str(buff,(uint32_t) sizeof(buff), system_charset_info);
565
session->getLex()->unit.print(&str, QT_ORDINARY);
527
session->lex->unit.print(&str, QT_ORDINARY);
566
528
str.append('\0');
567
529
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
568
530
ER_YES, str.ptr());
647
608
Session *session= lex->session;
649
610
if (!(select_lex= new (session->mem_root) Select_Lex()))
652
612
select_lex->select_number= ++session->select_number;
653
613
select_lex->parent_lex= lex; /* Used in init_query. */
654
614
select_lex->init_query();
655
615
select_lex->init_select();
656
616
lex->nest_level++;
658
617
if (lex->nest_level > (int) MAX_SELECT_NESTING)
660
619
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
664
622
select_lex->nest_level= lex->nest_level;
688
646
if (lex->current_select->order_list.first && !lex->current_select->braces)
690
648
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
694
651
select_lex->include_neighbour(lex->current_select);
695
652
Select_Lex_Unit *unit= select_lex->master_unit();
697
if (not unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
653
if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
700
655
select_lex->context.outer_context=
701
656
unit->first_select()->context.outer_context;
933
897
TableList *Select_Lex::add_table_to_list(Session *session,
936
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
937
thr_lock_type lock_type,
938
List<Index_hint> *index_hints_arg,
900
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
901
thr_lock_type lock_type,
902
List<Index_hint> *index_hints_arg,
939
903
LEX_STRING *option)
942
906
TableList *previous_table_ref; /* The table preceding the current one. */
944
LEX *lex= session->getLex();
908
LEX *lex= session->lex;
947
911
return NULL; // End of memory
1011
975
tables=tables->next_local)
1013
if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1014
not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
977
if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
978
!strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1016
980
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1075
1039
bool Select_Lex::init_nested_join(Session *session)
1077
1041
TableList *ptr;
1078
NestedJoin *nested_join;
1042
nested_join_st *nested_join;
1080
1044
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1081
sizeof(NestedJoin))))
1045
sizeof(nested_join_st))))
1083
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1047
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1084
1048
nested_join= ptr->getNestedJoin();
1085
1049
join_list->push_front(ptr);
1086
1050
ptr->setEmbedding(embedding);
1151
1115
TableList *Select_Lex::nest_last_join(Session *session)
1153
1117
TableList *ptr;
1154
NestedJoin *nested_join;
1118
nested_join_st *nested_join;
1155
1119
List<TableList> *embedded_list;
1157
1121
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1158
sizeof(NestedJoin))))
1122
sizeof(nested_join_st))))
1160
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1124
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1161
1125
nested_join= ptr->getNestedJoin();
1162
1126
ptr->setEmbedding(embedding);
1163
1127
ptr->setJoinList(join_list);
1164
1128
ptr->alias= (char*) "(nest_last_join)";
1165
1129
embedded_list= &nested_join->join_list;
1166
embedded_list->clear();
1130
embedded_list->empty();
1168
1132
for (uint32_t i=0; i < 2; i++)
1519
1484
bool update_precheck(Session *session, TableList *)
1521
1486
const char *msg= 0;
1522
Select_Lex *select_lex= &session->getLex()->select_lex;
1487
LEX *lex= session->lex;
1488
Select_Lex *select_lex= &lex->select_lex;
1524
if (session->getLex()->select_lex.item_list.elements != session->getLex()->value_list.elements)
1490
if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
1526
1492
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1530
if (session->getLex()->select_lex.table_list.elements > 1)
1496
if (session->lex->select_lex.table_list.elements > 1)
1532
1498
if (select_lex->order_list.elements)
1533
1499
msg= "ORDER BY";