[Greater-commits] r345 - trunk/GREAT-ER-DB/impl/postgresql/test/PostgreSQL
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 1 11:55:13 CEST 2011
Author: bricks
Date: 2011-07-01 11:55:12 +0200 (Fri, 01 Jul 2011)
New Revision: 345
Modified:
trunk/GREAT-ER-DB/impl/postgresql/test/PostgreSQL/create_db_objects.sql
Log:
Fix BIN_OBJ_PROCF and run BIN_OBJ_TABLE Trigger also on inserts to add remark values to the BIN_OBJ_SEARCH_TAB table
All trigger functions must return TRIGGER type
BIN_OBJ_PROCF had several issues: First it wasn't run for insert statements therefore no values where in BIN_OBJ_SEARCH_TAB,
second the decision in update case to drop and/or insert values to the BIN_OBJ_SEARCH_TAB was wrong and third the
separatorPos variable was declared as Numeric (float values) that resulted in an error while executing the insert
statement.
Modified: trunk/GREAT-ER-DB/impl/postgresql/test/PostgreSQL/create_db_objects.sql
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/test/PostgreSQL/create_db_objects.sql 2011-07-01 09:38:06 UTC (rev 344)
+++ trunk/GREAT-ER-DB/impl/postgresql/test/PostgreSQL/create_db_objects.sql 2011-07-01 09:55:12 UTC (rev 345)
@@ -222,27 +222,25 @@
* 20 - BIN_OBJ_PROC() - RETURNS OPAQUE -> 'nothing' *
********************************************************/
-CREATE FUNCTION BIN_OBJ_PROCF () RETURNS OPAQUE AS '
+CREATE FUNCTION BIN_OBJ_PROCF () RETURNS TRIGGER AS '
DECLARE
updateAction VARCHAR (10);
remarkString VARCHAR (2001);
- separatorPos NUMERIC (3);
+ separatorPos INT;
BEGIN
updateAction := ''nothing'';
IF TG_OP=''UPDATE'' THEN
IF (OLD.REMARK IS NOT NULL OR NEW.REMARK IS NOT NULL) THEN
- IF NEW.REMARK IS NULL THEN
+ IF NEW.REMARK IS NULL OR LENGTH(NEW.REMARK) = 0 THEN
updateAction := ''delete'';
- END IF;
- IF OLD.REMARK IS NULL THEN
+ ELSIF OLD.REMARK IS NULL OR LENGTH(OLD.REMARK) = 0 THEN
updateAction := ''insert'';
- END IF;
- IF OLD.REMARK != NEW.REMARK THEN
+ ELSIF OLD.REMARK != NEW.REMARK THEN
updateAction := ''rebuild'';
END IF;
END IF;
- END IF;
+ END IF;
IF (TG_OP=''DELETE'' OR updateAction = ''delete'' OR updateAction = ''rebuild'') THEN
DELETE FROM BIN_OBJ_SEARCH_TAB WHERE BIN_OBJ_ID = OLD.BIN_OBJ_ID;
RETURN OLD;
@@ -263,11 +261,11 @@
remarkString := RTRIM(remarkString, '';'');
remarkString := remarkString || '';'';
WHILE (LENGTH(remarkString) > 0) LOOP
- separatorPos := INSTR (remarkString, '';'');
+ separatorPos := strpos(remarkString, '';'');
INSERT INTO BIN_OBJ_SEARCH_TAB
(BIN_OBJ_ID, KEY_WORD)
- VALUES (NEW.BIN_OBJ_ID, SUBSTR(remarkString, 1, separatorPos-1));
- remarkString := SUBSTR (remarkString, separatorPos,
+ VALUES (NEW.BIN_OBJ_ID, substr(remarkString, 1, separatorPos - 1));
+ remarkString := substr(remarkString, separatorPos,
LENGTH (remarkString) - separatorPos + 1);
remarkString := LTRIM (remarkString, '';'');
END LOOP;
@@ -281,7 +279,7 @@
********************************************************/
CREATE TRIGGER BIN_OBJ_TRG
- AFTER UPDATE OR DELETE
+ AFTER UPDATE OR DELETE OR INSERT
ON BIN_OBJ_TAB
FOR EACH ROW
EXECUTE PROCEDURE BIN_OBJ_PROCF();
@@ -417,7 +415,7 @@
* 28 - CATCH_PROC() - RETURNS OPAQUE -> 'nothing' *
********************************************************/
-CREATE FUNCTION CATCH_PROCF () RETURNS OPAQUE AS '
+CREATE FUNCTION CATCH_PROCF () RETURNS TRIGGER AS '
BEGIN
IF TG_OP=''UPDATE'' THEN
IF OLD.CATCH_ID != NEW.CATCH_ID THEN
@@ -763,7 +761,7 @@
* 43 - RES_PROC() - RETURNS OPAQUE -> 'nothing' *
********************************************************/
-CREATE FUNCTION RES_PROCF() RETURNS OPAQUE AS '
+CREATE FUNCTION RES_PROCF() RETURNS TRIGGER AS '
BEGIN
IF TG_OP=''UPDATE'' THEN
IF OLD.RES_ID != NEW.RES_ID THEN
More information about the Greater-commits
mailing list