Commit 5a9ba869 authored by Sergei Golubchik's avatar Sergei Golubchik

Added read only system variable 'in_transaction' which tells if there's

an active transaction.

fixed a bug - not clearing "in transaction" status on set @@autocommit=1
parent e696da7b
......@@ -186,4 +186,33 @@ bytes_sent <> 0, binlog_bytes_written <> 0
from information_schema.client_statistics;
connected_time <> 0 busy_time <> 0 bytes_received <> 0 bytes_sent <> 0 binlog_bytes_written <> 0
1 1 1 1 1
create table t1 (a int) engine=innodb;
select @@in_transaction;
@@in_transaction
0
begin;
select @@in_transaction;
@@in_transaction
1
insert into t1 values (1);
select @@in_transaction;
@@in_transaction
1
commit;
select @@in_transaction;
@@in_transaction
0
set @@autocommit=0;
select @@in_transaction;
@@in_transaction
0
insert into t1 values (2);
select @@in_transaction;
@@in_transaction
1
set @@autocommit=1;
select @@in_transaction;
@@in_transaction
0
drop table t1;
set @@global.general_log=@save_general_log;
......@@ -85,5 +85,25 @@ select connected_time <> 0, busy_time <> 0, bytes_received <> 0,
bytes_sent <> 0, binlog_bytes_written <> 0
from information_schema.client_statistics;
#
# Test of in transaction
#
create table t1 (a int) engine=innodb;
select @@in_transaction;
begin;
select @@in_transaction;
insert into t1 values (1);
select @@in_transaction;
commit;
select @@in_transaction;
set @@autocommit=0;
select @@in_transaction;
insert into t1 values (2);
select @@in_transaction;
set @@autocommit=1;
select @@in_transaction;
drop table t1;
# Cleanup
set @@global.general_log=@save_general_log;
......@@ -156,6 +156,7 @@ static bool sys_update_slow_log_path(THD *thd, set_var * var);
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
static void fix_sys_log_slow_filter(THD *thd, enum_var_type);
static uchar *get_myisam_mmap_size(THD *thd);
static uchar *in_transaction(THD *thd);
static int check_max_allowed_packet(THD *thd, set_var *var);
static int check_net_buffer_length(THD *thd, set_var *var);
......@@ -997,6 +998,12 @@ static sys_var_enum_const sys_plugin_maturity(&vars, "plugin_maturity",
&plugin_maturity,
&plugin_maturity_values);
static sys_var_readonly sys_in_transaction(&vars, "in_transaction",
OPT_SESSION, SHOW_BOOL,
in_transaction);
bool sys_var::check(THD *thd, set_var *var)
{
var->save_result.ulonglong_value= var->value->val_int();
......@@ -3269,35 +3276,26 @@ static bool set_option_log_bin_bit(THD *thd, set_var *var)
static bool set_option_autocommit(THD *thd, set_var *var)
{
/* The test is negative as the flag we use is NOT autocommit */
ulonglong new_options= thd->options;
ulonglong org_options= thd->options;
if (var->save_result.ulong_value != 0)
thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
/* The test is negative as the flag we use is NOT autocommit */
if (var->save_result.ulong_value)
new_options&= ~OPTION_NOT_AUTOCOMMIT;
else
thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
new_options|= OPTION_NOT_AUTOCOMMIT;
if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
{
if ((org_options & OPTION_NOT_AUTOCOMMIT))
if ((new_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
{
/* We changed to auto_commit mode */
if (thd->transaction.xid_state.xa_state != XA_NOTR)
if ((thd->options & OPTION_NOT_AUTOCOMMIT))
{
thd->options= org_options;
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xid_state.xa_state]);
if (end_active_trans(thd))
return 1;
}
thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
thd->transaction.all.modified_non_trans_table= FALSE;
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
if (ha_commit(thd))
return 1;
thd->options= new_options;
}
else
{
thd->options= new_options;
thd->transaction.all.modified_non_trans_table= FALSE;
thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
}
......@@ -3399,6 +3397,12 @@ static uchar *get_myisam_mmap_size(THD *thd)
return (uchar *)&myisam_mmap_size;
}
static uchar *in_transaction(THD *thd)
{
thd->sys_var_tmp.my_bool_value=
test(thd->server_status & SERVER_STATUS_IN_TRANS);
return (uchar*) &thd->sys_var_tmp.my_bool_value;
}
/****************************************************************************
Main handling of variables:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment