* Standard COBOL (file "XTS798.SCO") calling SQL * procedures in file "XTS798.MCO".
*Copyright 1995 National Computing Centre Limited *and Computer Logic R&D S.A *on behalf of the 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 * * XTS798.PC TEST7001 * WRITTEN BY: Nickos Backalidis * TRANSLATED AUTOMATICALLY FROM EMBEDDED COBOL BY CHRIS SCHANZLE * * NULLIF which produces non-NULL * *REFERENCES *6.9 FT.2 <case abbreviation> *6.9 SR.1 *6.9 GR.1b *6.9 GR.2b *6.9 LR.2a -- Raised. Entry SQL restriction which prohibited * the use of a <case expression> *6.11 LR2c -- Raised *F#26 -- CASE expression * * DATE LAST ALTERED 18/12/95 CTS5 Hand-over Test * * Cleanups and fixes by V. Kogakis 18/12/95 * Print timestamp * Include Files * Define NOSUBCLASS/CHCKOK at test beginning * * QA STATUS : QA CHECK * * Revised by DWF 1996-02-27 * Fixed coding rule violations * Made printout match statements * Removed status checks after cursor definitions * Fixed result printout * Fixed string length * Fixed pass criteria * Fixed bogus code ****************************************************************
*insert 6 rows in the table STAFFb in order to test NULLIF DISPLAY"INSERT INTO STAFFb
- " VALUES(10000,'Kilroy',10000,'P4','Athens','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10000,'Kilroy',10000,'P4','Athens','M'); CALL"SUB3"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(15000,'Nickos',20000,'P6','Nickos','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(15000,'Nickos',20000,'P6','Nickos','M'); CALL"SUB4"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(NULL,'Nickos',NULL,'P5','Rhodes','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(NULL,'Nickos',NULL,'P5','Rhodes','M'); CALL"SUB5"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10010,'George',NULL,'P7','Georgia','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10010,'George',NULL,'P7','Georgia','M'); CALL"SUB6"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10005,NULL,30000,'P8',NULL,'M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10005,NULL,30000,'P8',NULL,'M'); CALL"SUB7"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10001,'Gregory',12000,'P9',NULL,'M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10001,'Gregory',12000,'P9',NULL,'M'); CALL"SUB8"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*Test NULLIF with numeric data types DISPLAY"DECLARE F CURSOR FOR SELECT EMPNAME, NULLIF
- " (SALARY,HOURS)" DISPLAY"FROM CTS1.STAFFb" DISPLAY"WHERE SEX = 'M' AND PNUM NOT IN
- " ('P1','P2','P3','P6','P8')" DISPLAY"AND (SALARY <> HOURS OR SALARY IS NULL OR HOURS IS
- " NULL)" DISPLAY"ORDER BY PNUM;" * EXEC SQL DECLARE F CURSOR FOR SELECT EMPNAME, NULLIF * (SALARY,HOURS) * FROM CTS1.STAFFb * WHERE SEX = 'M' AND PNUM NOT IN * ('P1','P2','P3','P6','P8') * AND (SALARY <> HOURS OR SALARY IS NULL OR HOURS IS NULL) * ORDER BY PNUM END-EXEC
DISPLAY"OPEN F" * EXEC SQL OPEN F; CALL"SUB9"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"NULLIF producing non-NULL the results should be:" * 3 rows satisfy the <search condition> of the query DISPLAY"FETCH F INTO :ename, :sal:indic1;" * EXEC SQL FETCH F INTO :ename, :sal:indic1; CALL"SUB10"USING SQLCODE SQLSTATE ename sal indic1 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Nickos; its value is ", ename DISPLAY"indic1 should be -1; its value is ", indic1 if ( ename NOT = "Nickos"OR indic1 NOT = -1 ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH F INTO :ename, :sal:indic1;" * EXEC SQL FETCH F INTO :ename, :sal:indic1; CALL"SUB11"USING SQLCODE SQLSTATE ename sal indic1 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be George; its value is ", ename DISPLAY"sal should be 10010; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( ename NOT = "George"OR indic1 NOT = 0 OR
sal NOT = 10010 ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH F INTO :ename, :sal:indic1;" * EXEC SQL FETCH F INTO :ename, :sal:indic1; CALL"SUB12"USING SQLCODE SQLSTATE ename sal indic1 MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Gregory; its value is ", ename DISPLAY"sal should be 10001; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( ename NOT = "Gregory"OR indic1 NOT = 0 OR
sal NOT = 10001 ) then MOVE 0 TO flag END-IF DISPLAY" "
DISPLAY"CLOSE F;" * EXEC SQL CLOSE F; CALL"SUB13"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
***** test NULLIF with character string values **** DISPLAY"DECLARE G CURSOR FOR SELECT NULLIF (EMPNAME,CITY),
- " SALARY" DISPLAY"FROM CTS1.STAFFb" DISPLAY"WHERE SEX = 'M' AND PNUM NOT IN
- " ('P1','P2','P3','P5','P7')" DISPLAY"AND (EMPNAME <> CITY OR EMPNAME IS NULL OR CITY IS
- " NULL)" DISPLAY"ORDER BY PNUM" * EXEC SQL DECLARE G CURSOR FOR SELECT NULLIF (EMPNAME,CITY), * SALARY * FROM CTS1.STAFFb * WHERE SEX = 'M' AND PNUM NOT IN * ('P1','P2','P3','P5','P7') * AND (EMPNAME <> CITY OR EMPNAME IS NULL OR CITY IS NULL) * ORDER BY PNUM END-EXEC
DISPLAY"OPEN G" * EXEC SQL OPEN G; CALL"SUB14"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"NULLIF producing non NULL the results should be:" * 3 rows satisfy the <search condition> of the query DISPLAY"FETCH G INTO :ename:indic1, :sal;" * EXEC SQL FETCH G INTO :ename:indic1, :sal; CALL"SUB15"USING SQLCODE SQLSTATE ename indic1 sal MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Kilroy; its value is ", ename DISPLAY"sal should be 10000; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( ename NOT = "Kilroy"OR indic1 NOT = 0 OR
sal NOT = 10000 ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH G INTO :ename:indic1, :sal;" * EXEC SQL FETCH G INTO :ename:indic1, :sal; CALL"SUB16"USING SQLCODE SQLSTATE ename indic1 sal MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"indic1 should be -1; its value is ", indic1 DISPLAY"sal should be 10005; its value is ", sal if ( indic1 NOT = -1 OR sal NOT = 10005 ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH G INTO :ename:indic1, :sal;" * EXEC SQL FETCH G INTO :ename:indic1, :sal; CALL"SUB17"USING SQLCODE SQLSTATE ename indic1 sal MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Gregory; its value is ", ename DISPLAY"sal should be 10001; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( ename NOT = "Gregory"OR indic1 NOT = 0 OR
sal NOT = 10001 ) then MOVE 0 TO flag END-IF
DISPLAY"CLOSE G;" * EXEC SQL CLOSE G; CALL"SUB18"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*restore CTS1.STAFFb in its original state DISPLAY"ROLLBACK WORK;" * EXEC SQL ROLLBACK WORK; CALL"SUB19"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*re-insert the same rows in table CTS1.STAFFb *so that a ROLLBACK will leave CTS1.STAFFb *unaffected and DROP TABLE TEMP1426 will work DISPLAY"INSERT INTO STAFFb
- " VALUES(10000,'Kilroy',10000,'P4','Athens','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10000,'Kilroy',10000,'P4','Athens','M'); CALL"SUB22"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(15000,'Nickos',20000,'P6','Nickos','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(15000,'Nickos',20000,'P6','Nickos','M'); CALL"SUB23"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(NULL,'Nickos',NULL,'P5','Rhodes','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(NULL,'Nickos',NULL,'P5','Rhodes','M'); CALL"SUB24"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10010,'George',NULL,'P7','Georgia','M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10010,'George',NULL,'P7','Georgia','M'); CALL"SUB25"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10005,NULL,30000,'P8',NULL,'M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10005,NULL,30000,'P8',NULL,'M'); CALL"SUB26"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO STAFFb
- " VALUES(10001,'Gregory',12000,'P9',NULL,'M');" * EXEC SQL INSERT INTO STAFFb * VALUES(10001,'Gregory',12000,'P9',NULL,'M'); CALL"SUB27"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"INSERT INTO TEMP1426" DISPLAY"SELECT NULLIF (10000,SALARY), EMPNAME FROM STAFFb" DISPLAY"WHERE SEX = 'M' AND PNUM NOT IN
- " ('P1','P2','P3','P6','P8','P9');" * EXEC SQL INSERT INTO TEMP1426 * SELECT NULLIF (10000,SALARY), EMPNAME FROM STAFFb * WHERE SEX = 'M' AND PNUM NOT IN * ('P1','P2','P3','P6','P8','P9'); CALL"SUB28"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"DECLARE H CURSOR FOR SELECT * FROM CTS1.TEMP1426" DISPLAY"ORDER BY EMPNAME;" * EXEC SQL DECLARE H CURSOR * FOR SELECT * FROM CTS1.TEMP1426 * ORDER BY EMPNAME END-EXEC
DISPLAY"OPEN H" * EXEC SQL OPEN H; CALL"SUB29"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
* 3 rows satisfy the <search condition> of the query DISPLAY"FETCH H INTO :sal:indic1, :ename;" * EXEC SQL FETCH H INTO :sal:indic1, :ename; CALL"SUB30"USING SQLCODE SQLSTATE sal indic1 ename MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be George; its value is ", ename DISPLAY"sal should be 10000; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( sal NOT = 10000 OR indic1 NOT = 0 OR ename NOT = "George" ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH H INTO :sal:indic1, :ename;" * EXEC SQL FETCH H INTO :sal:indic1, :ename; CALL"SUB31"USING SQLCODE SQLSTATE sal indic1 ename MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Kilroy; its value is ", ename DISPLAY"indic1 should be -1; its value is ", indic1 if ( indic1 NOT = -1 OR ename NOT = "Kilroy" ) then MOVE 0 TO flag END-IF DISPLAY" "
*initialise host variables MOVE 0 TO sal MOVE"xxxxxxxxxxxxxxxxxxxx"TO ename MOVE 99 TO indic1
DISPLAY"FETCH H INTO :sal:indic1, :ename;" * EXEC SQL FETCH H INTO :sal:indic1, :ename; CALL"SUB32"USING SQLCODE SQLSTATE sal indic1 ename MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"ename should be Nickos; its value is ", ename DISPLAY"sal should be 10000; its value is ", sal DISPLAY"indic1 should be 0; its value is ", indic1 if ( sal NOT = 10000 OR indic1 NOT = 0 OR ename NOT = "Nickos" ) then MOVE 0 TO flag END-IF DISPLAY" "
DISPLAY"CLOSE H;" * EXEC SQL CLOSE H; CALL"SUB33"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
******************** END TEST7002 ********************
**** 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.
¤ 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.0.18Bemerkung:
(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.