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

90 lines
5.9 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="concept" />
<meta name="DC.Title" content="Process SELECT statements in a DB2 UDB CLI application" />
<meta name="DC.subject" content="SQL, statements, SELECT" />
<meta name="keywords" content="SQL, statements, SELECT" />
<meta name="DC.Relation" scheme="URI" content="rzadpprocessresults.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="rzadpprocsel" />
<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>Process SELECT statements in a DB2 UDB CLI application</title>
</head>
<body id="rzadpprocsel"><a name="rzadpprocsel"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Process SELECT statements in a DB2<sup>®</sup> UDB CLI application</h1>
<div><div class="p">If the statement is a SELECT, the following steps are generally needed
to retrieve each row of the result set: <ol><li>Establish the structure of the result set, number of columns, column types
and lengths.</li>
<li>Bind application variables to columns in
order to receive the data.</li>
<li>Repeatedly fetch the next row of data, and receive it into the bound application
variables.<p>Columns that were not previously bound can be retrieved by calling <samp class="codeph">SQLGetData()</samp> after
each successful fetch.</p>
</li>
</ol>
</div>
<div class="note"><span class="notetitle">Note:</span> Each of the above steps requires some diagnostic checks.</div>
<div class="p">The first step requires analyzing the processed or prepared statement.
If the SQL statement is generated by the application, this step is not necessary.
This is because the application knows the structure of the result set and
the data types of each column. If the SQL statement is generated (for example,
entered by a user) at run time, the application needs to query:
<ul><li>The number of columns</li>
<li>The type of each column</li>
<li>The names of each column in the result set.</li>
</ul>
This information can be obtained by calling <samp class="codeph">SQLNumResultCols()</samp> and <samp class="codeph">SQLDescribeCol()</samp> (or <samp class="codeph">SQLColAttributes()</samp>) after preparing the statement or after executing the statement.</div>
<p>The second step allows
the application to retrieve column data directly into an application variable
on the next call to <samp class="codeph">SQLFetch()</samp>. For each column to be retrieved,
the application calls <samp class="codeph">SQLBindCol()</samp> to bind an application
variable to a column in the result set. Similar to variables bound to parameter
markers using <samp class="codeph">SQLSetParam()</samp>, columns are bound using deferred
arguments. This time the variables are output arguments, and data is written
to them when <samp class="codeph">SQLFetch()</samp> is called. <samp class="codeph">SQLGetData()</samp> can
also be used to retrieve data, so calling <samp class="codeph">SQLBindCol()</samp> is
optional.</p>
<p>The third step is to call <samp class="codeph">SQLFetch()</samp> to fetch the first
or next row of the result set. If any columns have been bound, the application
variable is updated. If any data conversion is indicated by the data types
specified on the call to <samp class="codeph">SQLBindCol</samp>, the conversion occurs
when <samp class="codeph">SQLFetch()</samp> is called. </p>
<p>The last (optional) step, is to call <samp class="codeph">SQLGetData()</samp> to retrieve
any columns that were not previously bound. All columns can be retrieved this
way, provided they were not bound, or a combination of both methods can be
used. <samp class="codeph">SQLGetData()</samp> is also useful for retrieving variable
length columns in smaller pieces, which cannot be done with bound columns.
Data conversion can also be indicated here, as in <samp class="codeph">SQLBindCol()</samp>. </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="rzadpfnbindc.htm#rzadpfnbindc">SQLBindCol - Bind a column to an application variable</a></li>
<li><a href="rzadpfncolat.htm#rzadpfncolat">SQLColAttributes - Obtain column attributes</a></li>
<li><a href="rzadpfndecol.htm#rzadpfndecol">SQLDescribeCol - Describe column attributes</a></li>
<li><a href="rzadpfnfetch.htm#rzadpfnfetch">SQLFetch - Fetch next row</a></li>
<li><a href="rzadpfngdata.htm#rzadpfngdata">SQLGetData - Get data from a column</a></li>
<li><a href="rzadpfnnrcol.htm#rzadpfnnrcol">SQLNumResultCols - Get number of result columns</a></li>
</ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadpprocessresults.htm">Processing results in a DB2 UDB CLI application</a></div>
</div>
</div>
</body>
</html>