141 lines
8.7 KiB
HTML
141 lines
8.7 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="SQLExecute - Execute a statement" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzadphdapi.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rzadpfnexec" />
|
||
|
<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>SQLExecute</title>
|
||
|
</head>
|
||
|
<body id="rzadpfnexec"><a name="rzadpfnexec"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">SQLExecute - Execute a statement</h1>
|
||
|
<div><div class="section"></div>
|
||
|
<div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLExecute()</samp> executes
|
||
|
a statement, that is successfully prepared using <samp class="codeph">SQLPrepare()</samp>,
|
||
|
once or multiple times. The statement is processed using the current values
|
||
|
of any application variables that were bound to parameter markers by <samp class="codeph">SQLBindParam()</samp>.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLExecute (SQLHSTMT hstmt);</pre>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Function arguments</h4>
|
||
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. SQLExecute arguments</caption><thead align="left"><tr><th align="left" valign="bottom" width="20%" id="d0e54">Data type</th>
|
||
|
<th align="left" valign="bottom" width="20%" id="d0e56">Argument</th>
|
||
|
<th align="left" valign="bottom" width="20%" id="d0e58">Use</th>
|
||
|
<th align="left" valign="bottom" width="40%" id="d0e60">Description</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="20%" headers="d0e54 ">SQLHSTMT</td>
|
||
|
<td align="left" valign="top" width="20%" headers="d0e56 "><em>hstmt</em></td>
|
||
|
<td align="left" valign="top" width="20%" headers="d0e58 ">Input</td>
|
||
|
<td align="left" valign="top" width="40%" headers="d0e60 ">Statement handle. There must not be an open
|
||
|
cursor associated with hstmt, see <a href="rzadpfnfstmt.htm#rzadpfnfstmt">SQLFreeStmt - Free (or reset) a statement handle</a>
|
||
|
for more information.</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Usage</h4><p>The SQL statement string might contain parameter
|
||
|
markers. A parameter marker is represented by a "?" character, and indicates
|
||
|
a position in the statement where the value of an application variable is
|
||
|
to be substituted, when <samp class="codeph">SQLExecute()</samp> is called. <samp class="codeph">SQLBindParam()</samp> is
|
||
|
used to bind (or associate) an application variable to each parameter marker,
|
||
|
and to indicate if any data conversion should be performed at the time the
|
||
|
data is transferred. All parameters must be bound before calling <samp class="codeph">SQLExecute()</samp>.</p>
|
||
|
<p>As
|
||
|
soon as the application has processed the results from the <samp class="codeph">SQLExecute()</samp> call,
|
||
|
it can process the statement again with new (or the same) values in the application
|
||
|
variables.</p>
|
||
|
<p>A statement processed by <samp class="codeph">SQLExecDirect()</samp> cannot
|
||
|
be reprocessed by calling <samp class="codeph">SQLExecute()</samp>; <samp class="codeph">SQLPrepare()</samp> must
|
||
|
be called first.</p>
|
||
|
<p>If the prepared SQL statement is a SELECT, <samp class="codeph">SQLExecute()</samp> generates
|
||
|
a cursor name, and opens the cursor. If the application has used <samp class="codeph">SQLSetCursorName()</samp> to
|
||
|
associate a cursor name with the statement handle, DB2<sup>®</sup> UDB CLI associates the application generated
|
||
|
cursor name with the internally generated cursor name.</p>
|
||
|
<p>To process a
|
||
|
SELECT statement more than once, the application must close the cursor by
|
||
|
calling call <samp class="codeph">SQLFreeStmt()</samp> with the SQL_CLOSE option. There
|
||
|
must not be an open cursor on the statement handle when calling <samp class="codeph">SQLExecute()</samp>.</p>
|
||
|
<p>To
|
||
|
retrieve a row from the result set generated by a SELECT statement, call <samp class="codeph">SQLFetch()</samp> after <samp class="codeph">SQLExecute()</samp> returns
|
||
|
successfully.</p>
|
||
|
<p>If the SQL statement is a positioned DELETE or a positioned
|
||
|
UPDATE, the cursor referenced by the statement must be positioned on a row
|
||
|
at the time <samp class="codeph">SQLExecute()</samp> is called, and must be defined on
|
||
|
a separate statement handle under the same connection handle.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Return codes</h4><ul><li>SQL_SUCCESS</li>
|
||
|
<li>SQL_SUCCESS_WITH_INFO</li>
|
||
|
<li>SQL_ERROR</li>
|
||
|
<li>SQL_INVALID_HANDLE</li>
|
||
|
<li>SQL_NO_DATA_FOUND</li>
|
||
|
</ul>
|
||
|
<p>SQL_NO_DATA_FOUND is returned if the SQL statement is a Searched UPDATE
|
||
|
or Searched DELETE and no rows satisfy the search condition.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Diagnostics</h4><div class="p">The SQLSTATEs for <samp class="codeph">SQLExecute()</samp> include
|
||
|
all those for <samp class="codeph">SQLExecDirect()</samp> (see <a href="rzadpfnexecd.htm#rzadpfnexecd__tbexecd">Table 2</a>)
|
||
|
except for <strong>HY</strong>009, and with the addition of the SQLSTATEs in the following
|
||
|
table.
|
||
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. SQLExecute
|
||
|
SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="top" width="25%" id="d0e183">SQLSTATE</th>
|
||
|
<th align="left" valign="top" width="25%" id="d0e185">Description</th>
|
||
|
<th align="left" valign="top" width="50%" id="d0e187">Explanation</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e183 "><strong>HY</strong>010</td>
|
||
|
<td align="left" valign="top" width="25%" headers="d0e185 ">Function sequence error</td>
|
||
|
<td align="left" valign="top" width="50%" headers="d0e187 ">The specified <em>hstmt</em> is not in prepared
|
||
|
state. <samp class="codeph">SQLExecute()</samp> is called without first calling <samp class="codeph">SQLPrepare</samp>.</td>
|
||
|
</tr>
|
||
|
<tr><td valign="top" width="25%" headers="d0e183 "><strong>HY</strong>021</td>
|
||
|
<td valign="top" width="25%" headers="d0e185 ">Internal descriptor that is not valid </td>
|
||
|
<td valign="top" width="50%" headers="d0e187 ">The internal descriptor cannot be addressed or allocated,
|
||
|
or it contains a value that is not valid.</td>
|
||
|
</tr>
|
||
|
<tr><td colspan="3" align="left" valign="top" headers="d0e183 d0e185 d0e187 "> <div class="note"><span class="notetitle">Note:</span> There
|
||
|
are many other SQLSTATE values that can be generated by the Database Management
|
||
|
System (DBMS), on processing of the statement.</div>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Example</h4></div>
|
||
|
<div class="example" id="rzadpfnexec__xmexec"><a name="rzadpfnexec__xmexec"><!-- --></a><p>Refer to the <samp class="codeph">SQLPrepare()</samp> <a href="rzadpfnprep.htm#rzadpfnprep__xmprep">rzadpfnprep.htm#rzadpfnprep__xmprep</a></p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">References</h4><ul><li><a href="rzadpfnexecd.htm#rzadpfnexecd">SQLExecDirect - Execute a statement directly</a></li>
|
||
|
<li><a href="rzadpfnbindc.htm#rzadpfnbindc">SQLBindCol - Bind a column to an application variable</a></li>
|
||
|
<li><a href="rzadpfnprep.htm#rzadpfnprep">SQLPrepare - Prepare a statement</a></li>
|
||
|
<li><a href="rzadpfnfetch.htm#rzadpfnfetch">SQLFetch - Fetch next row</a></li>
|
||
|
<li><a href="rzadpfnspara.htm#rzadpfnspara">SQLSetParam - Set parameter</a></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadphdapi.htm" title="This topic provides a description of each CLI function.">DB2 UDB CLI functions</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|