mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-5419 no audit events for warnings converted to errors in the strict mode.
Plugins get error notifications only when my_message_sql() is called. But errors are launched with THD::raise_condition() calls in other places. These are push_warning(), implementations of SIGNAL and RESIGNAL commands. So it makes sence to notify plugins there in THD::raise_condition().
This commit is contained in:
45
mysql-test/suite/plugins/r/sql_error_log.result
Normal file
45
mysql-test/suite/plugins/r/sql_error_log.result
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
drop procedure if exists test_error;
|
||||||
|
drop table if exists t1;
|
||||||
|
install plugin SQL_ERROR_LOG soname 'sql_errlog';
|
||||||
|
show variables like 'sql_error_log%';
|
||||||
|
Variable_name Value
|
||||||
|
sql_error_log_filename sql_errors.log
|
||||||
|
sql_error_log_rate 1
|
||||||
|
sql_error_log_rotate OFF
|
||||||
|
sql_error_log_rotations 9
|
||||||
|
sql_error_log_size_limit 1000000
|
||||||
|
set global sql_error_log_rate=1;
|
||||||
|
select * from t_doesnt_exist;
|
||||||
|
ERROR 42S02: Table 'test.t_doesnt_exist' doesn't exist
|
||||||
|
syntax_error_query;
|
||||||
|
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'syntax_error_query' at line 1
|
||||||
|
CREATE PROCEDURE test_error()
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER
|
||||||
|
FOR 1146
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL SQLSTATE '40000' SET
|
||||||
|
MYSQL_ERRNO = 1000,
|
||||||
|
MESSAGE_TEXT = 'new message';
|
||||||
|
END;
|
||||||
|
SELECT `c` FROM `temptab`;
|
||||||
|
END|
|
||||||
|
CALL test_error();
|
||||||
|
ERROR 40000: new message
|
||||||
|
drop procedure test_error;
|
||||||
|
SET SQL_MODE = STRICT_ALL_TABLES;
|
||||||
|
create table t1(id int);
|
||||||
|
insert into t1 values ('aa');
|
||||||
|
ERROR 22007: Incorrect integer value: 'aa' for column 'id' at row 1
|
||||||
|
SET SQL_MODE = '';
|
||||||
|
drop table t1;
|
||||||
|
uninstall plugin SQL_ERROR_LOG;
|
||||||
|
Warnings:
|
||||||
|
Warning 1620 Plugin is busy and will be uninstalled on shutdown
|
||||||
|
TIME HOSTNAME ERROR 1146: Table 'test.t_doesnt_exist' doesn't exist : select * from t_doesnt_exist
|
||||||
|
TIME HOSTNAME ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'syntax_error_query' at line 1 : syntax_error_query
|
||||||
|
TIME HOSTNAME ERROR 1146: Table 'test.temptab' doesn't exist : SELECT `c` FROM `temptab`
|
||||||
|
TIME HOSTNAME ERROR 1000: new message : RESIGNAL SQLSTATE '40000' SET
|
||||||
|
MYSQL_ERRNO = 1000,
|
||||||
|
MESSAGE_TEXT = 'new message'
|
||||||
|
TIME HOSTNAME ERROR 1366: Incorrect integer value: 'aa' for column 'id' at row 1 : insert into t1 values ('aa')
|
55
mysql-test/suite/plugins/t/sql_error_log.test
Normal file
55
mysql-test/suite/plugins/t/sql_error_log.test
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
--source include/not_embedded.inc
|
||||||
|
|
||||||
|
if (!$SQL_ERRLOG_SO) {
|
||||||
|
skip No SQL_ERROR_LOG plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
--disable_warnings
|
||||||
|
drop procedure if exists test_error;
|
||||||
|
drop table if exists t1;
|
||||||
|
--enable_warnings
|
||||||
|
|
||||||
|
install plugin SQL_ERROR_LOG soname 'sql_errlog';
|
||||||
|
|
||||||
|
show variables like 'sql_error_log%';
|
||||||
|
set global sql_error_log_rate=1;
|
||||||
|
--error ER_NO_SUCH_TABLE
|
||||||
|
select * from t_doesnt_exist;
|
||||||
|
--error 1064
|
||||||
|
syntax_error_query;
|
||||||
|
|
||||||
|
delimiter |;
|
||||||
|
|
||||||
|
CREATE PROCEDURE test_error()
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER
|
||||||
|
FOR 1146
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL SQLSTATE '40000' SET
|
||||||
|
MYSQL_ERRNO = 1000,
|
||||||
|
MESSAGE_TEXT = 'new message';
|
||||||
|
END;
|
||||||
|
SELECT `c` FROM `temptab`;
|
||||||
|
END|
|
||||||
|
|
||||||
|
delimiter ;|
|
||||||
|
|
||||||
|
--error 1000
|
||||||
|
CALL test_error();
|
||||||
|
drop procedure test_error;
|
||||||
|
|
||||||
|
SET SQL_MODE = STRICT_ALL_TABLES;
|
||||||
|
create table t1(id int);
|
||||||
|
--error 1366
|
||||||
|
insert into t1 values ('aa');
|
||||||
|
SET SQL_MODE = '';
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
|
uninstall plugin SQL_ERROR_LOG;
|
||||||
|
|
||||||
|
let $MYSQLD_DATADIR= `SELECT @@datadir`;
|
||||||
|
# replace the timestamp and the hostname with constant values
|
||||||
|
--replace_regex /[1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^E]*/TIME HOSTNAME /
|
||||||
|
cat_file $MYSQLD_DATADIR/sql_errors.log;
|
||||||
|
|
@ -3165,7 +3165,6 @@ void my_message_sql(uint error, const char *str, myf MyFlags)
|
|||||||
DBUG_ASSERT(str != NULL);
|
DBUG_ASSERT(str != NULL);
|
||||||
DBUG_ASSERT(error != 0);
|
DBUG_ASSERT(error != 0);
|
||||||
|
|
||||||
mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_ERROR, error, str);
|
|
||||||
if (MyFlags & ME_JUST_INFO)
|
if (MyFlags & ME_JUST_INFO)
|
||||||
{
|
{
|
||||||
level= MYSQL_ERROR::WARN_LEVEL_NOTE;
|
level= MYSQL_ERROR::WARN_LEVEL_NOTE;
|
||||||
@ -3188,6 +3187,8 @@ void my_message_sql(uint error, const char *str, myf MyFlags)
|
|||||||
thd->is_fatal_error= 1;
|
thd->is_fatal_error= 1;
|
||||||
(void) thd->raise_condition(error, NULL, level, str);
|
(void) thd->raise_condition(error, NULL, level, str);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
mysql_audit_general(0, MYSQL_AUDIT_GENERAL_ERROR, error, str);
|
||||||
|
|
||||||
/* When simulating OOM, skip writing to error log to avoid mtr errors */
|
/* When simulating OOM, skip writing to error log to avoid mtr errors */
|
||||||
DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_VOID_RETURN;);
|
DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_VOID_RETURN;);
|
||||||
|
@ -1145,6 +1145,7 @@ MYSQL_ERROR* THD::raise_condition(uint sql_errno,
|
|||||||
got_warning= 1;
|
got_warning= 1;
|
||||||
break;
|
break;
|
||||||
case MYSQL_ERROR::WARN_LEVEL_ERROR:
|
case MYSQL_ERROR::WARN_LEVEL_ERROR:
|
||||||
|
mysql_audit_general(this, MYSQL_AUDIT_GENERAL_ERROR, sql_errno, msg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DBUG_ASSERT(FALSE);
|
DBUG_ASSERT(FALSE);
|
||||||
|
Reference in New Issue
Block a user