~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Lee Bieber
  • Date: 2011-02-21 21:20:44 UTC
  • mfrom: (2187.1.2 build)
  • Revision ID: kalebral@gmail.com-20110221212044-x1j9pmv0230febuz
Merge Brian - getLex() usage and fix for table_name creation during admin commands.
Merge Olaf - Use List::begin() and Use List::iterator instead of List_iterator_fast

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
                         can be zero.
169
169
 
170
170
  @todo
171
 
    set session->lex->sql_command to SQLCOM_END here.
 
171
    set session->getLex()->sql_command to SQLCOM_END here.
172
172
  @todo
173
173
    The following has to be changed to an 8 byte integer
174
174
 
187
187
  DRIZZLE_COMMAND_START(session->thread_id, command);
188
188
 
189
189
  session->command= command;
190
 
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
 
190
  session->getLex()->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
191
191
  session->set_time();
192
192
  session->setQueryId(query_id.value());
193
193
 
201
201
    query_id.next();
202
202
  }
203
203
 
204
 
  /* @todo set session->lex->sql_command to SQLCOM_END here */
 
204
  /* @todo set session->getLex()->sql_command to SQLCOM_END here */
205
205
 
206
206
  plugin::Logging::preDo(session);
207
207
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
446
446
static int execute_command(Session *session)
447
447
{
448
448
  bool res= false;
449
 
  LEX  *lex= session->lex;
 
449
 
450
450
  /* first Select_Lex (have special meaning for many of non-SELECTcommands) */
451
 
  Select_Lex *select_lex= &lex->select_lex;
 
451
  Select_Lex *select_lex= &session->getLex()->select_lex;
 
452
 
452
453
  /* list of all tables in query */
453
454
  TableList *all_tables;
454
455
 
467
468
    assert(first_table == all_tables);
468
469
    assert(first_table == all_tables && first_table != 0);
469
470
  */
470
 
  lex->first_lists_tables_same();
 
471
  session->getLex()->first_lists_tables_same();
 
472
 
471
473
  /* should be assigned after making first tables same */
472
 
  all_tables= lex->query_tables;
 
474
  all_tables= session->getLex()->query_tables;
 
475
 
473
476
  /* set context for commands which do not use setup_tables */
474
 
  select_lex->
475
 
    context.resolve_in_table_list_only((TableList*)select_lex->
476
 
                                       table_list.first);
 
477
  select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
477
478
 
478
479
  /*
479
480
    Reset warning count for each query that uses tables
482
483
    variables, but for now this is probably good enough.
483
484
    Don't reset warnings when executing a stored routine.
484
485
  */
485
 
  if (all_tables || ! lex->is_single_level_stmt())
 
486
  if (all_tables || ! session->getLex()->is_single_level_stmt())
486
487
  {
487
488
    drizzle_reset_errors(session, 0);
488
489
  }
491
492
 
492
493
  if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
493
494
      && ! session->inTransaction()
494
 
      && lex->statement->isTransactional())
 
495
      && session->getLex()->statement->isTransactional())
