|
At 10:05 06/09/2001, Phil wrote: > * Check after each SQL statement to make sure > * it executed as expected > C if SQLCOD <> SQL_OK > C exsr SqlErrorHandler > C endif >Pete, >I would like to know more about your SqlErrorHandler routine (if you don't >mind). Right now I watch for 100, and not 0 or 100, to identify errors. If >the sqlcod isn't 0 or 100, I assume something unrecoverable happened. >Phil It's nothing fancy. Usually, I just need to notify the client so that it can display an error message. The RtnSqlMsg subroutine retrieves the message text from QSQLMSG and places it in the return data space, then executes RtnAppMsg, which handles any cleanup, sets a failure result code and terminates the module. RtnAppMsg can also be called directly to return custom application error messages. I'll call RtnSqlMsg whenever an unexpected situation occurs. I usually handle expected codes inline by setting SQLCOD to zero if an anticipated error is received, and treat any unanticipated SQL Code as a failure, figuring that if I didn't know it might happen, I need to learn about it. That way I find out about constraint violations, duplicate key errors, data type mismatches and such during testing if nothing else, the goal being to prevent the error subroutine from ever executing. I use a copybook with named constants containing all of the values I might want to monitor for (it's on my web site). * ----------------------------------------------------------------------- * Return an application error message * ----------------------------------------------------------------------- CSR RtnAppMsg begsr C eval Replycode = RP_FAILURE *Close all potentially open cursors C/EXEC SQL CLOSE SYSTABLES C/END-EXEC C return CSR endsr * ----------------------------------------------------------------------- * Return an SQL error message * ----------------------------------------------------------------------- CSR RtnSqlMsg begsr C eval VM_MsgID = 'SQL' C + %Subst(%EditW(SQLCOD:'0 '):6:4) C eval VM_MsgFile = 'QSQLMSG' C eval VM_MsgFLib = 'QSYS' C eval @VM_ReplaceDta = %Addr(SQLERM) C eval VM_RplDtaLen = %Size(SQLERM) C eval VM_RplSubstVal = '*YES' C call 'QMHRTVM' PL_QMHRTVM C eval DataSpace = %Subst(V1_RtnData:1:V1_MsgLen) C exsr RtnAppMsg CSR endsr Pete Hall pbhall@execpc.com http://www.execpc.com/~pbhall/ +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.