I'm trying to expand my horizons, so to speak.
The ability to put some of the data validation into the database using CHECK constraints and with triggers. How do I use this in the RPG code? If I have a series of CHECK constraints, how do I determine which constraint it didn't like, and what the valid values are for purposes of providing feedback to the user?
For example:
To utilize the CHECK above I would have to first update or write the data to the table. Let's say that the program is trying to update the table with TAPDCODE value of 8. It will fail, how do I programmatically determine which constraint rejected the update and perhaps the criteria used in the constraint?
Or is the preferred method of putting the validation logic at the Database (DB) level using triggers? I assume you'd use SIGNAL and specify a different value to flag what went wrong??????
The ability to put some of the data validation into the database using CHECK constraints and with triggers. How do I use this in the RPG code? If I have a series of CHECK constraints, how do I determine which constraint it didn't like, and what the valid values are for purposes of providing feedback to the user?
For example:
Code:
CREATE TABLE SYTTAPSCH ( TAPVOL CHAR(6) CCSID 37 NOT NULL DEFAULT '' , TAPDCODE NUMERIC(1, 0) NOT NULL DEFAULT 0 , TAPWCODE NUMERIC(1, 0) NOT NULL DEFAULT 0 , TAPBTYPE CHAR(1) CCSID 37 NOT NULL DEFAULT '' , TAPSAVTS TIMESTAMP DEFAULT CURRENT TIMESTAMP, TAPLSTUPD TIMESTAMP IMPLICITLY HIDDEN NOT NULL DEFAULT CURRENT TIMESTAMP, CONSTRAINT Q_QGPL_SYTTAPSCH_TAPVOL_00001 PRIMARY KEY( TAPVOL ), CHECK (TAPDCODE BETWEEN 1 AND 7), CHECK (TAPWCODE BETWEEN 1 AND 2), CHECK (TAPBTYPE IN ('F','D'))) RCDFMT TAPSCH ;
Or is the preferred method of putting the validation logic at the Database (DB) level using triggers? I assume you'd use SIGNAL and specify a different value to flag what went wrong??????
Comment