~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
16
 
#include "config.h"
 
16
#include <config.h>
17
17
 
18
18
#define DRIZZLE_LEX 1
19
19
 
20
 
#include "drizzled/item/num.h"
21
 
#include "drizzled/abort_exception.h"
22
 
#include <drizzled/my_hash.h>
 
20
#include <drizzled/item/num.h>
 
21
#include <drizzled/abort_exception.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>
31
 
#include <drizzled/db.h>
32
30
#include <drizzled/function/time/unix_timestamp.h>
33
31
#include <drizzled/function/get_system_var.h>
34
32
#include <drizzled/item/cmpfunc.h>
41
39
#include <drizzled/plugin/client.h>
42
40
#include <drizzled/statement.h>
43
41
#include <drizzled/statement/alter_table.h>
44
 
#include "drizzled/probes.h"
45
 
#include "drizzled/global_charset_info.h"
46
 
 
47
 
#include "drizzled/plugin/logging.h"
48
 
#include "drizzled/plugin/query_rewrite.h"
49
 
#include "drizzled/plugin/query_cache.h"
50
 
#include "drizzled/plugin/authorization.h"
51
 
#include "drizzled/optimizer/explain_plan.h"
52
 
#include "drizzled/pthread_globals.h"
53
 
#include "drizzled/plugin/event_observer.h"
54
 
#include "drizzled/visibility.h"
 
42
#include <drizzled/probes.h>
 
43
#include <drizzled/charset.h>
 
44
#include <drizzled/plugin/logging.h>
 
45
#include <drizzled/plugin/query_rewrite.h>
 
46
#include <drizzled/plugin/query_cache.h>
 
47
#include <drizzled/plugin/authorization.h>
 
48
#include <drizzled/optimizer/explain_plan.h>
 
49
#include <drizzled/pthread_globals.h>
 
50
#include <drizzled/plugin/event_observer.h>
 
51
#include <drizzled/display.h>
 
52
#include <drizzled/visibility.h>
 
53
#include <drizzled/kill.h>
 
54
#include <drizzled/schema.h>
 
55
#include <drizzled/item/subselect.h>
 
56
#include <drizzled/diagnostics_area.h>
 
57
#include <drizzled/table_ident.h>
 
58
#include <drizzled/statistics_variables.h>
 
59
#include <drizzled/system_variables.h>
 
60
#include <drizzled/session/times.h>
 
61
#include <drizzled/session/transactions.h>
55
62
 
56
63
#include <limits.h>
57
64
 
58
65
#include <bitset>
59
66
#include <algorithm>
60
67
#include <boost/date_time.hpp>
61
 
#include "drizzled/internal/my_sys.h"
 
68
#include <drizzled/internal/my_sys.h>
62
69
 
63
70
using namespace std;
64
71
 
65
 
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
 
72
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
66
73
 
67
 
namespace drizzled
68
 
