**************************************************************** * * COMMENT SECTION * * DATE 1988/10/25 EMBEDDED COBOL LANGUAGE * NIST SQL VALIDATION TEST SUITE V6.0 * DISCLAIMER: * This program was written by employees of NIST to test SQL * implementations for conformance to the SQL standards. * NIST assumes no responsibility for any party's use of * this program. * * DML041.PCO * WRITTEN BY: HU YANPING * TRANSLATED AUTOMATICALLY FROM EMBEDDED C BY CHRIS SCHANZLE * * THIS ROUTINE TESTS THE ENFORCEMENT OF * CHECK CONSTRAINTS IN NESTED VIEWS * * REFERENCES * AMERICAN NATIONAL STANDARD database language - SQL * X3.135-1989 * * 8.7 <insert statement>, 8.11 & 8.12 <update statements> * ****************************************************************
MOVE"HU"TO uid CALL"AUTHID"USING uid MOVE"not logged in, not"TO uidx EXECSQLSELECT
USER INTO :uidx FROM HU.ECCO END-EXEC if (uid NOT = uidx) then DISPLAY"ERROR: User " uid " expected." DISPLAY"User " uidx " connected." DISPLAY" " STOPRUN END-IF
MOVE 0 TO errcnt DISPLAY "SQL Test Suite, V6.0, Embedded COBOL, dml041.pco" DISPLAY" " DISPLAY "59-byte ID" DISPLAY"TEd Version #" DISPLAY" " * date_time print * ACCEPT TO-DAY FROMDATE ACCEPT THE-TIME FROMTIME DISPLAY"Date run YYMMDD: " TO-DAY " at hhmmssff: " THE-TIME
******************** BEGIN TEST0212 *******************
* CREATE VIEW V_WORKS1 * AS SELECT * FROM WORKS * WHERE HOURS > 15 * WITH CHECK OPTION;
* CREATE VIEW V_WORKS2 * AS SELECT * FROM V_WORKS1 * WHERE EMPNUM = 'E1' * OR EMPNUM = 'E6';
* CREATE VIEW V_WORKS3 * AS SELECT * FROM V_WORKS2 * WHERE PNUM = 'P2' * OR PNUM = 'P7' * WITH CHECK OPTION;
MOVE 1 TO ifpass
EXECSQLINSERTINTO V_WORKS2
VALUES('E9','P7',13) END-EXEC MOVE SQLCODE TO SQL-COD
if (SQLCODE = 0) then DISPLAY"Fail: Violates constraint of " DISPLAY" underlying view (with check option)" MOVE 0 TO ifpass END-IF
EXECSQLINSERTINTO V_WORKS2
VALUES('E7','P4',95) END-EXEC MOVE SQLCODE TO SQL-COD
if (SQLCODE NOT = 0) then DISPLAY"Fail: Will not insert outside of view 2 def. (no
- " check)," DISPLAY"Satisfies constraint of underlying view (with
- " check opt)" MOVE 0 TO ifpass END-IF
EXECSQLINSERTINTO V_WORKS3
VALUES('E8','P2',85) END-EXEC MOVE SQLCODE TO SQL-COD
*NOTE: The standard is not completely clear which of these * options is intended, so this code does not result in * pass or fail. *Either of the two following results is acceptable: *This is just an informational sub-test if (SQLCODE = 0) then DISPLAY"Inserts row which is:" DISPLAY" Inside view 1 def. (with check)" DISPLAY" Outside view 2 def. (no check)" DISPLAY" Inside view 3 def. (with check)" DISPLAY"Outer check option does not imply inner check
- " options" else DISPLAY"Will not insert row which is:" DISPLAY" Inside view 1 def. (with check)" DISPLAY" Outside view 2 def. (no check)" DISPLAY" Inside view 3 def. (with check)" DISPLAY"Outer check option implies inner check options" END-IF
EXECSQLINSERTINTO V_WORKS3
VALUES('E1','P7',90) END-EXEC MOVE SQLCODE TO SQL-COD
if (SQLCODE NOT = 0) then DISPLAY"Fail: Will not insert row satisfying " DISPLAY" all nested view definitions" MOVE 0 TO ifpass END-IF
EXECSQLINSERTINTO V_WORKS3
VALUES('E9','P2',10) END-EXEC MOVE SQLCODE TO SQL-COD
if (SQLCODE = 0) then DISPLAY"Fail: Violates constraint of " DISPLAY" underlying view (with check option)" MOVE 0 TO ifpass END-IF
MOVE 0 TO I
EXECSQLSELECTCOUNT(*) INTO :I FROM WORKS
WHERE EMPNUM = 'E9'END-EXEC MOVE SQLCODE TO SQL-COD
if (I > 0 ) then MOVE 0 TO ifpass DISPLAY"Fail: Nested views fail to enforce " DISPLAY" underlying check constraint." END-IF
MOVE 0 TO I
EXECSQLSELECTCOUNT(*) INTO :I FROM WORKS
WHERE HOURS > 85 END-EXEC MOVE SQLCODE TO SQL-COD
if (I < 2) then DISPLAY"Fail: Will not insert rows satisfying underlying
- " views" MOVE 0 TO ifpass END-IF
EXECSQL ROLLBACK WORK END-EXEC MOVE SQLCODE TO SQL-COD
if (ifpass = 1) then DISPLAY" *** pass *** " EXECSQLINSERTINTO TESTREPORT VALUES('0212','pass','PCO') END-EXEC MOVE SQLCODE TO SQL-COD else DISPLAY" dml041.pco *** fail *** " EXECSQLINSERTINTO TESTREPORT VALUES('0212','fail','PCO') END-EXEC ADD 1 TO errcnt MOVE SQLCODE TO SQL-COD END-IF
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.