 DROP FUNCTION IF EXISTS has_perm $$
 CREATE FUNCTION has_perm(pID INTEGER, action INTEGER, tableN VARCHAR(255)) RETURNS BOOLEAN READS SQL DATA
 BEGIN
-  DECLARE perms varchar(255);
+  DECLARE p varchar(255);
   DECLARE rtn BOOLEAN;
-  SELECT perms INTO perms FROM person WHERE personID = pID;
+  SELECT perms INTO p FROM person WHERE personID = pID;
 
   SELECT count(*) INTO rtn
     FROM permission
    WHERE tableName = tableN
      AND (actions & action = action)
-     AND (roleName IS NULL OR roleName = '' OR find_in_set(roleName,perms)>0);
+     AND (roleName IS NULL OR roleName = '' OR find_in_set(roleName,p)>0);
   return rtn;
 END
 $$

  IF (empty(NEW.timeLimit)) THEN SET NEW.timeLimit = NEW.timeExpected; END IF;
  
  IF (empty(NEW.timeLimit) AND NEW.projectID) THEN
    SELECT defaultTaskLimit INTO defaultTaskLimit FROM project WHERE projectID = NEW.projectID;
    SET NEW.timeLimit = defaultTaskLimit;
  END IF;
 
  IF (empty(NEW.estimatorID) AND (NEW.timeWorst OR NEW.timeBest OR NEW.timeExpected)) THEN

CREATE TRIGGER before_insert_timeSheet BEFORE INSERT ON timeSheet
FOR EACH ROW
BEGIN
  DECLARE pref_tfID INTEGER;
  DECLARE cbd BIGINT(20);
  DECLARE cur VARCHAR(3);
  SET NEW.personID = personID();
  SET NEW.status = 'edit';
  SELECT preferred_tfID INTO pref_tfID FROM person WHERE personID = personID();
  SET NEW.recipient_tfID = pref_tfID;
  SELECT customerBilledDollars,currencyTypeID INTO cbd,cur FROM project WHERE projectID = NEW.projectID;
  SET NEW.customerBilledDollars = cbd;
  SET NEW.currencyTypeID = cur;
