Subject Trigger checking for empty strings and replace with NULL
Author pc_frik@bluewin.ch
Hello,

I don't know if this is the right place to ask my question about
Firebird syntax. Please correct me if this is the wrong place.

Im using FB 2.5 with IBExpert.

I currently try to create a Trigger that checks on insert if the
inserting values are Empty Strings, if yes replace them with NULL.
Here a Example:


-------------------------------------------------------------------------------------------------------------------------------------


SET TERM ^^ ;
CREATE TRIGGER <TABELLE>_BI FOR <TABELLE> ACTIVE BEFORE INSERT or UPDATE POSITION 0 AS
begin
if ( new.<field> = ' ') then new.<field> = NULL;
if ( new.<field> = ' ') then new.<field> = NULL;
if ( new.<field> = ' ') then new.<field> = NULL;
end ^^
SET TERM ; ^^


-------------------------------------------------------------------------------------------------------------------------------------


This works fine but i have always to update the Fields manually if i add or remove fields on the database.

Is it Possible to create a solution that checks every existing field that exists on the table ?

Something like follow example (this doesn't work):



-------------------------------------------------------------------------------------------------------------------------------------


CREATE OR ALTER trigger " _TBTEST_BI0" for " _TBTEST"
active before insert position 0
AS
declare variable field_name varchar(255);
begin
for select rdb$field_name from rdb$relation_fields where rdb$relation_name=upper(' _TBTEST') into :field_name
do
begin
if (new.:field_name = ' ') then new.:field_name = NULL;
end
end



-------------------------------------------------------------------------------------------------------------------------------------



im getting here a Parsing error (new.:field_name)

Regards P.S

[Non-text portions of this message have been removed]