4
4
SET client_min_messages=ERROR;
6
CREATE OR REPLACE FUNCTION bug_summary_inc(d bugsummary) RETURNS VOID
10
-- Shameless adaption from postgresql manual
12
-- first try to update the row
13
UPDATE BugSummary SET count = count + 1
15
((d.product IS NULL AND product IS NULL)
16
OR product = d.product)
17
AND ((d.productseries IS NULL AND productseries IS NULL)
18
OR productseries = d.productseries)
19
AND ((d.distribution IS NULL AND distribution IS NULL)
20
OR distribution = d.distribution)
21
AND ((d.distroseries IS NULL AND distroseries IS NULL)
22
OR distroseries = d.distroseries)
23
AND ((d.sourcepackagename IS NULL AND sourcepackagename IS NULL)
24
OR sourcepackagename = d.sourcepackagename)
25
AND ((d.viewed_by IS NULL AND viewed_by IS NULL)
26
OR viewed_by = d.viewed_by)
27
AND ((d.tag IS NULL AND tag IS NULL)
29
AND ((d.status IS NULL AND status IS NULL)
31
AND ((d.milestone IS NULL AND milestone IS NULL)
32
OR milestone = d.milestone);
36
-- not there, so try to insert the key
37
-- if someone else inserts the same key concurrently,
38
-- we could get a unique-key failure
40
INSERT INTO BugSummary(
41
count, product, productseries, distribution,
42
distroseries, sourcepackagename, viewed_by, tag,
45
1, d.product, d.productseries, d.distribution,
46
d.distroseries, d.sourcepackagename, d.viewed_by, d.tag,
47
d.status, d.milestone);
49
EXCEPTION WHEN unique_violation THEN
50
-- do nothing, and loop to try the UPDATE again
56
COMMENT ON FUNCTION bug_summary_inc(bugsummary) IS
57
'UPSERT into bugsummary incrementing one row';
59
CREATE OR REPLACE FUNCTION bug_summary_dec(bugsummary) RETURNS VOID
62
-- We own the row reference, so in the absence of bugs this cannot
63
-- fail - just decrement the row.
64
UPDATE BugSummary SET count = count - 1
66
(($1.product IS NULL AND product IS NULL)
67
OR product = $1.product)
68
AND (($1.productseries IS NULL AND productseries IS NULL)
69
OR productseries = $1.productseries)
70
AND (($1.distribution IS NULL AND distribution IS NULL)
71
OR distribution = $1.distribution)
72
AND (($1.distroseries IS NULL AND distroseries IS NULL)
73
OR distroseries = $1.distroseries)
74
AND (($1.sourcepackagename IS NULL AND sourcepackagename IS NULL)
75
OR sourcepackagename = $1.sourcepackagename)
76
AND (($1.viewed_by IS NULL AND viewed_by IS NULL)
77
OR viewed_by = $1.viewed_by)
78
AND (($1.tag IS NULL AND tag IS NULL)
80
AND (($1.status IS NULL AND status IS NULL)
81
OR status = $1.status)
82
AND (($1.milestone IS NULL AND milestone IS NULL)
83
OR milestone = $1.milestone);
84
-- gc the row (perhaps should be garbo but easy enough to add here:
85
DELETE FROM bugsummary
88
AND (($1.product IS NULL AND product IS NULL)
89
OR product = $1.product)
90
AND (($1.productseries IS NULL AND productseries IS NULL)
91
OR productseries = $1.productseries)
92
AND (($1.distribution IS NULL AND distribution IS NULL)
93
OR distribution = $1.distribution)
94
AND (($1.distroseries IS NULL AND distroseries IS NULL)
95
OR distroseries = $1.distroseries)
96
AND (($1.sourcepackagename IS NULL AND sourcepackagename IS NULL)
97
OR sourcepackagename = $1.sourcepackagename)
98
AND (($1.viewed_by IS NULL AND viewed_by IS NULL)
99
OR viewed_by = $1.viewed_by)
100
AND (($1.tag IS NULL AND tag IS NULL)
102
AND (($1.status IS NULL AND status IS NULL)
103
OR status = $1.status)
104
AND (($1.milestone IS NULL AND milestone IS NULL)
105
OR milestone = $1.milestone);
106
-- If its not found then someone else also dec'd and won concurrently.
6
110
-- bad comment fixup
7
111
COMMENT ON FUNCTION bug_summary_dec(bugsummary) IS
8
112
'UPSERT into bugsummary incrementing one row';