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

103 lines
5.8 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="Use 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, which is a named set of elementary C or C++ variables." />
<meta name="description" content="In C and C++ programs, you can define a host structure, which is a named set of elementary C or C++ variables." />
<meta name="DC.subject" content="C program, host structure, declaring, C++ program, C, C++" />
<meta name="keywords" content="C program, host structure, declaring, C++ program, C, C++" />
<meta name="DC.Relation" scheme="URI" content="rzajpc.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajphoststrucdeclaration.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajphoststrucindicator.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="rzajphoststrucc" />
<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 host structures in C and C++ applications that use SQL</title>
</head>
<body id="rzajphoststrucc"><a name="rzajphoststrucc"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Use host structures in C and C++ applications that use SQL</h1>
<div><p>In C and C++ programs, you can define a <em>host structure</em>,
which is a named set of elementary C or C++ variables.</p>
<div class="section"><p>Host structures have a maximum of two levels, even though the
host structure might itself occur within a multilevel structure. An exception
is the declaration of a varying-length string, which requires another structure.</p>
</div>
<div class="section"><p>A host structure name can be a group name whose subordinate levels
name elementary C or C++ variables. For example: </p>
<pre> struct {
struct {
char c1;
char c2;
} b_st;
} a_st;</pre>
</div>
<div class="section"><p>In this example, b_st is the name of a host structure consisting
of the elementary items c1 and c2.</p>
</div>
<div class="section"><p>You can use the structure name as a shorthand notation for a list
of scalars, but only for a two-level structure. You can qualify a host variable
with a structure name (for example, structure.field). Host structures are
limited to two levels. (For example, in the above host structure example,
the a_st cannot be referred to in SQL.) A structure cannot contain an intermediate
level structure. In the previous example, a_st could not be used as a host
variable or referred to in an SQL statement. A host structure for SQL data
has two levels and can be thought of as a named set of host variables. After
the host structure is defined, you can refer to it in an SQL statement instead
of listing the several host variables (that is, the names of the host variables
that make up the host structure).</p>
</div>
<div class="section"><p>For example, you can retrieve all column values from selected
rows of the table CORPDATA.EMPLOYEE with: </p>
<pre> struct { char empno[7];
struct { short int firstname_len;
char firstname_text[12];
} firstname;
char midint,
struct { short int lastname_len;
char lastname_text[15];
} lastname;
char workdept[4];
} pemp1;
.....
strcpy("000220",pemp1.empno);
.....
exec sql
<strong>SELECT</strong> *
<strong>INTO</strong> :pemp1
<strong>FROM</strong> corpdata.employee
<strong>WHERE</strong> empno=:pemp1.empno;</pre>
</div>
<div class="section"><p>Notice that in the declaration of pemp1, two varying-length string
elements are included in the structure: firstname and lastname.</p>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzajphoststrucdeclaration.htm">Host structure declarations in C and C++ applications that use SQL</a></strong><br />
These figures show the valid syntax for host structure declarations.</li>
<li class="ulchildlink"><strong><a href="rzajphoststrucindicator.htm">Host structure indicator array in C and C++ applications that use SQL</a></strong><br />
This figure shows the valid syntax for host structure indicator array 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>