dynamic(?) buffer compare over table-name

jakke

New Member
Hi All,

Trying to find some general way for next issue.

In a trigger u ussually compare the values of the new buffer and the old buffer. Lets use "customer" as a table name.
In this case we can compare in customertrigw the fields of customer vs o_customer.

BUT i wanna place some of this logic in a general trigger include. In here i have a variable cTableName having value "customer"... how can i go from this value to the buffer of customer and o_customer and do some sort of "buffer-compare... save in" to them to find out which fields are updated.

I tried to go over CREATE BUFFER cTableName etc but keep bumping into the fact that i need the real customer and o_customer handles of the current record in those buffers....

ANY suggestions?
Thx.
Jakke
 
AFAIK new buffer and old buffer are references which can only be used in the trigger-procedure statement.

Casper.
 
Hi Casper,

(Hope i interprete your reply correct)
I agree but the new and old buffers are also for hands at runtime in the general includes aftrigtopw.i , so my question is more or less is there a generic way to get hands on those buffers in the includes... so independant on which table you are working on that you get your hands on these buffers to compare...

Thx for your reply.
 
Ok ,you got me: I don't know of any aftrigtopw.i. (e.g. dynamics)
If it (new buffer/old buffer) is used there, are you sure this include isnt used for generating trigger procedures?

Casper
 
What exactly do you mean by old and new buffers. If you mean something like the OLD BUFFER option that can be used in the TRIGGER PROCEDURE statement then you need to roll your own logic because that is only available in database trigger procedures and does only make sense in a WRITE trigger.

You should be a little bit more specific as to what it is that you want to achieve - maybe their are other concepts that could be applicable to your situation.

Heavy Regards, RealHeavyDude.
 
You might also use something like this ?

Code:
run genericprocedure.p (input buffer customer:handle, input buffer o_customer:handle).
 
genericprocedure.p:
define input parameter newbuffer as handle no-undo.
define input parameter oldbuffer as handle no-undo.
 
if newbuffer:buffer-field(fieldname):buffer-value ...
 
Hi,

I am writing a class to audit the DB changes. How do i store the old buffer value .? Please check the below code.
If I pass v_New_old var as "new" , then it will store the new value(changed value) in the buffer.
And if I pass v_New_old var as "old" , then it will store the old value in the buffer.
I will not be able to do the BUFFER-COMPARE. In any of the above case , I can only store either old or new.
How do i store both the value so that I can do buffer-compare and then can audit the changes.

CLASS Audit:
METHOD PRIVATE HANDLE creBuff (INPUT pcTableName AS CHAR):
DEFINE VARIABLE hTableBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hTempTable AS HANDLE NO-UNDO.
CREATE BUFFER hTableBuffer FOR TABLE pcTableName.
CREATE TEMP-TABLE hTempTable.
hTempTable:CREATE-LIKE(hTableBuffer).
hTempTable:TEMP-TABLE-PREPARE("tt" + pcTableName).
RETURN hTempTable:DEFAULT-BUFFER-HANDLE.

END METHOD.

METHOD PUBLIC VOID log( INPUT v_tablename AS CHARACTER,INPUT Row_ID AS INTEGER, INPUT v_New_old AS CHARACTER):
DEF VAR hOldBuff AS HANDLE NO-UNDO.
DEF VAR hNewBuff AS HANDLE NO-UNDO.
IF v_New_old EQ "old" THEN
hOldBuff = creBuff(v_tablename).
ELSE IF v_New_old EQ "new" THEN
hNewBuff = creBuff(v_tablename). END METHOD.
 
When you post any code, please enclose it with code tags - it makes it much better readable for us.

Without looking at your code more detail I think your problem is that you have no means to know the old values in your implementation. In order to achieve that you must store a copy of a changed record in a Temp-Table before it gets changed. I don't see something like this in the code you've posted. Although you have method that creates a dynamic Temp-Table object based on the definition of another Temp-Table or database table. But I don't see where that dynamic Temp-Table is populated. Furthermore I don't see any code to handle the lifecycle of the dynamic Temp-Table object which most likely will produce a memory leak.

Since you are using classes you should be on a reasonable recent version of OpenEdge. I would have a look at ProDataSets. They add the ability to track changes on the Temp-Tables they contain maintaining a before image version of the Temp-Table for you which allows you to keep track of the changes in your application rather easily.

Heavy Regards, RealHeavyDude.
 
Back
Top