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());
1075
1046
bool Select_Lex::init_nested_join(Session *session)
1077
1048
TableList *ptr;
1078
NestedJoin *nested_join;
1049
nested_join_st *nested_join;
1080
1051
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1081
sizeof(NestedJoin))))
1052
sizeof(nested_join_st))))
1083
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1054
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1084
1055
nested_join= ptr->getNestedJoin();
1085
1056
join_list->push_front(ptr);
1086
1057
ptr->setEmbedding(embedding);
1151
1122
TableList *Select_Lex::nest_last_join(Session *session)
1153
1124
TableList *ptr;
1154
NestedJoin *nested_join;
1125
nested_join_st *nested_join;
1155
1126
List<TableList> *embedded_list;
1157
1128
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1158
sizeof(NestedJoin))))
1129
sizeof(nested_join_st))))
1160
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1131
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1161
1132
nested_join= ptr->getNestedJoin();
1162
1133
ptr->setEmbedding(embedding);
1163
1134
ptr->setJoinList(join_list);
1164
1135
ptr->alias= (char*) "(nest_last_join)";
1165
1136
embedded_list= &nested_join->join_list;
1166
embedded_list->clear();
1137
embedded_list->empty();
1168
1139
for (uint32_t i=0; i < 2; i++)
1519
1491
bool update_precheck(Session *session, TableList *)
1521
1493
const char *msg= 0;
1522
Select_Lex *select_lex= &session->getLex()->select_lex;
1494
LEX *lex= session->lex;
1495
Select_Lex *select_lex= &lex->select_lex;
1524
if (session->getLex()->select_lex.item_list.elements != session->getLex()->value_list.elements)
1497
if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
1526
1499
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1530
if (session->getLex()->select_lex.table_list.elements > 1)
1503
if (session->lex->select_lex.table_list.elements > 1)
1532
1505
if (select_lex->order_list.elements)
1533
1506
msg= "ORDER BY";