salix/db/changes/10221-accountModule/00-myUser_getId.sql

28 lines
540 B
SQL

DROP FUNCTION IF EXISTS account.myUser_getId;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `account`.`myUser_getId`() RETURNS int(11)
READS SQL DATA
DETERMINISTIC
BEGIN
/**
* Returns the current user id.
*
* @return The user id
*/
DECLARE vUser INT DEFAULT NULL;
IF myUser_checkLogin()
THEN
SET vUser = @userId;
ELSE
SELECT id INTO vUser FROM user
WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1);
END IF;
RETURN vUser;
END$$
DELIMITER ;
GRANT EXECUTE ON FUNCTION account.myUser_getId TO guest@localhost;