diff options
-rw-r--r-- | sql/sql_audit.cc | 4 | ||||
-rw-r--r-- | sql/sql_audit.h | 12 |
2 files changed, 12 insertions, 4 deletions
diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 1dab45800d9..108b74cac5f 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -84,7 +84,7 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap) event.general_rows= (unsigned long long) va_arg(ap, ha_rows); event.database= va_arg(ap, const char *); event.database_length= va_arg(ap, unsigned int); - event.query_id= (unsigned long long) thd->query_id; + event.query_id= (unsigned long long) (thd ? thd->query_id : 0); event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event); } @@ -134,7 +134,7 @@ static void table_class_handler(THD *thd, uint event_subclass, va_list ap) event.new_database_length= va_arg(ap, unsigned int); event.new_table= va_arg(ap, const char *); event.new_table_length= va_arg(ap, unsigned int); - event.query_id= (unsigned long long) thd->query_id; + event.query_id= (unsigned long long) (thd ? thd->query_id : 0); event_class_dispatch(thd, MYSQL_AUDIT_TABLE_CLASS, &event); } diff --git a/sql/sql_audit.h b/sql/sql_audit.h index 9acd4abbdca..3f3f97a2730 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -90,11 +90,13 @@ void mysql_audit_general_log(THD *thd, time_t time, { CHARSET_INFO *clientcs= thd ? thd->variables.character_set_client : global_system_variables.character_set_client; + const char *db= thd ? thd->db : ""; + size_t db_length= thd ? thd->db_length : 0; mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, MYSQL_AUDIT_GENERAL_LOG, 0, time, user, userlen, cmd, cmdlen, query, querylen, clientcs, (ha_rows) 0, - thd->db, thd->db_length); + db, db_length); } } @@ -123,6 +125,8 @@ void mysql_audit_general(THD *thd, uint event_subtype, char user_buff[MAX_USER_HOST_SIZE]; CSET_STRING query; ha_rows rows; + const char *db; + size_t db_length; if (thd) { @@ -130,18 +134,22 @@ void mysql_audit_general(THD *thd, uint event_subtype, user= user_buff; userlen= make_user_name(thd, user_buff); rows= thd->warning_info->current_row_for_warning(); + db= thd->db; + db_length= thd->db_length; } else { user= 0; userlen= 0; rows= 0; + db= ""; + db_length= 0; } mysql_audit_notify(thd, MYSQL_AUDIT_GENERAL_CLASS, event_subtype, error_code, time, user, userlen, msg, msglen, query.str(), query.length(), query.charset(), rows, - thd->db, thd->db_length); + db, db_length); } } |