ibm-information-center/dist/eclipse/plugins/i5OS.ic.cli_5.4.0.1/rzadpfnexecd.htm

160 lines
9.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="SQLExecDirect - Execute a statement directly" />
<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="rzadpfnexecd" />
<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>SQLExecDirect</title>
</head>
<body id="rzadpfnexecd"><a name="rzadpfnexecd"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">SQLExecDirect - Execute a statement directly</h1>
<div><div class="section"></div>
<div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLExecDirect()</samp> directly
executes the specified SQL statement. The statement can only be processed
once. Also, the connected database server must be able to prepare the statement.</p>
</div>
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLExecDirect (SQLHSTMT hstmt,
SQLCHAR *szSqlStr,
SQLINTEGER cbSqlStr);</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. SQLExecDirect arguments</caption><thead align="left"><tr><th align="left" valign="bottom" width="20%" id="d0e48">Data type</th>
<th align="left" valign="bottom" width="20%" id="d0e50">Argument</th>
<th align="left" valign="bottom" width="20%" id="d0e52">Use</th>
<th align="left" valign="bottom" width="40%" id="d0e54">Description</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="20%" headers="d0e48 ">SQLCHAR *</td>
<td align="left" valign="top" width="20%" headers="d0e50 "><em>szSqlStr</em></td>
<td align="left" valign="top" width="20%" headers="d0e52 ">Input</td>
<td align="left" valign="top" width="40%" headers="d0e54 ">SQL statement string. The connected database
server must be able to prepare the statement.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e48 ">SQLHSTMT</td>
<td align="left" valign="top" width="20%" headers="d0e50 "><em>hstmt</em></td>
<td align="left" valign="top" width="20%" headers="d0e52 ">Input</td>
<td align="left" valign="top" width="40%" headers="d0e54 ">Statement handle. There must not be an open
cursor associated with <em>hstmt</em>. See <a href="rzadpfnfstmt.htm#rzadpfnfstmt">SQLFreeStmt - Free (or reset) a statement handle</a>
for more information.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e48 ">SQLINTEGER</td>
<td align="left" valign="top" width="20%" headers="d0e50 "><em>cbSqlStr</em></td>
<td align="left" valign="top" width="20%" headers="d0e52 ">Input</td>
<td align="left" valign="top" width="40%" headers="d0e54 ">Length of contents of <em>szSqlStr</em> argument.
The length must be set to either the exact length of the statement, or if
the statement is null-terminated, set to SQL_NTS.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Usage</h4><p>The SQL statement cannot be a COMMIT or ROLLBACK.
Instead, <samp class="codeph">SQLTransact()</samp> must be called to issue COMMIT or
ROLLBACK. For more information about supported SQL statements refer to <a href="rzadpdifferences.htm#rzadpdifferences__sqlsts">Table 1</a>.</p>
<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">SQLExecDirect()</samp> is
called. <samp class="codeph">SQLBindParam()</samp> binds (or associates) an application
variable to each parameter marker, 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">SQLExecDirect()</samp>.</p>
<p>If the SQL statement
is a SELECT, <samp class="codeph">SQLExecDirect()</samp> generates a cursor name, and
open 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 one.</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">SQLExecDirect()</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.
Additionally the SQL statement must be defined on a separate statement handle
under the same connection handle.</p>
<p>There must not be an open cursor on
the statement 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="tablenoborder"><a name="rzadpfnexecd__tbexecd"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzadpfnexecd__tbexecd" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. SQLExecDirect SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="top" width="25%" id="d0e172">SQLSTATE</th>
<th align="left" valign="top" width="25%" id="d0e174">Description</th>
<th align="left" valign="top" width="50%" id="d0e176">Explanation</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e172 "><strong>HY</strong>001</td>
<td align="left" valign="top" width="25%" headers="d0e174 ">Memory allocation failure</td>
<td align="left" valign="top" width="50%" headers="d0e176 ">The driver is unable to allocate memory required
to support the processing or completion of the function.</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e172 "><strong>HY</strong>009</td>
<td align="left" valign="top" width="25%" headers="d0e174 ">Argument value</td>
<td align="left" valign="top" width="50%" headers="d0e176 ">The argument <em>szSqlStr</em> is a null pointer.
<p>The argument <em>cbSqlStr</em> is less than 1, but not equal to SQL_NTS.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e172 "><strong>HY</strong>010</td>
<td align="left" valign="top" width="25%" headers="d0e174 ">Function sequence error</td>
<td align="left" valign="top" width="50%" headers="d0e176 ">Either no connection or there is an open
cursor for this statement handle.</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e172 "><strong>HY</strong>013 <strong>*</strong></td>
<td align="left" valign="top" width="25%" headers="d0e174 ">Memory management problem</td>
<td align="left" valign="top" width="50%" headers="d0e176 ">The driver is unable to access memory required
to support the processing or completion of the function.</td>
</tr>
<tr><td valign="top" width="25%" headers="d0e172 "><strong>HY</strong>021</td>
<td valign="top" width="25%" headers="d0e174 ">Internal descriptor </td>
<td valign="top" width="50%" headers="d0e176 ">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="d0e172 d0e174 d0e176 "> <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 class="section"><h4 class="sectiontitle">Example</h4></div>
<div class="example" id="rzadpfnexecd__xmexecd"><a name="rzadpfnexecd__xmexecd"><!-- --></a><p>Refer to the <samp class="codeph">SQLFetch()</samp> <a href="rzadpfnfetch.htm#rzadpfnfetch__xmfetch">rzadpfnfetch.htm#rzadpfnfetch__xmfetch</a>.</p>
</div>
<div class="section"><h4 class="sectiontitle">References</h4><ul><li><a href="rzadpfnexec.htm#rzadpfnexec">SQLExecute - Execute 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>