Editing
PrimesSQL Design
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
# pgcobol Wiki > **pgcobol** β Three-tier GnuCOBOL / PostgreSQL prime-numbers application Β· v1.0 Β· reverse-engineered 2026-03-17 --- ## What is pgcobol? pgcobol is a batch COBOL application that demonstrates a clean three-tier architecture on Linux. It generates prime numbers by trial division, persists each prime in a PostgreSQL database, and produces a paginated printed report of all stored primes. There is no interactive interface; everything is driven from a single command-line argument. ``` primesmain generate β primesgen β primes (DAL) β PostgreSQL primesmain report β primesgen β primes (DAL) β primesui β primes.prt ``` --- ## Quick Start | Goal | Command | |---|---| | Generate primes | `./primesmain generate` | | Produce report | `./primesmain report` | | Reset database | `psql -f reset-primes.sql` | **Prerequisites:** GnuCOBOL 4.0, GixSQL pre-processor, PostgreSQL 11+, schema initialised with `primes_schema.sql`, prime 2 manually inserted. > β **Known issue:** The generate loop is commented out in `primesmain.cbl` line 51. Generation mode does not execute the sieve in the current source. See [Technical Specification βΊ Known Issues](design/technical-spec.md#7-known-technical-issues). --- ## Source Files | File | Type | Role | |---|---|---| | `primesmain.cbl` | COBOL | Entry point and session orchestrator | | `primesgen.cbl` | COBOL | Business logic β sieve algorithm and report loop | | `primes.cbl` | COBOL + GixSQL | Data access layer β all SQL | | `primesui.cbl` | COBOL | Presentation β print file and console | | `primes-session.cpy` | Copybook | Session-tier interface contract | | `primes-dal.cpy` | Copybook | DAL-tier interface contract | | `primes-ui.cpy` | Copybook | UI-tier interface contract (all programs) | | `primes-table.cpy` | Copybook | SQL host variable β character format | | `primes_table.cpy` | Copybook | SQL host variable β COMP-3 packed (alternate) | | `SQLCA.cpy` | Copybook | GixSQL SQL Communications Area | | `primes_schema.sql` | DDL | Schema, sequence, table definition | | `reset-primes.sql` | DDL | Drop and recreate for a clean test run | --- ## Design-Level Documentation These pages describe **what** the system does and how it is structured. | Page | Contents | |---|---| | [Business Requirements](design/business-requirements.md) | Functional requirements (FR-01βFR-06), non-functional requirements, stakeholders, constraints | | [Technical Specification](design/technical-spec.md) | Architecture diagram, component inventory, full pseudocode for all four programs, database connection parameters, SQL statement inventory, file I/O specification, known defects | | [Data Dictionary](design/data-dictionary.md) | Every field in every copybook and working-storage section β name, level, picture, usage, semantic description, all 88-level conditions; database schema objects | | [Flow Diagrams](design/flow-diagrams.md) | Eight Mermaid diagrams: top-level flow, primesgen dispatch, generate sieve loop, report loop, DAL dispatch, UI dispatch, generate sequence diagram, report sequence diagram | --- ## Program-Level Documentation These pages describe **how** each program works internally. > π§ *Program-level pages are listed here for completeness. Contents are defined in the program-level specification set.* | Page | Contents | |---|---| | Program Logic | Step-by-step paragraph logic for all four programs | | Business Rules | Primality algorithm rules, validation, formatting rules, error-handling conventions | | I/O Behaviour | File handling, console output, database call patterns | | Control Flow | PERFORM/CALL/EVALUATE trees, loop structure, paragraph maps | --- ## Architecture at a Glance ``` βββββββββββββββββββββββββββββββββββββββββββββ β primesmain β Orchestrator β Reads arg β dispatches β shuts down β ββββββββββββββββββββ¬βββββββββββββββββββββββββ β CALL using primes-session ββββββββββββΌβββββββββββ β primesgen β Business Logic β sieve / report β βββββ¬ββββββββββββββββββ β primes-dal β primes-ui ββββββββββΌβββββββ ββββββββββΌβββββββββββ β primes β β primesui β Presentation β (DAL / SQL) β β primes.prt β βββββββββ¬ββββββββ ββββββββββββββββββββββ β βββββββββΌββββββββ β PostgreSQL β β primes.primesβ βββββββββββββββββ ``` All inter-program communication uses **method-dispatch**: the caller moves a verb string into a control-block field, calls the subprogram, and reads a numeric result code on return. The control blocks are defined in copybooks (`primes-session.cpy`, `primes-dal.cpy`, `primes-ui.cpy`) which serve as the published interface contracts between tiers. --- ## Result Code Convention Used consistently across all three control blocks: | Code | Meaning | |---|---| | `0` | Success | | `1` | Error / failure | | `9` | End of data (session tier) | | `99` | End of data (DAL tier) | --- ## Open Issues | ID | Severity | Description | See | |---|---|---|---| | T1 | High | Generate loop commented out β generation does not run | [Tech Spec Β§7](design/technical-spec.md#7-known-technical-issues) | | T2 | High | Connection alias mismatch (`primes` vs `primesdb`) | [Tech Spec Β§7](design/technical-spec.md#7-known-technical-issues) | | T3 | Medium | COMMIT on INSERT is commented out | [Tech Spec Β§7](design/technical-spec.md#7-known-technical-issues) | | T4 | Medium | Prime 2 not seeded before sieve starts | [Business Requirements Β§5](design/business-requirements.md#5-assumptions-and-constraints) | | T5 | Low | Database credentials hard-coded in source | [Data Dictionary Β§2.3](design/data-dictionary.md#23-primes-dal) | | T6 | Low | Two near-duplicate host-variable copybooks | [Data Dictionary Β§1.4](design/data-dictionary.md#14-primes-table--sql-host-variable-character) | --- *Last updated: 2026-03-17 Β· Source: reverse-engineered from pgcobol v1.0 artifacts*
Summary:
Please note that all contributions to Webhuis wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see
Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Voorpagina
Cobol and PostgreSQL
PostgreSQL
CFEngine
Proxmox
Webhuis Kennisbank
Basale infra
Webhuis bouwstenen
Webhuis configuratie
Webhuis Infra
Webhuis Support
Webhuis Raspberry
Opzet Applicaties
Business Applicaties
Community portal
Current events
Recent changes
Random page
Help
sitesupport
Tools
What links here
Related changes
Special pages
Page information