~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-11-17 05:52:09 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117055209-69m035q6h7e1txrc
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Bug#52199 utf32: mbminlen=4, mbmaxlen=4, type->mbminlen=0, type->mbmaxlen=4

Merge and adjust a forgotten change to fix this bug.
rb://393 approved by Jimmy Yang
  ------------------------------------------------------------------------
  r3794 | marko | 2009-01-07 14:14:53 +0000 (Wed, 07 Jan 2009) | 18 lines

  branches/6.0: Allow the minimum length of a multi-byte character to be
  up to 4 bytes. (Bug #35391)

  dtype_t, dict_col_t: Replace mbminlen:2, mbmaxlen:3 with mbminmaxlen:5.
  In this way, the 5 bits can hold two values of 0..4, and the storage size
  of the fields will not cross the 64-bit boundary.  Encode the values as
  DATA_MBMAX * mbmaxlen + mbminlen.  Define the auxiliary macros
  DB_MBMINLEN(mbminmaxlen), DB_MBMAXLEN(mbminmaxlen), and
  DB_MINMAXLEN(mbminlen, mbmaxlen).

  Try to trim and pad UTF-16 and UTF-32 with spaces as appropriate.

  Alexander Barkov suggested the use of cs->cset->fill(cs, buff, len, 0x20).
  ha_innobase::store_key_val_for_row() now does that, but the added function
  row_mysql_pad_col() does not, because it doesn't have the MySQL TABLE object.

  rb://49 approved by Heikki Tuuri
  ------------------------------------------------------------------------

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;
200
187
    query_id.next();
201
188
  }
202
189
 
203
 
  /* @todo set session->lex->sql_command to SQLCOM_END here */
 
190
  /* TODO: set session->lex->sql_command to SQLCOM_END here */
204
191
 
205
192
  plugin::Logging::preDo(session);
206
193
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
221
208
 
222
209
    string tmp(packet, packet_length);
223
210
 
224
 
    identifier::Schema identifier(tmp);
 
211
    SchemaIdentifier identifier(tmp);
225
212
 
226
 
    if (not change_db(session, identifier))
 
213
    if (not mysql_change_db(session, identifier))
227
214
    {
228
215
      session->my_ok();
229
216
    }
235
222
      break;                                    // fatal error is set
236
223
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
237
224
                        session->thread_id,
238
 
                        const_cast<const char *>(session->schema()->c_str()));
 
225
                        const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
239
226
 
240
 
    parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
 
227
    plugin::QueryRewriter::rewriteQuery(session->getSchema(), session->getQueryString());
 
228
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
241
229
 
242
230
    break;
243
231
  }
270
258
  /* If commit fails, we should be able to reset the OK status. */
271
259
  session->main_da.can_overwrite_status= true;
272
260
  TransactionServices &transaction_services= TransactionServices::singleton();
273
 
  transaction_services.autocommitOrRollback(*session, session->is_error());
 
261
  transaction_services.autocommitOrRollback(session, session->is_error());
274
262
  session->main_da.can_overwrite_status= false;
275
263
 
276
264
  session->transaction.stmt.reset();
