ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafydrdacursor.htm

80 lines
4.7 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="Cursors and prepared statements" />
<meta name="abstract" content="Cursors and prepared statements are scoped to the compilation unit and also to the connection." />
<meta name="description" content="Cursors and prepared statements are scoped to the compilation unit and also to the connection." />
<meta name="DC.subject" content="distributed unit of work, cursors, prepared statements, cursor, distributed unit of work, prepared statement, examples, cursor in DUW program" />
<meta name="keywords" content="distributed unit of work, cursors, prepared statements, cursor, distributed unit of work, prepared statement, examples, cursor in DUW program" />
<meta name="DC.Relation" scheme="URI" content="rbafyduwex.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="rbafydrdacursor" />
<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>Cursors and prepared statements</title>
</head>
<body id="rbafydrdacursor"><a name="rbafydrdacursor"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Cursors and prepared statements</h1>
<div><p>Cursors and prepared statements are scoped to the compilation unit
and also to the connection. </p>
<div class="section"><p>Scoping to the compilation unit means that a program called from
another separately compiled program cannot use a cursor or prepared statement
that was opened or prepared by the calling program. Scoping to the connection
means that each connection within a program can have its own separate instance
of a cursor or prepared statement.</p>
</div>
<div class="section"><p>The following distributed unit of work example shows how the same
cursor name is opened in two different connections, resulting in two instances
of cursor C1.</p>
</div>
<div class="example"> <div class="fignone"><span class="figcap">Figure 1. Example of cursors in a DUW program</span><pre> .....
EXEC SQL <strong>DECLARE</strong> C1 <strong>CURSOR FOR</strong>
<strong>SELECT * FROM</strong> CORPDATA.EMPLOYEE;
/* Connect to local and open C1 */
EXEC SQL <strong>CONNECT TO</strong> LOCALSYS;
EXEC SQL <strong>OPEN</strong> C1;
/* Connect to the remote system and open C1 */
EXEC SQL <strong>CONNECT TO</strong> SYSA;
EXEC SQL <strong>OPEN</strong> C1;
/* Keep processing until done */
while (NOT_DONE) {
/* Fetch a row of data from the local system */
EXEC SQL <strong>SET CONNECTION</strong> LOCALSYS;
EXEC SQL <strong>FETCH</strong> C1 <strong>INTO</strong> :local_emp_struct;
/* Fetch a row of data from the remote system */
EXEC SQL <strong>SET CONNECTION</strong> SYSA;
EXEC SQL <strong>FETCH</strong> C1 <strong>INTO</strong> :rmt_emp_struct;
/* Process the data */
.....
}
/* Close the cursor on the remote system */
EXEC SQL <strong>CLOSE</strong> C1;
/* Close the cursor on the local system */
EXEC SQL <strong>SET CONNECTION</strong> LOCALSYS;
EXEC SQL <strong>CLOSE</strong> C1;
.....</pre>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyduwex.htm" title="Distributed unit of work (DUW) allows access to multiple application servers within the same unit of work. Each SQL statement can access only one application server. Using distributed unit of work allows changes at multiple applications servers to be committed or rolled back within a single unit of work.">Distributed unit of work</a></div>
</div>
</div>
</body>
</html>