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

329 lines
21 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="SQLColAttributes - Obtain column attributes" />
<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="rzadpfncolat" />
<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>SQLColAttributes - Obtain column attributes</title>
</head>
<body id="rzadpfncolat"><a name="rzadpfncolat"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">SQLColAttributes - Obtain column attributes</h1>
<div><div class="section"></div>
<div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLColAttributes()</samp> obtains
an attribute for a column of the result set, and is also used to determine
the number of columns. <samp class="codeph">SQLColAttributes()</samp> is a more extensible
alternative to the <samp class="codeph">SQLDescribeCol()</samp> function.</p>
<p>Either <samp class="codeph">SQLPrepare()</samp> or <samp class="codeph">SQLExecDirect()</samp> must
be called before calling this function.</p>
<p>This function (or <samp class="codeph">SQLDescribeCol()</samp>)
must be called before <samp class="codeph">SQLBindCol()</samp>, if the application does
not know the various attributes (such as data type and length) of the column.</p>
</div>
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLColAttributes (SQLHSTMT hstmt,
SQLSMALLINT icol,
SQLSMALLINT fDescType,
SQLCHAR *rgbDesc,
SQLINTEGER cbDescMax,
SQLINTEGER *pcbDesc,
SQLINTEGER *pfDesc);</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. SQLColAttributes 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 ">SQLCHAR *</td>
<td align="left" valign="top" width="20%" headers="d0e72 "><em>rgbDesc</em></td>
<td align="left" valign="top" width="20%" headers="d0e74 ">Output</td>
<td align="left" valign="top" width="40%" headers="d0e76 ">Pointer to buffer for string column attributes.</td>
</tr>
<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>pcbDesc</em></td>
<td align="left" valign="top" width="20%" headers="d0e74 ">Output</td>
<td align="left" valign="top" width="40%" headers="d0e76 "><p>Actual number of bytes
in the descriptor to return. If this argument contains a value equal to or
higher than the length <em>rgbDesc</em> buffer, truncation has occurred. The
descriptor is then truncated to <em>cbDescMax</em> - 1 bytes.</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>pfDesc</em></td>
<td align="left" valign="top" width="20%" headers="d0e74 ">Output</td>
<td align="left" valign="top" width="40%" headers="d0e76 ">Pointer to integer which holds information
regarding numeric column attributes.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLINTEGER</td>
<td align="left" valign="top" width="20%" headers="d0e72 "><em>cbDescMax</em></td>
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
<td align="left" valign="top" width="40%" headers="d0e76 ">Length of descriptor buffer (<em>rgbDesc</em>)</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e70 ">SQLSMALLINT</td>
<td align="left" valign="top" width="20%" headers="d0e72 "><em>fDescType</em></td>
<td align="left" valign="top" width="20%" headers="d0e74 ">Input</td>
<td align="left" valign="top" width="40%" headers="d0e76 ">Supported values are described in <a href="#rzadpfncolat__tbdesct">Table 2</a>.</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 ">Column number in result set (must be between
1 and the number of columns in the results set inclusive). This argument is
ignored when SQL_DESC_COUNT is specified.</td>
</tr>
</tbody>
</table>
</div>
<div class="tablenoborder"><a name="rzadpfncolat__tbdesct"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzadpfncolat__tbdesct" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. fDescType descriptor types</caption><thead align="left"><tr><th align="left" valign="top" width="40.15151515151515%" id="d0e171">Descriptor</th>
<th align="left" valign="top" width="13.825757575757574%" id="d0e173">Type</th>
<th align="left" valign="top" width="46.02272727272727%" id="d0e175">Description</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_AUTO_INCREMENT</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">INTEGER</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">This is SQL_TRUE if the column can be incremented
automatically upon insertion of a new row to the table. SQL_FALSE if the column
cannot be incremented automatically.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_BASE_COLUMN</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The name of the actual column in the underlying
table over which this column is built. <p>For this attribute to be retrieved,
the attribute SQL_ATTR_EXTENDED_COL_INFO must have been set to SQL_TRUE for
either the statement handle or the connection handle.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_BASE_SCHEMA</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The schema name of the underlying table over
which this column is built. <p>For this attribute to be retrieved, the attribute
SQL_ATTR_EXTENDED_COL_INFO must have been set to SQL_TRUE for either the statement
handle or the connection handle.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_BASE_TABLE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The name of the underlying table over which
this column is built. <p>For this attribute to be retrieved, the attribute
SQL_ATTR_EXTENDED_COL_INFO must have been set to SQL_TRUE for either the statement
handle or the connection handle.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_COUNT</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The number of columns in the result set is
returned in <em>pfDesc</em>.</td>
</tr>
<tr><td valign="top" width="40.15151515151515%" headers="d0e171 "><p><img src="./delta.gif" alt="Start of change" />SQL_DESC_DISPLAY_SIZE<img src="./deltaend.gif" alt="End of change" /></p>
</td>
<td valign="top" width="13.825757575757574%" headers="d0e173 "><p><img src="./delta.gif" alt="Start of change" />SMALLINT<img src="./deltaend.gif" alt="End of change" /></p>
</td>
<td valign="top" width="46.02272727272727%" headers="d0e175 "><p><img src="./delta.gif" alt="Start of change" />The maximum number
of bytes needed to display the data in character form is returned in <em>pfDesc</em>.<img src="./deltaend.gif" alt="End of change" /></p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_LABEL</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The label for this column, if one exists.
Otherwise, a zero-length string. <p>For this attribute to be retrieved, the
attribute SQL_ATTR_EXTENDED_COL_INFO must have been set to SQL_TRUE for either
the statement handle or the connection handle.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_LENGTH</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">INTEGER</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The number of <em>bytes</em> of data associated
with the column is returned in <em>pfDesc</em>. <p>If the column identified
in <em>icol</em> is character based, for example, SQL_CHAR, SQL_VARCHAR, or
SQL_LONG_VARCHAR, the actual length or maximum length is returned.</p>
<p>If
the column type is SQL_DECIMAL or SQL_NUMERIC, SQL_DESC_LENGTH is <em>(precision
* 256) + scale</em>. This is returned so that the same value can be passed
as input on <samp class="codeph">SQLBindCol()</samp>. The precision and scale can also
be obtained as separate values for these data types by using SQL_DESC_PRECISION
and SQL_DESC_SCALE.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_NAME</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The name of the column <em>icol</em> is returned
in <em>rgbDesc</em>. If the column is an expression, then the result returned
is product specific.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_NULLABLE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">If the column identified by <em>icol</em> can
contain nulls, then SQL_NULLABLE is returned in <em>pfDesc</em>. <p>If the
column is constrained not to accept nulls, then SQL_NO_NULLS is returned in <em>pfDesc</em>.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_PRECISION</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The precision attribute of the column is
returned.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_SCALE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The scale attribute of the column is returned.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_SEARCHABLE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">INTEGER</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">This is SQL_UNSEARCHABLE if the column cannot
be used in a <strong>WHERE</strong> clause. <p>This is SQL_LIKE_ONLY if the column can
be used in a <strong>WHERE</strong> clause only with the <strong>LIKE</strong> predicate.</p>
<p>This
is SQL_ALL_EXCEPT_LIKE if the column can be used in a <strong>WHERE</strong> clause
with all comparison operators except <strong>LIKE</strong>.</p>
<p>This is SQL_SEARCHABLE
if the column can be used in a <strong>WHERE</strong> clause with any comparison operator.</p>
<p>For
this attribute to be retrieved, the attribute SQL_ATTR_EXTENDED_COL_INFO must
have been set to SQL_TRUE for either the statement handle or the connection
handle.</p>
</td>
</tr>
<tr><td valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_TYPE_NAME </td>
<td valign="top" width="13.825757575757574%" headers="d0e173 ">CHAR(128)</td>
<td valign="top" width="46.02272727272727%" headers="d0e175 ">The character representation of the SQL data type of
the column identified in <em>icol</em>. This is returned in <em>rgbDesc</em>.
The possible values for the SQL data type are listed in<a href="rzadphddtdcn.htm#rzadphddtdcn__tbcsql">Table 1</a>.
In addition, user-defined type (UDT) information is also returned. The format
for the UDT is &lt;schema name qualifier&gt;&lt;job's current separator&gt;&lt;UDT
name&gt;.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_TYPE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">The SQL data type of the column identified
in <em>icol</em> is returned in <em>pfDesc</em>. The possible values for <em>pfSqlType</em> are
listed in <a href="rzadphddtdcn.htm#rzadphddtdcn__tbcsql">Table 1</a>.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_UNNAMED</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">SMALLINT</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">This is SQL_NAMED if the NAME field is an
actual name, or SQL_UNNAMED if the NAME field is an implementation-generated
name.</td>
</tr>
<tr><td align="left" valign="top" width="40.15151515151515%" headers="d0e171 ">SQL_DESC_UPDATABLE</td>
<td align="left" valign="top" width="13.825757575757574%" headers="d0e173 ">INTEGER</td>
<td align="left" valign="top" width="46.02272727272727%" headers="d0e175 ">Column is described by the values for the
defined constants: <p>SQL_ATTR_READONLY<br />
SQL_ATTR_WRITE<br />
SQL_ATTR_READWRITE_UNKNOWN</p>
<p>SQL_COLUMN_UPDATABLE describes the updatability
of the column in the result set. Whether a column can be updated can be based
on the data type, user privileges, and the definition of the result set itself.
If it is unclear whether a column can be updated, SQL_ATTR_READWRITE_UNKNOWN
should be returned.</p>
<p>For this attribute to be retrieved, the attribute
SQL_ATTR_EXTENDED_COL_INFO must have been set to SQL_TRUE for either the statement
handle or the connection handle.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Usage</h4><p>Instead of returning a specific set of arguments
like <samp class="codeph">SQLDescribeCol()</samp>, <samp class="codeph">SQLColAttributes()</samp> can
be used to specify which attribute you want to receive for a specific column.
If the required information is a string, it is returned in <em>rgbDesc</em>.
If the required information is a number, it is returned in <em>pfDesc</em>.</p>
<p>Although <samp class="codeph">SQLColAttributes()</samp> allows
for future extensions, it requires more calls to receive the same information
than <samp class="codeph">SQLDescribeCol()</samp> for each column.</p>
<p>If a <em>fDescType</em> descriptor
type does not apply to the database server, an empty string is returned in <em>rgbDesc</em> or
zero is returned in <em>pfDesc</em>, depending on the expected result of the
descriptor.</p>
<p>Columns are identified by a number (numbered sequentially
from left to right starting with 1) and can be described in any order.</p>
<p>Calling <samp class="codeph">SQLColAttributes()</samp> with <em>fDescType</em> set
to SQL_DESC_COUNT is an alternative to calling <samp class="codeph">SQLNumResultCols()</samp> to
determine whether any columns can be returned.</p>
<p>Call <samp class="codeph">SQLNumResultCols()</samp> before
calling <samp class="codeph">SQLColAttributes()</samp> to determine whether a result
set exists.</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>
</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 3. SQLColAttributes SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="top" width="25%" id="d0e496">SQLSTATE</th>
<th align="left" valign="top" width="25%" id="d0e498">Description</th>
<th align="left" valign="top" width="50%" id="d0e500">Explanation</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e496 "><strong>07</strong>009</td>
<td align="left" valign="top" width="25%" headers="d0e498 ">Column number that is not valid</td>
<td align="left" valign="top" width="50%" headers="d0e500 ">The value specified for the argument <em>icol</em> is
less than 1.</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e496 "><strong>HY</strong>009</td>
<td align="left" valign="top" width="25%" headers="d0e498 ">Argument value that is not valid</td>
<td align="left" valign="top" width="50%" headers="d0e500 ">The value specified for the argument <em>fDescType</em> is
not equal to a value specified in <a href="#rzadpfncolat__tbdesct">Table 2</a>. <p>The
argument <em>rgbDesc</em>, <em>pcbDesc</em>, or <em>pfDesc</em> is a null pointer.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e496 "><strong>HY</strong>010</td>
<td align="left" valign="top" width="25%" headers="d0e498 ">Function sequence error</td>
<td align="left" valign="top" width="50%" headers="d0e500 ">The function is called before calling <samp class="codeph">SQLPrepare()</samp> or <samp class="codeph">SQLExecDirect()</samp> for
the <em>hstmt</em>.</td>
</tr>
<tr><td valign="top" width="25%" headers="d0e496 "><strong>HY</strong>021</td>
<td valign="top" width="25%" headers="d0e498 ">Internal descriptor that is not valid</td>
<td valign="top" width="50%" headers="d0e500 ">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="d0e496 "><strong>HY</strong>C00</td>
<td align="left" valign="top" width="25%" headers="d0e498 ">Driver not capable</td>
<td align="left" valign="top" width="50%" headers="d0e500 ">The SQL data type returned by the database
server for column <em>icol</em> is not recognized by DB2<sup>®</sup> UDB CLI.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">References</h4><ul><li><a href="rzadpfnbindc.htm#rzadpfnbindc">SQLBindCol - Bind a column to an application variable</a></li>
<li><a href="rzadpfndecol.htm#rzadpfndecol">SQLDescribeCol - Describe column attributes</a></li>
<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="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>