ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzajp_5.4.0.1/rzajpequivsqlc.htm

266 lines
18 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="reference" />
<meta name="DC.Title" content="Determine equivalent SQL and C or C++ data types" />
<meta name="abstract" content="The precompiler determines the base SQLTYPE and SQLLEN of host variables based on the following table. If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one." />
<meta name="description" content="The precompiler determines the base SQLTYPE and SQLLEN of host variables based on the following table. If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one." />
<meta name="DC.subject" content="C program, SQL data types, determining equivalent C, C++ program, SQL data types, determining equivalent C++, data type, determining equivalent, C, C++" />
<meta name="keywords" content="C program, SQL data types, determining equivalent C, C++ program, SQL data types, determining equivalent C++, data type, determining equivalent, C, C++" />
<meta name="DC.Relation" scheme="URI" content="rzajpc.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpcvariabledecnotes.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzajpequivsqlc" />
<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>Determine equivalent SQL and C or C++ data types</title>
</head>
<body id="rzajpequivsqlc"><a name="rzajpequivsqlc"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Determine equivalent SQL and C or C++ data types</h1>
<div><p>The precompiler determines the base SQLTYPE and SQLLEN of host
variables based on the following table. If a host variable appears with an
indicator variable, the SQLTYPE is the base SQLTYPE plus one.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. C or C++ declarations mapped
to typical SQL data types</caption><thead align="left"><tr><th align="left" valign="bottom" width="25%" id="d0e51">C or C++ data type</th>
<th align="left" valign="bottom" width="25%" id="d0e53">SQLTYPE of host variable</th>
<th align="left" valign="bottom" width="25%" id="d0e55">SQLLEN of host variable</th>
<th align="left" valign="bottom" width="25%" id="d0e57">SQL data type</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e51 ">short int</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">500</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">2</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">SMALLINT</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">long int</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">496</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">4</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">INTEGER</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">long long int</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">492</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">8</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">BIGINT</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">decimal(p,s)</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">484</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">DECIMAL (p,s)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">float</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">480</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">4</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">FLOAT (single precision)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">double</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">480</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">8</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">FLOAT (double precision)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">single-character form</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">452</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">1</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">CHAR(1)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">NUL-terminated character form</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">460</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">length</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">VARCHAR (length - 1)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">VARCHAR structured form </td>
<td align="left" valign="top" width="25%" headers="d0e53 ">448</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">length</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">VARCHAR (length)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">single-graphic form</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">468</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">1</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">GRAPHIC(1)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">NUL-terminated single-graphic form</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">400</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">length</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">VARGRAPHIC (length - 1)</td>
</tr>
<tr><td align="left" valign="top" width="25%" headers="d0e51 ">VARGRAPHIC structured form</td>
<td align="left" valign="top" width="25%" headers="d0e53 ">464</td>
<td align="left" valign="top" width="25%" headers="d0e55 ">length</td>
<td align="left" valign="top" width="25%" headers="d0e57 ">VARGRAPHIC (length)</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><p>You can use the following table to determine the C or C++ data
type that is equivalent to a given SQL data type.</p>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 2. SQL data types mapped to typical
C or C++ declarations</caption><thead align="left"><tr><th align="left" valign="bottom" width="33.33333333333333%" id="d0e180">SQL data type</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e182">C or C++ data type</th>
<th align="left" valign="bottom" width="33.33333333333333%" id="d0e184">Notes</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">SMALLINT</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">short int</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">INTEGER</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">long int</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">BIGINT</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">long long int</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">DECIMAL(p,s)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">decimal(p,s)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">p is a positive integer from 1 to 63, and
s is a positive integer from 0 to 63.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">NUMERIC(p,s) or nonzero scale binary</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">No exact equivalent</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use DECIMAL (p,s).</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">FLOAT (single precision)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">float</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">FLOAT (double precision)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">double</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">CHAR(1)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">single-character form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">CHAR(n)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">No exact equivalent</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">If <em>n</em>&gt;1, use NUL-terminated character
form</td>
</tr>
<tr><td rowspan="2" align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">VARCHAR(n)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">NUL-terminated character form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Allow at least <em>n</em>+1 to accommodate
the NUL-terminator. If data can contain character NULs (\0), use VARCHAR structured
form or SQL VARCHAR. <p><em>n</em> is a positive integer. The maximum value
of <em>n</em> is 32740.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">VARCHAR structured form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">The maximum value of <em>n</em> is 32740. The
SQL VARCHAR form may also be used.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">CLOB</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a CLOB in C or
C++.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">GRAPHIC (1)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">single-graphic form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">GRAPHIC (n)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">No exact equivalent</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td rowspan="2" align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">VARGRAPHIC(n)</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">NUL-terminated graphic form</td>
<td valign="top" width="33.33333333333333%" headers="d0e184 ">If <em>n</em> &gt; 1, use NUL-terminated graphic form.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">VARGRAPHIC structured form</td>
<td valign="top" width="33.33333333333333%" headers="d0e184 ">If data can contain graphic NUL values (/0/0), use VARGRAPHIC structured
form. Allow at least <em>n</em> + 1 to accommodate the NUL-terminator. <p><em>n</em> is
a positive integer. The maximum value of <em>n</em> is 16370.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">DBCLOB</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a DBCLOB in C
or C++.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">BINARY</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a BINARY in C
or C++.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">VARBINARY</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a VARBINARY in
C or C++.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">BLOB</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a BLOB in C or
C++.</td>
</tr>
<tr><td rowspan="2" align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">DATE</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">NUL-terminated character form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">If the format is *USA, *ISO, *JIS, or *EUR,
allow at least 11 characters to accommodate the NUL-terminator. If the format
is *MDY, *YMD, or *DMY, allow at least 9 characters to accommodate the NUL-terminator.
If the format is *JUL, allow at least 7 characters to accommodate the NUL-terminator.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">VARCHAR structured form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">If the format is *USA, *ISO, *JIS, or *EUR,
allow at least 10 characters. If the format is *MDY, *YMD, or *DMY, allow
at least 8 characters. If the format is *JUL, allow at least 6 characters.</td>
</tr>
<tr><td rowspan="2" align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">TIME</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">NUL-terminated character form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Allow at least 7 characters (9 to include
seconds) to accommodate the NUL-terminator.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">VARCHAR structured form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Allow at least 6 characters; 8 to include
seconds.</td>
</tr>
<tr><td rowspan="2" align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">TIMESTAMP</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">NUL-terminated character form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Allow at least 20 characters (27 to include
microseconds at full precision) to accommodate the NUL-terminator. If n is
less than 27, truncation occurs on the microseconds part.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">VARCHAR structured form</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e184 ">Allow at least 19 characters. To include
microseconds at full precision, allow 26 characters. If the number of characters
is less than 26, truncation occurs on the microseconds part.</td>
</tr>
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e180 ">DATALINK</td>
<td align="left" valign="top" width="33.33333333333333%" headers="d0e182 ">Not supported</td>
<td valign="top" width="33.33333333333333%" headers="d0e184 ">&nbsp;</td>
</tr>
<tr><td valign="top" width="33.33333333333333%" headers="d0e180 ">ROWID</td>
<td valign="top" width="33.33333333333333%" headers="d0e182 ">None</td>
<td valign="top" width="33.33333333333333%" headers="d0e184 ">Use SQL TYPE IS to declare a ROWID in C or C++.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzajpcvariabledecnotes.htm">Notes on C and C++ variable declaration and usage</a></strong><br />
Single quotation marks and quotation marks have different meanings in C, C++, and SQL.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpc.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in a C or C++ program.">Code SQL statements in C and C++ applications</a></div>
</div>
</div>
</body>
</html>