Consultor Eletrônico



Kbase P4316: How to run the same code against databases with same schema
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/19/2007
Status: Verified

GOAL:

How to run the same code against databases with same schema

GOAL:

How to run compiled r-code with a copy of original database if the copy has a different name ?

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)

FIX:

This solution explains how you can run the same procedure against two databases which have the same schema but different data.
(The information can then be extended to cover situations with many more than two databases, but for the purposes of this solution we will assume only two.)

The example given below assumes that you want to connect to one database at a time, running the same procedure against each individually.

One basic requirement is that the two databases be identical in terms of schema and CRC. This example will not work if the databases differ IN ANY WAY, even if the procedure to be run against them is not saved as r-code.

A second basic requirement is that logical database names be used when compiling and connecting, rather than physical names.


STEP 1: Create the two identical databases. For this example, the physical names of the databases will be "firstdb" and "seconddb".

STEP 2: Whenever connecting to either "firstdb" or "seconddb" at runtime *or* during development, include a logical name that is identical for each. For this example, the logical name will be "maindb".

STEP 3: Load different data into the two databases so that when it is displayed you will be able to verify that you are indeed seeing the data from the proper database.

STEP 4: Write a brief program to display the data. For example:

FOR EACH table1:
DISPLAY field1 field2 WITH SIDE-LABELS.
END.

Save this program as "display.p".

STEP 5: Compile and save "display.p" so that "display.r" results. (This is where it is critical for you to have used the logical name when connecting to the database to create "display.p".)

STEP 6: Write a main program that handles connecting and disconnecting to the two databases, as well as running the display program. For example:

CONNECT firstdb -1 -ld maindb.
RUN display.r.
DISCONNECT maindb.

CONNECT seconddb -1 -ld maindb.
RUN display.r.
DISCONNECT maindb.


IMPORTANT NOTE: The connection and disconnection from the target databases takes place in the main program, while the actual processing that uses the databases takes place in the called program. You will be unable to include the code from display.p in the same procedure where you do your connecting and disconnecting. This is a characteristic of the PROGRESS architecture.