86 lines
5.4 KiB
HTML
86 lines
5.4 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="Use pointer data types in C and C++ applications that use SQL" />
|
||
|
<meta name="abstract" content="You can also declare host variables that are pointers to the supported C and C++ data types, with the following restrictions." />
|
||
|
<meta name="description" content="You can also declare host variables that are pointers to the supported C and C++ data types, with the following restrictions." />
|
||
|
<meta name="DC.subject" content="pointer, C, C++, C program, host variable, using pointers, C++ program, using pointers" />
|
||
|
<meta name="keywords" content="pointer, C, C++, C program, host variable, using pointers, C++ program, using pointers" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzajpc.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="rzajppointerdtc" />
|
||
|
<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>Use pointer data types in C and C++ applications that use SQL</title>
|
||
|
</head>
|
||
|
<body id="rzajppointerdtc"><a name="rzajppointerdtc"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Use pointer data types in C and C++ applications that use SQL</h1>
|
||
|
<div><p>You can also declare host variables that are pointers to the supported
|
||
|
C and C++ data types, with the following restrictions.</p>
|
||
|
<div class="section"><ul><li>If a host variable is declared as a pointer, then that host variable must
|
||
|
be declared with asterisks followed by a host variable. The following examples
|
||
|
are all valid: <pre>short *mynum; /* Ptr to an integer */
|
||
|
long **mynumptr; /* Ptr to a ptr to a long integer */
|
||
|
char *mychar; /* Ptr to a single character */
|
||
|
char(*mychara)[20]; /* Ptr to a char array of 20 bytes */
|
||
|
struct { /* Ptr to a variable char array of 30 */
|
||
|
short mylen; /* bytes. */
|
||
|
char mydata[30];
|
||
|
} *myvarchar;
|
||
|
</pre>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Parentheses are only allowed when declaring a pointer to
|
||
|
a NUL-terminated character array, in which case they are required. If the
|
||
|
parentheses were not used, you would be declaring an array of pointers rather
|
||
|
than the desired pointer to an array. For example: <pre>char (*a)[10]; /* pointer to a null-terminated char array */
|
||
|
char *a[10]; /* pointer to an array of pointers */
|
||
|
</pre>
|
||
|
</div>
|
||
|
</li>
|
||
|
<li>If a host variable is declared as a pointer, then no other host variable
|
||
|
can be declared with that same name within the same source file. For example,
|
||
|
the second declaration below would be invalid: <pre>char *mychar; /* This declaration is valid */
|
||
|
char mychar; /* But this one is invalid */
|
||
|
</pre>
|
||
|
</li>
|
||
|
<li>When a host variable is referenced within an SQL statement, that host
|
||
|
variable must be referenced exactly as declared, with the exception of pointers
|
||
|
to NUL-terminated character arrays. For example, the following declaration
|
||
|
required parentheses: <pre>char (*mychara)[20]; /* ptr to char array of 20 bytes */</pre>
|
||
|
<p>However,
|
||
|
the parentheses are not allowed when the host variable is referenced in an
|
||
|
SQL statement, such as a SELECT: </p>
|
||
|
<pre>EXEC SQL <strong>SELECT</strong> name <strong>INTO</strong> :*mychara <strong>FROM</strong> mytable;</pre>
|
||
|
</li>
|
||
|
<li>Only the asterisk can be used as an operator over a host variable name.</li>
|
||
|
<li>The maximum length of a host variable name is affected by the number of
|
||
|
asterisks specified, as these asterisks are considered part of the name.</li>
|
||
|
<li>Pointers to structures are not usable as host variables except for variable
|
||
|
character structures. Also, pointer fields in structures are not usable as
|
||
|
host variables.</li>
|
||
|
<li>SQL requires that all specified storage for based host variables be allocated.
|
||
|
If the storage is not allocated, unpredictable results can occur.</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<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>
|