291 lines
17 KiB
HTML
291 lines
17 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="SQLBindCol - Bind a column to an application variable" />
|
|
<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="rzadpfnbindc" />
|
|
<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>SQLBindCol - Bind a column to an application variable</title>
|
|
</head>
|
|
<body id="rzadpfnbindc"><a name="rzadpfnbindc"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">SQLBindCol - Bind a column to an application variable</h1>
|
|
<div><div class="section"></div>
|
|
<div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLBindCol()</samp> associates (bind)
|
|
columns in a result set to application variables (storage buffers), for all
|
|
data types. Data is transferred from the Database Management System (DBMS)
|
|
to the application when <samp class="codeph">SQLFetch()</samp> is called.</p>
|
|
<p>This
|
|
function is also used to specify any data conversion required. It is called
|
|
once for each column in the result set that the application needs to retrieve.</p>
|
|
<p><samp class="codeph">SQLPrepare()</samp> or <samp class="codeph">SQLExecDirect()</samp> is typically called before this function. It might also be necessary to
|
|
call <samp class="codeph">SQLDescribeCol()</samp> or <samp class="codeph">SQLColAttributes()</samp>.</p>
|
|
<p><samp class="codeph">SQLBindCol()</samp> must
|
|
be called before <samp class="codeph">SQLFetch()</samp>, to transfer data to the storage
|
|
buffers specified by this call.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLBindCol (SQLHSTMT hstmt,
|
|
SQLSMALLINT icol,
|
|
SQLSMALLINT fCType,
|
|
SQLPOINTER rgbValue,
|
|
SQLINTEGER cbValueMax,
|
|
SQLINTEGER *pcbValue);</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. SQLBindCol arguments</caption><thead align="left"><tr><th align="left" valign="bottom" width="20%" id="d0e70">Data type</th>
|
|
<th align="left" valign="bottom" width="20%" id="d0e72">Argument</th>
|
|
<th align="left" valign="bottom" width="20%" id="d0e74">Use</th>
|
|
<th align="left" valign="bottom" width="40%" id="d0e76">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLHSTMT</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>hstmt</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Statement handle.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLINTEGER *</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>pcbValue</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Output (deferred)</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Pointer to value which indicates the number
|
|
of bytes DB2<sup>®</sup> UDB
|
|
CLI has available to return in the <em>rgbValue</em> buffer. <p><samp class="codeph">SQLFetch()</samp> returns <samp class="codeph">SQL_NULL_DATA</samp>
|
|
in this argument if the data value of the column is null. SQL_NTS is returned
|
|
in this argument if the data value of the column is returned as a null-terminated
|
|
string.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLINTEGER</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>cbValueMax</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Size of <em>rgbValue</em> buffer in bytes available
|
|
to store the column data. <p>If <em>fCType</em> is either SQL_CHAR or SQL_DEFAULT,
|
|
then <em>cbValueMax</em> must be > 0 otherwise an error is returned.</p>
|
|
<p>If <em>fcType</em> is
|
|
either SQL_DECIMAL or SQL_NUMERIC, <em>cbValueMax</em> must actually be a precision
|
|
and scale. The method to specify both values is to use <em>(precision * 256)
|
|
+ scale</em>. This is also the value returned as the LENGTH of these data types
|
|
when using <samp class="codeph">SQLColAttributes()</samp>.</p>
|
|
<p>If <em>fcType</em> specifies
|
|
any form of double-byte character data, then <em>cbValueMax</em> must be the
|
|
number of double-byte characters, not the number of bytes.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLPOINTER</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>rgbValue</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Output (deferred)</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Pointer to buffer where DB2 UDB CLI is
|
|
to store the column data when the fetch occurs. <p>If <em>rgbValue</em> is
|
|
null, the column is unbound.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>fCType</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Application data type for column number <em>icol</em> in
|
|
the result set. The following types are supported: <ul><li>SQL_BIGINT</li>
|
|
<li>SQL_BINARY</li>
|
|
<li>SQL_BLOB</li>
|
|
<li>SQL_BLOB_LOCATOR</li>
|
|
<li>SQL_CHAR</li>
|
|
<li>SQL_CLOB</li>
|
|
<li>SQL_CLOB_LOCATOR</li>
|
|
<li>SQL_DATALINK </li>
|
|
<li>SQL_DATETIME</li>
|
|
<li>SQL_DBCLOB</li>
|
|
<li>SQL_DBCLOB_LOCATOR</li>
|
|
<li>SQL_DECIMAL</li>
|
|
<li>SQL_DOUBLE</li>
|
|
<li>SQL_FLOAT</li>
|
|
<li>SQL_GRAPHIC</li>
|
|
<li>SQL_INTEGER</li>
|
|
<li>SQL_NUMERIC</li>
|
|
<li>SQL_REAL</li>
|
|
<li>SQL_SMALLINT</li>
|
|
<li>SQL_TYPE_DATE</li>
|
|
<li>SQL_TYPE_TIME</li>
|
|
<li>SQL_TYPE_TIMESTAMP</li>
|
|
<li>SQL_VARBINARY</li>
|
|
<li>SQL_VARCHAR</li>
|
|
<li>SQL_VARGRAPHIC</li>
|
|
<li>SQL_WCHAR</li>
|
|
<li>SQL_WVARCHAR</li>
|
|
</ul>
|
|
<p>Specifying SQL_DEFAULT causes data to be transferred to its default
|
|
data type; refer to <a href="rzadphddtdcn.htm#rzadphddtdcn__tbcsql">Table 1</a> for
|
|
more information.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="20%" headers="d0e72 "><em>icol</em></td>
|
|
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
|
|
<td align="left" valign="top" width="40%" headers="d0e76 ">Number identifying the column. Columns are
|
|
numbered sequentially, from left to right, starting at 1.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note"><span class="notetitle">Note:</span> </div>
|
|
<p>For this function, both <em>rgbValue</em> and <em>pcbValue</em> are
|
|
deferred outputs, meaning that the storage locations these pointers point
|
|
to are not updated until <samp class="codeph">SQLFetch()</samp> is called. The locations
|
|
referred to by these pointers must remain valid until <samp class="codeph">SQLFetch()</samp> is
|
|
called.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Usage</h4><p>The application calls <samp class="codeph">SQLBindCol()</samp> once
|
|
for each column in the result set that it wants to retrieve. When <samp class="codeph">SQLFetch()</samp> is
|
|
called, the data in each of these <em>bound</em> columns is placed in the assigned
|
|
location (given by the pointers <em>rgbValue</em> and <em>pcbValue</em>).</p>
|
|
<p>The
|
|
application can query the attributes (such as data type and length) of the
|
|
column by first calling <samp class="codeph">SQLDescribeCol()</samp> or <samp class="codeph">SQLColAttributes()</samp>.
|
|
This information can then be used to specify the correct data type of the
|
|
storage locations, or to indicate data conversion to other data types. Refer
|
|
to <a href="rzadphddtdcn.htm#rzadphddtdcn">Data types and data conversion in DB2 UDB CLI functions</a> for more information.</p>
|
|
<p>In
|
|
later fetches, the application can change the binding of these columns or
|
|
bind unbound columns by calling <samp class="codeph">SQLBindCol()</samp>. The new binding
|
|
does not apply to data fetched, it is used when the next <samp class="codeph">SQLFetch()</samp> is
|
|
called. To unbind a single column, call <samp class="codeph">SQLBindCol()</samp> with <em>rgbValue</em> set
|
|
to NULL. To unbind all the columns, the application should call <samp class="codeph">SQLFreeStmt()</samp> with
|
|
the <em>fOption</em> input set to SQL_UNBIND.</p>
|
|
<p>Columns are identified by
|
|
a number, assigned sequentially from left to right, starting at 1. The number
|
|
of columns in the result set can be determined by calling <samp class="codeph">SQLNumResultCols()</samp> or <samp class="codeph">SQLColAttributes()</samp> with
|
|
the <em>fdescType</em> argument set to SQL_DESC_COUNT.</p>
|
|
<p>All
|
|
character data is treated as the default job coded character set identifier
|
|
(CCSID) if the SQL_ATTR_UTF8 environment attribute is not set to SQL_TRUE. </p>
|
|
<p>An
|
|
application can choose not to bind every column, or even not to bind any columns.
|
|
The data in the unbound columns (and only the unbound columns) can be retrieved
|
|
using <samp class="codeph">SQLGetData()</samp> after <samp class="codeph">SQLFetch()</samp> has
|
|
been called. <samp class="codeph">SQLBindCol()</samp> is more efficient than <samp class="codeph">SQLGetData()</samp>,
|
|
and should be used whenever possible.</p>
|
|
<p>The application
|
|
must ensure enough storage is allocated for the data to be retrieved. If the
|
|
buffer is to contain variable length data, the application must allocate as
|
|
much storage as the maximum length of the bound column requires; otherwise,
|
|
the data might be truncated.</p>
|
|
<div class="p">The default is null termination
|
|
for output character strings. To change this you must set the <samp class="codeph">SQLSetEnvAttr()</samp> attribute
|
|
SQL_ATTR_OUTPUT_NTS to SQL_FALSE. The output values for <em>pcbValue</em> after
|
|
a call to <samp class="codeph">SQLFetch()</samp> behave in the following way for character
|
|
data types:<ul><li>If the null termination attribute is set (the default) and no truncation
|
|
occurs, then SQL_NTS is returned in the <em>pcbValue</em>.</li>
|
|
<li>If the null termination attribute is not set and no truncation occurs,
|
|
then the value of <em>cbValueMax</em> is returned in <em>pcbValue</em>.</li>
|
|
<li>If the null termination attribute is set or not set and truncation occurs,
|
|
then the value of <em>cbValueMax</em> is returned in <em>pcbValue</em>.</li>
|
|
</ul>
|
|
</div>
|
|
<p>If truncation occurs and the <samp class="codeph">SQLSetEnvAttr()</samp> attribute
|
|
SQL_ATTR_TRUNCATION_RTNC is set to SQL_FALSE (which is the default), then
|
|
SQL_SUCCESS is returned in the <samp class="codeph">SQLFetch()</samp> return code. If
|
|
truncation occurs and the attribute is SQL_TRUE, then SQL_SUCCESS_WITH_INFO
|
|
is returned. SQL_SUCCESS is returned in both cases if no truncation occurs.</p>
|
|
<p>Truncation occurs when argument <em>cbValueMax</em> does not
|
|
allocate space for the amount of fetched data. If the environment is set to
|
|
run with null terminated strings, make sure to allocate space for the additional
|
|
byte in <em>cbValueMax</em>. For additional truncation information, refer to <a href="rzadpfnfetch.htm#rzadpfnfetch">SQLFetch - Fetch next row</a>.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Return codes</h4><ul><li>SQL_SUCCESS</li>
|
|
<li>SQL_ERROR</li>
|
|
<li>SQL_INVALID_HANDLE</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Diagnostics</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. SQLBindCol SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="bottom" width="25%" id="d0e430">SQLSTATE</th>
|
|
<th align="left" valign="bottom" width="25%" id="d0e432">Description</th>
|
|
<th align="left" valign="bottom" width="50%" id="d0e434">Explanation</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>40</strong>003 <strong>*</strong></td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Statement completion unknown</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">The communication link between the CLI and
|
|
the data source fails before the function completes processing.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>58</strong>004</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">System error</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">Unrecoverable system error.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>001</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Memory allocation failure</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">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="d0e430 "><strong>HY</strong>002</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Column number that is not valid</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">The value specified for the argument <em>icol</em> is
|
|
0. <p>The value specified for the argument <em>icol</em> exceeded the maximum
|
|
number of columns supported by the data source.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>003</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Program type out of range</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 "><em>fCType</em> is not a valid data type.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>009</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Argument value that is not valid</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 "><em>rgbValue</em> is a null pointer. <p>The
|
|
value specified for the argument <em>cbValueMax</em> is less than 1, and the
|
|
argument <em>fCType</em> is either SQL_CHAR or SQL_DEFAULT.</p>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>013 <strong>*</strong></td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Memory management problem</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">The driver is unable to access memory required
|
|
to support the processing or completion of the function.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>014 </td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Too many handles</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">The maximum number of handles has been allocated,
|
|
and use of this function requires an additional descriptor handle.
|
|
</td>
|
|
</tr>
|
|
<tr><td valign="top" width="25%" headers="d0e430 "><strong>HY</strong>021</td>
|
|
<td valign="top" width="25%" headers="d0e432 ">Internal descriptor that is not valid</td>
|
|
<td valign="top" width="50%" headers="d0e434 ">The internal descriptor cannot be addressed or allocated,
|
|
or it contains a value that is not valid.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e430 "><strong>HY</strong>C00</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e432 ">Driver not capable</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e434 ">The driver recognizes, but does not support
|
|
the data type specified in the argument <em>fCType</em> (see also <strong>HY</strong>003).</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Example</h4></div>
|
|
<div class="example" id="rzadpfnbindc__xmbindc"><a name="rzadpfnbindc__xmbindc"><!-- --></a><p>Refer to the example in <a href="rzadpfnfetch.htm">SQLFetch - Fetch next row</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="rzadpfnexec.htm#rzadpfnexec">SQLExecute - Execute a statement</a></li>
|
|
<li><a href="rzadpfnfetch.htm#rzadpfnfetch">SQLFetch - Fetch next row</a></li>
|
|
<li><a href="rzadpfnprep.htm#rzadpfnprep">SQLPrepare - Prepare a statement</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> |