{
 
74
namespace drizzled {
69
75
 
70
76
/* Prototypes */
71
 
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 
77
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
72
78
static bool parse_sql(Session *session, Lex_input_stream *lip);
73
 
void parse(Session *session, const char *inBuf, uint32_t length);
 
79
void parse(Session&, const char *inBuf, uint32_t length);
74
80
 
75
81
/**
76
82
  @defgroup Runtime_Environment Runtime Environment
78
84
*/
79
85
 
80
86
extern size_t my_thread_stack_size;
81
 
extern const CHARSET_INFO *character_set_filesystem;
 
87
extern const charset_info_st *character_set_filesystem;
82
88
 
83
89
namespace
84
90
{
91
97
  "Shutdown",
92
98
  "Connect",
93
99
  "Ping",
 
100
  "Kill",
94
101
  "Error"  // Last command number
95
102
};
96
103
 
167
174
                         can be zero.
168
175
 
169
176
  @todo
170
 
    set session->lex->sql_command to SQLCOM_END here.
 
177
    set session->lex().sql_command to SQLCOM_END here.
171
178
  @todo
172
179
    The following has to be changed to an 8 byte integer
173
180
 
177
184
    1   request of thread shutdown, i. e. if command is
178
185
        COM_QUIT/COM_SHUTDOWN
179
186
*/
180
 
bool dispatch_command(enum enum_server_command command, Session *session,
 
187
bool dispatch_command(enum_server_command command, Session *session,
181
188
                      char* packet, uint32_t packet_length)
182
189
{
183
190
  bool error= 0;
186
193
  DRIZZLE_COMMAND_START(session->thread_id, command);
187
194
 
188
195
  session->command= command;
189
 
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
190
 
  session->set_time();
 
196
  session->lex().sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
 
197
  session->times.set_time();
191
198
  session->setQueryId(query_id.value());
192
199
 
193
200
  switch( command ) {
200
207
    query_id.next();
201
208
  }
202
209
 
203
 
  /* @todo set session->lex->sql_command to SQLCOM_END here */
 
210
  /* @todo set session->lex().sql_command to SQLCOM_END here */
204
211
 
205
212
  plugin::Logging::preDo(session);
206
213
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
210
217
 
211
218
  session->server_status&=
212
219
           ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
 
220
 
213
221
  switch (command) {
214
222
  case COM_INIT_DB:
215
223
  {
218
226
      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
219
227
      break;
220
228
    }
221
 
 
222
 
    string tmp(packet, packet_length);
223
 
 
224
 
    identifier::Schema identifier(tmp);
225
 
 
226
 
    if (not change_db(session, identifier))
 
229
    if (not schema::change(*session, identifier::Schema(string(packet, packet_length))))
227
230
    {
228
231
      session->my_ok();
229
232
    }
231
234
  }
232
235
  case COM_QUERY:
233
236
  {
234
 
    if (not session->readAndStoreQuery(packet, packet_length))
235
 
      break;                                    // fatal error is set
236
 
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
237
 
                        session->thread_id,
238
 
                        const_cast<const char *>(session->schema()->c_str()));
239
 
 
240
 
    parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
241
 
 
 
237
    session->readAndStoreQuery(packet, packet_length);
 
238
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(), session->thread_id, session->schema()->c_str());
 
239
    parse(*session, session->getQueryString()->c_str(), session->getQueryString()->length());
242
240
    break;
243
241
  }
244
242
  case COM_QUIT:
245
243
    /* We don't calculate statistics for this command */
246
 
    session->main_da.disable_status();              // Don't send anything back
247
 
    error=true;                                 // End server
 
244
    session->main_da().disable_status();              // Don't send anything back
 
245
    error= true;                                        // End server
248
246
    break;
 
247
  case COM_KILL:
 
248
    {
 
249
      if (packet_length != 4)
 
250
      {
 
251
        my_error(ER_NO_SUCH_THREAD, MYF(0), 0);
 
252
        break;
 
253
      }
 
254
      else
 
255
      {
 
256
        uint32_t kill_id;
 
257
        memcpy(&kill_id, packet, sizeof(uint32_t));
 
258
 
 
259
        kill_id= ntohl(kill_id);
 
260
        (void)drizzled::kill(*session->user(), kill_id, true);
 
261
      }
 
262
      session->my_ok();
 
263
      break;
 
264
    }
249
265
  case COM_SHUTDOWN:
250
266
  {
251
267
    session->status_var.com_other++;
252
268
    session->my_eof();
253
269
    session->close_thread_tables();                     // Free before kill
254
270
    kill_drizzle();
255
 
    error=true;
 
271
    error= true;
256
272
    break;
257
273
  }
258
274
  case COM_PING:
268
284
  }
269
285
 
270
286
  /* If commit fails, we should be able to reset the OK status. */
271
 
  session->main_da.can_overwrite_status= true;
 
287
  session->main_da().can_overwrite_status= true;
272
288
  TransactionServices &transaction_services= TransactionServices::singleton();
273
289
  transaction_services.autocommitOrRollback(*session, session->is_error());
274
 
  session->main_da.can_overwrite_status= false;
 
290
  session->main_da().can_overwrite_status= false;
275
291
 
276
292
  session->transaction.stmt.reset();
277
293
 
279
295
  /* report error issued during command execution */
280
296
  if (session->killed_errno())
281
297
  {
282
 
    if (! session->main_da.is_set())
 
298
    if (! session->main_da().is_set())
283
299
      session->send_kill_message();
284
300
  }
285
301
  if (session->getKilled() == Session::KILL_QUERY || session->getKilled() == Session::KILL_BAD_DATA)
289
305
  }
