~ubuntu-branches/ubuntu/natty/mysql-5.1/natty

« back to all changes in this revision

Viewing changes to sql/sql_parse.cc

Tags: 5.1.54-1ubuntu1
* Synchronize from Debian Experimental:
* Merge from debian unstable:
  + debian/control:
     * Update maintainer according to spec.
     * Move section from "misc" to "database".
     * Added libmysqlclient16-dev an empty transitional package. 
     * Added mysql-client-core-5.1 package.
     * Suggest mailx for mysql-server-5.1
     * Add mysql-testsuite package so you can run the testsuite seperately.
  + debian/additions/my.cnf:
    * Remove language options. Error message files are located in a different directory in Mysql
      5.0. Setting the language option to use /usr/share/mysql/english breaks Mysql 5.0. Both 5.0
      and 5.1 use a different value that works. (LP: #316974)
  + Add apparmor profile:
    + debian/apparmor-profile: apparmor-profile
    + debian/rules, debian/mysql-server-5.1.files: install apparmor profile
    + debian/mysql-server-5.1.dirs: add etc/apparmor.d/fore-complain
    + debian/mysql-server-5.1.postrm: remove symlink in force-complain/ on purge.
    + debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    + debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    + debian/mysql-server-5.1.postinst: reload apparmor profiles
  * Convert the package from sysvinit to upstart:
    + debian/mysql-server-5.1.mysql.upstart: Add upstart script.
    + debian/mysql-server-5.1.mysql.init: Dropped, unused now with upstart.
    + debian/additions/mysqld_safe_syslog.cnf: Dropped, unused now with upstart.
    + debian/additons/my.cnf: Remove pid declaration and setup error logging to /var/log/mysql since
      we're not piping anything around logger anymore.
    + debian/rules, debian/mysql-server-5.1.logcheck.ignore.{paranoid,worstation},
      debian/mysql-server-5.1.logcheck.ignore.server: : Remove references to mysqld_safe
    + debian/patches/38_scripts_mysqld_safe.sh_signals.dpatch: Dropped
  * Added -fno-strict-aliasing to CFLAGS to get around mysql testsuite build failures.
  * Add Apport hook (LP: #354188):
    + debian/mysql-server-5.1.py: apport package hook
    + debian/rules: Make it installable
  * debian/mysql-server-5.1.mysql-server.logrotate: Check to see if mysql is running before
    running logrotate. (LP: #513135)
  * Make the testsuite installable. (LP: #530752)
    + debian/mysql-server-5.1.files, debian/rules: install apport package hook
  * debian/mysql-server-5.1.preinst: Set mysql user's home directory
    to /nonexistent to protect against having the /var/lib/mysql
    user-writeable. If an attacker can trick mysqld into creating
    dot files in the home directory, he could do .rhost-like attacks
    on the system. (LP: #293258)
  * debian/control: mysql-client-5.1 should depend on mysql-core-client-5.1.
    (LP: #590952)
  * debian/mysql-server.5.1.postinst: Specify the mysql user when installing 
    the mysql databases. (LP: #591875)
  * Installing mysql_config_pic in /usr/bin so users of libmysqld-pic
    can extract the appropriate compile flags. (LP: #605021) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "sp_cache.h"
28
28
#include "events.h"
29
29
#include "sql_trigger.h"
 
30
#include "debug_sync.h"
30
31
 
31
32
/**
32
33
  @defgroup Runtime_Environment Runtime Environment
465
466
      }
466
467
      buff= (char*) thd->net.buff;
467
468
      res= fgets(buff + length, thd->net.max_packet - length, file);
 
469
      if (!res && !feof(file))
 
470
      {
 
471
        net_end_statement(thd);
 
472
        bootstrap_error= 1;
 
473
        break;
 
474
      }
468
475
      length+= (ulong) strlen(buff + length);
469
476
      /* purecov: end */
470
477
    }
1535
1542
  {
1536
1543
    STATUS_VAR current_global_status_var;
1537
1544
    ulong uptime;
1538
 
    uint length;
 
1545
    uint length __attribute__((unused));
1539
1546
    ulonglong queries_per_second1000;
1540
1547
    char buff[250];
1541
1548
    uint buff_len= sizeof(buff);
1548
1555
    else
1549
1556
      queries_per_second1000= thd->query_id * LL(1000) / uptime;
1550
1557
 
1551
 
    length= my_snprintf((char*) buff, buff_len - 1,
 
1558
    length= my_snprintf(buff, buff_len - 1,
1552
1559
                        "Uptime: %lu  Threads: %d  Questions: %lu  "
1553
1560
                        "Slow queries: %lu  Opens: %lu  Flush tables: %lu  "
1554
1561
                        "Open tables: %u  Queries per second avg: %u.%u",
1560
1567
                        cached_open_tables(),
1561
1568
                        (uint) (queries_per_second1000 / 1000),
1562
1569
                        (uint) (queries_per_second1000 % 1000));
1563
 
#ifdef EMBEDDED_LIBRARY
1564
 
    /* Store the buffer in permanent memory */
1565
 
    my_ok(thd, 0, 0, buff);
1566
 
#endif
1567
1570
#ifdef SAFEMALLOC
1568
1571
    if (sf_malloc_cur_memory)                           // Using SAFEMALLOC
1569
1572
    {
1578
1581
    VOID(my_net_write(net, (uchar*) buff, length));
1579
1582
    VOID(net_flush(net));
1580
1583
    thd->main_da.disable_status();
 
1584
#else
 
1585
    /* Store the buffer in permanent memory */
 
1586
    my_ok(thd, 0, 0, buff);
1581
1587
#endif
1582
1588
    break;
1583
1589
  }
2712
2718
        {
2713
2719
          TABLE_LIST *duplicate;
2714
2720
          create_table= lex->unlink_first_table(&link_to_local);
 
2721
 
 
2722
          if (create_table->view)
 
2723
          {
 
2724
            if (create_info.options & HA_LEX_CREATE_IF_NOT_EXISTS)
 
2725
            {
 
2726
              push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2727
                                  ER_TABLE_EXISTS_ERROR,
 
2728
                                  ER(ER_TABLE_EXISTS_ERROR),
 
2729
                                  create_info.alias);
 
2730
              my_ok(thd);
 
2731
            }
 
2732
            else
 
2733
            {
 
2734
              my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_info.alias);
 
2735
              res= 1;
 
2736
            }
 
2737
            goto end_with_restore_list;
 
2738
          }
 
2739
 
2715
2740
          if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
2716
2741
          {
2717
2742
            update_non_unique_table_error(create_table, "CREATE", duplicate);
3234
3259
      thd->first_successful_insert_id_in_cur_stmt=
3235
3260
        thd->first_successful_insert_id_in_prev_stmt;
3236
3261
 
 
3262
    DBUG_EXECUTE_IF("after_mysql_insert",
 
3263
                    {
 
3264
                      const char act[]=
 
3265
                        "now "
 
3266
                        "wait_for signal.continue";
 
3267
                      DBUG_ASSERT(opt_debug_sync_timeout > 0);
 
3268
                      DBUG_ASSERT(!debug_sync_set_action(current_thd,
 
3269
                                                         STRING_WITH_LEN(act)));
 
3270
                    };);
3237
3271
    break;
3238
3272
  }
3239
3273
  case SQLCOM_REPLACE_SELECT:
3889
3923
    if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1, 0) &&
3890
3924
        check_global_access(thd,CREATE_USER_ACL))
3891
3925
      break;
 
3926
 
 
3927
    /* Replicate current user as grantor */
 
3928
    thd->binlog_invoker();
 
3929
 
3892
3930
    /* Conditionally writes to binlog */
3893
3931
    if (!(res = mysql_revoke_all(thd, lex->users_list)))
3894
3932
      my_ok(thd);
3909
3947
                     is_schema_db(select_lex->db) : 0))
3910
3948
      goto error;
3911
3949
 
 
3950
    /* Replicate current user as grantor */
 
3951
    thd->binlog_invoker();
 
3952
 
3912
3953
    if (thd->security_ctx->user)              // If not replication
3913
3954
    {
3914
3955
      LEX_USER *user, *tmp_user;
4730
4771
        my_error(ER_XAER_NOTA, MYF(0));
4731
4772
        break;
4732
4773
      }
4733
 
      thd->transaction.xid_state.xa_state=XA_ACTIVE;
 
4774
      thd->transaction.xid_state.xa_state= XA_ACTIVE;
4734
4775
      my_ok(thd);
4735
4776
      break;
4736
4777
    }
4750
4791
      my_error(ER_XAER_OUTSIDE, MYF(0));
4751
4792
      break;
4752
4793
    }
4753
 
    if (xid_cache_search(thd->lex->xid))
4754
 
    {
4755
 
      my_error(ER_XAER_DUPID, MYF(0));
4756
 
      break;
4757
 
    }
4758
4794
    DBUG_ASSERT(thd->transaction.xid_state.xid.is_null());
4759
 
    thd->transaction.xid_state.xa_state=XA_ACTIVE;
 
4795
    thd->transaction.xid_state.xa_state= XA_ACTIVE;
4760
4796
    thd->transaction.xid_state.rm_error= 0;
4761
4797
    thd->transaction.xid_state.xid.set(thd->lex->xid);
4762
 
    xid_cache_insert(&thd->transaction.xid_state);
 
4798
    if (xid_cache_insert(&thd->transaction.xid_state))
 
4799
    {
 
4800
      thd->transaction.xid_state.xa_state= XA_NOTR;
 
4801
      thd->transaction.xid_state.xid.null();
 
4802
      break;
 
4803
    }
4763
4804
    thd->transaction.all.modified_non_trans_table= FALSE;
4764
4805
    thd->options= ((thd->options & ~(OPTION_KEEP_LOG)) | OPTION_BEGIN);
4765
4806
    thd->server_status|= SERVER_STATUS_IN_TRANS;
4813
4854
  case SQLCOM_XA_COMMIT:
4814
4855
    if (!thd->transaction.xid_state.xid.eq(thd->lex->xid))
4815
4856
    {
 
4857
      /*
 
4858
        xid_state.in_thd is always true beside of xa recovery
 
4859
        procedure. Note, that there is no race condition here
 
4860
        between xid_cache_search and xid_cache_delete, since we're always
 
4861
        deleting our own XID (thd->lex->xid == thd->transaction.xid_state.xid).
 
4862
        The only case when thd->lex->xid != thd->transaction.xid_state.xid
 
4863
        and xid_state->in_thd == 0 is in ha_recover() functionality,
 
4864
        which is called before starting client connections, and thus is
 
4865
        always single-threaded.
 
4866
      */
4816
4867
      XID_STATE *xs=xid_cache_search(thd->lex->xid);
4817
4868
      if (!xs || xs->in_thd)
4818
4869
        my_error(ER_XAER_NOTA, MYF(0));
5931
5982
  Parse a query.
5932
5983
 
5933
5984
  @param       thd     Current thread
5934
 
  @param       inBuf   Begining of the query text
 
5985
  @param       rawbuf  Begining of the query text
5935
5986
  @param       length  Length of the query text
5936
5987
  @param[out]  found_semicolon For multi queries, position of the character of
5937
5988
                               the next query in the query text.
5938
5989
*/
5939
5990
 
5940
 
void mysql_parse(THD *thd, const char *inBuf, uint length,
 
5991
void mysql_parse(THD *thd, char *rawbuf, uint length,
5941
5992
                 const char ** found_semicolon)
5942
5993
{
5943
5994
  DBUG_ENTER("mysql_parse");
5963
6014
  lex_start(thd);
5964
6015
  mysql_reset_thd_for_next_command(thd);
5965
6016
 
5966
 
  if (query_cache_send_result_to_client(thd, (char*) inBuf, length) <= 0)
 
6017
  if (query_cache_send_result_to_client(thd, rawbuf, length) <= 0)
5967
6018
  {
5968
6019
    LEX *lex= thd->lex;
5969
6020
 
5972
6023
 
5973
6024
    Parser_state parser_state;
5974
6025
    bool err;
5975
 
    if (!(err= parser_state.init(thd, inBuf, length)))
 
6026
    if (!(err= parser_state.init(thd, rawbuf, length)))
5976
6027
    {
5977
6028
      err= parse_sql(thd, & parser_state, NULL);
5978
6029
      *found_semicolon= parser_state.m_lip.found_semicolon;
6058
6109
    1   can be ignored
6059
6110
*/
6060
6111
 
6061
 
bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
 
6112
bool mysql_test_parse_for_slave(THD *thd, char *rawbuf, uint length)
6062
6113
{
6063
6114
  LEX *lex= thd->lex;
6064
6115
  bool error= 0;
6065
6116
  DBUG_ENTER("mysql_test_parse_for_slave");
6066
6117
 
6067
6118
  Parser_state parser_state;
6068
 
  if (!(error= parser_state.init(thd, inBuf, length)))
 
6119
  if (!(error= parser_state.init(thd, rawbuf, length)))
6069
6120
  {
6070
6121
    lex_start(thd);
6071
6122
    mysql_reset_thd_for_next_command(thd);
7654
7705
  if (! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))
7655
7706
    return 0;
7656
7707
 
7657
 
  get_default_definer(thd, definer);
 
7708
  thd->get_definer(definer);
7658
7709
 
7659
7710
  return definer;
7660
7711
}