* Standard COBOL (file "YTS799.SCO") calling SQL * procedures in file "YTS799.MCO".
*Copyright 1996 National Computing Centre Ltd, *and Computer Logic R&D S.A *on behalf of CTS5 SQL2 Project. *All rights reserved. *The CTS5 SQL2 Project is sponsored by the European Community. * *The National Computing Centre Limited and Computer Logic R&D *have given permission to NIST to distribute this program *over the World Wide Web in order to promote SQL standards. *DISCLAIMER: *This program was reviewed by employees of NIST for *conformance to the SQL standards. *NIST assumes no responsibility for any party's use of *this program.
**************************************************************** * * COMMENT SECTION * * SQL VALIDATION TEST SUITE V6.0 * * YTS799.SCO * WRITTEN BY: Susan Watters * TRANSLATED AUTOMATICALLY FROM EMBEDDED COBOL BY CHRIS SCHANZLE * * <subquery> as <row value constructor> in <null predicate> * * * REFERENCES * 8.6 GR2 <null predicate> IS NULL * 8.6 GR3 <null predicate> IS NOT NULL * 7.11 <scalar subquery>,<row subquery> & <table subquery> * 7.1 <row value constructor> * F#48 Expanded null predicate * * DATE LAST ALTERED 02.01.96 CTS5 Hand-over Test * * QA Status: Full FC * * Revised by DWF 1996-03-26 * Added rollback after authid * Removed EXEC SQL from printf * Fixed expected result * Renamed variables * Removed leveling rule violations * Fixed logic errors ****************************************************************
*declare cursor to test for null vals of <null pred > *If scalar subquery is empty, result is NULL (6.11 GR.2)
DISPLAY"DECLARE CRA CURSOR FOR" DISPLAY"SELECT TTA, TTB, TTC FROM CTS1.TT" DISPLAY"WHERE (SELECT TUD FROM TU WHERE TU.TUE = TT.TTA)" DISPLAY"IS NULL ORDER BY TTA DESC;" * EXEC SQL DECLARE CRA CURSOR FOR * SELECT TTA, TTB, TTC FROM CTS1.TT * WHERE (SELECT TUD FROM TU WHERE TU.TUE = TT.TTA) * IS NULL ORDER BY TTA DESC END-EXEC
*Result: *5 42 26 (because TUD is NULL) *2 98 NULL (because subquery is empty) *1 NULL 99 (because subquery is empty)
DISPLAY"OPEN CRA;" * EXEC SQL OPEN CRA; CALL"SUB3"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD
PERFORM CHCKOK DISPLAY" "
*fetch rows of cursor
MOVE 0 TO col1 MOVE 0 TO col2 MOVE 0 TO col3
DISPLAY"FETCH CRA INTO :col1, :col2, :col3;" * EXEC SQL FETCH CRA INTO :col1, :col2, :col3; CALL"SUB4"USING SQLCODE SQLSTATE col1 col2 col3 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"5, 42, 26 expected; ", col1, ", ", col2, ", ",
col3, " returned." if (col1 NOT = 5 OR col2 NOT = 42 OR col3 NOT =
26) then MOVE 0 TO flag END-IF
MOVE 0 TO col1 MOVE 0 TO col2 MOVE 99 TO indic1 MOVE 99 TO indic2
DISPLAY"FETCH CRA INTO :col1, :col2:indic2, :col3:indic1;" * EXEC SQL FETCH CRA INTO :col1, :col2:indic2, :col3:indic1 * ; CALL"SUB5"USING SQLCODE SQLSTATE col1 col2 indic2 col3
indic1 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"col1 should be 2; its value is ", col1 DISPLAY"col2 should be 98; its value is ", col2 DISPLAY"indic1 should be -1; its value is ", indic1 DISPLAY"indic2 should be 0; its value is ", indic2 if (col1 NOT = 2 OR col2 NOT = 98 OR indic1 NOT =
-1) then MOVE 0 TO flag END-IF if (indic2 NOT = 0) then MOVE 0 TO flag END-IF
MOVE 0 TO col1 MOVE 0 TO col3 MOVE 99 TO indic1 MOVE 99 TO indic2
DISPLAY"FETCH CRA INTO :col1, :col2:indic2, :col3:indic1;" * EXEC SQL FETCH CRA INTO :col1, :col2:indic2, :col3:indic1 * ; CALL"SUB6"USING SQLCODE SQLSTATE col1 col2 indic2 col3
indic1 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"col1 should be 1; its value is ", col1 DISPLAY"col3 should be 99; its value is ", col3 DISPLAY"indic1 should be 0; its value is ", indic1 DISPLAY"indic2 should be -1; its value is ", indic2 if (col1 NOT = 1 OR col3 NOT = 99 OR indic1 NOT =
0) then MOVE 0 TO flag END-IF if (indic2 NOT = -1) then MOVE 0 TO flag END-IF
*declare cursor to test for non-null vals of <null pred>
DISPLAY"DECLARE CRB CURSOR FOR" DISPLAY"SELECT TTA, TTB, TTC FROM CTS1.TT" DISPLAY"WHERE (SELECT TUD FROM TU WHERE TU.TUE = TT.TTA)" DISPLAY"IS NOT NULL ORDER BY TTA;" * EXEC SQL DECLARE CRB CURSOR FOR * SELECT TTA, TTB, TTC FROM CTS1.TT * WHERE (SELECT TUD FROM TU WHERE TU.TUE = TT.TTA) * IS NOT NULL ORDER BY TTA END-EXEC
*Result: *3 97 96 *4 NULL NULL
*open cursor
DISPLAY"OPEN CRB;" * EXEC SQL OPEN CRB; CALL"SUB7"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
MOVE 99 TO col1 MOVE 99 TO col2 MOVE 99 TO col3 MOVE 99 TO indic1 MOVE 99 TO indic2
DISPLAY"FETCH CRB INTO :col1, :col2:indic1, :col3:indic2;" * EXEC SQL FETCH CRB INTO :col1, :col2:indic1, :col3:indic2 * ; CALL"SUB8"USING SQLCODE SQLSTATE col1 col2 indic1 col3
indic2 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"col1 should be 3; its value is ", col1 DISPLAY"col2 should be 97; its value is ", col2 DISPLAY"col3 should be 96; its value is ", col3 DISPLAY"indic1, indic2 should be 0, 0; they are ", indic1, ", ", indic2 if (col1 NOT = 3 OR col2 NOT = 97 OR col3 NOT =
96) then MOVE 0 TO flag END-IF if (indic1 NOT = 0 OR indic2 NOT = 0) then MOVE 0 TO flag END-IF
MOVE 99 TO col1 MOVE 99 TO col2 MOVE 99 TO col3 MOVE 99 TO indic1 MOVE 99 TO indic2
DISPLAY"FETCH CRB INTO :col1, :col2:indic1, :col3:indic2;" * EXEC SQL FETCH CRB INTO :col1, :col2:indic1, :col3:indic2 * ; CALL"SUB9"USING SQLCODE SQLSTATE col1 col2 indic1 col3
indic2 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"col1 should be 4; its value is ", col1 DISPLAY"indic1 should be -1; its value is ", indic1 DISPLAY"indic2 should be -1; its value is ", indic2 if (col1 NOT = 4) then MOVE 0 TO flag END-IF if (indic1 NOT = -1 OR indic2 NOT = -1) then MOVE 0 TO flag END-IF
*select rows in TT where either TTB or TTC or both are NULL
MOVE 0 TO co DISPLAY"SELECT COUNT (*) INTO :co FROM CTS1.TT" DISPLAY"WHERE TTB IS NULL OR TTC IS NULL;" * EXEC SQL SELECT COUNT (*) INTO :co FROM CTS1.TT * WHERE TTB IS NULL OR TTC IS NULL; CALL"SUB10"USING SQLCODE SQLSTATE co MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"Number of rows expected was 3 number returned ",
co if (co NOT = 3) then MOVE 0 TO flag END-IF
*select rows in TT where neither TTB nor TTC is NULL
MOVE 0 TO co DISPLAY"SELECT COUNT (*) INTO :co FROM CTS1.TT" DISPLAY"WHERE TTB IS NOT NULL AND TTC IS NOT NULL;" * EXEC SQL SELECT COUNT (*) INTO :co FROM CTS1.TT * WHERE TTB IS NOT NULL AND TTC IS NOT NULL; CALL"SUB11"USING SQLCODE SQLSTATE co MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"Number of rows expected was 2 number returned ",
co if (co NOT = 2) then MOVE 0 TO flag END-IF
*select rows in TT where at least one val in TTB and TTC is non-
MOVE 0 TO co DISPLAY"SELECT COUNT (*) INTO :co FROM CTS1.TT" DISPLAY"WHERE NOT (TTB IS NULL AND TTC IS NULL);"
* EXEC SQL SELECT COUNT (*) INTO :co FROM CTS1.TT * WHERE NOT (TTB IS NULL AND TTC IS NULL); CALL"SUB12"USING SQLCODE SQLSTATE co MOVE SQLCODE TO SQL-COD DISPLAY"Number of rows expected was 4 number returned ",
co if (co NOT = 4) then MOVE 0 TO flag END-IF
* EXEC SQL COMMIT WORK; CALL"SUB16"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD ******************** END TEST7531 ********************
**** TESTER MAY CHOOSE TO INSERT CODE FOR errcnt > 0 STOPRUN.
* **** Procedures for PERFORM statements
*Test SQLCODE and SQLSTATE for normal completion.
CHCKOK. DISPLAY"SQLCODE should be 0; its value is ", SQL-COD DISPLAY"SQLSTATE should be 00000; its value is ", SQLSTATE PERFORM NOSUBCLASS THRU EXIT-NOSUBCLASS if (SQLCODE NOT = 0 OR NORMSQ NOT = "00000") then MOVE 0 TO flag END-IF if (NORMSQ = "00000"AND NORMSQ NOT = SQLSTATE) then DISPLAY"Valid implementation-defined SQLSTATE accepted." END-IF
.
NOSUBCLASS.
*This routine replaces valid implementation-defined *subclasses with 000. This replacement equates valid *implementation-defined subclasses with the 000 value *expected by the test case; otherwise the test will fail. *After calling NOSUBCLASS, NORMSQ will be tested * SQLSTATE will be printed.
MOVE SQLSTATE TO NORMSQ
MOVE 3 TO norm1 *subclass begins in position 3 of char array NORMSQ *valid subclass begins with 5-9, I-Z, end of ALPNUM table PERFORMVARYING norm2 FROM 14 BY 1 UNTIL norm2 > 36 if (NORMSQX(norm1) = ALPNUM(norm2)) then MOVE"0"TO NORMSQX(norm1) END-IF END-PERFORM
*Quit if NORMSQ is unchanged. Subclass is not impl.-def. *Changed NORMSQ means implementation-defined subclass, *so proceed to zero it out, if valid (0-9,A-Z) if (NORMSQ = SQLSTATE) then GOTO EXIT-NOSUBCLASS END-IF
MOVE 4 TO norm1 *examining position 4 of char array NORMSQ *valid characters are 0-9, A-Z PERFORMVARYING norm2 FROM 1 BY 1 UNTIL norm2 > 36 if (NORMSQX(norm1) = ALPNUM(norm2)) then MOVE"0"TO NORMSQX(norm1) END-IF END-PERFORM
MOVE 5 TO norm1 *valid characters are 0-9, A-Z *examining position 5 of char array NORMSQ PERFORMVARYING norm2 FROM 1 BY 1 UNTIL norm2 > 36 if (NORMSQX(norm1) = ALPNUM(norm2)) then MOVE"0"TO NORMSQX(norm1) END-IF END-PERFORM
*implementation-defined subclasses are allowed for warnings *(class = 01). These equate to successful completion *SQLSTATE values of 00000. *Reference SQL-92 4.28 SQL-transactions, paragraph 2
if (NORMSQX(1) = "0"AND NORMSQX(2) = "1") then MOVE"0"TO NORMSQX(2) END-IF
.
EXIT-NOSUBCLASS. EXIT.
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
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.