Editing
IO behaviour
(section)
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!
== 3. Database I/O (primes.cbl via GixSQL) == <span id="connection-management"></span> === 3.1 Connection Management === {| !width="33%"| Operation !width="33%"| SQL !width="33%"| Paragraph |- | Connect | <code>CONNECT TO :DATASRC AS primes USER :DBUSR USING :DBPWD</code> | s00-connect |- | Disconnect | <code>CONNECT RESET primes</code> | s99-disconnect |} Connection string: <code>pgsql://localhost:5432/primes&default_schema=primes</code><br /> Connection alias: <code>primes</code> (used in all <code>EXEC SQL AT primes</code> statements) <span id="cursor-lifecycle-report-path-only"></span> === 3.2 Cursor Lifecycle (report path only) === {| !width="33%"| Operation !width="33%"| SQL !width="33%"| Paragraph |- | Declare | <code>DECLARE primescursor CURSOR FOR SELECT * FROM primes</code> | compile-time |- | Begin transaction | <code>START TRANSACTION</code> | s01-cursor |- | Open | <code>OPEN primescursor</code> | s01-cursor |- | Fetch one row | <code>FETCH primescursor INTO :primes-row</code> | s02-fetch |- | (Close) | not explicitly closed β connection reset closes it | β |} Each <code>FETCH</code> populates <code>primes-row</code> (r-ident, r-prime), which is then copied to <code>primes-sequence</code> and <code>prime-number</code> in <code>primes-dal</code> for the caller. End-of-cursor is signalled by <code>SQLCODE β 0</code>; <code>dal-result</code> is set to 1, which primesgen maps to <code>session-method-eof</code> implicitly (by checking <code>session-method-eof</code> condition, value 9 β note: there is a mapping gap; dal-result=1 does not equal session-result=9; the report loop relies on <code>session-method-eof</code> which is never explicitly set in the current code β see defect D-RPT-01 below). <span id="dml-generate-path"></span> === 3.3 DML (generate path) === {| !width="33%"| Operation !width="33%"| SQL !width="33%"| Paragraph |- | Insert prime | <code>INSERT INTO primes (prime) VALUES (:prime)</code> | r83-write-prime |} * Host variable <code>:prime</code> maps to <code>prime-number</code> in <code>primes-dal.primes-data</code>. * No explicit COMMIT in the current code (statement is commented out). * PostgreSQL default auto-commit applies per statement unless inside the transaction opened by <code>s01-cursor</code>. <span id="queries-generate-path-divider-lookup"></span> === 3.4 Queries (generate path β divider lookup) === {| !width="33%"| Operation !width="33%"| SQL !width="33%"| Paragraph |- | Get next divider | <code>SELECT prime INTO :test-divider FROM primes WHERE ident = :new-ident</code> | r81-get-next-divider |} * <code>:new-ident</code> = <code>old-ident + 1</code> (computed inline before the SELECT). * <code>:test-divider</code> is in the local <code>primes</code> working-storage group in primesgen, not in <code>primes-dal</code>. <span id="error-handling-pattern"></span> === 3.5 Error Handling Pattern === Every SQL statement uses the same pattern: <pre>EXEC SQL ... END-EXEC IF SQLCODE = 0 THEN [success actions] ELSE [log error / set result code]</pre> No <code>WHENEVER</code> directives are used. ----- <span id="command-line-input"></span>
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