1. PostgreSQL copy of all MySQL created and tested.\n 2. Purchase Orders and Sales Orders and stock level management added to MySQL, PostgreSQL, and server and front end code.
This commit is contained in:
47
static/PostgreSQL/304_tri_Shop_General.sql
Normal file
47
static/PostgreSQL/304_tri_Shop_General.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
-- Shop General
|
||||
|
||||
CREATE OR REPLACE FUNCTION before_insert_Shop_General()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.created_on = CURRENT_TIMESTAMP;
|
||||
NEW.created_by = CURRENT_USER;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE TRIGGER tri_before_insert_Shop_General
|
||||
BEFORE INSERT ON Shop_General
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION before_insert_Shop_General();
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION before_update_Shop_General()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN
|
||||
RAISE EXCEPTION 'New change Set ID must be provided.'
|
||||
USING ERRCODE = '45000';
|
||||
END IF;
|
||||
|
||||
INSERT INTO Shop_General_Audit (
|
||||
id_general,
|
||||
name_field,
|
||||
value_prev,
|
||||
value_new,
|
||||
id_change_set
|
||||
)
|
||||
-- Changed quantity max
|
||||
SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set
|
||||
WHERE NOT OLD.quantity_max <=> NEW.quantity_max
|
||||
;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE TRIGGER tri_before_update_Shop_General
|
||||
BEFORE UPDATE ON Shop_General
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION before_update_Shop_General();
|
||||
Reference in New Issue
Block a user