Skip to content

Db2 support: COBTUPDT translated with no model and proven on real IBM Db2 - #4098

Merged
squid-protocol merged 4 commits into
mainfrom
feat/db2
Oct 2, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
feat/db2

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

What

Db2 support, proven on real Db2. The first Db2 program, CardDemo's COBTUPDT (batch), is translated with no model and proven equal against IBM Db2.

output COBOL Java (det port)
RETURN-CODE 4 4
CARDDEMO.TRANSACTION_TYPE 9 rows 9/9 equal, trailing blanks included
SYSOUT 32 lines 32/32 equal, including the SQLCODE -803 message

The case covers a new row, a duplicate key (-803), an update and a delete of no row (+100), a 50-character description, inner blanks, a comment and an invalid type. One example of what real Db2 settles: a PIC X(50) host variable keeps its trailing blanks in a VARCHAR(50) column.

How

The oracle (COBOL side).

  • No Db2 precompiler for GnuCOBOL, so the harness has one (tests/tools/equivalence_sql.py). It rewrites each EXEC SQL into CALL 'GGSQL' and writes a statement table.
  • tests/equivalence/db2/ggsql.c runs each statement on Db2 through IBM's CLI driver.
  • Host variables are bound as the Db2 precompiler declares them for COBOL: CHAR, VARCHAR (49-level pairs), DECIMAL, binary.
  • The SQLCA comes from Db2 itself.
  • Forms it doesn't model are refused by name: WHENEVER, positioned UPDATE/DELETE, dynamic SQL, host-variable arrays, a program that shows SQLERRMC.
  • One database for both sides (tests/tools/equivalence_db2.py): IBM Db2 Community Edition in a container. Tables are created from the corpus DDL, reset to the case's seed before every run on both sides, and dumped row by row.

The translator (Java side).

  • det/sql.py maps each statement to its generated repository method by source line. The generator already writes one method per statement, with the SQL as written.
  • cobolrt/sql/DetSql converts host variables by the same Db2 rules, maps outcomes to the SQLCA (+100, -811, Db2's own SQLCODE), and runs cursors at OPEN.

Also fixed

A statement's line number is its source line again. Two things were wrong:

  • the EXEC placeholder collapsed a multi-line block into one line;
  • the PROCEDURE DIVISION base was two lines early.

Until now this only affected hole messages. All 31 proven ports still translate byte-for-byte as before, and a regression test covers it.

Declared, not measured

  • Db2 for Linux, not z/OS, runs the SQL. It uses the same SQLCODEs for these statements.
  • EXEC SQL leaves RETURN-CODE unchanged. Whether IBM's precompiled DSNHLI call resets it is unknown.
  • A run that ends normally commits.
  • The Java side commits each statement as it runs, so ROLLBACK is a hole for now.

Tests

  • test_equivalence_sql.py: 10 tests (precompiler).
  • A line-number regression test.
  • Full suite: 13,315 passed. Ruff audit, mypy, the dead-key audit and the 3.9 check are all clean.
  • The Db2 proof itself needs Docker and the Db2 container, so it runs locally, not in CI.

Next: the two CardDemo CICS Db2 programs (COTRTLIC cursor list, COTRTUPC update), then CBSA and GenApp.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ

squid-protocol and others added 2 commits October 2, 2026 06:31
…, both sides on one database

The COBOL side: tests/tools/equivalence_sql.py rewrites each EXEC SQL into CALL 'GGSQL' and a statement table;
tests/equivalence/db2/ggsql.c runs each statement on IBM Db2 (Community Edition, in a container) through IBM's CLI
driver, host variables bound as the Db2 precompiler declares them for COBOL (CHAR, VARCHAR, DECIMAL, binary), the
SQLCA from Db2 itself; forms not modelled are refused by name. tests/tools/equivalence_db2.py: the container, the
case's DDL, a reset to the seed before every run on both sides, and each compared table dumped row by row (trailing
blanks included). The Java side's Db2 repositories reach the same database (IBM's JDBC driver, a test configuration).
A case declares "db2" {ddl, seed, compare}; carddemo-cobtupdt is the first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
…s method; COBTUPDT proven on real Db2

det/sql.py finds each statement's generated method by its source line; cobolrt/sql/DetSql converts host variables
as Db2's precompiler declares them and turns outcomes into the SQLCA (+100, -811, Db2's SQLCODE); cursors run
their query at OPEN. COBTUPDT: RETURN-CODE 4 = 4, CARDDEMO.TRANSACTION_TYPE 9/9 rows, SYSOUT 32/32 lines.

Also: a statement's line is its source line again -- the EXEC placeholder kept the block's line count only for its
own line, and the PROCEDURE DIVISION base was two lines early (hole messages only, until now); all 31 proven ports
translate byte for byte as before. DCLGEN members (.dcl) are found as copybooks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
Comment thread tests/tools/equivalence.py Fixed
Comment thread tests/tools/equivalence.py Fixed
Comment thread tests/tools/equivalence_sql.py Fixed
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

squid-protocol and others added 2 commits October 2, 2026 06:40
- ggsql.c takes the SQLCA Db2 returns (SQLGetSQLCA: the code, the state, SQLERRMC's message tokens, the warnings,
  SQLERRD); DetSql copies the same from IBM's JDBC driver (DB2Diagnosable.getSqlca, by reflection). A program that
  shows SQLERRMC is no longer refused.
- The connection reaches the COBOL step's container as its environment, not written into run.sh.
- det: the generator catches the SQL translator's error through its instance (no det.sql import: no cycle).
- A port's cursors are closed at each task's / step's start.
COBTUPDT re-proves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
…epository method

GalaxyIR.db2_tables marks a statement found in a member a program COPYs or EXEC SQL INCLUDEs with included_by (the
including programs, transitively; presence-keyed); the Db2 forge gives it a method per including program, documented
at the member's own file and line. CardDemo's COTRTLIC runs CSDB2RPY's priming query (SELECT 1 FROM
SYSIBM.SYSDUMMY1) on every entry: it had no method, so its det port could not run at all -- it now translates 631 of
632 statements (the one left is DSNTIAC's dynamic CALL on the Db2-error path). Golden masters, the ground-truth ledger
and the full suite are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants