* Standard COBOL (file "MPB003.SCO") calling SQL * procedures in file "MPB003.MCO". * STANDARD COBOL (file "MPB003.SCO")
**************************************************************** * * COMMENT SECTION * * DATE 1988/12/07 STANDARD 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. * * MPB003.SCO * WRITTEN BY: J Sullivan * * THIS PROGRAM IS PART A OF A TWO-PART PROGRAM(A & B) THAT * TESTS THE CONCURRENCY OF SQL * * REFERENCES * AMERICAN NATIONAL STANDARD database language - SQL * X3.135-1989 * * SECTION 4.16 Transactions * Paragraph Two ****************************************************************
DISPLAY" *** This program is part B of a two-part
- " " DISPLAY" *** program (A & B) that tests for the
- " concurrency " DISPLAY" *** of SQL. Program A inserts 1000 rows into " DISPLAY" *** a table and waits for Program B.
- " "
* -----Synchronization-----
.
P100. *pause a little * EXEC SQL DELETE FROM MP3_MM2; CALL"SUB3"USINGSQLCODE MOVESQLCODETO SQL-COD MOVE1TO i
.
P101. * EXEC SQL INSERT INTO MP3_MM2 VALUES (:i); CALL"SUB4"USINGSQLCODE i MOVESQLCODETO SQL-COD COMPUTE i = i + 1 if (i < pauze) then GOTO P101 END-IF *end of pause
*are we in sync?
MOVE0TO dollar * EXEC SQL SELECT DOLLARS * INTO :dollar * FROM MP3_NEXTKEY WHERE KEYNUM = 999; CALL"SUB5"USINGSQLCODE dollar MOVESQLCODETO SQL-COD
if (dollar = 500) then DISPLAY"This is Program B. " DISPLAY"Program A has initialized the table. " else DISPLAY"Waiting for program MPA003 to start " GOTO P100 END-IF
*YES, we are in sync! DISPLAY"MPB003: account 500 has $500 and account 999 has
- " $500"
MOVE0TO doldif MOVE0TO concur MOVE500TO olddol MOVE0TO i
* EXEC SQL UPDATE MP3_NEXTKEY * SET DOLLARS = DOLLARS + 10 WHERE KEYNUM = 999; CALL"SUB7"USINGSQLCODE MOVESQLCODETO SQL-COD if (SQLCODENOT = 0) then MOVE1TO iserr GOTO P901 END-IF
* EXEC SQL UPDATE MP3_NEXTKEY * SET DOLLARS = DOLLARS - 10 WHERE KEYNUM = 500; CALL"SUB8"USINGSQLCODE MOVESQLCODETO SQL-COD if (SQLCODENOT = 0) then MOVE1TO iserr GOTO P901 END-IF
* EXEC SQL SELECT DOLLARS INTO :dol500 * FROM MP3_NEXTKEY WHERE KEYNUM = 500; CALL"SUB9"USINGSQLCODE dol500 MOVESQLCODETO SQL-COD if (SQLCODENOT = 0) then MOVE1TO iserr GOTO P901 END-IF
* EXEC SQL SELECT DOLLARS INTO :dol999 * FROM MP3_NEXTKEY WHERE KEYNUM = 999; CALL"SUB10"USINGSQLCODE dol999 MOVESQLCODETO SQL-COD if (SQLCODENOT = 0) then MOVE1TO iserr GOTO P901 END-IF
.
P901. if (iserr = 0) then * EXEC SQL COMMIT WORK; CALL"SUB11"USINGSQLCODE MOVESQLCODETO SQL-COD DISPLAY"MPB003:account 500 has $", dol500 " and account
- " 999 has $", dol999 COMPUTE doldif = olddol - dol500 MOVE dol500 TO olddol END-IF if (iserr = 1ORSQLCODENOT = 0) then MOVE1TO iserr * EXEC SQL ROLLBACK WORK; CALL"SUB12"USINGSQLCODE MOVESQLCODETO SQL-COD COMPUTE tranct = tranct + 1 DISPLAY"ROLLBACK due to nonzero SQLCODE (Deadlock?)" END-IF
if (iserr = 0AND doldif > 10) then COMPUTE concur = concur + 1 DISPLAY" *** B interleaved #", concur END-IF
*end record lock
COMPUTE i = i + 1 if (i < tranct) then GOTO P120 END-IF
* -----Evaluation-----
.
P130. MOVE0TO dollar * EXEC SQL SELECT SUM(DOLLARS) INTO :dollar * FROM MP3_NEXTKEY * WHERE KEYNUM = 1 OR KEYNUM = 500 OR KEYNUM = 999 * ; CALL"SUB13"USINGSQLCODE dollar MOVESQLCODETO SQL-COD if (SQLCODENOT = 0) then DISPLAY"Cannot select from MP3_NEXTKEY" GOTO P130 END-IF DISPLAY"MPB003: sum of accounts 1, 500, and 999 = $",
dollar DISPLAY" sum should be $1500 after transferring money"
if (concur < 3AND dollar = 1500) then DISPLAY" Insufficient interleaving to demonstrate
- " concurrency!" DISPLAY" Using TEd, decrease variable pauze to start" DISPLAY" MPB003 sooner or increase value of variable
- " tranct" DISPLAY" in both MPA003 and MPB003 to lengthen test." DISPLAY" Then RERUN!" GOTO P140 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 und die Messung sind noch experimentell.