290
306
 
291
307
  /* Can not be true, but do not take chances in production. */
292
 
  assert(! session->main_da.is_sent);
 
308
  assert(! session->main_da().is_sent);
293
309
 
294
 
  switch (session->main_da.status())
 
310
  switch (session->main_da().status())
295
311
  {
296
312
  case Diagnostics_area::DA_ERROR:
297
313
    /* The query failed, send error to log and abort bootstrap. */
298
 
    session->getClient()->sendError(session->main_da.sql_errno(),
299
 
                               session->main_da.message());
 
314
    session->getClient()->sendError(session->main_da().sql_errno(),
 
315
                               session->main_da().message());
300
316
    break;
301
317
 
302
318
  case Diagnostics_area::DA_EOF:
316
332
    break;
317
333
  }
318
334
 
319
 
  session->main_da.is_sent= true;
 
335
  session->main_da().is_sent= true;
320
336
 
321
337
  session->set_proc_info("closing tables");
322
338
  /* Free tables */
386
402
  session->make_lex_string(&db, "data_dictionary", sizeof("data_dictionary"), false);
387
403
  session->make_lex_string(&table, schema_table_name, false);
388
404
 
389
 
  if (! sel->add_table_to_list(session, new Table_ident(db, table),
390
 
                               NULL, table_options, TL_READ))
 
405
  if (not sel->add_table_to_list(session, new Table_ident(db, table), NULL, table_options, TL_READ))
391
406
  {
392
407
    return true;
393
408
  }
394
409
  return false;
395
410
}
396
411
 
397
 
