~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#define DRIZZLE_LEX 1
19
19
 
20
 
#include "drizzled/item/num.h"
21
 
#include "drizzled/abort_exception.h"
22
20
#include <drizzled/my_hash.h>
23
21
#include <drizzled/error.h>
24
22
#include <drizzled/nested_join.h>
34
32
#include <drizzled/item/cmpfunc.h>
35
33
#include <drizzled/item/null.h>
36
34
#include <drizzled/session.h>
37
 
#include <drizzled/session/cache.h>
38
35
#include <drizzled/sql_load.h>
39
36
#include <drizzled/lock.h>
40
37
#include <drizzled/select_send.h>
42
39
#include <drizzled/statement.h>
43
40
#include <drizzled/statement/alter_table.h>
44
41
#include "drizzled/probes.h"
 
42
#include "drizzled/session_list.h"
45
43
#include "drizzled/global_charset_info.h"
46
44
 
47
45
#include "drizzled/plugin/logging.h"
51
49
#include "drizzled/optimizer/explain_plan.h"
52
50
#include "drizzled/pthread_globals.h"
53
51
#include "drizzled/plugin/event_observer.h"
54
 
#include "drizzled/visibility.h"
55
52
 
56
53
#include <limits.h>
57
54
 
58
55
#include <bitset>
59
56
#include <algorithm>
60
 
#include <boost/date_time.hpp>
 
57
 
61
58
#include "drizzled/internal/my_sys.h"
62
59
 
63
60
using namespace std;
70
67
/* Prototypes */
71
68
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
72
69
static bool parse_sql(Session *session, Lex_input_stream *lip);
73
 
void parse(Session *session, const char *inBuf, uint32_t length);
 
70
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
74
71
 
75
72
/**
76
73
  @defgroup Runtime_Environment Runtime Environment
80
77
extern size_t my_thread_stack_size;
81
78
extern const CHARSET_INFO *character_set_filesystem;
82
79
 
83
 
namespace
84
 
{
85
 
 
86
 
static const std::string command_name[COM_END+1]={
87
 
  "Sleep",
88
 
  "Quit",
89
 
  "Init DB",
90
 
  "Query",
91
 
  "Shutdown",
92
 
  "Connect",
93
 
  "Ping",
94
 
  "Error"  // Last command number
 
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
95
89
};
96
90
 
97
 
}
98
 
 
99
91
const char *xa_state_names[]={
100
92
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
101
93
};
114
106
*/
115
107
bitset<CF_BIT_SIZE> sql_command_flags[SQLCOM_END+1];
116
108
 
117
 
const std::string &getCommandName(const enum_server_command& command)
118
 
{
119
 
  return command_name[command];
120
 
}
121
 
 
122
109
void init_update_queries(void)
123
110
{
124
111
  uint32_t x;
183
170
  bool error= 0;
184
171
  Query_id &query_id= Query_id::get_query_id();
185
172
 
186
 
  DRIZZLE_COMMAND_START(session->thread_id, command);
 
173
  DRIZZLE_COMMAND_START(session->thread_id,
 
174
                        command);
187
175
 
188
176
  session->command= command;
189
177
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
200
188
    query_id.next();
201
189
  }
202
190
 
203
 
  /* @todo set session->lex->sql_command to SQLCOM_END here */
 
191
  /* TODO: set session->lex->sql_command to SQLCOM_END here */
204
192
 
205
193
  plugin::Logging::preDo(session);
206
194
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
221
209
 
222
210
    string tmp(packet, packet_length);
223
211
 
224
 
    identifier::Schema identifier(tmp);
 
212
    SchemaIdentifier identifier(tmp);
225
213
 
226
 
    if (not change_db(session, identifier))
 
214
    if (not mysql_change_db(session, identifier))
227
215
    {
228
216
      session->my_ok();
229
217
    }
231
219
  }
232
220
  case COM_QUERY:
