Database Logic

Database logic, strictly defined, is the code that implements the following Maintain database commands:

Applications typically apply a stack to these commands to load or put back data to and from a database. The stack or stacks are typically visible in the presentation logic because they are bound to visual controls. This enables the user to work with the data in the stacks on a form.

In a partitioned application, the stacks are initialized in both the presentation logic procedures and the database logic procedures, either through INFER or COMPUTE statements. The stack data is then passed back and forth between the two sets of Maintain procedures using the CALL parameter syntax, FROM and INTO.

In normal practice, however, the stack retrieved from the database and the stack presented to the user have usually gone through some amount of transformation, so little similarity remains between them. For example, new columns may be added, the stack may be sorted differently, or it may be copied to a secondary stack for purposes important to the logic of the application. Therefore, there will always be more logic required than simple database commands creating stacks that are then presented to the user. Additional logic must be included between these two actions.

The best place for these non-database commands and logic (which are also not presentation logic) is in the database logic component of the application. This way, the presentation logic procedures must only show forms and send and receive data stacks from the database logic procedures. The database logic procedures take on the role of interfacing with the DBMS, as well as preparing the stacks for presentation and/or re-preparing them for DBMS interaction.

One way to characterize this processing is pre-form stack processing and pre-database stack processing. The stacks must be fully transformed to match the data control being used on the form before being returned to the presentation logic procedure. The stacks may also need to be re-transformed before being addressed back to the DBMS.