Trigger not occuring with a different logical name

I have added a trigger to the structure of my database (Progress 9.1B). It really works well (the trigger only write into a log file to tell which record has been created or deleted).

But when I'm connected with a different logical name to the database (it means with a logical name that is different from the former one), the trigger does not work anymore.

Example 1:
----------

/* Connecting to the database */
/* with the former db logical name */

IF NOT CONNECTED("probase") THEN CONNECT -pf mybase.pf -ld probase.

/* Now playing with the trigger */

FIND FIRST probase.mytable.
DELETE mytable. /* the trigger write to the log file correctly */

/* This example works FINE in every situation */

Example 2:
----------

/* Connecting to the same database */
/* with the another logical name */
/* we are not connected to any database at this time */

IF NOT CONNECTED("probase2") THEN CONNECT -pf mybase.pf -ld probase2.

/* Now playing with the trigger */

FIND FIRST probase2.mytable.
DELETE mytable. /* the trigger does not occur */



Of course I've checked that the connection with a different logical name was working well , and that 'mytable' was not an empty table. Everything works well in Example 2, except the trigger.

So, I guess that the trigger is linked with probase.mytable and not with probase2.mytable, and that's why it doesn't work.

How could I make it work for any logical name (dont tell me to keep the former logical name, because I really need to use a different logical name).

Any help appreciated :rolleyes:


Happy 31st December :wavey:
 

bendaluz2

Member
Yeah, you are right, the trigger has been compiled with a database name of probase, so when you try and run it against probase2, it doesnt like it. The only ways to resolve this are to run uncompiled code for you trigger or to make the logical names match. Just out of interest, why do you really need to use a different logical name?

Originally posted by Olivier_Desmars
I have added a trigger to the structure of my database (Progress 9.1B). It really works well (the trigger only write into a log file to tell which record has been created or deleted).

But when I'm connected with a different logical name to the database (it means with a logical name that is different from the former one), the trigger does not work anymore.

Example 1:
----------

/* Connecting to the database */
/* with the former db logical name */

IF NOT CONNECTED("probase") THEN CONNECT -pf mybase.pf -ld probase.

/* Now playing with the trigger */

FIND FIRST probase.mytable.
DELETE mytable. /* the trigger write to the log file correctly */

/* This example works FINE in every situation */

Example 2:
----------

/* Connecting to the same database */
/* with the another logical name */
/* we are not connected to any database at this time */

IF NOT CONNECTED("probase2") THEN CONNECT -pf mybase.pf -ld probase2.

/* Now playing with the trigger */

FIND FIRST probase2.mytable.
DELETE mytable. /* the trigger does not occur */



Of course I've checked that the connection with a different logical name was working well , and that 'mytable' was not an empty table. Everything works well in Example 2, except the trigger.

So, I guess that the trigger is linked with probase.mytable and not with probase2.mytable, and that's why it doesn't work.

How could I make it work for any logical name (dont tell me to keep the former logical name, because I really need to use a different logical name).

Any help appreciated :rolleyes:


Happy 31st December :wavey:
 

bendaluz2

Member
Oh yeah, just thought of another way to do it.

Do this:
<pre>
IF NOT CONNECTED("probase") THEN
DO:
CONNECT -pf mybase.pf -ld probase.
CREATE ALIAS trig-probase FOR DATABASE probase.
END.
ELSE
IF NOT CONNECTED("probase2") THEN
DO:
CONNECT -pf mybase.pf -ld probase2.
CREATE ALIAS trig-probase FOR DATABASE probase2.
END.
RUN find-del.

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

find-del.p

FIND FIRST trig-probase.mytable.
DELETE trig-probase.mytable.
</pre>
Then, change your trigger so that it explicitly references trig-probase as the database name and compile it and find-del.p (make sure the alias is defined in the compilation environment)
 
Thanks guy. I guess I see what you mean. I'll try this immediatly and report the result here.


The main purpose to connect to database with different logical names is to make synchronisation between two databases (the main database and a copy of the main database). This synchronisation method has been developped in Progress and has been implemented in our solution for 3 years now. It's used by a little more than 100 of customers ; and each of our customers has between 1 and 60 copies of the main database , mostly installed on portable PC. So you can work on a copy of the database with our solution when you're outside (or not connected to the network), and when you're back to the office, you can synchronise your database with the main one : you only send what's new or modified or deleted in your database, and you only receive what's new/modified/deleted from the main database. It results in a quite fast and reliable synchronisation method , still better than comparing all 'time-stamped' records on each database and sending the 'most recent one' to the other.

