~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

merged with up to date trunk

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/abort_exception.h"
20
21
#include <drizzled/my_hash.h>
21
22
#include <drizzled/error.h>
22
23
#include <drizzled/nested_join.h>
67
68
/* Prototypes */
68
69
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
69
70
static bool parse_sql(Session *session, Lex_input_stream *lip);
70
 
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
 
71
void parse(Session *session, const char *inBuf, uint32_t length);
71
72
 
72
73
/**
73
74
  @defgroup Runtime_Environment Runtime Environment
210
211
 
211
212
    SchemaIdentifier identifier(tmp);
212
213
 
213
 
    if (not mysql_change_db(session, identifier))
 
214
    if (not change_db(session, identifier))
214
215
    {
215
216
      session->my_ok();
216
217
    }
224
225
                        session->thread_id,
225
226
                        const_cast<const char *>(session->schema()->c_str()));
226
227
 
227
 
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
 
228
    parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
228
229
 
229
230
    break;
230
231
  }
282
283
  {
283
284
  case Diagnostics_area::DA_ERROR:
284
285
    /* The query failed, send error to log and abort bootstrap. */
285
 
    session->client->sendError(session->main_da.sql_errno(),
 
286
    session->getClient()->sendError(session->main_da.sql_errno(),
286
287
                               session->main_da.message());
287
288
    break;
288
289
 
289
290
  case Diagnostics_area::DA_EOF:
290
 
    session->client->sendEOF();
 
291
    session->getClient()->sendEOF();
291
292
    break;
292
293
 
293
294
  case Diagnostics_area::DA_OK:
294
 
    session->client->sendOK();
 
295
    session->getClient()->sendOK();
295
296
    break;
296
297
 
297
298
  case Diagnostics_area::DA_DISABLED:
299
300
 
300
301
  case Diagnostics_area::DA_EMPTY:
301
302
  default:
302
 
    session->client->sendOK();
 
303
    session->getClient()->sendOK();
303
304
    break;
304
305
  }
305
306
 
429
430
    true        Error
430
431
*/
431
432
 
432
 
static int mysql_execute_command(Session *session)
 
433
static int execute_command(Session *session)
433
434
{
434
435
  bool res= false;
435
436
  LEX  *lex= session->lex;
587
588
 
588
589
 
589
590
void
590
 
mysql_init_select(LEX *lex)
 
591
init_select(LEX *lex)
591
592
{
592
593
  Select_Lex *select_lex= lex->current_select;
593
594
  select_lex->init_select();
601
602
 
602
603
 
603
604
bool
604
 
mysql_new_select(LEX *lex, bool move_down)
 
605
new_select(LEX *lex, bool move_down)
605
606
{
606
607
  Select_Lex *select_lex;
607
608
  Session *session= lex->session;
687
688
 
688
689
  session= current_session;
689
690
  lex= session->lex;
690
 
  mysql_init_select(lex);
 
691
  init_select(lex);
691
692
  lex->sql_command= SQLCOM_SELECT;
692
693
  tmp.str= (char*) var_name;
693
694
  tmp.length=strlen(var_name);
714
715
  @param       length  Length of the query text
715
716
*/
716
717
 
717
 
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
 
718
void parse(Session *session, const char *inBuf, uint32_t length)
718
719
{
719
 
  boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
720
720
  session->lex->start(session);
721
721
 
722
722
  session->reset_for_next_command();
748
748
        /* Actually execute the query */
749
749
        try 
750
750
        {
751
 
          mysql_execute_command(session);
 
751
          execute_command(session);
752
752
        }
753
753
        catch (...)
754
754
        {
755
755
          // Just try to catch any random failures that could have come
756
756
          // during execution.
757
 
          unireg_abort(1);
 
757
          DRIZZLE_ABORT;
758
758
        }
759
759
        DRIZZLE_QUERY_EXEC_DONE(0);
760
760
      }
768
768
  session->set_proc_info("freeing items");
769
769
  session->end_statement();
770
770
  session->cleanup_after_query();
771
 
  boost::posix_time::ptime end_time=boost::posix_time::microsec_clock::local_time();
772
 
  session->status_var.execution_time_nsec+=(end_time-start_time).total_microseconds();
 
771
  session->set_end_timer();
773
772
}
774
773
 
775
774
 
1423
1422
    1   error   ; In this case the error messege is sent to the client
1424
1423
*/
1425
1424
 
1426
 
bool check_simple_select()
 
1425
bool check_simple_select(Session::pointer session)
1427
1426
{
1428
 
  Session *session= current_session;
1429
1427
  LEX *lex= session->lex;
1430
1428
  if (lex->current_select != &lex->select_lex)
1431
1429
  {
1542
1540
 
1543
1541
 
1544
1542
/**
1545
 
  CREATE TABLE query pre-check.
1546
 
 
1547
 
  @param session                        Thread handler
1548
 
  @param tables         Global table list
1549
 
  @param create_table           Table which will be created
1550
 
 
1551
 
  @retval
1552
 
    false   OK
1553
 
  @retval
1554
 
    true   Error
1555
 
*/
1556
 
 
1557
 
bool create_table_precheck(TableIdentifier &identifier)
1558
 
{
1559
 
  if (not plugin::StorageEngine::canCreateTable(identifier))
1560
 
  {
1561
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
1562
 
    return true;
1563
 
  }
1564
 
 
1565
 
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
1566
 
  {
1567
 
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
1568
 
    return true;
1569
 
  }
1570
 
 
1571
 
  return false;
1572
 
}
1573
 
 
1574
 
 
1575
 
/**
1576
1543
  negate given expression.
1577
1544
 
1578
1545
  @param session  thread handler
1639
1606
}
1640
1607
 
1641
1608
 
1642
 
bool check_identifier_name(LEX_STRING *str, uint32_t err_code,
 
1609
bool check_identifier_name(LEX_STRING *str, error_t err_code,
1643
1610
                           uint32_t max_char_length,
1644
1611
                           const char *param_for_err_msg)
1645
1612
{
1665
1632
 
1666
1633
  switch (err_code)
1667
1634
  {
1668
 
  case 0:
 
1635
  case EE_OK:
1669
1636
    break;
1670
1637
  case ER_WRONG_STRING_LENGTH:
1671
1638
    my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length);
1677
1644
    assert(0);
1678
1645
    break;
1679
1646
  }
 
1647
 
1680
1648
  return true;
1681
1649
}
1682
1650
 
1705
1673
 
1706
1674
  /* Parse the query. */
1707
1675
 
1708
 
  bool mysql_parse_status= DRIZZLEparse(session) != 0;
 
1676
  bool parse_status= DRIZZLEparse(session) != 0;
1709
1677
 
1710
1678
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1711
1679
 
1712
 
  assert(!mysql_parse_status || session->is_error());
 
1680
  assert(!parse_status || session->is_error());
1713
1681
 
1714
1682
  /* Reset Lex_input_stream. */
1715
1683
 
1716
1684
  session->m_lip= NULL;
1717
1685
 
1718
 
  DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
 
1686
  DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
1719
1687
 
1720
1688
  /* That's it. */
1721
1689
 
1722
 
  return mysql_parse_status || session->is_fatal_error;
 
1690
  return parse_status || session->is_fatal_error;
1723
1691
}
1724
1692
 
1725
1693
/**