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

23 lines
595 B
MySQL
Raw Normal View History

DROP FUNCTION IF EXISTS account.user_getMysqlRole;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `account`.`user_getMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
BEGIN
/**
* From a username, it returns the associated MySQL wich should be used when
* using external authentication systems.
*
* @param vUserName The user name
* @return The associated MySQL role
*/
DECLARE vRole VARCHAR(255);
SELECT CONCAT(IF(r.hasLogin, 'z-', ''), r.name) INTO vRole
FROM role r
JOIN user u ON u.role = r.id
WHERE u.name = vUserName;
RETURN vRole;
END$$
DELIMITER ;