~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

updating

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
                         can be zero.
170
170
 
171
171
  @todo
172
 
    set session->getLex()->sql_command to SQLCOM_END here.
 
172
    set session->lex().sql_command to SQLCOM_END here.
173
173
  @todo
174
174
    The following has to be changed to an 8 byte integer
175
175
 
188
188
  DRIZZLE_COMMAND_START(session->thread_id, command);
189
189
 
190
190
  session->command= command;
191
 
  session->getLex()->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
 
191
  session->lex().sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
192
192
  session->set_time();
193
193
  session->setQueryId(query_id.value());
194
194
 
202
202
    query_id.next();
203
203
  }
204
204
 
205
 
  /* @todo set session->getLex()->sql_command to SQLCOM_END here */
 
205
  /* @todo set session->lex().sql_command to SQLCOM_END here */
206
206
 
207
207
  plugin::Logging::preDo(session);
208
208
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
260
260
      {
261
261
        uint32_t kill_id;
262
262
        memcpy(&kill_id, packet, sizeof(uint32_t));
263
 
        
 
263
 
264
264
        kill_id= ntohl(kill_id);
265
265
        (void)drizzled::kill(*session->user(), kill_id, true);
266
266
      }
415
415
  return false;
416
416
}
417
417
 
418
 
int prepare_new_schema_table(Session *session, LEX *lex,
 
418
int prepare_new_schema_table(Session *session, LEX& lex,
419
419
                             const string& schema_table_name)
420
420
{
421
421
  Select_Lex *schema_select_lex= NULL;
422
422
 
423
 
  Select_Lex *select_lex= lex->current_select;
 
423
  Select_Lex *select_lex= lex.current_select;
424
424
  assert(select_lex);
425
425
  if (_schema_select(session, select_lex, schema_table_name))
426
426
  {
468
468
  bool res= false;
469
469
 
470
470
  /* first Select_Lex (have special meaning for many of non-SELECTcommands) */
471
 
  Select_Lex *select_lex= &session->getLex()->select_lex;
 
471
  Select_Lex *select_lex= &session->lex().select_lex;
472
472
 
473
473
  /* list of all tables in query */
474
474
  TableList *all_tables;
488
488
    assert(first_table == all_tables);
489
489
    assert(first_table == all_tables && first_table != 0);
490
490
  */
491
 
  session->getLex()->first_lists_tables_same();
 
491
  session->lex().first_lists_tables_same();
492
492
 
493
493
  /* should be assigned after making first tables same */
494
 
  all_tables= session->getLex()->query_tables;
 
494
  all_tables= session->lex().query_tables;
495
495
 
496
496
  /* set context for commands which do not use setup_tables */
497
497
  select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
503
503
    variables, but for now this is probably good enough.
504
504
    Don't reset warnings when executing a stored routine.
505
505
  */
506
 
  if (all_tables || ! session->getLex()->is_single_level_stmt())
 
506
  if (all_tables || ! session->lex().is_single_level_stmt())
507
507
  {
508
508
    drizzle_reset_errors(session, 0);
509
509
  }
512
512
 
513
513
  if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
514
514
      && ! session->inTransaction()
515
 
      && session->getLex()->statement->isTransactional())
 
515
      && session->lex().statement->isTransactional())
516
516
  {
517
517
    if (session->startTransaction() == false)
518
518
    {
522
522
  }
523
523
 
524
524
  /* now we are ready to execute the statement */
525
 
  res= session->getLex()->statement->execute();
 
525
  res= session->lex().statement->execute();
526
526
  session->set_proc_info("query end");
527
527
  /*
528
528
    The return value for ROW_COUNT() is "implementation dependent" if the
530
530
    wants. We also keep the last value in case of SQLCOM_CALL or
531
531
    SQLCOM_EXECUTE.
532
532
  */
533
 
  if (! (sql_command_flags[session->getLex()->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
 
533
  if (! (sql_command_flags[session->lex().sql_command].test(CF_BIT_HAS_ROW_COUNT)))
534
534
  {
535
535
    session->row_count_func= -1;
536
536
  }
539
539
}
540
540
bool execute_sqlcom_select(Session *session, TableList *all_tables)
541
541
{
542
 
  LEX   *lex= session->getLex();
 
542
  LEX   *lex= &session->lex();
543
543
  select_result *result=lex->result;
544
544
  bool res= false;
545
545
  /* assign global limit variable if limit is not given */
576
576
        return true;
577
577
      session->send_explain_fields(result);
578
578
      optimizer::ExplainPlan planner;
579
 
      res= planner.explainUnion(session, &session->getLex()->unit, result);
 
579
      res= planner.explainUnion(session, &session->lex().unit, result);
580
580
      if (lex->describe & DESCRIBE_EXTENDED)
581
581
      {
582
582
        char buff[1024];
583
583
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
584
584
        str.length(0);
585
 
        session->getLex()->unit.print(&str);
 
585
        session->lex().unit.print(&str);
586
586
        str.append('\0');
587
587
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
588
588
                     ER_YES, str.ptr());
600
600
        return true;
601
601
 
602
602
      /* Init the Query Cache plugin */
603
 
      plugin::QueryCache::prepareResultset(session); 
 
603
      plugin::QueryCache::prepareResultset(session);
604
604
      res= handle_select(session, lex, result, 0);
605
605
      /* Send the Resultset to the cache */
606
 
      plugin::QueryCache::setResultset(session); 
 
606
      plugin::QueryCache::setResultset(session);
607
607
 
608
608
      if (result != lex->result)
609
609
        delete result;
618
618
 
619
619
bool my_yyoverflow(short **yyss, ParserType **yyvs, ulong *yystacksize)
620
620
{
621
 
  LEX   *lex= current_session->getLex();
 
621
  LEX   *lex= &current_session->lex();
622
622
  ulong old_info=0;
623
623
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
624
624
    return 1;
751
751
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
752
752
  char *end= buff;
753
753
 
754
 
  lex= session->getLex();
 
754
  lex= &session->lex();
755
755
  init_select(lex);
756
756
  lex->sql_command= SQLCOM_SELECT;
757
757
  tmp.str= (char*) var_name;
780
780
 
781
781
void parse(Session *session, const char *inBuf, uint32_t length)
782
782
{
783
 
  session->getLex()->start(session);
 
783
  session->lex().start(session);
784
784
 
785
785
  session->reset_for_next_command();
786
786
  /* Check if the Query is Cached if and return true if yes
796
796
  {
797
797
    return;
798
798
  }
799
 
  LEX *lex= session->getLex();
 
799
  LEX *lex= &session->lex();
800
800
  Lex_input_stream lip(session, inBuf, length);
801
801
  bool err= parse_sql(session, &lip);
802
802
  if (!err)
809
809
                                 const_cast<const char *>(session->schema()->c_str()));
810
810
        // Implement Views here --Brian
811
811
        /* Actually execute the query */
812
 
        try 
 
812
        try
813
813
        {
814
814
          execute_command(session);
815
815
        }
853
853
                       List<String> *interval_list, const CHARSET_INFO * const cs)
854
854
{
855
855
  register CreateField *new_field;
856
 
  LEX  *lex= session->getLex();
 
856
  LEX  *lex= &session->lex();
857
857
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
858
858
 
859
859
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
961
961
  TableList *ptr;
962
962
  TableList *previous_table_ref; /* The table preceding the current one. */
963
963
  char *alias_str;
964
 
  LEX *lex= session->getLex();
 
964
  LEX *lex= &session->lex();
965
965
 
966
966
  if (!table)
967
967
    return NULL;                                // End of memory
1331
1331
  fake_select_lex->include_standalone(this,
1332
1332
                                      (Select_Lex_Node**)&fake_select_lex);
1333
1333
  fake_select_lex->select_number= INT_MAX;
1334
 
  fake_select_lex->parent_lex= session_arg->getLex(); /* Used in init_query. */
 
1334
  fake_select_lex->parent_lex= &session_arg->lex(); /* Used in init_query. */
1335
1335
  fake_select_lex->make_empty_select();
1336
1336
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1337
1337
  fake_select_lex->select_limit= 0;
1351
1351
    */
1352
1352
    global_parameters= fake_select_lex;
1353
1353
    fake_select_lex->no_table_names_allowed= 1;
1354
 
    session_arg->getLex()->current_select= fake_select_lex;
 
1354
    session_arg->lex().current_select= fake_select_lex;
1355
1355
  }
1356
 
  session_arg->getLex()->pop_context();
 
1356
  session_arg->lex().pop_context();
1357
1357
  return(0);
1358
1358
}
1359
1359
 
1389
1389
    left_op->first_leaf_for_name_resolution();
1390
1390
  on_context->last_name_resolution_table=
1391
1391
    right_op->last_leaf_for_name_resolution();
1392
 
  return session->getLex()->push_context(on_context);
 
1392
  return session->lex().push_context(on_context);
1393
1393
}
1394
1394
 
1395
1395
 
1479
1479
 
1480
1480
bool check_simple_select(Session::pointer session)
1481
1481
{
1482
 
  if (session->getLex()->current_select != &session->getLex()->select_lex)
 
1482
  if (session->lex().current_select != &session->lex().select_lex)
1483
1483
  {
1484
1484
    char command[80];
1485
1485
    Lex_input_stream *lip= session->m_lip;
1539
1539
bool update_precheck(Session *session, TableList *)
1540
1540
{
1541
1541
  const char *msg= 0;
1542
 
  Select_Lex *select_lex= &session->getLex()->select_lex;
 
1542
  Select_Lex *select_lex= &session->lex().select_lex;
1543
1543
 
1544
 
  if (session->getLex()->select_lex.item_list.size() != session->getLex()->value_list.size())
 
1544
  if (session->lex().select_lex.item_list.size() != session->lex().value_list.size())
1545
1545
  {
1546
1546
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1547
1547
    return(true);
1548
1548
  }
1549
1549
 
1550
 
  if (session->getLex()->select_lex.table_list.size() > 1)
 
1550
  if (session->lex().select_lex.table_list.size() > 1)
1551
1551
  {
1552
1552
    if (select_lex->order_list.size())
1553
1553
      msg= "ORDER BY";
1581
1581
    Check that we have modify privileges for the first table and
1582
1582
    select privileges for the rest
1583
1583
  */
1584
 
  if (session->getLex()->update_list.size() != session->getLex()->value_list.size())
 
1584
  if (session->lex().update_list.size() != session->lex().value_list.size())
1585
1585
  {
1586
1586
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1587
1587
    return(true);
1608
1608
  {
1609
1609
    /* it is NOT(NOT( ... )) */
1610
1610
    Item *arg= ((Item_func *) expr)->arguments()[0];
1611
 
    enum_parsing_place place= session->getLex()->current_select->parsing_place;
 
1611
    enum_parsing_place place= session->lex().current_select->parsing_place;
1612
1612
    if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING)
1613
1613
      return arg;
1614
1614
    /*