If you want to parse the SQL statement, do NOT rely on your own parsing capabilities - there is too much, that you will get wrong.
But there is the SQL function PARSE_STATEMENT - this will do most of the heavy lifting.
https://www.ibm.com/docs/en/i/7.4.0?topic=services-parse-statement-table-function
It should give you enough information - but of course it will add some overhead to SQL execution times, but you can limit this easily to "remote SQL sessions" only, and don't parse statements, that are issued from programs.
HTH
Daniel
------------------------------
Daniel Gross
#IBMChampion
Senior Core Developer, Geis Group
Pegnitz, Germany
https://blog.qpgmr.de/------------------------------
Original Message:
Sent: 08/29/26 01:37 PM
From: Cristian Ballestero
Subject: SQL limits in 7.4
Hi,
Regarding your question about whether it is possible to validate SQL statements sent by a user in IBM i (for example, to restrict access so only SELECT statements are allowed), yes, it is completely feasible.
This is achieved by intercepting external database connections (such as ODBC, JDBC, or .NET) using an exit program. Here is a breakdown of how it works technically, along with the official documentation and community code examples to help you get started:
Technical Overview
- The Exit Point: You need to register your custom program under the native system exit point
QIBM_QZDA_SQL2 using the ZDAQ0200 parameter format. - The Code Logic: The operating system passes a structured data structure to your program (usually written in RPGLE or C). This structure contains the user profile, the request type, and the exact raw SQL text.
- The Verdict: Your program inspects the text string (e.g., verifying it starts with
SELECT and does not contain unauthorized keywords like DELETE, UPDATE, or DROP). If authorized, it returns a parameter value of X'F1' (allow); if unauthorized, it returns X'F0' (reject), which immediately kills the execution and returns a database error to the user.
Documentation and Code Examples:
Important Considerations:
While this approach is excellent for auditing or perimeter blocking, it does introduce a minor performance overhead because the program triggers for every single SQL statement sent to the server. Furthermore, parsing raw text can sometimes be bypassed using SQL evasion tricks (such as embedding inline comments like UPD/*comment*/ATE).
Because of this, IBM always recommends pairing or prioritizing native object-level security. If a user is restricted to read-only (*READ) authority at the database level, the Db2 for i engine will automatically block any write attempts natively, which is inherently more secure.
------------------------------
Cristian Ballestero
Software Arquitect
BAC
------------------------------