In Transparent Mode, PROIV automatically generates the necessary SQL statements for SQL table data access/manipulation for the access modes allowed.  In order to do this it uses the PROIV SQL File Definitions referenced in the function. The statements are executed according to the normal PROIV Timing Cycle, that is, reading from and writing to an SQL table occurs at the same point in the PROIV execution cycle as for all PROISAM files.

The following sections describe how, and in what format, SQL statements are automatically generated for access of the Primary File (first name specified in the File Information section of a function definition) and a Secondary File (any subsequent name specified in the FILE INFORMATION section).

Primary Files

PROIV generates a 'default' SELECT statement for each SQL file definition in a function, with the selection criteria based upon the K (key) type fields for that file.  This SELECT statement:

Paging Cycle

For the primary file of a Paging Cycle:

Non-Paging Cycle

For the primary file of a non-Paging Cycle:

Non-One Time Report and Update Cycles

For the primary file of a non-one time Report and Update Cycles:

One Time Report and Update Cycles

For the primary file of a one time Report and Update Cycles:

Secondary Files

PROIV automatically constructs an SQL SELECT statement for all SQL secondary files in a function, retrieving all columns referenced in the PROIV File Definition. The SELECT statement includes a WHERE clause specifying a value for each key field defined in the PROIV File Definition using the equal to (=) relational operator.

SQL Statements Generated

This section shows the typical format of the SQL statements generated in various situations.

Read File - Single Row

Where only one row is expected (primary file in a non-Paging Cycle, one-time report or update, all secondary files), a statement of the form:

SELECT key-column-name, key-column-name ... column-name, column-name ...
FROM table-name
WHERE key-column-name = ?, key-column-name = ? ...
FOR UPDATE OF column-name ...

is generated.  (Note that the statement format may vary between the different supported RDBMSs). The FOR UPDATE clause is only appended if the file mode is change or delete (that is, there is update intent).  The table-name is taken from the FILE NAME or ALTERNATE FILE NAME field defined in the PROIV file definition.  The col-name and key-col-name are taken from the PROIV file definition VARIABLE NAME or ALTERNATE fields.

The substitution parameters (the question marks) designate where run-time values are to be assigned to column variables during statement execution.  The actual values passed depend on the current values of the PROIV variables at run-time.

Read File - Multiple Row

Where multiple rows are expected (Paging Cycle, screen Cycle Update, many-time report or update), a typical statement of the form:

SELECT key-col-name, key-col-name ... col-name, col-name ...
FROM table-name

WHERE key-col-name between ? and ?,

      key-col-name between ? and ? ...

ORDER BY key-col-name, key-col-name ...

is generated. The order of the key-col-names in the ORDER BY clause is as specified in the PROIV File Definition.

It is not generally possible to specify FOR UPDATE with an ORDER BY clause, and so PROIV never attempts this.  If there is update intent, a second statement is generated as for single row reads, with a FOR UPDATE OF clause appended using the data retrieved by the above SELECT statement.

The values of the substitution parameters (the question marks) depend on the SEL-xxx statements that have been executed (if any) or if the file is auto-sequenced.

Update File

Rows are normally updated a row at a time except when clearing a file.

A statement of the form:

UPDATE table-name

WHERE CURRENT OF cursor-name

SET (col-name = ?, col-name = ? ...)

Or:

DELETE FROM table-name

WHERE CURRENT OF cursor-name

Or:

INSERT INTO table-name

SET (key-col-name, key-col-name ... col-name, col-name ...)

VALUES (?, ? ...)

is generated according to the operation required.  (Note that the statement format may vary between the different supported DBMS's - see Oracle SQL Statement Generation for details). The cursor names are internal to PROIV.

Comment on this topic

Topic ID: 720261