Database Trigger Variable

Posted by bart.syryn on 30-Jan-2019 19:42

Hi, I was wondering if it's possible to somehow pass a variable from an appserver call to a database trigger that is triggered by the appserver call. I know you can set a session:context in the appserver connect procedure but has the database trigger the same session ? Is there a way to set something without using the appserver connect procedure. I just want to pass some value from the appserver to the db-trigger. Best regards, Bart.

All Replies

Posted by onnodehaan on 30-Jan-2019 20:29

A few suggstions:

- You could write a value to the database from the appserver call and pick that up in the trigger

- You can publish a "getValue" from the trigger and let the AppServer call "subscribe" to it

- You can use a singleton procedure thats started with the session that holds variables for you

- You could use a super-procedure to store the values, but I would prefer a singleton instead

So multiple options to get the job done.

Posted by Matt Baker on 31-Jan-2019 02:30

1. Use a Static property in a class.

2. Don't use a trigger.

Posted by bart.syryn on 31-Jan-2019 16:51

Hi,

Thanks for the suggestions.

I ended up with using a property in a class.

I didn't know that the session in the database trigger was the same as the session of the appserver-procedure.

Posted by Francisco Morales López on 13-Feb-2019 02:36

It is important to know the cause for which you want to use the value in the trigger, regardless of whether it is the app server or a normal procedure, the trigger inherits attributes of the previous procedure, these will be available as long as you prepare them properly.

Ordinarily a value should not be used in the database trigger, since its objective is only processes on the record.

If you still want to use a value in the trigger and inherit it from the call of the local procedure or app server, you can use a shared variable, it is not the most elegant method but it works.

The disadvantage is that at compile time you should always load the definition of this variable into memory and ensure that it is created at run time.

Posted by bart.syryn on 13-Feb-2019 12:57

Reason is logging if some fields are changed.

The application has his own user table, not defined as database-users. The info of the userid is passed to the appserver, and in the database-trigger we need to create a log-record and save userid, datetime and old- new value.

Posted by Francisco Morales López on 20-Feb-2019 02:17

I understand, as control fields or bitacoras.

The case you describe is very simple if you use shared variables.

In the main process declare a new shared variable and in the trigger you use it only.

main proc:

define new shared var vsIdUser as char.

...

assign

vdsIdUser = "blablabla".

proc trigger:

define shared var vsIdUser as char.

....

assign

table.idUser = vsIdUser.

This thread is closed