stored procedures - Pass concatenated string parameter in informix trigger -
i have trigger passes parameters procedure , invoke it.
create trigger trig_ins insert on mytable referencing new new each row(execute procedure sp_ins("mytable", new.id, 'i'));
is there way can pass concatenated char second parameter above procedure call?
i need because may need allow these parameters:
"id = " . new.id "field1 =" . new.field1 . "and field2 = " . new.field2
i impression produce sort of shared audit or logging table. you'll need define trigger
on per-table basis, each declaration, nominate relevant fields, e.g.
create trigger trig_ins insert on mytable referencing new new each row(execute procedure sp_ins("mytable", "field1 = " || new.field1 || " , field2 = " || new.field2, 'i'));
but looks , feels bit clumsy. can't thinking xy problem of sort.
update
(following comment 'need not where_clause
')
well, obvious answer make sure every table has simple, single surrogate key column, can treated rowid.
that's more said done when have existing model, of course. if that's not possible, want representation of compound key in manner can parsed later if need be. how depends on how intend parse it: programmatically or through preconstructed sql fragment first proposed. former more controllable, won't produce 'injectable' sql fragments:
execute procedure sp_ins("mytable", "<field1>" || nvl(new.field1,"") || "</field1>" || "<field2>" || nvl(new.field2,"") || "</field2>", "i");
...is 1 way of doing it. can sql fragment approach, it's construction messy, shown above. example, if field1 string, sql broken, , need this:
execute procedure sp_ins("mytable", "field1 " || nvl('= "'||new.field1||'"','is null') || ' , ' || "field2 " || nvl('= "'||new.field2||'"','is null'), "i")
... , can sure sooner or later you'll run irish problem name o'malley
or sylvester "sly" stallone
breaks embedded quotes. there's no elegant solution because it's inelegant thing you're trying do.
informix provides out-of-the-box audit features, , ways , means of exploring logical logs. can't thinking you'd better off exploring those.
Comments
Post a Comment