* Standard COBOL (file "XTS752.SCO") calling SQL * procedures in file "XTS752.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 * * XTS752.SCO * WRITTEN BY: Nickos Backalidis * TRANSLATED AUTOMATICALLY FROM EMBEDDED COBOL BY CHRIS SCHANZLE * * ALTER TABLE ADD TABLE CONSTRAINT * * * REFERENCES * 11.10 -- <Alter table statement> * 11.10 AR.1 * 11.16 -- <Add table constraint definition> * F#1 -- Dynamic SQL * F#2 -- Basic Information Schema * F#38 -- Schema manipulation * * DATE LAST ALTERED 18/12/95 CTS5 Hand-over Test * * Cleanups and fixes by V. Kogakis 15/12/95 * Print timestamp * Include Files * Define NOSUBCLASS/CHCKOK at test beginning * * QA STATUS : QA CHECK * * Revised by DWF 1996-02-15 * Fixed SDL transactions * Changed long string code * Fixed SQL syntax errors * Upcased info schem identifiers * Fixed Dynamic SQL * Removed printf field widths ****************************************************************
*Access the Information Shema KEY_COLUMN_USAGE view *and check if the table constraint was added OK MOVE 0 TO counok DISPLAY"SELECT COUNT(*) INTO :counok" DISPLAY"FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE" DISPLAY"WHERE TABLE_SCHEMA = 'CTS1' AND TABLE_NAME =
- " 'TAB752A'" DISPLAY"AND CONSTRAINT_NAME = 'TA752A_PRKEY' AND
- " COLUMN_NAME = 'COL1';" * EXEC SQL SELECT COUNT(*) INTO :counok * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE * WHERE TABLE_SCHEMA = 'CTS1' AND TABLE_NAME = 'TA752A' * AND CONSTRAINT_NAME = 'TA752A_PRKEY' AND COLUMN_NAME = * 'COL1'; CALL"SUB9"USING SQLCODE SQLSTATE counok MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"counok should be 1; its value is ", counok if (counok NOT = 1) then MOVE 0 TO flag END-IF DISPLAY" "
*Use Dynamic SQL with an preparable statement *and access the key column usage view and check *if the constraint is present
* EXEC SQL DELETE FROM CONCATBUF; CALL"SUB13"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD * EXEC SQL INSERT INTO CONCATBUF VALUES ( * 'SELECT COUNT(*) FROM * INFORMATION_SCHEMA.KEY_COLUMN_USAGE' || * ' WHERE TABLE_SCHEMA = ''CTS1''' || * ' AND TABLE_NAME = ''TAB752B''' || * ' AND CONSTRAINT_NAME = ''TA752B_FKEY''' || * ' AND COLUMN_NAME = ''C2''' * ); CALL"SUB14"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD * EXEC SQL SELECT ZZ INTO :longst FROM CONCATBUF; CALL"SUB15"USING SQLCODE SQLSTATE longst MOVE SQLCODE TO SQL-COD DISPLAY"longst=""", longst, """"
DISPLAY"PREPARE S FROM :longst;" * EXEC SQL PREPARE S FROM :longst; CALL"SUB16"USING SQLCODE SQLSTATE longst MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"DECLARE SCUR CURSOR FOR S;" * EXEC SQL DECLARE SCUR CURSOR FOR S END-EXEC
DISPLAY"OPEN SCUR;" * EXEC SQL OPEN SCUR; CALL"SUB17"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
MOVE 0 TO counok DISPLAY"FETCH SCUR INTO :counok;" * EXEC SQL FETCH SCUR INTO :counok; CALL"SUB18"USING SQLCODE SQLSTATE counok MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"Counok should be 1; its value is ", counok if (counok NOT = 1) then MOVE 0 TO flag END-IF DISPLAY" "
*attempt to insert one row in TAB752a that violates *CHECK constraint COL3_CHECK DISPLAY"INSERT INTO TAB752a
- " VALUES(1000,'KILLER','PAROS');" * EXEC SQL INSERT INTO TAB752a VALUES(1000,'KILLER','PAROS') * ; CALL"SUB22"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD *Check that an exception condition of integrity *constraint violation is raised indicated in the *value of SQLSTATE which should be '23000'. DISPLAY"SQLCODE should be < 0; its value is ", SQL-COD DISPLAY"SQLSTATE should be 23000; its value is ", SQLSTATE PERFORM NOSUBCLASS THRU EXIT-NOSUBCLASS if (SQLCODE NOT < 0) then MOVE 0 TO flag END-IF if (NORMSQ NOT = "23000") then MOVE 0 TO flag END-IF if (NORMSQ = "23000"AND NORMSQ NOT = SQLSTATE) then DISPLAY"Valid implementation-defined SQLSTATE accepted." END-IF DISPLAY" "
if ( flag = 1 ) then DISPLAY" xts752.mco *** pass *** " * EXEC SQL INSERT INTO CTS1.TESTREPORT * VALUES('7052','pass','MCO'); CALL"SUB28"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD else DISPLAY" xts752.mco *** fail *** " * EXEC SQL INSERT INTO CTS1.TESTREPORT * VALUES('7052','fail','MCO'); CALL"SUB29"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD COMPUTE errcnt = errcnt + 1 END-IF
DISPLAY"========================================"
* EXEC SQL COMMIT WORK; CALL"SUB30"USING SQLCODE SQLSTATE MOVE SQLCODE TO SQL-COD ******************** END TEST7052 ********************
**** 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.29 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.