295
283
  {
296
284
  case Diagnostics_area::DA_ERROR:
297
285
    /* The query failed, send error to log and abort bootstrap. */
298
 
    session->getClient()->sendError(session->main_da.sql_errno(),
 
286
    session->client->sendError(session->main_da.sql_errno(),
299
287
                               session->main_da.message());
300
288
    break;
301
289
 
302
290
  case Diagnostics_area::DA_EOF:
303
 
    session->getClient()->sendEOF();
 
291
    session->client->sendEOF();
304
292
    break;
305
293
 
306
294
  case Diagnostics_area::DA_OK:
307
 
    session->getClient()->sendOK();
 
295
    session->client->sendOK();
308
296
    break;
309
297
 
310
298
  case Diagnostics_area::DA_DISABLED:
312
300
 
313
301
  case Diagnostics_area::DA_EMPTY:
314
302
  default:
315
 
    session->getClient()->sendOK();
 
303
    session->client->sendOK();
316
304
    break;
317
305
  }
318
306
 
442
430
    true        Error
443
431
*/
444
432
 
445
 
static int execute_command(Session *session)
 
433
static int mysql_execute_command(Session *session)
446
434
{
447
435
  bool res= false;
448
436
  LEX  *lex= session->lex;
488
476
 
489
477
  assert(session->transaction.stmt.hasModifiedNonTransData() == false);
490
478
 
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
479
  /* now we are ready to execute the statement */
503
480
  res= lex->statement->execute();
504
481
  session->set_proc_info("query end");
527
504
      param->select_limit=
528
505
        new Item_int((uint64_t) session->variables.select_limit);
529
506
  }
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
507
  if (not (res= session->openTablesLock(all_tables)))
544
508
  {
545
509
    if (lex->describe)
624
588
 
625
589
 
626
590
void
627
 
init_select(LEX *lex)
 
591
mysql_init_select(LEX *lex)
628
592
{
629
593
  Select_Lex *select_lex= lex->current_select;
630
594
  select_lex->init_select();
638
602
 
639
603
 
640
604
bool
641
 
new_select(LEX *lex, bool move_down)
 
605
mysql_new_select(LEX *lex, bool move_down)
642
606
{
643
607
  Select_Lex *select_lex;
644
608
  Session *session= lex->session;
645
609
 
646
610
  if (!(select_lex= new (session->mem_root) Select_Lex()))
647
 
    return true;
648
 
 
 
611
    return(1);
649
612
  select_lex->select_number= ++session->select_number;
650
613
  select_lex->parent_lex= lex; /* Used in init_query. */
651
614
  select_lex->init_query();
652
615
  select_lex->init_select();
653
616
  lex->nest_level++;
654
 
 
655
617
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
656
618
  {
657
619
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
658
620
    return(1);
659
621
  }
660
 
 
661
622
  select_lex->nest_level= lex->nest_level;
662
623
  if (move_down)
663
624
  {
685
646
    if (lex->current_select->order_list.first && !lex->current_select->braces)
686
647
    {
687
648
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
688
 
      return true;
 
649
      return(1);
689
650
    }
690
 
 
691
651
    select_lex->include_neighbour(lex->current_select);
692
652
    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
 
 
 
653
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
 
654
      return(1);
697
655
    select_lex->context.outer_context=
698
656
                unit->first_select()->context.outer_context;
699
657
  }
706
664
    list
707
665
  */
708
666
  select_lex->context.resolve_in_select_list= true;
709
 
 
710
 
  return false;
 
667
  return(0);
711
668
}
712
669
 
713
670
/**
720
677
  @param var_name               Variable name
721
678
*/
722
679
 
723
 
void create_select_for_variable(Session *session, const char *var_name)
 
680
void create_select_for_variable(const char *var_name)
724
681
{
 
682
  Session *session;
725
683
  LEX *lex;
726
684
  LEX_STRING tmp, null_lex_string;
727
685
  Item *var;
728
686
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
729
687
  char *end= buff;
730
688
 
 
689
  session= current_session;
731
690
  lex= session->lex;
732
 
  init_select(lex);
 
691
  mysql_init_select(lex);
733
692
  lex->sql_command= SQLCOM_SELECT;
734
693
  tmp.str= (char*) var_name;
735
694
  tmp.length=strlen(var_name);
744
703
    var->set_name(buff, end-buff, system_charset_info);
745
704
    session->add_item_to_list(var);
746
705
  }
 
706
  return;
747
707
}
748
708
 
749
709
 
755
715
  @param       length  Length of the query text
756
716
*/
757
717
 
758
 
void parse(Session *session, const char *inBuf, uint32_t length)
 
718
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
759
719
{
 
720
  uint64_t start_time= my_getsystime();
760
721
  session->lex->start(session);
761
 
 
762
722
  session->reset_for_next_command();
763
723
  /* Check if the Query is Cached if and return true if yes
764
724
   * TODO the plugin has to make sure that the query is cacheble
783
743
      {
784
744
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
785
745
                                 session->thread_id,
786
 
                                 const_cast<const char *>(session->schema()->c_str()));
 
746
                                 const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
787
747
        // Implement Views here --Brian
788
748
        /* Actually execute the query */
789
749
        try 
790
750
        {
791
 
          execute_command(session);
 
751
          mysql_execute_command(session);
792
752
        }
793
753
        catch (...)
794
754
        {
795
755
          // Just try to catch any random failures that could have come
796
756
          // during execution.
797
 
          DRIZZLE_ABORT;
798
757
        }
799
758
        DRIZZLE_QUERY_EXEC_DONE(0);
800
759
      }
808
767
  session->set_proc_info("freeing items");
809
768
  session->end_statement();
810
769
  session->cleanup_after_query();
811
 
  session->set_end_timer();
 
770
  session->status_var.execution_time_nsec+= my_getsystime() - start_time;
812
771
}
813
772
 
814
773
 
868
827
    */
869
828
    if (default_value->type() == Item::FUNC_ITEM &&
870
829
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
871
 
         (type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
 
830
         type == DRIZZLE_TYPE_TIMESTAMP))
872
831
    {
873
832
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
874
833
      return true;
876
835
    else if (default_value->type() == Item::NULL_ITEM)
877
836
    {
878
837
      default_value= 0;
879
 
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
 
838
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
 
839
          NOT_NULL_FLAG)
880
840
      {
881
841
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
882
842
        return true;
889
849
    }
890
850
  }
891
851
 
892
 
  if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
 
852
  if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
893
853
  {
894
854
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
895
855
    return true;
908
868
}
909
869
 
910
870
 
 
871
/** Store position for column in ALTER TABLE .. ADD column. */
 
872
 
 
873
void store_position_for_column(const char *name)
 
874
{
 
875
  current_session->lex->last_field->after=const_cast<char*> (name);
 
876
}
 
877
 
911
878
/**
912
879
  Add a table to list of used tables.
913
880
 
928
895
*/
929
896
 
930
897
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,
 
898
                                                             Table_ident *table,
 
899
                                                             LEX_STRING *alias,
 
900
                                                             const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
901
                                                             thr_lock_type lock_type,
 
902
                                                             List<Index_hint> *index_hints_arg,
936
903
                                         LEX_STRING *option)
