labtech
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_CreateAndAssignNewPermissionId
Parameters
Name
Type
Mode
entityId
int
IN
entityType
int
IN
Definition
BEGIN -- The PermID column is totally arbitrary, so the most reliable thing we can do is -- find the largest value in any of the 3 tables and add 1. SELECT GREATEST( (SELECT MAX(`Permissions`) FROM `clients`), (SELECT MAX(`Permissions`) FROM `mastergroups`), (SELECT MAX(`PermID`) FROM `permissions`) ) INTO @permId; SET @permId := @permId + 1; IF entityType = 1 THEN -- Client UPDATE `clients` SET `Permissions` = @permId WHERE `ClientID` = entityId; ELSEIF entityType = 2 THEN -- Group UPDATE `mastergroups` SET `Permissions` = @permId WHERE `GroupID` = entityId; ELSE SELECT 0 INTO @permId; END IF; SELECT @permId; END