233
221
  {
234
 
    if (not session->readAndStoreQuery(packet, packet_length))
 
222
    if (! session->readAndStoreQuery(packet, packet_length))
235
223
      break;                                    // fatal error is set
236
 
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
 
224
    DRIZZLE_QUERY_START(session->query.c_str(),
237
225
                        session->thread_id,
238
 
                        const_cast<const char *>(session->schema()->c_str()));
 
226
                        const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
239
227
 
240
 
    parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
 
228
    plugin::QueryRewriter::rewriteQuery(session->db, session->query);
 
229
    mysql_parse(session, session->query.c_str(), session->query.length());
241
230
 
242
231
    break;
243
232
  }
270
259
  /* If commit fails, we should be able to reset the OK status. */
271
260
  session->main_da.can_overwrite_status= true;
272
261
  TransactionServices &transaction_services= TransactionServices::singleton();
273
 
  transaction_services.autocommitOrRollback(*session, session->is_error());
 
262
  transaction_services.autocommitOrRollback(session, session->is_error());
274
263
  session->main_da.can_overwrite_status= false;
275
264
 
276
265
  session->transaction.stmt.reset();
282
271
    if (! session->main_da.is_set())
283
272
      session->send_kill_message();
284
273
  }
285
 
  if (session->getKilled() == Session::KILL_QUERY || session->getKilled() == Session::KILL_BAD_DATA)
 
274
  if (session->killed == Session::KILL_QUERY || session->killed == Session::KILL_BAD_DATA)
286
275
  {
287
 
    session->setKilled(Session::NOT_KILLED);
 
276
    session->killed= Session::NOT_KILLED;
288
277
    session->setAbort(false);
289
278
  }
290
279
 
