I have the following TRIGGER which inserts certain specific data for the purpose of auditing. I need that in the field Audit user the id of the user who started the session in the system and not the one in the database is saved.
DELIMITER //
CREATE TRIGGER tr_up_salario
AFTER UPDATE ON empleadocargo
FOR EACH ROW
BEGIN
declare _user varchar(20);
declare _idD, _idA int;
set _user = (select USER());
set _idD = NEW.idEmpleadoCargo;
insert into rrhh.auditoria (usuarioAuditoria, accion, tabla, registroNro)
VALUES (_user, 'UPDATE', 'EmpleadoCargo', _idD);
set _idA = (LAST_INSERT_ID());
insert into rrhh.detalleauditoria (Auditoria_idAuditoria, nombreColumna, antiguaDescripcion, nuevaDescripcion)
VALUES (_idA, 'Salario', OLD.salarioFijo, NEW.salarioFijo);
END //
DELIMITER ;
How do I access the user id and insert it into the table from the TRIGGER?