101 lines
5.9 KiB
HTML
101 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="reference" />
|
||
|
<meta name="DC.Title" content="Use arrays of host structures in C and C++ applications that use SQL" />
|
||
|
<meta name="abstract" content="In C and C++ programs, you can define a host structure array that has the dimension attribute. Host structure arrays have a maximum of two levels, even though the array might occur within a multiple-level structure. Another structure is not needed if a varying-length character string or a varying-length graphic string is not used." />
|
||
|
<meta name="description" content="In C and C++ programs, you can define a host structure array that has the dimension attribute. Host structure arrays have a maximum of two levels, even though the array might occur within a multiple-level structure. Another structure is not needed if a varying-length character string or a varying-length graphic string is not used." />
|
||
|
<meta name="DC.subject" content="arrays of host structures, using arrays, C, C++, host structure, C program, arrays, declaring, C++ program" />
|
||
|
<meta name="keywords" content="arrays of host structures, using arrays, C, C++, host structure, C program, arrays, declaring, C++ program" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzajpc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzajphoststrucarrayc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzajphoststrucindicatorc.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="rzajphostarrayc" />
|
||
|
<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 arrays of host structures in C and C++ applications that use SQL</title>
|
||
|
</head>
|
||
|
<body id="rzajphostarrayc"><a name="rzajphostarrayc"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Use arrays of host structures in C and C++ applications that use SQL</h1>
|
||
|
<div><p>In C and C++ programs, you can define a host structure array that
|
||
|
has the dimension attribute. Host structure arrays have a maximum of two levels,
|
||
|
even though the array might occur within a multiple-level structure. Another
|
||
|
structure is not needed if a varying-length character string or a varying-length
|
||
|
graphic string is not used.</p>
|
||
|
<div class="section"><p>In this C example, </p>
|
||
|
<pre>struct {
|
||
|
_Packed struct{
|
||
|
char c1_var[20];
|
||
|
short c2_var;
|
||
|
} b_array[10];
|
||
|
} a_struct;
|
||
|
</pre>
|
||
|
</div>
|
||
|
<div class="section"><p>and in this C++ example, </p>
|
||
|
<pre>#pragma pack(1)
|
||
|
struct {
|
||
|
struct{
|
||
|
char c1_var[20];
|
||
|
short c2_var;
|
||
|
} b_array[10];
|
||
|
} a_struct;
|
||
|
#pragma pack()</pre>
|
||
|
<p>the following are true: </p>
|
||
|
<ul><li>All of the members in b_array must be valid variable declarations.</li>
|
||
|
<li>The _Packed attribute must be specified for the struct tag.</li>
|
||
|
<li>b_array is the name of an array of host structures containing the members
|
||
|
c1_var and c2_var.</li>
|
||
|
<li>b_array may only be used on the blocked forms of FETCH statements and
|
||
|
INSERT statements.</li>
|
||
|
<li>c1_var and c2_var are not valid host variables in any SQL statement.</li>
|
||
|
<li>A structure cannot contain an intermediate level structure.</li>
|
||
|
</ul>
|
||
|
<p> For example, in C you can retrieve 10 rows from the cursor with: </p>
|
||
|
<pre>_Packed struct {char first_initial;
|
||
|
char middle_initial;
|
||
|
_Packed struct {short lastname_len;
|
||
|
char lastname_data[15];
|
||
|
} lastname;
|
||
|
double total_salary;
|
||
|
} employee_rec[10];
|
||
|
struct { short inds[4];
|
||
|
} employee_inds[10];
|
||
|
…
|
||
|
EXEC SQL <strong>DECLARE</strong> C1 <strong>CURSOR</strong> FOR
|
||
|
<strong>SELECT SUBSTR</strong>(FIRSTNME,1,1), MIDINIT, LASTNAME,
|
||
|
SALARY+BONUS+COMM
|
||
|
<strong>FROM</strong> CORPDATA.EMPLOYEE;
|
||
|
EXEC SQL <strong>OPEN</strong> C1;
|
||
|
EXEC SQL <strong>FETCH</strong> C1 <strong>FOR</strong> 10 <strong>ROWS INTO</strong> :employee_rec:employee_inds;
|
||
|
…</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rzajphoststrucarrayc.htm">Host structure array in C and C++ applications that use SQL</a></strong><br />
|
||
|
The following figure shows the valid syntax for host structure array declarations.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rzajphoststrucindicatorc.htm">Host structure array indicator structure in C and C++ applications that use SQL</a></strong><br />
|
||
|
The figure shows the valid syntax for host structure array indicator structure declarations.</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>
|