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

124 lines
7.3 KiB
HTML

<?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="Define the SQL communications area in C and C++ applications that use SQL" />
<meta name="abstract" content="A C or C++ program can be written to use the SQLCA to check return status for embedded SQL statements, or the program can use the SQL diagnostics area to check return status." />
<meta name="description" content="A C or C++ program can be written to use the SQLCA to check return status for embedded SQL statements, or the program can use the SQL diagnostics area to check return status." />
<meta name="DC.subject" content="application program, SQLCA (SQL communication area), C, C++, SQLCA (SQL communication area), C program, SQLCA, declaring, SQLCODE, declaring, SQLSTATE, declaring, C++ program, SQLCODE, SQLSTATE" />
<meta name="keywords" content="application program, SQLCA (SQL communication area), C, C++, SQLCA (SQL communication area), C program, SQLCA, declaring, SQLCODE, declaring, SQLSTATE, declaring, C++ program, SQLCODE, SQLSTATE" />
<meta name="DC.Relation" scheme="URI" content="rzajpc.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpdiagnostics.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstsqlcca.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="rzajpsqlcac" />
<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>Define the SQL communications area in C and C++ applications that use
SQL</title>
</head>
<body id="rzajpsqlcac"><a name="rzajpsqlcac"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Define the SQL communications area in C and C++ applications that use
SQL</h1>
<div><p>A C or C++ program can be written to use the SQLCA to check return
status for embedded SQL statements, or the program can use the SQL diagnostics
area to check return status.</p>
<div class="section"></div>
<div class="section"><p>When using the SQLCA, a C or C++ program that contains SQL statements
must include one or both of the following: </p>
<ul><li>An SQLCODE variable declared as long SQLCODE</li>
<li>An SQLSTATE variable declared as char SQLSTATE[6]</li>
</ul>
</div>
<div class="section"><p>Or, </p>
<ul><li>An SQLCA (which contains an SQLCODE and SQLSTATE variable).</li>
</ul>
<p>The SQLCODE and SQLSTATE values are set by the database manager after
each SQL statement is run. An application can check the SQLCODE or SQLSTATE
value to determine whether the last SQL statement was successful.</p>
</div>
<div class="section"><p><img src="./delta.gif" alt="Start of change" />You can code the SQLCA in a C or C++ program
directly or by using the SQL INCLUDE statement. When coding it directly, initialize
the SQLCA using the following statement: <img src="./deltaend.gif" alt="End of change" /></p>
<img src="./delta.gif" alt="Start of change" /><pre>struct sqlca sqlca = {0x0000000000000000};</pre><img src="./deltaend.gif" alt="End of change" />
<p>Using
the SQL INCLUDE statement requests the inclusion of a standard declaration: </p>
<pre> EXEC SQL <strong>INCLUDE SQLCA</strong> ;</pre>
</div>
<div class="section"><p><img src="./delta.gif" alt="Start of change" />A standard declaration includes a structure definition
and a data area that are named sqlca.<img src="./deltaend.gif" alt="End of change" /></p>
</div>
<div class="section"><p>The SQLCODE, SQLSTATE, and SQLCA variables must appear before
any executable statements. The scope of the declaration must include the scope
of all SQL statements in the program.</p>
</div>
<div class="section"><p id="rzajpsqlcac__css"><a name="rzajpsqlcac__css"><!-- --></a>The included C and C++ source statements for the SQLCA
are: </p>
<pre> #ifndef SQLCODE
struct sqlca {
unsigned char sqlcaid[8];
long sqlcabc;
long sqlcode;
short sqlerrml;
unsigned char sqlerrmc[70];
unsigned char sqlerrp[8];
long sqlerrd[6];
unsigned char sqlwarn[11];
unsigned char sqlstate[5];
};
#define SQLCODE sqlca.sqlcode
#define SQLWARN0 sqlca.sqlwarn[0]
#define SQLWARN1 sqlca.sqlwarn[1]
#define SQLWARN2 sqlca.sqlwarn[2]
#define SQLWARN3 sqlca.sqlwarn[3]
#define SQLWARN4 sqlca.sqlwarn[4]
#define SQLWARN5 sqlca.sqlwarn[5]
#define SQLWARN6 sqlca.sqlwarn[6]
#define SQLWARN7 sqlca.sqlwarn[7]
#define SQLWARN8 sqlca.sqlwarn[8]
#define SQLWARN9 sqlca.sqlwarn[9]
#define SQLWARNA sqlca.sqlwarn[10]
#define SQLSTATE sqlca.sqlstate
#endif
struct sqlca sqlca = {0x0000000000000000};</pre>
</div>
<div class="section"><div class="p">When a declare for SQLCODE is found in the program
and the precompiler provides the SQLCA, SQLCADE replaces SQLCODE. When a declare
for SQLSTATE is found in the program and the precompiler provides the SQLCA,
SQLSTOTE replaces SQLSTATE. <div class="note"><span class="notetitle">Note:</span> Many SQL error messages contain message
data that is of varying length. The lengths of these data fields are embedded
in the value of the SQLCA <samp class="codeph">sqlerrmc</samp> field. Because of these
lengths, printing the value of <samp class="codeph">sqlerrmc</samp> from a C or C++ program
might give unpredictable results.</div>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpc.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in a C or C++ program.">Code SQL statements in C and C++ applications</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><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/rbafzmstsqlcca.htm">SQL Communication Area</a></div>
<div><a href="../db2/rbafzmstgetdiag.htm">GET DIAGNOSTICS</a></div>
</div>
</div>
</body>
</html>