*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 * * XTS718.PCO * WRITTEN BY: Manolis Megaloikonomou * TRANSLATED AUTOMATICALLY FROM EMBEDDED C BY CHRIS SCHANZLE * REVIEWED BY: Nickos Backalidis * * SET SESSION AUTHORIZATION to different value * * REFERENCES * 16.4 -- <set session authorization identifier statement> * 16.4 GR.2 * 16.4 GR.5 * 16.4 LR.2a -- Raised. Entry SQL restriction that * prohibits the use of any <set session * authorization identifier statement>. * 6.2 -- <value specification> and <target specification> * 6.2 GR.10 * 6.2 GR.11 * 6.2 LR.2c -- Raised. Entry SQL restriction which * prohibits the specification of CURRENT_USER, * SYSTEM_USER or SESSION_USER in a * <general value specification>. * 5.4 -- <Names and identifiers> * 5.4 SR.3 * 5.4 SR.18 * F#32 -- User authorization. * * DATE LAST ALTERED 12/12/95 CTS5 Hand-over Test * * Cleanups and fixes by V. Kogakis 01/12/95: * Respect length of strings * * QA Status: QA Check * *Revised by DWF 1/23/96 * Removed status code checks after cursor definition * Deleted subtest with 128-char authid string * Fixed SQLCODE checks * Document possible problems * Added subtest to detect super-user where CTS2 should be ****************************************************************
MOVE"CTS1 "TO uid CALL"AUTHID"USING uid MOVE"not logged in, not"TO uidx EXECSQLSELECT USER INTO :uidx FROM CTS1.ECCO END-EXEC MOVE SQLCODE TO SQL-COD EXECSQL ROLLBACK WORK END-EXEC MOVE SQLCODE TO SQL-COD if (uid NOT = uidx) then DISPLAY"ERROR: User ", uid, " expected. User ", uidx, "
- " connected" STOPRUN END-IF MOVE 0 TO errcnt
DISPLAY"SQL Test Suite, V6.0, Embedded COBOL, xts718.pco" DISPLAY "59-byte ID" DISPLAY"TEd Version #" *date_time print ACCEPT TO-DAY FROMDATE ACCEPT THE-TIME FROMTIME DISPLAY"Date run YYMMDD: " TO-DAY " at hhmmssff: " THE-TIME
******************** BEGIN TEST7018 *******************
DISPLAY"This test attempts to change session
- " authorizations. Because" DISPLAY"authorizations are implementation-defined, this
- " test may need" DISPLAY"modification. The following actions may help to
- " pass the test:" DISPLAY" -- Change the initial authid to an authid with
- " DBA privileges" DISPLAY" -- Insert code to work around
- " implementation-defined" DISPLAY" authentication mechanisms (e.g. to reconnect
- " with a" DISPLAY" different authid)." DISPLAY"It might not be possible to change the session
- " authorization," DISPLAY"as explained in 16.4 GR.4. In this case, the
- " restrictions that" DISPLAY"render it impossible should be documented and the
- " test assumed" DISPLAY"to be passed."
*Preserve the original authorization identifier CTS1 into *a host variable with padded leading and trailing spaces. MOVE" CTS1 "TO xuser
*Ensure that the current authorization has access rights *to table STAFF. MOVE 99 TO coun DISPLAY"SELECT COUNT(*) INTO :coun FROM CTS1.STAFF;" EXECSQLSELECTCOUNT(*) INTO :coun FROM CTS1.STAFF END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"coun should be 5; its value is ", coun if ( coun NOT = 5 ) then MOVE 0 TO flag END-IF DISPLAY" "
DISPLAY"ROLLBACK WORK;" EXECSQL ROLLBACK WORK END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*Change the session authorization identifier to CTS2 DISPLAY"SET SESSION AUTHORIZATION 'CTS2';" EXECSQLSET SESSION AUTHORIZATION 'CTS2'END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
MOVE 99 TO coun DISPLAY"SELECT COUNT(*) INTO :coun FROM CTS2.PROJ_MAN;" EXECSQLSELECTCOUNT(*) INTO :coun FROM CTS2.PROJ_MAN END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"Coun should be 0; its value is ", coun if ( coun NOT = 0 ) then MOVE 0 TO flag END-IF DISPLAY" "
*Verify that we are not still CTS1 or super-user DISPLAY"SELECT COUNT(*) INTO :coun FROM CTS1.STAFF;" EXECSQLSELECTCOUNT(*) INTO :coun FROM CTS1.STAFF END-EXEC MOVE SQLCODE TO SQL-COD DISPLAY"SQLCODE should be < 0; its value is ", SQL-COD if (SQLCODE NOT < 0) then MOVE 0 TO flag END-IF DISPLAY"SQLSTATE should be 42000; its value is ", SQLSTATE PERFORM NOSUBCLASS THRU EXIT-NOSUBCLASS if (NORMSQ NOT = "42000") then MOVE 0 TO flag END-IF if (NORMSQ = "42000"AND NORMSQ NOT = SQLSTATE) then DISPLAY"Valid implementation-defined SQLSTATE accepted." END-IF DISPLAY" "
DISPLAY"ROLLBACK WORK;" EXECSQL ROLLBACK WORK END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
DISPLAY"SET SESSION AUTHORIZATION 'ILLEGALUSER';" EXECSQLSET SESSION AUTHORIZATION 'ILLEGALUSER'END-EXEC MOVE SQLCODE TO SQL-COD *Check that an exception condition of invalid *authorization specification is raised indicated by *the value returned in SQLSTATE which should be '28000'. DISPLAY"SQLCODE should be < 0; its value is ", SQL-COD DISPLAY"SQLSTATE should be 28000; its value is ", SQLSTATE PERFORM NOSUBCLASS THRU EXIT-NOSUBCLASS if (SQLCODE NOT < 0 OR NORMSQ NOT = "28000") then MOVE 0 TO flag END-IF if (NORMSQ = "28000"AND NORMSQ NOT = SQLSTATE) then DISPLAY"Valid implementation-defined SQLSTATE accepted." END-IF DISPLAY" "
*Change session auth-id to PUBLIC
DISPLAY"SET SESSION AUTHORIZATION 'PUBLIC';" EXECSQLSET SESSION AUTHORIZATION 'PUBLIC'END-EXEC MOVE SQLCODE TO SQL-COD *Check that an exception condition of invalid *authorization specification is raised indicated by *the value returned in SQLSTATE which should be '28000' DISPLAY"SQLCODE should be < 0; its value is ", SQL-COD DISPLAY"SQLSTATE should be 28000; its value is ", SQLSTATE PERFORM NOSUBCLASS THRU EXIT-NOSUBCLASS if (SQLCODE NOT < 0 OR NORMSQ NOT = "28000") then MOVE 0 TO flag END-IF if (NORMSQ = "28000"AND NORMSQ NOT = SQLSTATE) then DISPLAY"Valid implementation-defined SQLSTATE accepted." END-IF DISPLAY" "
*change to xuser i.e. CTS1 auth-id DISPLAY"xuser = '", xuser, "'" DISPLAY"SET SESSION AUTHORIZATION :xuser;" EXECSQLSET SESSION AUTHORIZATION :xuser END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*check access to STAFF table MOVE 99 TO coun DISPLAY"SELECT COUNT(*) INTO :coun FROM CTS1.STAFF;" EXECSQLSELECTCOUNT(*) INTO :coun FROM CTS1.STAFF END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY"coun should be 5; coun is ", coun if ( coun NOT = 5 ) then MOVE 0 TO flag END-IF DISPLAY" "
DISPLAY"ROLLBACK WORK;" EXECSQL ROLLBACK WORK END-EXEC MOVE SQLCODE TO SQL-COD PERFORM CHCKOK DISPLAY" "
*now record results
if ( flag = 1 ) then DISPLAY" xts718.pco *** pass *** " EXECSQLINSERTINTO CTS1.TESTREPORT
VALUES('7018','pass','PCO') END-EXEC MOVE SQLCODE TO SQL-COD else DISPLAY" xts718.pco *** fail *** " EXECSQLINSERTINTO CTS1.TESTREPORT
VALUES('7018','fail','PCO') END-EXEC MOVE SQLCODE TO SQL-COD COMPUTE errcnt = errcnt + 1 END-IF
DISPLAY"========================================"
EXECSQL COMMIT WORK END-EXEC MOVE SQLCODE TO SQL-COD
******************** END TEST7018 ********************
**** 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.21 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.