937
904
{
938
905
  TableList *ptr;
954
921
  {
955
922
    my_casedn_str(files_charset_info, table->db.str);
956
923
 
957
 
    identifier::Schema schema_identifier(string(table->db.str));
 
924
    SchemaIdentifier schema_identifier(string(table->db.str));
958
925
    if (not check_db_name(session, schema_identifier))
959
926
    {
960
927
 
971
938
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
972
939
      return NULL;
973
940
    }
974
 
    if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
 
941
    if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1)))
975
942
      return NULL;
976
943
  }
977
944
  if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
990
957
 
991
958
  ptr->alias= alias_str;
992
959
  ptr->setIsAlias(alias ? true : false);
 
960
  if (table->table.length)
 
961
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
993
962
  ptr->setTableName(table->table.str);
994
963
  ptr->table_name_length=table->table.length;
995
964
  ptr->lock_type=   lock_type;
1007
976
         tables ;
1008
977
         tables=tables->next_local)
1009
978
    {
1010
 
      if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1011
 
          not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
 
979
      if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
 
980
          !strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1012
981
      {
1013
982
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1014
983
        return NULL;
1072
1041
bool Select_Lex::init_nested_join(Session *session)
1073
1042
{
1074
1043
  TableList *ptr;
1075
 
  NestedJoin *nested_join;
 
1044
  nested_join_st *nested_join;
1076
1045
 
1077
1046
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1078
 
                                       sizeof(NestedJoin))))
 
1047
                                       sizeof(nested_join_st))))
1079
1048
    return true;
1080
 
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1049
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1081
1050
  nested_join= ptr->getNestedJoin();
1082
1051
  join_list->push_front(ptr);
1083
1052
  ptr->setEmbedding(embedding);
1107
1076
TableList *Select_Lex::end_nested_join(Session *)
1108
1077
{
1109
1078
  TableList *ptr;
1110
 
  NestedJoin *nested_join;
 
1079
  nested_join_st *nested_join;
1111
1080
 
1112
1081
  assert(embedding);
1113
1082
  ptr= embedding;
1148
1117
TableList *Select_Lex::nest_last_join(Session *session)
1149
1118
{
1150
1119
  TableList *ptr;
1151
 
  NestedJoin *nested_join;
 
1120
  nested_join_st *nested_join;
1152
1121
  List<TableList> *embedded_list;
1153
1122
 
1154
1123
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1155
 
                                          sizeof(NestedJoin))))
 
1124
                                          sizeof(nested_join_st))))
1156
1125
    return NULL;
1157
 
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1126
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1158
1127
  nested_join= ptr->getNestedJoin();
1159
1128
  ptr->setEmbedding(embedding);
1160
1129
  ptr->setJoinList(join_list);
1446
1415
 
1447
1416
 
1448
1417
/**
 
1418
  kill on thread.
 
1419
 
 
1420
  @param session                        Thread class
 
1421
  @param id                     Thread id
 
1422
  @param only_kill_query        Should it kill the query or the connection
 
1423
 
 
1424
  @note
 
1425
    This is written such that we have a short lock on LOCK_thread_count
 
1426
*/
 
1427
 
 
1428
static unsigned int
 
1429
kill_one_thread(Session *, session_id_t id, bool only_kill_query)
 
