Permalink
Browse files

Fix ambiguous variable name in the exception trigger function. Bug found

and fix proposed by Bartosz Dmytrak
  • Loading branch information...
1 parent ec3dc41 commit 7c14901f55cbd97fdddcfe3652d302d19e12d3aa @dpage dpage committed Sep 20, 2012
Showing with 35 additions and 5 deletions.
  1. +5 −5 pgagent.sql
  2. +30 −0 pgagent_upgrade.sql
View
@@ -618,27 +618,27 @@ COMMENT ON TRIGGER pga_schedule_trigger ON pgagent.pga_schedule IS 'Update the j
CREATE OR REPLACE FUNCTION pgagent.pga_exception_trigger() RETURNS "trigger" AS '
DECLARE
- jobid int4 := 0;
+ v_jobid int4 := 0;
BEGIN
IF TG_OP = ''DELETE'' THEN
- SELECT INTO jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = OLD.jexscid;
+ SELECT INTO v_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = OLD.jexscid;
-- update pga_job from remaining schedules
-- the actual calculation of jobnextrun will be performed in the trigger
UPDATE pgagent.pga_job
SET jobnextrun = NULL
- WHERE jobenabled AND jobid=jobid;
+ WHERE jobenabled AND jobid = v_jobid;
RETURN OLD;
ELSE
- SELECT INTO jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = NEW.jexscid;
+ SELECT INTO v_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = NEW.jexscid;
UPDATE pgagent.pga_job
SET jobnextrun = NULL
- WHERE jobenabled AND jobid=jobid;
+ WHERE jobenabled AND jobid = v_jobid;
RETURN NEW;
END IF;
END;
View
@@ -16,6 +16,36 @@ BEGIN
END;
' LANGUAGE 'plpgsql' VOLATILE;
+CREATE OR REPLACE FUNCTION pgagent.pga_exception_trigger() RETURNS "trigger" AS '
+DECLARE
+
+ v_jobid int4 := 0;
+
+BEGIN
+
+ IF TG_OP = ''DELETE'' THEN
+
+ SELECT INTO v_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = OLD.jexscid;
+
+ -- update pga_job from remaining schedules
+ -- the actual calculation of jobnextrun will be performed in the trigger
+ UPDATE pgagent.pga_job
+ SET jobnextrun = NULL
+ WHERE jobenabled AND jobid = v_jobid;
+ RETURN OLD;
+ ELSE
+
+ SELECT INTO v_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = NEW.jexscid;
+
+ UPDATE pgagent.pga_job
+ SET jobnextrun = NULL
+ WHERE jobenabled AND jobid = v_jobid;
+ RETURN NEW;
+ END IF;
+END;
+' LANGUAGE 'plpgsql' VOLATILE;
+COMMENT ON FUNCTION pgagent.pga_exception_trigger() IS 'Update the job''s next run time whenever an exception changes';
+
ALTER TABLE pgagent.pga_jobstep ADD COLUMN jstconnstr text NOT NULL DEFAULT '' CONSTRAINT pga_jobstep_connstr_check CHECK ((jstconnstr != '' AND jstkind = 's' ) OR (jstconnstr = '' AND (jstkind = 'b' OR jstdbname != '')));
ALTER TABLE pgagent.pga_jobstep DROP CONSTRAINT pga_jobstep_check;

0 comments on commit 7c14901

Please sign in to comment.