295
284
  {
296
285
  case Diagnostics_area::DA_ERROR:
297
286
    /* The query failed, send error to log and abort bootstrap. */
298
 
    session->getClient()->sendError(session->main_da.sql_errno(),
 
287
    session->client->sendError(session->main_da.sql_errno(),
299
288
                               session->main_da.message());
300
289
    break;
301
290
 
302
291
  case Diagnostics_area::DA_EOF:
303
 
    session->getClient()->sendEOF();
 
292
    session->client->sendEOF();
304
293
    break;
305
294
 
306
295
  case Diagnostics_area::DA_OK:
307
 
    session->getClient()->sendOK();
 
296
    session->client->sendOK();
308
297
    break;
309
298
 
310
299
  case Diagnostics_area::DA_DISABLED:
312
301
 
313
302
  case Diagnostics_area::DA_EMPTY:
314
303
  default:
315
 
    session->getClient()->sendOK();
 
304
    session->client->sendOK();
316
305
    break;
317
306
  }
318
307
 
331
320
  /* Store temp state for processlist */
332
321
  session->set_proc_info("cleaning up");
333
322
  session->command= COM_SLEEP;
334
 
  session->resetQueryString();
 
323
  memset(session->process_list_info, 0, PROCESS_LIST_WIDTH);
 
324
  session->query.clear();
335
325
 
336
326
  session->set_proc_info(NULL);
337
327
  session->mem_root->free_root(MYF(memory::KEEP_PREALLOC));
442
432
    true        Error
443
433
*/
444
434
 
445
 
static int execute_command(Session *session)
 
435
static int
 
436
mysql_execute_command(Session *session)
446
437
{
447
438
  bool res= false;
448
439
  LEX  *lex= session->lex;
450
441
  Select_Lex *select_lex= &lex->select_lex;
451
442
  /* list of all tables in query */
452
443
  TableList *all_tables;
 
444
  /* A peek into the query string */
 
445
  size_t proc_info_len= session->query.length() > PROCESS_LIST_WIDTH ?
 
446
                        PROCESS_LIST_WIDTH : session->query.length();
 
447
 
 
448
  memcpy(session->process_list_info, session->query.c_str(), proc_info_len);
 
449
  session->process_list_info[proc_info_len]= '\0';
453
450
 
454
451
  /*
455
452
    In many cases first table of main Select_Lex have special meaning =>
488
485
 
489
486
  assert(session->transaction.stmt.hasModifiedNonTransData() == false);
490
487
 
491
 
  if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
492
 
      && ! session->inTransaction()
493
 
      && lex->statement->isTransactional())
494
 
  {
495
 
    if (session->startTransaction() == false)
496
 
    {
497
 
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
498
 
      return true;
499
 
    }
500
 
  }
501
 
 
502
488
  /* now we are ready to execute the statement */
503
489
  res= lex->statement->execute();
504
490
  session->set_proc_info("query end");
527
513
      param->select_limit=
528
514
        new Item_int((uint64_t) session->variables.select_limit);
529
515
  }
530
 
 
531
 
  if (all_tables
532
 
      && ! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
533
 
      && ! session->inTransaction()
534
 
      && ! lex->statement->isShow())
535
 
  {
536
 
    if (session->startTransaction() == false)
537
 
    {
538
 
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
539
 
      return true;
540
 
    }
541
 
  }
542
 
 
543
516
  if (not (res= session->openTablesLock(all_tables)))
544
517
  {
545
518
    if (lex->describe)
624
597
 
625
598
 
626
599
void
627
 
init_select(LEX *lex)
 
600
mysql_init_select(LEX *lex)
628
601
{
629
602
  Select_Lex *select_lex= lex->current_select;
630
603
  select_lex->init_select();
638
611
 
639
612
 
640
613
bool
641
 
new_select(LEX *lex, bool move_down)
 
614
mysql_new_select(LEX *lex, bool move_down)
642
615
{
643
616
  Select_Lex *select_lex;
644
617
  Session *session= lex->session;
645
618
 
646
619
  if (!(select_lex= new (session->mem_root) Select_Lex()))
647
 
    return true;
648
 
 
 
620
    return(1);
649
621
  select_lex->select_number= ++session->select_number;
650
622
  select_lex->parent_lex= lex; /* Used in init_query. */
651
623
  select_lex->init_query();
652
624
  select_lex->init_select();
653
625
  lex->nest_level++;
654
 
 
655
626
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
656
627
  {
657
628
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
658
629
    return(1);
659
630
  }
660
 
 
661
631
  select_lex->nest_level= lex->nest_level;
662
632
  if (move_down)
663
633
  {
685
655
    if (lex->current_select->order_list.first && !lex->current_select->braces)
686
656
    {
687
657
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
688
 
      return true;
 
658
      return(1);
689
659
    }
690
 
 
691
660
    select_lex->include_neighbour(lex->current_select);
692
661
    Select_Lex_Unit *unit= select_lex->master_unit();
693
 
 
694
 
    if (not unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
695
 
      return true;
696
 
 
 
662
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
 
663
      return(1);
697
664
    select_lex->context.outer_context=
698
665
                unit->first_select()->context.outer_context;
699
666
  }
706
673
    list
707
674
  */
708
675
  select_lex->context.resolve_in_select_list= true;
709
 
 
710
 
  return false;
 
676
  return(0);
711
677
}
712
678
 
713
679
/**
720
686
  @param var_name               Variable name
721
687
*/
722
688
 
723
 
void create_select_for_variable(Session *session, const char *var_name)
 
689
void create_select_for_variable(const char *var_name)
724
690
{
 
691
  Session *session;
725
692
  LEX *lex;
726
693
  LEX_STRING tmp, null_lex_string;
727
694
  Item *var;
728
695
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
729
696
  char *end= buff;
730
697
 
 
698
  session= current_session;
731
699
  lex= session->lex;
732
 
  init_select(lex);
 
700
  mysql_init_select(lex);
733
701
  lex->sql_command= SQLCOM_SELECT;
734
702
  tmp.str= (char*) var_name;
735
703
  tmp.length=strlen(var_name);
744
712
    var->set_name(buff, end-buff, system_charset_info);
745
713
    session->add_item_to_list(var);
746
714
  }
 
715
  return;
747
716
}
748
717
 
749
718
 
755
724
  @param       length  Length of the query text
756
725
*/
757
726
 
758
 
void parse(Session *session, const char *inBuf, uint32_t length)
 
727
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
759
728
{
760
 
  session->lex->start(session);
761
 
 
 
729
  uint64_t start_time= my_getsystime();
 
730
  lex_start(session);
762
731
  session->reset_for_next_command();
763
732
  /* Check if the Query is Cached if and return true if yes
764
733
   * TODO the plugin has to make sure that the query is cacheble
779
748
  if (!err)
780
749
  {
781
750
    {
782
 
      if (not session->is_error())
 
751
      if (! session->is_error())
783
752
      {
784
 
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
 
753
        DRIZZLE_QUERY_EXEC_START(session->query.c_str(),
785
754
                                 session->thread_id,
786
 
                                 const_cast<const char *>(session->schema()->c_str()));
 
755
                                 const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
787
756
        // Implement Views here --Brian
788
757
        /* Actually execute the query */
789
758
        try 
790
759
        {
791
 
          execute_command(session);
 
760
          mysql_execute_command(session);
792
761
        }
793
762
        catch (...)
794
763
        {
795
764
          // Just try to catch any random failures that could have come
796
765
          // during execution.
797
 
          DRIZZLE_ABORT;
798
766
        }
799
767
        DRIZZLE_QUERY_EXEC_DONE(0);
800
768
      }
808
776
  session->set_proc_info("freeing items");
809
777
  session->end_statement();
810
778
  session->cleanup_after_query();
811
 
  session->set_end_timer();
 
779
  session->status_var.execution_time_nsec+= my_getsystime() - start_time;
812
780
}
813
781
 
814
782
 
868
836
    */
869
837
    if (default_value->type() == Item::FUNC_ITEM &&
870
838
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
871
 
         (type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
 
839
         type == DRIZZLE_TYPE_TIMESTAMP))
872
840
    {
873
841
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
874
842
      return true;
876
844
    else if (default_value->type() == Item::NULL_ITEM)
877
845
    {
878
846
      default_value= 0;
879
 
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
 
847
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
 
848
          NOT_NULL_FLAG)
880
849
      {
881
850
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
882
851
        return true;
889
858
    }
890
859
  }
891
860
 
892
 
  if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
 
861
  if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
893
862
  {
894
863
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
895
864
    return true;
908
877
}
909
878
 
910
879
 
 
880
/** Store position for column in ALTER TABLE .. ADD column. */
 
881
 
 
882
void store_position_for_column(const char *name)
 
883
{
 
884
  current_session->lex->last_field->after=const_cast<char*> (name);
 
885
}
 
886
 
911
887
/**
912
888
  Add a table to list of used tables.
913
889
 
928
904
*/
929
905
 
930
906
TableList *Select_Lex::add_table_to_list(Session *session,
931
 
                                         Table_ident *table,
932
 
                                         LEX_STRING *alias,
933
 
                                         const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
934
 
                                         thr_lock_type lock_type,
935
 
                                         List<Index_hint> *index_hints_arg,
 
907
                                                             Table_ident *table,
 
908
                                                             LEX_STRING *alias,
 
909
                                                             const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
910
                                                             thr_lock_type lock_type,
 
911
                                                             List<Index_hint> *index_hints_arg,
936
912
                                         LEX_STRING *option)
937
913
{
938
914
  TableList *ptr;
954
930
  {
955
931
    my_casedn_str(files_charset_info, table->db.str);
956
932
 
957
 
    identifier::Schema schema_identifier(string(table->db.str));
 
933
    SchemaIdentifier schema_identifier(string(table->db.str));
958
934
    if (not check_db_name(session, schema_identifier))
959
935
    {
960
936
 
971
947
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
972
948
      return NULL;
973
949
    }
974
 
    if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
 
950
    if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1)))
975
951
      return NULL;
976
952
  }
