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

105 lines
6.2 KiB
HTML
Raw 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="concept" />
<meta name="DC.Title" content="Preparation and processing tasks in a DB2 UDB CLI application" />
<meta name="DC.Relation" scheme="URI" content="rzadphdptran.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="rzadpprepexec" />
<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>Preparation and processing tasks in a DB2 UDB CLI application</title>
</head>
<body id="rzadpprepexec"><a name="rzadpprepexec"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Preparation and processing tasks in a DB2 UDB CLI application</h1>
<div><div class="p">As soon as a statement handle has been allocated, there are two methods
of specifying and executing SQL statements: <ol><li>Prepare, and then execute: <ol type="a"><li>Call <samp class="codeph">SQLPrepare()</samp> with an SQL statement as an argument.</li>
<li>Call <samp class="codeph">SQLSetParam()</samp>, if the SQL statement contains <em>parameter
markers</em>.</li>
<li>Call <samp class="codeph">SQLExecute()</samp></li>
</ol>
</li>
<li>Execute direct: <ol type="a"><li>Call <samp class="codeph">SQLSetParam()</samp>, if the SQL statement contains <em>parameter
markers</em>.</li>
<li>Call <samp class="codeph">SQLExecDirect()</samp> with an SQL statement as an argument.</li>
</ol>
</li>
</ol>
</div>
<div class="p">The first method splits the preparation of the statement from the processing.
This method is used when: <ul><li>The statement is processed repeatedly (typically with different parameter
values). This avoids having to prepare the same statement more than once.</li>
<li>The application requires information about the columns in the result set,
before statement processing.</li>
</ul>
</div>
<div class="p">The second method combines the preparation step and the processing step
into one. This method is used when: <ul><li>The statement is processed once. This avoids having to call two functions
to process the statement.</li>
<li>The application does not require information about the columns in the
result set, before the statement is processed.</li>
</ul>
</div>
<p><strong>Binding parameters in SQL statements in a DB2<sup>®</sup> UDB CLI application</strong></p>
<p>Both processing methods allow the use of parameter markers in place of
an <em>expression</em> (or host variable in embedded SQL) in an SQL statement.</p>
<p>Parameter markers are represented
by the '?' character and indicate the position in the SQL statement where
the contents of application variables are to be substituted when the statement
is processed. The markers are referenced sequentially, from left to right,
starting at 1.</p>
<div class="p">When an application variable is
associated with a parameter marker, it is <em>bound</em> to the
parameter marker. Binding is carried out by calling the <samp class="codeph">SQLSetParam()</samp> function
with: <ul><li>The number of the parameter marker</li>
<li>A pointer to the application variable</li>
<li>The SQL type of the parameter</li>
<li>The data type and length of the variable.</li>
</ul>
The application variable is called a <em>deferred</em> argument because
only the pointer is passed when <samp class="codeph">SQLSetParam()</samp> is called.
No data is read from the variable until the statement is processed. This applies
to both buffer arguments and arguments that indicate the length of the data
in the buffer. Deferred arguments allow the application to modify the contents
of the bound parameter variables, and repeat the processing of the statement
with the new values.</div>
<p>When calling <samp class="codeph">SQLSetParam()</samp>, it is possible
to bind a variable of a different type from that required by the SQL statement.
In this case DB2 UDB
CLI converts the contents of the bound variable to the correct type. For example,
the SQL statement might require an integer value, but your application has
a string representation of an integer. The string can be bound to the parameter,
and DB2 UDB
CLI converts the string to an integer when you process the statement.</p>
<div class="p">For more information and examples refer to: <ul><li><a href="rzadphddtdcn.htm#rzadphddtdcn">Data types and data conversion in DB2 UDB CLI functions</a></li>
<li><a href="rzadpfnprep.htm#rzadpfnprep">SQLPrepare - Prepare a statement</a></li>
<li><a href="rzadpfnspara.htm#rzadpfnspara">SQLSetParam - Set parameter</a></li>
<li><a href="rzadpfnexec.htm#rzadpfnexec">SQLExecute - Execute a statement</a></li>
<li><a href="rzadpfnexecd.htm#rzadpfnexecd">SQLExecDirect - Execute a statement directly</a></li>
</ul>
</div>
<p>If the SQL statement uses parameter markers instead of expressions (or
host variables in embedded SQL), you must bind the application variable to
the parameter marker.</p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadphdptran.htm" title="This topic shows a typical order of function calls in a DB2 UDB CLI application.">Transaction processing task in a DB2 UDB CLI application</a></div>
</div>
</div>
</body>
</html>