1430
{
 
1431
  Session *tmp= NULL;
 
1432
  uint32_t error= ER_NO_SUCH_THREAD;
 
1433
  
 
1434
  {
 
1435
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
1436
    for (SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
 
1437
    {
 
1438
      if ((*it)->thread_id == id)
 
1439
      {
 
1440
        tmp= *it;
 
1441
        tmp->lockForDelete();
 
1442
        break;
 
1443
      }
 
1444
    }
 
1445
  }
 
1446
 
 
1447
  if (tmp)
 
1448
  {
 
1449
 
 
1450
    if (tmp->isViewable())
 
1451
    {
 
1452
      tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
 
1453
      error= 0;
 
1454
    }
 
1455
 
 
1456
    tmp->unlockForDelete();
 
1457
  }
 
1458
  return(error);
 
1459
}
 
1460
 
 
1461
 
 
1462
/*
 
1463
  kills a thread and sends response
 
1464
 
 
1465
  SYNOPSIS
 
1466
    sql_kill()
 
1467
    session                     Thread class
 
1468
    id                  Thread id
 
1469
    only_kill_query     Should it kill the query or the connection
 
1470
*/
 
1471
 
 
1472
void sql_kill(Session *session, int64_t id, bool only_kill_query)
 
1473
{
 
1474
  uint32_t error;
 
1475
  if (!(error= kill_one_thread(session, id, only_kill_query)))
 
1476
    session->my_ok();
 
1477
  else
 
1478
    my_error(error, MYF(0), id);
 
1479
}
 
1480
 
 
1481
 
 
1482
/**
1449
1483
  Check if the select is a simple select (not an union).
1450
1484
 
1451
1485
  @retval
1454
1488
    1   error   ; In this case the error messege is sent to the client
1455
1489
*/
1456
1490
 
1457
 
bool check_simple_select(Session::pointer session)
 
1491
bool check_simple_select()
1458
1492
{
 
1493
  Session *session= current_session;
1459
1494
  LEX *lex= session->lex;
1460
1495
  if (lex->current_select != &lex->select_lex)
1461
1496
  {
1572
1607
 
1573
1608
 
1574
1609
/**
 
1610
  CREATE TABLE query pre-check.
 
1611
 
 
1612
  @param session                        Thread handler
 
1613
  @param tables         Global table list
 
1614
  @param create_table           Table which will be created
 
1615
 
 
1616
  @retval
 
1617
    false   OK
 
1618
  @retval
 
1619
    true   Error
 
1620
*/
 
1621
 
 
1622
bool create_table_precheck(TableIdentifier &identifier)
 
1623
{
 
1624
  if (not plugin::StorageEngine::canCreateTable(identifier))
 
1625
  {
 
1626
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
 
1627
    return true;
 
1628
  }
 
1629
 
 
1630
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
1631
  {
 
1632
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
 
1633
    return true;
 
1634
  }
 
1635
 
 
1636
  return false;
 
1637
}
 
1638
 
 
1639
 
 
1640
/**
1575
1641
  negate given expression.
1576
1642
 
1577
1643
  @param session  thread handler
1638
1704
}
1639
1705
 
1640
1706
 
1641
 
bool check_identifier_name(LEX_STRING *str, error_t err_code,
 
1707
bool check_identifier_name(LEX_STRING *str, uint32_t err_code,
1642
1708
                           uint32_t max_char_length,
1643
1709
                           const char *param_for_err_msg)
1644
1710
{
1664
1730
 
1665
1731
  switch (err_code)
1666
1732
  {
1667
 
  case EE_OK:
 
1733
  case 0:
1668
1734
    break;
1669
1735
  case ER_WRONG_STRING_LENGTH:
1670
1736
    my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length);
1676
1742
    assert(0);
1677
1743
    break;
1678
1744
  }
1679
 
 
1680
1745
  return true;
1681
1746
}
1682
1747
 
1705
1770
 
1706
1771
  /* Parse the query. */
1707
1772
 
1708
 
  bool parse_status= DRIZZLEparse(session) != 0;
 
1773
  bool mysql_parse_status= DRIZZLEparse(session) != 0;
1709
1774
 
1710
1775
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1711
1776
 
1712
 
  assert(!parse_status || session->is_error());
 
1777
  assert(!mysql_parse_status || session->is_error());
1713
1778
 
1714
1779
  /* Reset Lex_input_stream. */
1715
1780
 
1716
1781
  session->m_lip= NULL;
1717
1782
 
1718
 
  DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
 
1783
  DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
1719
1784
 
1720
1785
  /* That's it. */
1721
1786
 
1722
 
  return parse_status || session->is_fatal_error;
 
1787
  return mysql_parse_status || session->is_fatal_error;
1723
1788
}
1724
1789
 
1725
1790
/**