delimiter $$
drop function if exists sql_log_start $$
create function sql_log_start(log_type varchar(50),log_text varchar(255))
returns char(32) deterministic
BEGIN

DECLARE retGUID char(32);

set retGUID = replace(uuid(),'-','');


insert into sql_log values(retGUID,log_type,log_text,0,0,current_user(),now());

return retGUID;

END $$

drop function if exists sql_log_complete $$
create function sql_log_complete(log_id char(32),log_text varchar(255), succeeded tinyint)
returns int deterministic
BEGIN
DECLARE dt timestamp;
DECLARE duration int;

select logged_on from sql_log where id = log_id into dt;

SELECT TIME_TO_SEC(TIMEDIFF(NOW(), dt))  into duration;

update sql_log set sql_log.log_text = log_text, sql_log.succeeded = succeeded, duration_seconds = duration where id = log_id;

return duration;

END $$

drop function if exists sql_log $$
create function sql_log(log_type varchar(50),log_text varchar(255), succeeded int)
returns char(32) deterministic
BEGIN

DECLARE retGUID char(32);

set retGUID = replace(uuid(),'-','');


insert into sql_log values(retGUID,log_type,log_text,0,succeeded,current_user(),now());

return retGUID;



END $$
