ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzajp_5.4.0.1/rzajpdiaglog.htm

84 lines
4.1 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Logging items from the SQL diagnostics area" />
<meta name="abstract" content="In this example, an application needs to log all errors for security reasons. The log could be used to monitor the health of a system or to monitor for inappropriate use of a database." />
<meta name="description" content="In this example, an application needs to log all errors for security reasons. The log could be used to monitor the health of a system or to monitor for inappropriate use of a database." />
<meta name="DC.Relation" scheme="URI" content="rzajpdiagnostics.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstgetdiag.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzajpdiaglog" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Logging items from the SQL diagnostics area</title>
</head>
<body id="rzajpdiaglog"><a name="rzajpdiaglog"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Logging items from the SQL diagnostics area</h1>
<div><p>In this example, an application needs to log all errors for security
reasons. The log could be used to monitor the health of a system or to monitor
for inappropriate use of a database.</p>
<div class="section"><p>For each SQL error that occurs, an entry is placed in the log.
The entry includes when the error occurred, what user was using the application,
what type of SQL statement was run, the returned SQLSTATE value, and the message
number and corresponding complete message text.</p>
</div>
<div class="section"><pre>char stmt_command[256];
long int error_count;
long int condition_number;
char auth_id[256];
char error_state[6];
char msgid[128];
char msgtext[1024];
EXEC SQL WHENEVER SQLERROR GOTO error;
(application code)
error:
EXEC SQL GET DIAGNOSTICS :stmt_command = COMMAND_FUNCTION,
:error_count = NUMBER;
for (condition_number=1;i&lt;=error_count;++condition_number)
{
EXEC SQL GET DIAGNOSTICS CONDITION :condition_number
:auth_id = DB2_AUTHORIZATION_ID,
:error_state = RETURNED_SQLSTATE,
:msgid = DB2_MESSAGE_ID,
:msgtext = DB2_MESSAGE_TEXT;
EXEC SQL INSERT INTO error_log VALUES(CURRENT_TIMESTAMP,
:stmt_command,
:condition_number,
:auth_id,
:error_state,
:msgid,
:msgtext);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpdiagnostics.htm" title="The SQL diagnostics area is used to keep the returned information for an SQL statement that has been run in a program. It contains all the information that is available to you as an application programmer through the SQLCA.">Use the SQL diagnostics area</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../db2/rbafzmstgetdiag.htm">GET DIAGNOSTICS</a></div>
</div>
</div>
</body>
</html>