977
953
  if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
990
966
 
991
967
  ptr->alias= alias_str;
992
968
  ptr->setIsAlias(alias ? true : false);
 
969
  if (table->table.length)
 
970
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
993
971
  ptr->setTableName(table->table.str);
994
972
  ptr->table_name_length=table->table.length;
995
973
  ptr->lock_type=   lock_type;
1007
985
         tables ;
1008
986
         tables=tables->next_local)
1009
987
    {
1010
 
      if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1011
 
          not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
 
988
      if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
 
989
          !strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1012
990
      {
1013
991
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1014
992
        return NULL;
1072
1050
bool Select_Lex::init_nested_join(Session *session)
1073
1051
{
1074
1052
  TableList *ptr;
1075
 
  NestedJoin *nested_join;
 
1053
  nested_join_st *nested_join;
1076
1054
 
1077
1055
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1078
 
                                       sizeof(NestedJoin))))
 
1056
                                       sizeof(nested_join_st))))
1079
1057
    return true;
1080
 
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1058
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1081
1059
  nested_join= ptr->getNestedJoin();
1082
1060
  join_list->push_front(ptr);
1083
1061
  ptr->setEmbedding(embedding);
1107
1085
TableList *Select_Lex::end_nested_join(Session *)
1108
1086
{
1109
1087
  TableList *ptr;
1110
 
  NestedJoin *nested_join;
 
1088
  nested_join_st *nested_join;
1111
1089
 
1112
1090
  assert(embedding);
1113
1091
  ptr= embedding;
1148
1126
TableList *Select_Lex::nest_last_join(Session *session)
1149
1127
{
1150
1128
  TableList *ptr;
1151
 
  NestedJoin *nested_join;
 
1129
  nested_join_st *nested_join;
1152
1130
  List<TableList> *embedded_list;
1153
1131
 
1154
1132
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1155
 
                                          sizeof(NestedJoin))))
 
