1
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
5
Removed sequence functions.
9
"""DROP FUNCTION next_devicebus_product_sequence(INTEGER)""",
10
"""DROP FUNCTION next_devicebus_vendor_sequence(INTEGER)""",
11
"""DROP FUNCTION next_system_sequence(INTEGER)""",
13
CREATE OR REPLACE FUNCTION systemunit_insert_before() RETURNS TRIGGER
17
UPDATE system SET counter = counter + 1
18
WHERE id = NEW.system RETURNING counter INTO NEW.sequence;
25
CREATE OR REPLACE FUNCTION systemunit_insert_after() RETURNS TRIGGER
29
UPDATE devicestate SET date_deleted = NEW.date_created
30
WHERE date_deleted = '3000-01-01'
31
AND system_unit = NEW.id;
32
UPDATE processorstate SET date_deleted = NEW.date_created
33
WHERE date_deleted = '3000-01-01'
34
AND system_unit = NEW.id;
41
CREATE OR REPLACE FUNCTION deviceproduct_product() RETURNS TRIGGER
45
IF TG_OP = 'INSERT' THEN
46
IF NEW.product IS NULL THEN
47
UPDATE devicebus SET product_counter = product_counter + 1
48
WHERE id = NEW.bus RETURNING product_counter INTO NEW.product;
49
ELSIF NEW.product > x'FFFF'::int THEN
50
RAISE EXCEPTION 'product must be less than 2^16: %s', NEW.product;
53
IF NEW.text_search_vector IS NULL
54
AND NOT NEW.name IS NULL THEN
55
NEW.text_search_vector := SETWEIGHT(TO_TSVECTOR(
56
'simple', text_as_grams(NEW.name)), 'A');
58
ELSIF TG_OP = 'UPDATE' THEN
59
IF NOT NEW.product = OLD.product THEN
60
RAISE EXCEPTION 'product cannot be updated';
63
IF NEW.text_search_vector = OLD.text_search_vector
64
AND NOT NEW.name = OLD.name THEN
65
NEW.text_search_vector := SETWEIGHT(TO_TSVECTOR(
66
'simple', text_as_grams(NEW.name)), 'A');
74
CREATE OR REPLACE FUNCTION devicevendor_vendor() RETURNS TRIGGER
78
IF TG_OP = 'INSERT' THEN
79
IF NEW.vendor IS NULL THEN
80
UPDATE devicebus SET vendor_counter = vendor_counter + 1
81
WHERE id = NEW.bus RETURNING vendor_counter INTO NEW.vendor;
82
ELSIF NEW.vendor > x'FFFF'::int THEN
83
RAISE EXCEPTION 'vendor must be less than 2^16: %s', NEW.vendor;
86
IF NEW.text_search_vector IS NULL
87
AND NOT NEW.name IS NULL THEN
88
NEW.text_search_vector := SETWEIGHT(TO_TSVECTOR(
89
'simple', text_as_grams(NEW.name)), 'A');
91
ELSIF TG_OP = 'UPDATE' THEN
92
IF NOT NEW.vendor = OLD.vendor THEN
93
RAISE EXCEPTION 'vendor cannot be updated';
96
IF NEW.text_search_vector = OLD.text_search_vector
97
AND NOT NEW.name = OLD.name THEN
98
NEW.text_search_vector := SETWEIGHT(TO_TSVECTOR(
99
'simple', text_as_grams(NEW.name)), 'A');
111
for statement in statements:
112
store.execute(statement)