int prepare_new_schema_table(Session *session, LEX *lex,
 
412
int prepare_new_schema_table(Session *session, LEX& lex,
398
413
                             const string& schema_table_name)
399
414
{
400
415
  Select_Lex *schema_select_lex= NULL;
401
416
 
402
 
  Select_Lex *select_lex= lex->current_select;
 
417
  Select_Lex *select_lex= lex.current_select;
403
418
  assert(select_lex);
404
419
  if (_schema_select(session, select_lex, schema_table_name))
405
420
  {
445
460
static int execute_command(Session *session)
446
461
{
447
462
  bool res= false;
448
 
  LEX  *lex= session->lex;
 
463
 
449
464
  /* first Select_Lex (have special meaning for many of non-SELECTcommands) */
450
 
  Select_Lex *select_lex= &lex->select_lex;
 
465
  Select_Lex *select_lex= &session->lex().select_lex;
 
466
 
451
467
  /* list of all tables in query */
452
468
  TableList *all_tables;
453
469
 
466
482
    assert(first_table == all_tables);
467
483
    assert(first_table == all_tables && first_table != 0);
468
484
  */
469
 
  lex->first_lists_tables_same();
 
485
  session->lex().first_lists_tables_same();
 
486
 
470
487
  /* should be assigned after making first tables same */
471
 
  all_tables= lex->query_tables;
 
488
  all_tables= session->lex().query_tables;
 
489
 
472
490
  /* set context for commands which do not use setup_tables */
473
 
  select_lex->
474
 
    context.resolve_in_table_list_only((TableList*)select_lex->
475
 
                                       table_list.first);
 
491
  select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
476
492
 
477
493
  /*
478
494
    Reset warning count for each query that uses tables
481
497
    variables, but for now this is probably good enough.
482
498
    Don't reset warnings when executing a stored routine.
483
499
  */
484
 
  if (all_tables || ! lex->is_single_level_stmt())
 
500
  if (all_tables || ! session->lex().is_single_level_stmt())
485
501
  {
486
502
    drizzle_reset_errors(session, 0);
487
503
  }
490
506
 
491
507
  if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
492
508
      && ! session->inTransaction()
493
 
      && lex->statement->isTransactional())
 
509
      && session->lex().statement->isTransactional())
494
510
  {
495
511
    if (session->startTransaction() == false)
496
512
    {
500
516
  }
501
517
 
502
518
  /* now we are ready to execute the statement */
503
 
  res= lex->statement->execute();
 
519
  res= session->lex().statement->execute();
504
520
  session->set_proc_info("query end");
505
521
  /*
506
522
    The return value for ROW_COUNT() is "implementation dependent" if the
508
524
    wants. We also keep the last value in case of SQLCOM_CALL or
509
525
    SQLCOM_EXECUTE.
510
526
  */
511
 
  if (! (sql_command_flags[lex->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
 
527
  if (! (sql_command_flags[session->lex().sql_command].test(CF_BIT_HAS_ROW_COUNT)))
512
528
  {
513
529
    session->row_count_func= -1;
514
530
  }
517
533
}
518
534
bool execute_sqlcom_select(Session *session, TableList *all_tables)
519
535
{
520
 
  LEX   *lex= session->lex;
 
536
  LEX   *lex= &session->lex();
521
537
  select_result *result=lex->result;
522
538
  bool res= false;
523
539
  /* assign global limit variable if limit is not given */
554
570
        return true;
555
571
      session->send_explain_fields(result);
556
572
      optimizer::ExplainPlan planner;
557
 
      res= planner.explainUnion(session, &session->lex->unit, result);
 
573
      res= planner.explainUnion(session, &session->lex().unit, result);
558
574
      if (lex->describe & DESCRIBE_EXTENDED)
559
575
      {
560
576
        char buff[1024];
561
577
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
562
578
        str.length(0);
563
 
        session->lex->unit.print(&str, QT_ORDINARY);
 
579
        session->lex().unit.print(&str);
564
580
        str.append('\0');
565
581
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
566
582
                     ER_YES, str.ptr());
569
585
        result->abort();
570
586
      else
571
587
        result->send_eof();
 
588
 
572
589
      delete result;
573
590
    }
574
591
    else
577
594
        return true;
578
595
 
579
596
      /* Init the Query Cache plugin */
580
 
      plugin::QueryCache::prepareResultset(session); 
 
597
      plugin::QueryCache::prepareResultset(session);
581
598
      res= handle_select(session, lex, result, 0);
582
599
      /* Send the Resultset to the cache */
583
 
      plugin::QueryCache::setResultset(session); 
 
600
      plugin::QueryCache::setResultset(session);
584
601
 
585
602
      if (result != lex->result)
586
603
        delete result;
593
610
#define MY_YACC_INIT 1000                       // Start with big alloc
594
611
#define MY_YACC_MAX  32000                      // Because of 'short'
595
612
 
596
 
bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
 
613
bool my_yyoverflow(short **yyss, ParserType **yyvs, ulong *yystacksize)
597
614
{
598
 
  LEX   *lex= current_session->lex;
 
615
  LEX   *lex= &current_session->lex();
599
616
  ulong old_info=0;
600
617
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
601
618
    return 1;
618
635
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
619
636
  }
620
637
  *yyss=(short*) lex->yacc_yyss;
621
 
  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
 
638
  *yyvs=(ParserType*) lex->yacc_yyvs;
622
639
  return 0;
623
640
}
624
641
 
722
739
 
723
740
void create_select_for_variable(Session *session, const char *var_name)
724
741
{
725
 
  LEX *lex;
726
 
  LEX_STRING tmp, null_lex_string;
727
 
  Item *var;
728
 
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
729
 
  char *end= buff;
730
 
 
731
 
  lex= session->lex;
732
 
  init_select(lex);
733
 
  lex->sql_command= SQLCOM_SELECT;
 
742
  LEX& lex= session->lex();
 
743
  init_select(&lex);
 
744
  lex.sql_command= SQLCOM_SELECT;
 
745
  LEX_STRING tmp;
734
746
  tmp.str= (char*) var_name;
735
747
  tmp.length=strlen(var_name);
 
748
  LEX_STRING null_lex_string;
736
749
  memset(&null_lex_string.str, 0, sizeof(null_lex_string));
737
750
  /*
738
751
    We set the name of Item to @@session.var_name because that then is used
739
752
    as the column name in the output.
740
753
  */
741
 
  if ((var= get_system_var(session, OPT_SESSION, tmp, null_lex_string)))
 
754
  if (Item* var= get_system_var(session, OPT_SESSION, tmp, null_lex_string))
742
755
  {
 
756
    char buff[MAX_SYS_VAR_LENGTH*2+4+8];
 
757
    char *end= buff;
743
758
    end+= snprintf(buff, sizeof(buff), "@@session.%s", var_name);
744
759
    var->set_name(buff, end-buff, system_charset_info);
745
760
    session->add_item_to_list(var);
755
770
  @param       length  Length of the query text
756
771
*/
757
772
 
758
 
void parse(Session *session, const char *inBuf, uint32_t length)
 
773
void parse(Session& session, const char *inBuf, uint32_t length)
759
774
{
760
 
  session->lex->start(session);
761
 
 
762
 
  session->reset_for_next_command();
 
775
  session.lex().start(&session);
 
776
  session.reset_for_next_command();
763
777
  /* Check if the Query is Cached if and return true if yes
764
778
   * TODO the plugin has to make sure that the query is cacheble
765
779
   * by setting the query_safe_cache param to TRUE
766
780
   */
767
 
  bool res= true;
768
 
  if (plugin::QueryCache::isCached(session))
769
 
  {
770
 
    res= plugin::QueryCache::sendCachedResultset(session);
771
 
  }
772
 
  if (not res)
773
 
  {
774
 
    return;
775
 
  }
776
 
  LEX *lex= session->lex;
777
 
  Lex_input_stream lip(session, inBuf, length);
778
 
  bool err= parse_sql(session, &lip);
779
 
  if (!err)
780
 
  {
781
 
    {
782
 
      if (not session->is_error())
783
 
      {
784
 
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
785
 
                                 session->thread_id,
786
 
                                 const_cast<const char *>(session->schema()->c_str()));
787
 
        // Implement Views here --Brian
788
 
        /* Actually execute the query */
789
 
        try 
790
 
        {
791
 
          execute_command(session);
792
 
        }
793
 
        catch (...)
794
 
        {
795
 
          // Just try to catch any random failures that could have come
796
 
          // during execution.
797
 
          DRIZZLE_ABORT;
798
 
        }
799
 
        DRIZZLE_QUERY_EXEC_DONE(0);
800
 
      }
801
 
    }
802
 
  }
803
 
  else
804
 
  {
805
 
    assert(session->is_error());
806
 
  }
807
 
  lex->unit.cleanup();
808
 
  session->set_proc_info("freeing items");
809
 
  session->end_statement();
810
 
  session->cleanup_after_query();
811
 
  session->set_end_timer();
 
781
  if (plugin::QueryCache::isCached(&session) && not plugin::QueryCache::sendCachedResultset(&session))
 
782
      return;
 
783
  Lex_input_stream lip(&session, inBuf, length);
 
784
  if (parse_sql(&session, &lip))
 
785
    assert(session.is_error());
 
786
  else if (not session.is_error())
 
787
  {
 
788
    DRIZZLE_QUERY_EXEC_START(session.getQueryString()->c_str(), session.thread_id,
 
789
                             const_cast<const char *>(session.schema()->c_str()));
 
790
    // Implement Views here --Brian
 
791
    /* Actually execute the query */
 
792
    try
 
793
    {
 
794
      execute_command(&session);
 
795
    }
 
796
    catch (...)
 
797
    {
 
798
      // Just try to catch any random failures that could have come
 
799
      // during execution.
 
800
      DRIZZLE_ABORT;
 
801
    }
 
802
    DRIZZLE_QUERY_EXEC_DONE(0);
 
803
  }
 
804
  session.lex().unit.cleanup();
 
805
  session.set_proc_info("freeing items");
 
806
  session.end_statement();
 
807
  session.cleanup_after_query();
 
808
  session.times.set_end_timer(session);
812
809
}
813
810
 
814
811
 
815
 
 
816
812
/**
817
813
  Store field definition for create.
818
814
 
827
823
                       Item *default_value, Item *on_update_value,
828
824
                       LEX_STRING *comment,
829
825
                       char *change,
830
 
                       List<String> *interval_list, const CHARSET_INFO * const cs)
 
826
                       List<String> *interval_list, const charset_info_st * const cs)
831
827
{
832
828
  register CreateField *new_field;
833
 
  LEX  *lex= session->lex;
 
829
  LEX  *lex= &session->lex();
834
830
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
835
831
 
836
832
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
844
840
                      &default_key_create_info,
845
841
                      0, lex->col_list);
846
842
    statement->alter_info.key_list.push_back(key);
847
 
    lex->col_list.empty();
 
843
    lex->col_list.clear();
848
844
  }
849
845
  if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
850
846
  {
854
850
                 &default_key_create_info, 0,
855
851
                 lex->col_list);
856
852
    statement->alter_info.key_list.push_back(key);
857
 
    lex->col_list.empty();
 
853
    lex->col_list.clear();
858
854
  }
859
855
 
860
856
  if (default_value)
895
891
    return true;
896
892
  }
897
893
 
898
 
  if (!(new_field= new CreateField()) ||
899
 
      new_field->init(session, field_name->str, type, length, decimals, type_modifier,
900
 
                      default_value, on_update_value, comment, change,
901
 
                      interval_list, cs, 0, column_format))
 
894
  if (!(new_field= new CreateField())
 
895
      || new_field->init(session, field_name->str, type, length, decimals,
 
896
                         type_modifier, comment, change, interval_list,
 
897
                         cs, 0, column_format)
 
898
      || new_field->setDefaultValue(default_value, on_update_value))
902
899
    return true;
903
900
 
904
901
  statement->alter_info.create_list.push_back(new_field);
935
932
                                         List<Index_hint> *index_hints_arg,
936
933
                                         LEX_STRING *option)
937
934
{
938
 
  TableList *ptr;
939
935
  TableList *previous_table_ref; /* The table preceding the current one. */
940
936
  char *alias_str;
941
 
  LEX *lex= session->lex;
 
937
  LEX *lex= &session->lex();
942
938
 
943
939
  if (!table)
944
940
    return NULL;                                // End of memory
955
951
    my_casedn_str(files_charset_info, table->db.str);
956
952
 
957
953
    identifier::Schema schema_identifier(string(table->db.str));
958
 
    if (not check_db_name(session, schema_identifier))
 
954
    if (not schema::check(*session, schema_identifier))
959
955
    {
960
956
 
961
957
      my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
974
970
    if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
975
971
      return NULL;
976
972
  }
977
 
  if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
978
 
    return NULL;
 
973
  TableList *ptr = (TableList *) session->calloc(sizeof(TableList));
979
974
 
980
975
  if (table->db.str)
981
976
  {
1016
1011
    }
1017
1012
  }
1018
1013
  /* Store the table reference preceding the current one. */
1019
 
  if (table_list.elements > 0)
 
1014
  if (table_list.size() > 0)
1020
1015
  {
1021
1016
    /*
1022
1017
      table_list.next points to the last inserted TableList->next_local'
1085
1080
  ptr->alias= (char*) "(nested_join)";
1086
1081
  embedding= ptr;
1087
1082
  join_list= &nested_join->join_list;
1088
 
  join_list->empty();
 
1083
  join_list->clear();
1089
1084
  return false;
1090
1085
}
1091
1086
 
1114
1109
  join_list= ptr->getJoinList();
1115
1110
  embedding= ptr->getEmbedding();
1116
1111
  nested_join= ptr->getNestedJoin();
1117
 
  if (nested_join->join_list.elements == 1)
 
1112
  if (nested_join->join_list.size() == 1)
1118
1113
  {
1119
 
    TableList *embedded= nested_join->join_list.head();
 
1114
    TableList *embedded= &nested_join->join_list.front();
1120
1115
    join_list->pop();
1121
1116
    embedded->setJoinList(join_list);
1122
1117
    embedded->setEmbedding(embedding);
1123
1118
    join_list->push_front(embedded);
1124
1119
    ptr= embedded;
1125
1120
  }
1126
 
  else if (nested_join->join_list.elements == 0)
 
1121
  else if (nested_join->join_list.size() == 0)
1127
1122
  {
1128
1123
    join_list->pop();
1129
1124
    ptr= NULL;                                     // return value
1160
1155
  ptr->setJoinList(join_list);
1161
1156
  ptr->alias= (char*) "(nest_last_join)";
1162
1157
  embedded_list= &nested_join->join_list;
1163
 
  embedded_list->empty();
 
1158
  embedded_list->clear();
1164
1159
 
1165
1160
  for (uint32_t i=0; i < 2; i++)
1166
1161
  {
1308
1303
  fake_select_lex->include_standalone(this,
1309
1304
                                      (Select_Lex_Node**)&fake_select_lex);
1310
1305
  fake_select_lex->select_number= INT_MAX;
1311
 
  fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */
 
1306
  fake_select_lex->parent_lex= &session_arg->lex(); /* Used in init_query. */
1312
1307
  fake_select_lex->make_empty_select();
1313
1308
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1314
1309
  fake_select_lex->select_limit= 0;
1328
1323
    */
1329
1324
    global_parameters= fake_select_lex;
1330
1325
    fake_select_lex->no_table_names_allowed= 1;
1331
 
    session_arg->lex->current_select= fake_select_lex;
 
1326
    session_arg->lex().current_select= fake_select_lex;
1332
1327
  }
1333
 
  session_arg->lex->pop_context();
 
1328
  session_arg->lex().pop_context();
1334
1329
  return(0);
1335
1330
}
1336
1331
 
1354
1349
    true   if a memory allocation error occured
1355
1350
*/
1356
1351
 
1357
 
bool
1358
 
push_new_name_resolution_context(Session *session,
1359
 
                                 TableList *left_op, TableList *right_op)
 
1352
void push_new_name_resolution_context(Session& session, TableList& left_op, TableList& right_op)
1360
1353
{
1361
 
  Name_resolution_context *on_context;
1362
 
  if (!(on_context= new (session->mem_root) Name_resolution_context))
1363
 
    return true;
 
1354
  Name_resolution_context *on_context= new (session.mem_root) Name_resolution_context;
1364
1355
  on_context->init();
1365
 
  on_context->first_name_resolution_table=
1366
 
    left_op->first_leaf_for_name_resolution();
1367
 
  on_context->last_name_resolution_table=
1368
 
    right_op->last_leaf_for_name_resolution();
1369
 
  return session->lex->push_context(on_context);
 
1356
  on_context->first_name_resolution_table= left_op.first_leaf_for_name_resolution();
 
1357
  on_context->last_name_resolution_table= right_op.last_leaf_for_name_resolution();
 
1358
  session.lex().push_context(on_context);
1370
1359
}
1371
1360
 
1372
1361
 
1454
1443
    1   error   ; In this case the error messege is sent to the client
1455
1444
*/
1456
1445
 
1457
 
bool check_simple_select(Session::pointer session)
 
1446
bool check_simple_select(Session* session)
1458
1447
{
1459
 
  LEX *lex= session->lex;
1460
 
  if (lex->current_select != &lex->select_lex)
 
1448
  if (session->lex().current_select != &session->lex().select_lex)
1461
1449
  {
1462
1450
    char command[80];
1463
1451
    Lex_input_stream *lip= session->m_lip;
1517
1505
bool update_precheck(Session *session, TableList *)
1518
1506
{
1519
1507
  const char *msg= 0;
1520
 
  LEX *lex= session->lex;
1521
 
  Select_Lex *select_lex= &lex->select_lex;
 
1508
  Select_Lex *select_lex= &session->lex().select_lex;
1522
1509
 
1523
 
  if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
 
1510
  if (session->lex().select_lex.item_list.size() != session->lex().value_list.size())
1524
1511
  {
1525
1512
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1526
1513
    return(true);
1527
1514
  }
1528
1515
 
1529
 
  if (session->lex->select_lex.table_list.elements > 1)
 
1516
  if (session->lex().select_lex.table_list.size() > 1)
1530
1517
  {
1531
 
    if (select_lex->order_list.elements)
 
1518
    if (select_lex->order_list.size())
1532
1519
      msg= "ORDER BY";
1533
1520
    else if (select_lex->select_limit)
1534
1521
      msg= "LIMIT";
1556
1543
 
1557
1544
bool insert_precheck(Session *session, TableList *)
1558
1545
{
1559
 
  LEX *lex= session->lex;
1560
 
 
1561
1546
  /*
1562
1547
    Check that we have modify privileges for the first table and
1563
1548
    select privileges for the rest
1564
1549
  */
1565
 
  if (lex->update_list.elements != lex->value_list.elements)
 
1550
  if (session->lex().update_list.size() != session->lex().value_list.size())
1566
1551
  {
1567
1552
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1568
1553
    return(true);
1589
1574
  {
1590
1575
    /* it is NOT(NOT( ... )) */
1591
1576
    Item *arg= ((Item_func *) expr)->arguments()[0];
1592
 
    enum_parsing_place place= session->lex->current_select->parsing_place;
 
1577
    enum_parsing_place place= session->lex().current_select->parsing_place;
1593
1578
    if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING)
1594
1579
      return arg;
1595
1580
    /*
1622
1607
 
1623
1608
 
1624
1609
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
1625
 
                              uint32_t max_char_length, const CHARSET_INFO * const cs,
 
1610
                              uint32_t max_char_length, const charset_info_st * const cs,
1626
1611
                              bool no_error)
1627
1612
{
1628
1613
  int well_formed_error;
1647
1632
    so they should be prohibited until such support is done.
1648
1633
    This is why we use the 3-byte utf8 to check well-formedness here.
1649
1634
  */
1650
 
  const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
 
1635
  const charset_info_st * const cs= &my_charset_utf8mb4_general_ci;
1651
1636
 
1652
1637
  int well_formed_error;
1653
1638
  uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
1705
1690
 
1706
1691
  /* Parse the query. */
1707
1692
 
1708
 
  bool parse_status= DRIZZLEparse(session) != 0;
 
1693
  bool parse_status= base_sql_parse(session) != 0;
1709
1694
 
1710
1695
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1711
1696