1133
                                          sizeof(nested_join_st))))
1156
1134
    return NULL;
1157
 
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1135
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1158
1136
  nested_join= ptr->getNestedJoin();
1159
1137
  ptr->setEmbedding(embedding);
1160
1138
  ptr->setJoinList(join_list);
1446
1424
 
1447
1425
 
1448
1426
/**
 
1427
  kill on thread.
 
1428
 
 
1429
  @param session                        Thread class
 
1430
  @param id                     Thread id
 
1431
  @param only_kill_query        Should it kill the query or the connection
 
1432
 
 
1433
  @note
 
1434
    This is written such that we have a short lock on LOCK_thread_count
 
1435
*/
 
1436
 
 
1437
static unsigned int
 
1438
kill_one_thread(Session *, session_id_t id, bool only_kill_query)
 
1439
{
 
1440
  Session *tmp= NULL;
 
1441
  uint32_t error= ER_NO_SUCH_THREAD;
 
1442
  
 
1443
  {
 
1444
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
1445
    for (SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
 
1446
    {
 
1447
      if ((*it)->thread_id == id)
 
1448
      {
 
1449
        tmp= *it;
 
1450
        tmp->lockForDelete();
 
1451
        break;
 
1452
      }
 
1453
    }
 
1454
  }
 
1455
 
 
1456
  if (tmp)
 
1457
  {
 
1458
 
 
1459
    if (tmp->isViewable())
 
1460
    {
 
1461
      tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
 
1462
      error= 0;
 
1463
    }
 
1464
 
 
1465
    tmp->unlockForDelete();
 
1466
  }
 
1467
  return(error);
 
1468
}
 
1469
 
 
1470
 
 
1471
/*
 
1472
  kills a thread and sends response
 
1473
 
 
1474
  SYNOPSIS
 
1475
    sql_kill()
 
1476
    session                     Thread class
 
1477
    id                  Thread id
 
1478
    only_kill_query     Should it kill the query or the connection
 
1479
*/
 
1480
 
 
1481
void sql_kill(Session *session, int64_t id, bool only_kill_query)
 
1482
{
 
1483
  uint32_t error;
 
1484
  if (!(error= kill_one_thread(session, id, only_kill_query)))
 
1485
    session->my_ok();
 
1486
  else
 
1487
    my_error(error, MYF(0), id);
 
1488
}
 
1489
 
 
1490
 
 
1491
/**
1449
1492
  Check if the select is a simple select (not an union).
1450
1493
 
1451
1494
  @retval
1454
1497
    1   error   ; In this case the error messege is sent to the client
1455
1498
*/
1456
1499
 
1457
 
bool check_simple_select(Session::pointer session)
 
1500
bool check_simple_select()
1458
1501
{
 
1502
  Session *session= current_session;
1459
1503
  LEX *lex= session->lex;
1460
1504
  if (lex->current_select != &lex->select_lex)
1461
1505
  {
1572
1616
 
1573
1617
 
1574
1618
/**
 
1619
  CREATE TABLE query pre-check.
 
1620
 
 
1621
  @param session                        Thread handler
 
1622
  @param tables         Global table list
 
1623
  @param create_table           Table which will be created
 
1624
 
 
1625
  @retval
 
1626
    false   OK
 
1627
  @retval
 
1628
    true   Error
 
1629
*/
 
1630
 
 
1631
bool create_table_precheck(TableIdentifier &identifier)
 
1632
{
 
1633
  if (not plugin::StorageEngine::canCreateTable(identifier))
 
1634
  {
 
1635
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
 
1636
    return true;
 
1637
  }
 
1638
 
 
1639
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
1640
  {
 
1641
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
 
1642
    return true;
 
1643
  }
 
1644
 
 
1645
  return false;
 
1646
}
 
1647
 
 
1648
 
 
1649
/**
1575
1650
  negate given expression.
1576
1651
 
1577
1652
  @param session  thread handler
1638
1713
}
1639
1714
 
1640
1715
 
1641
 
bool check_identifier_name(LEX_STRING *str, error_t err_code,
 
1716
bool check_identifier_name(LEX_STRING *str, uint32_t err_code,
1642
1717
                           uint32_t max_char_length,
1643
1718
                           const char *param_for_err_msg)
1644
1719
{
1664
1739
 
1665
1740
  switch (err_code)
1666
1741
  {
1667
 
  case EE_OK:
 
1742
  case 0:
1668
1743
    break;
1669
1744
  case ER_WRONG_STRING_LENGTH:
1670
1745
    my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length);
1676
1751
    assert(0);
1677
1752
    break;
1678
1753
  }
1679
 
 
1680
1754
  return true;
1681
1755
}
1682
1756
 
1697
1771
{
1698
1772
  assert(session->m_lip == NULL);
1699
1773
 
1700
 
  DRIZZLE_QUERY_PARSE_START(session->getQueryString()->c_str());
 
1774
  DRIZZLE_QUERY_PARSE_START(session->query.c_str());
1701
1775
 
1702
1776
  /* Set Lex_input_stream. */
1703
1777
 
1705
1779
 
1706
1780
  /* Parse the query. */
1707
1781
 
1708
 
  bool parse_status= DRIZZLEparse(session) != 0;
 
1782
  bool mysql_parse_status= DRIZZLEparse(session) != 0;
1709
1783
 
1710
1784
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1711
1785
 
1712
 
  assert(!parse_status || session->is_error());
 
1786
  assert(!mysql_parse_status || session->is_error());
1713
1787
 
1714
1788
  /* Reset Lex_input_stream. */
1715
1789
 
1716
1790
  session->m_lip= NULL;
1717
1791
 
1718
 
  DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
 
1792
  DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
1719
1793
 
1720
1794
  /* That's it. */
1721
1795
 
1722
 
  return parse_status || session->is_fatal_error;
 
1796
  return mysql_parse_status || session->is_fatal_error;
1723
1797
}
1724
1798
 
1725
1799
/**