 DROP PROCEDURE IF EXISTS check_edit_timeSheet $$
 CREATE PROCEDURE check_edit_timeSheet(IN id INTEGER)
 BEGIN
-  SELECT status INTO @timeSheetStatus FROM timeSheet WHERE timeSheetID = id;
-  if (neq(@timeSheetStatus, "edit") AND NOT has_perm(personID(),512,"timeSheet")) THEN
+  DECLARE timeSheetStatus VARCHAR(255);
+  SELECT status INTO timeSheetStatus FROM timeSheet WHERE timeSheetID = id;
+  if (neq(timeSheetStatus, "edit") AND NOT has_perm(personID(),512,"timeSheet")) THEN
     call alloc_error('Time sheet is not editable.');
   END IF;
 END

CREATE TRIGGER before_insert_task BEFORE INSERT ON task
FOR EACH ROW
BEGIN
  call check_edit_task(NEW.projectID);

  SET NEW.creatorID = personID();
  SET NEW.dateCreated = current_timestamp();

  -- inserted closed edge-case
  IF (NEW.dateActualCompletion AND neq(substring(NEW.taskStatus,1,5), 'close')) THEN
    SET NEW.taskStatus = 'closed_complete';
  END IF;


DROP PROCEDURE IF EXISTS update_search_index $$
CREATE PROCEDURE update_search_index(eName VARCHAR(255), eID INTEGER)
BEGIN
  DECLARE num INTEGER;
  IF (using_views()) THEN
    SELECT count(indexQueueID) INTO num FROM indexQueue WHERE entity = eName AND entityID = eID;
    IF (num = 0) THEN
      INSERT INTO indexQueue (entity,entityID) VALUES (eName, eID);
    END IF;
  END IF;