So each time a client database is synchronizing, it connects to the main database as 'probase2', while the local db is still called 'probase'. Then we can write or delete records from probase to probase2 or the opposite. The weakest link of this method is that when you're changing the structure of the main database, you also have to change have all the clients database, else it would results in a CRC error while synchronizing. Hopefully, adding a trigger on the main database does not change the CRC for programs compiled with the previous structure.

As this method if implemented in all of our solutions, in would be (economicly) impossible to change it to all our customers, just in order to add a little trigger on the main db :awink:.

Ok I try something with your solution and I'll report the results here later.
 

bendaluz2

Member
Just so you know, adding a trigger will change the CRC. If you just modify the trigger procedure, that wont change the CRC, but adding / removing a trigger does.

Hope that doesnt cause too many problems

Originally posted by Olivier_Desmars
Thanks guy. I guess I see what you mean. I'll try this immediatly and report the result here.


The main purpose to connect to database with different logical names is to make synchronisation between two databases (the main database and a copy of the main database). This synchronisation method has been developped in Progress and has been implemented in our solution for 3 years now. It's used by a little more than 100 of customers ; and each of our customers has between 1 and 60 copies of the main database , mostly installed on portable PC. So you can work on a copy of the database with our solution when you're outside (or not connected to the network), and when you're back to the office, you can synchronise your database with the main one : you only send what's new or modified or deleted in your database, and you only receive what's new/modified/deleted from the main database. It results in a quite fast and reliable synchronisation method , still better than comparing all 'time-stamped' records on each database and sending the 'most recent one' to the other.

So each time a client database is synchronizing, it connects to the main database as 'probase2', while the local db is still called 'probase'. Then we can write or delete records from probase to probase2 or the opposite. The weakest link of this method is that when you're changing the structure of the main database, you also have to change have all the clients database, else it would results in a CRC error while synchronizing. Hopefully, adding a trigger on the main database does not change the CRC for programs compiled with the previous structure.

As this method if implemented in all of our solutions, in would be (economicly) impossible to change it to all our customers, just in order to add a little trigger on the main db :awink:.

Ok I try something with your solution and I'll report the results here later.
 
Ok, I first tried to remove the .r file containing the trigger code, only letting the .p file.

It then always gives an error when I'm connected to both base and when the trigger occurs :

"The table exists in both database probase and probase2 (425) "

And then error 545 (Unknown or ambiguous table) and then 196 ( Could not understand line .). This last error is because the trigger begins by 'TRIGGER PROCEDURE FOR DELETE OF ' .

So, I guess I'm quite stuck because the trigger code must be compiled and can only be compiled for one logical name. I also try to switch the db logical name before the 'TRIGGER PROCEDURE FOR DELETE OF ' declaration , but Progress needs it as the 1st line of the code. It means it's not possible to trick Progress with the logical name.

But anyway, in this situation, the main database will always be 'probase2', so I've recompiled the trigger code connected under 'probase2' and now it works well : when the client database synchronized , all deleted record it sends to the main database are :
- also deleted on the main db
- logged in a file on the server with the main db.

(I forgot to say that almost nobody work directly on the main db).

So that's quite nice because everything is logged in one file on the server.

Thanks anyway for your help . I didn't know that it was possible to make an alias on an already-connected db , so I've learned something interesting today

Cheers
 

bendaluz2

Member
Reference the alias in the trigger procedure.

so

TRIGGER PROCEDURE FOR DELETE OF trig-probase.mytable.

run echolog ("updated" + trig-probase.mytable.myfield).

You must set up the alias before the first procedure that references it. i.e. you cant set it up and reference it in the same procedure. I would do it in your startup procedure for the application. Then, it will be available for use anywhere in the application


Originally posted by Olivier_Desmars
Ok, I first tried to remove the .r file containing the trigger code, only letting the .p file.

It then always gives an error when I'm connected to both base and when the trigger occurs :

"The table exists in both database probase and probase2 (425) "

And then error 545 (Unknown or ambiguous table) and then 196 ( Could not understand line .). This last error is because the trigger begins by 'TRIGGER PROCEDURE FOR DELETE OF ' .

So, I guess I'm quite stuck because the trigger code must be compiled and can only be compiled for one logical name. I also try to switch the db logical name before the 'TRIGGER PROCEDURE FOR DELETE OF ' declaration , but Progress needs it as the 1st line of the code. It means it's not possible to trick Progress with the logical name.

But anyway, in this situation, the main database will always be 'probase2', so I've recompiled the trigger code connected under 'probase2' and now it works well : when the client database synchronized , all deleted record it sends to the main database are :
- also deleted on the main db
- logged in a file on the server with the main db.

(I forgot to say that almost nobody work directly on the main db).

So that's quite nice because everything is logged in one file on the server.

Thanks anyway for your help . I didn't know that it was possible to make an alias on an already-connected db , so I've learned something interesting today

Cheers
 
Top