diff options
author | Sebastian Reichel <sre@ring0.de> | 2012-10-02 01:05:51 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2012-10-02 01:05:51 +0200 |
commit | 186049b3ed33f025eeb87eb34c19a28e1d5ba70a (patch) | |
tree | 5d892564001404fe979e18eac0e65dfcad65ed5e /sql/trigger.sql | |
parent | 9713c98dbceb54d8d00c186ba8f41f3a5befcfd1 (diff) | |
download | serial-barcode-scanner-186049b3ed33f025eeb87eb34c19a28e1d5ba70a.tar.bz2 |
restructure code, switch from GTK to Web based UI
- move barcode generation scripts into generation/
- move code to src/
- remove database analysis from invoice/graph
- put database creation sql files into sql/
- remove glade builder file
- add new templates/ directory, which contains files
used by the Web-UI
Diffstat (limited to 'sql/trigger.sql')
-rw-r--r-- | sql/trigger.sql | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sql/trigger.sql b/sql/trigger.sql new file mode 100644 index 0000000..8a9bede --- /dev/null +++ b/sql/trigger.sql @@ -0,0 +1,27 @@ +BEGIN TRANSACTION; +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_restock_insert AFTER INSERT ON restock BEGIN + UPDATE products SET amount = products.amount + NEW.amount WHERE products.id = NEW.product; +END; + +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_restock_delete AFTER DELETE ON restock BEGIN + UPDATE products SET amount = products.amount - OLD.amount WHERE products.id = OLD.product; +END; + +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_restock_update AFTER UPDATE ON restock BEGIN + UPDATE products SET amount = products.amount - OLD.amount WHERE products.id = OLD.product; + UPDATE products SET amount = products.amount + NEW.amount WHERE products.id = NEW.product; +END; + +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_sells_insert AFTER INSERT ON sells BEGIN + UPDATE products SET amount = products.amount - 1 WHERE products.id = NEW.product; +END; + +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_sells_delete AFTER DELETE ON sells BEGIN + UPDATE products SET amount = products.amount + 1 WHERE products.id = OLD.product; +END; + +CREATE TRIGGER IF NOT EXISTS update_product_amount_on_sells_update AFTER UPDATE ON sells BEGIN + UPDATE products SET amount = products.amount + 1 WHERE products.id = OLD.product; + UPDATE products SET amount = products.amount - 1 WHERE products.id = NEW.product; +END; +COMMIT; |