Ideas for comparisons

whwar9739

Member
Does anyone know of a way to compare an existing database table with the default buffer for the table? Essentially I would like to be able to accomplish the following:

Code:
assign
   table.field   = 1
   table.field2 = 2
.

buffer-compare table to default buffer for table
   save result in l-changed-fields.

display l-changed fields.
 
Although statements like FIND or ASSIGN move the data between database and record buffer, from the 4GL you can only access a record buffer associated with the table. There is no way to bypass that mechanism and access the contents of the database table.

In order to achieve something like this you need to have two record buffers. Frameworks like the ADM2 for example, achieve functionality like that because the read the contents of a record into a temp-table, let the user update the contents of the temp-table and, before the record gets saved to the database, compare the contents of the changed record in the temp-table against the contents of the database record read into a record buffer.

Whether you use the BUFFER-COMPARE or implement your own logic with dynamic buffer objects is up to you but you need to have two record buffers to compare them.

That's the whole idea of separating your application into distinct layers for data access, business logic and presentation ( user interface ). That's what the data access layer does, it transfers the contents of database records in temp-tables and writes them back. Practically there is no point in using database triggers to update records in related tables in this architecture because something like that should only happen in the business logic layer ...

Don't know whether this is the answer you hoped to get, but it should give you an idea on what to take into consideration and that you reach the end of the line regarding functionality of legacy client/server architectures at some point.

HTH, RealHeayDude.
 
Ok, so if I were to use multiple buffers what would be the simplest solution to solve my issue? Also if I were to create two buffers, both pointing to the same record, and run an assign statement to the one would an 'on write of' still be the core database table name?
 
For an individual record, if you CREATE a new record in a buffer, it will correspond to the defaults for that table. If you then create and modify a record in another buffer, you can compare the two. If you use a temp-table, you can accomplish this this by creating a record and then turn on tracking changes so that the default will be the before image ... but that goofs up the intent of how the TT is supposed to keep track of new records, so I wouldn't go there.
 
A logic similar like this should do ( using Thunderbird as editor - so it's not syntax checked ):

DEFINE VARIABLE hBeforeBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hAfterBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE cChangedFields AS CHARACTER NO-UNDO.
DEFINE VARIABLE iField AS INTEGER NO-UNDO.

DEFINE BUFFER b_before FOR cfr_InstrumentIdScheme.
DEFINE BUFFER b_after FOR cfr_InstrumentIdScheme.

/* Your logic to retrieve the records */

/* Grab the handle to the static buffer objects */
ASSIGN hBeforeBuffer = BUFFER b_before:HANDLE
hAfterBuffer = BUFFER b_after:HANDLE.

/* Loop through all fields of the static buffer objects */
DO iField = 1 TO hBeforeBuffer:NUM-FIELDS:

/* If the buffer values don't match add the field up to the list of changed fields */
IF hBeforeBuffer:BUFFER-FIELD ( iField ):BUFFER-VALUE <> hAfterBuffer:BUFFER-FIELD ( iField ):BUFFER-VALUE THEN
ASSIGN cChangedFields = cChangedFields ( IF cChangedFields = '':U THEN '':U ELSE ',':U ) + hBeforeBuffer:BUFFER-FIELD ( iField ):NAME.

END.
HTH, RealHeavyDude.
 
Back
Top