495
496
  {
496
497
    if (session->startTransaction() == false)
497
498
    {
501
502
  }
502
503
 
503
504
  /* now we are ready to execute the statement */
504
 
  res= lex->statement->execute();
 
505
  res= session->getLex()->statement->execute();
505
506
  session->set_proc_info("query end");
506
507
  /*
507
508
    The return value for ROW_COUNT() is "implementation dependent" if the
509
510
    wants. We also keep the last value in case of SQLCOM_CALL or
510
511
    SQLCOM_EXECUTE.
511
512
  */
512
 
  if (! (sql_command_flags[lex->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
 
513
  if (! (sql_command_flags[session->getLex()->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
513
514
  {
514
515
    session->row_count_func= -1;
515
516
  }
518
519
}
519
520
bool execute_sqlcom_select(Session *session, TableList *all_tables)
520
521
{
521
 
  LEX   *lex= session->lex;
 
522
  LEX   *lex= session->getLex();
522
523
  select_result *result=lex->result;
523
524
  bool res= false;
524
525
  /* assign global limit variable if limit is not given */
555
556
        return true;
556
557
      session->send_explain_fields(result);
557
558
      optimizer::ExplainPlan planner;
558
 
      res= planner.explainUnion(session, &session->lex->unit, result);
 
559
      res= planner.explainUnion(session, &session->getLex()->unit, result);
559
560
      if (lex->describe & DESCRIBE_EXTENDED)
560
561
      {
561
562
        char buff[1024];
562
563
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
563
564
        str.length(0);
564
 
        session->lex->unit.print(&str, QT_ORDINARY);
 
565
        session->getLex()->unit.print(&str, QT_ORDINARY);
565
566
        str.append('\0');
566
567
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
567
568
                     ER_YES, str.ptr());
597
598
 
598
599
bool my_yyoverflow(short **yyss, ParserType **yyvs, ulong *yystacksize)
599
600
{
600
 
  LEX   *lex= current_session->lex;
 
601
  LEX   *lex= current_session->getLex();
601
602
  ulong old_info=0;
602
603
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
603
604
    return 1;
730
731
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
731
732
  char *end= buff;
732
733
 
733
 
  lex= session->lex;
 
734
  lex= session->getLex();
734
735
  init_select(lex);
735
736
  lex->sql_command= SQLCOM_SELECT;
736
737
  tmp.str= (char*) var_name;
759
760
 
760
761
void parse(Session *session, const char *inBuf, uint32_t length)
761
762
{
762
 
  session->lex->start(session);
 
763
  session->getLex()->start(session);
763
764
 
764
765
  session->reset_for_next_command();
765
766
  /* Check if the Query is Cached if and return true if yes
775
776
  {
776
777
    return;
777
778
  }
778
 
  LEX *lex= session->lex;
 
779
  LEX *lex= session->getLex();
779
780
  Lex_input_stream lip(session, inBuf, length);
780
781
  bool err= parse_sql(session, &lip);
781
782
  if (!err)
832
833
                       List<String> *interval_list, const CHARSET_INFO * const cs)
833
834
{
834
835
  register CreateField *new_field;
835
 
  LEX  *lex= session->lex;
 
836
  LEX  *lex= session->getLex();
836
837
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
837
838
 
838
839
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
940
941
  TableList *ptr;
941
942
  TableList *previous_table_ref; /* The table preceding the current one. */
942
943
  char *alias_str;
943
 
  LEX *lex= session->lex;
 
944
  LEX *lex= session->getLex();
944
945
 
945
946
  if (!table)
946
947
    return NULL;                                // End of memory
1310
1311
  fake_select_lex->include_standalone(this,
1311
1312
                                      (Select_Lex_Node**)&fake_select_lex);
1312
1313
  fake_select_lex->select_number= INT_MAX;
1313
 
  fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */
 
1314
  fake_select_lex->parent_lex= session_arg->getLex(); /* Used in init_query. */
1314
1315
  fake_select_lex->make_empty_select();
1315
1316
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1316
1317
  fake_select_lex->select_limit= 0;
1330
1331
    */
1331
1332
    global_parameters= fake_select_lex;
1332
1333
    fake_select_lex->no_table_names_allowed= 1;
1333
 
    session_arg->lex->current_select= fake_select_lex;
 
1334
    session_arg->getLex()->current_select= fake_select_lex;
1334
1335
  }
1335
 
  session_arg->lex->pop_context();
 
1336
  session_arg->getLex()->pop_context();
1336
1337
  return(0);
1337
1338
}
1338
1339
 
1368
1369
    left_op->first_leaf_for_name_resolution();
1369
1370
  on_context->last_name_resolution_table=
1370
1371
    right_op->last_leaf_for_name_resolution();
1371
 
  return session->lex->push_context(on_context);
 
1372
  return session->getLex()->push_context(on_context);
1372
1373
}
1373
1374
 
1374
1375
 
1458
1459
 
1459
1460
bool check_simple_select(Session::pointer session)
1460
1461
{
1461
 
  LEX *lex= session->lex;
1462
 
  if (lex->current_select != &lex->select_lex)
 
1462
  if (session->getLex()->current_select != &session->getLex()->select_lex)
1463
1463
  {
1464
1464
    char command[80];
1465
1465
    Lex_input_stream *lip= session->m_lip;
1519
1519
bool update_precheck(Session *session, TableList *)
1520
1520
{
1521
1521
  const char *msg= 0;
1522
 
  LEX *lex= session->lex;
1523
 
  Select_Lex *select_lex= &lex->select_lex;
 
1522
  Select_Lex *select_lex= &session->getLex()->select_lex;
1524
1523
 
1525
 
  if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
 
1524
  if (session->getLex()->select_lex.item_list.elements != session->getLex()->value_list.elements)
1526
1525
  {
1527
1526
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1528
1527
    return(true);
1529
1528
  }
1530
1529
 
1531
 
  if (session->lex->select_lex.table_list.elements > 1)
 
1530
  if (session->getLex()->select_lex.table_list.elements > 1)
1532
1531
  {
1533
1532
    if (select_lex->order_list.elements)
1534
1533
      msg= "ORDER BY";
1558
1557
 
1559
1558
bool insert_precheck(Session *session, TableList *)
1560
1559
{
1561
 
  LEX *lex= session->lex;
1562
 
 
1563
1560
  /*
1564
1561
    Check that we have modify privileges for the first table and
1565
1562
    select privileges for the rest
1566
1563
  */
1567
 
  if (lex->update_list.elements != lex->value_list.elements)
 
1564
  if (session->getLex()->update_list.elements != session->getLex()->value_list.elements)
1568
1565
  {
1569
1566
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1570
1567
    return(true);
1591
1588
  {
1592
1589
    /* it is NOT(NOT( ... )) */
1593
1590
    Item *arg= ((Item_func *) expr)->arguments()[0];
1594
 
    enum_parsing_place place= session->lex->current_select->parsing_place;
 
1591
    enum_parsing_place place= session->getLex()->current_select->parsing_place;
1595
1592
    if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING)
1596
1593
      return arg;
1597
1594
    /*