salix/db/routines/vn/procedures/worker_checkMultipleDevice.sql

23 lines
566 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
vSelf INT
)
BEGIN
/**
* Verify if a worker has multiple assigned devices,
* except for freelancers.
*
* @param vUserFk worker id.
*/
DECLARE vHasPda BOOLEAN;
DECLARE vIsFreelance BOOLEAN;
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = vSelf;
SELECT isFreelance INTO vIsFreelance FROM worker WHERE id = vSelf;
IF NOT vIsFreelance AND vHasPda > 1 THEN
CALL util.throw('You can only have one PDA');
END IF;
END$$
DELIMITER ;