245 lines
16 KiB
HTML
245 lines
16 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="concept" />
|
||
|
<meta name="DC.Title" content="Differences between DB2 UDB CLI and embedded SQL" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzadpbackground.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rzadpdifferences" />
|
||
|
<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>Differences between DB2 UDB CLI and embedded SQL</title>
|
||
|
</head>
|
||
|
<body id="rzadpdifferences"><a name="rzadpdifferences"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Differences between DB2 UDB CLI and embedded SQL</h1>
|
||
|
<div><p>An application that uses an embedded SQL interface requires a precompiler
|
||
|
to convert the SQL statements into code. Code is compiled, bound to the database,
|
||
|
and processed. In contrast, a DB2<sup>®</sup> UDB CLI application does not require
|
||
|
precompilation or binding, but instead uses a standard set of functions to
|
||
|
run SQL statements and related services at run time.</p>
|
||
|
<p>This difference is important because, traditionally, precompilers
|
||
|
have been specific to a database product, which effectively ties your applications
|
||
|
to that product. DB2 UDB CLI enables you to write portable applications
|
||
|
that are independent of any particular database product. This independence
|
||
|
means that a DB2 UDB
|
||
|
CLI application does not need to be recompiled or rebound to access-different
|
||
|
database products. An application selects the appropriate database products
|
||
|
at run time.</p>
|
||
|
<div class="p">DB2 UDB
|
||
|
CLI and embedded SQL also differ in the following ways: <ul><li>DB2 UDB CLI does not require the explicit
|
||
|
declaration of cursors. DB2 UDB CLI generates them as needed. The application
|
||
|
can then use the generated cursor in the normal cursor fetch model for multiple
|
||
|
row <samp class="codeph">SELECT</samp> statements and positioned <samp class="codeph">UPDATE</samp> and <samp class="codeph">DELETE</samp> statements.</li>
|
||
|
<li>The <samp class="codeph">OPEN</samp> statement is not necessary in DB2 UDB CLI. Instead,
|
||
|
the processing of a <samp class="codeph">SELECT</samp> automatically causes a cursor
|
||
|
to be opened.</li>
|
||
|
<li>Unlike embedded SQL, DB2 UDB CLI allows the use of parameter markers on the
|
||
|
equivalent of the <samp class="codeph">EXECUTE IMMEDIATE</samp> statement (the <samp class="codeph">SQLExecDirect()</samp> function).</li>
|
||
|
<li>A <samp class="codeph">COMMIT</samp> or <samp class="codeph">ROLLBACK</samp> in DB2 UDB CLI is
|
||
|
issued through the <samp class="codeph">SQLTransact()</samp> or <samp class="codeph">SQLEndTran()</samp> function
|
||
|
call rather than by passing it as an SQL statement.</li>
|
||
|
<li>DB2 UDB
|
||
|
CLI manages statement-related information on behalf of the application, and
|
||
|
provides a <em>statement handle</em> to refer to it as an abstract object. This
|
||
|
handle avoids the need for the application to use product-specific data structures.</li>
|
||
|
<li>Similar to the statement handle, the <em>environment handle</em> and <em>connection
|
||
|
handle</em> provide a means to refer to all global variables and connection
|
||
|
specific information.</li>
|
||
|
<li>DB2 UDB
|
||
|
CLI uses the SQLSTATE values defined by the X/Open SQL CAE specification.
|
||
|
Although the format and many of the values are consistent with values that
|
||
|
are used by the IBM<sup>®</sup> relational
|
||
|
database products, there are differences.</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="p">Despite these differences, there is an important common concept between
|
||
|
embedded SQL and DB2 UDB CLI: <ul><li>DB2 UDB
|
||
|
CLI can process any SQL statement that can be prepared dynamically in embedded
|
||
|
SQL. This is guaranteed because DB2 UDB CLI does not actually process the
|
||
|
SQL statement itself, but passes it to the Database Management System (DBMS)
|
||
|
for dynamic processing.</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="p"><a href="#rzadpdifferences__sqlsts">Table 1</a> lists each SQL statement,
|
||
|
and whether it can be processed using DB2 UDB CLI.
|
||
|
<div class="tablenoborder"><a name="rzadpdifferences__sqlsts"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzadpdifferences__sqlsts" width="100%" frame="border" border="1" rules="all"><caption>Table 1. SQL statements</caption><thead align="left"><tr><th align="left" valign="top" width="42.92929292929293%" id="d0e165">SQL statement</th>
|
||
|
<th align="left" valign="top" width="14.14141414141414%" id="d0e167">Dyn <sup>1</sup></th>
|
||
|
<th align="left" valign="top" width="42.92929292929293%" id="d0e171">CLI <sup>3</sup></th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody><tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">ALTER TABLE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">BEGIN DECLARE SECTION <sup>2</sup></td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "> </td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CALL</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X </td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CLOSE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLFreeStmt()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">COMMENT ON</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">COMMIT</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLTransact()</samp>, <samp class="codeph">SQLEndTran()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CONNECT (Type 1)</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLConnect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CONNECT (Type 2)</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLConnect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CREATE INDEX</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CREATE TABLE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">CREATE VIEW</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">DECLARE CURSOR <sup>b</sup></td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLAllocStmt()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">DELETE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">DESCRIBE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLDescribeCol()</samp>, <samp class="codeph">SQLColAttributes()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">DISCONNECT</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLDisconnect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">DROP</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">END DECLARE SECTION <sup>b</sup></td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "> </td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">EXECUTE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLExecute()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">EXECUTE IMMEDIATE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLExecDirect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">FETCH</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLFetch()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">GRANT</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">INCLUDE <sup>b</sup></td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "> </td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">INSERT</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">LOCK TABLE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">OPEN</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLExecute()</samp>, <samp class="codeph">SQLExecDirect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">PREPARE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLPrepare()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">RELEASE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLDisconnect()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">REVOKE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">ROLLBACK</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "><samp class="codeph">SQLTransact()</samp>, <samp class="codeph">SQLEndTran()</samp></td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">SELECT</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">SET CONNECTION</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "> </td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">UPDATE</td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 ">X</td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 ">X</td>
|
||
|
</tr>
|
||
|
<tr><td align="left" valign="top" width="42.92929292929293%" headers="d0e165 ">WHENEVER <sup>2</sup></td>
|
||
|
<td align="left" valign="top" width="14.14141414141414%" headers="d0e167 "> </td>
|
||
|
<td align="left" valign="top" width="42.92929292929293%" headers="d0e171 "> </td>
|
||
|
</tr>
|
||
|
<tr><td colspan="3" align="left" valign="top" headers="d0e165 d0e167 d0e171 "><div class="note"><span class="notetitle">Notes:</span> <dl><dt class="dlterm"><sup>1</sup></dt>
|
||
|
<dd><em>Dyn</em> stands for dynamic. All statements in this list can be coded
|
||
|
as static SQL, but only those marked with <strong>X</strong> can be coded as dynamic
|
||
|
SQL.</dd>
|
||
|
<dt class="dlterm"><sup>2</sup></dt>
|
||
|
<dd>This is a nonprocessable statement.</dd>
|
||
|
<dt class="dlterm"><sup>3</sup></dt>
|
||
|
<dd>An X indicates that this statement can be processed using either <samp class="codeph">SQLExecDirect()</samp> or <samp class="codeph">SQLPrepare()</samp> and <samp class="codeph">SQLExecute()</samp>. If there is an equivalent DB2 UDB CLI function, the function name
|
||
|
is listed.</dd>
|
||
|
</dl>
|
||
|
</div>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
<p>Each DBMS might have additional statements that can be
|
||
|
dynamically prepared, in which case DB2 UDB CLI passes them to the DBMS. There
|
||
|
is one exception, COMMIT and ROLLBACK can be dynamically prepared by some
|
||
|
DBMSs but are not passed. Instead, the <samp class="codeph">SQLTransact()</samp> or <samp class="codeph">SQLEndTran()</samp> should
|
||
|
be used to specify either COMMIT or ROLLBACK.</p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadpbackground.htm" title="Learn about the basics of the DB2 UDB CLI, how it compares to embedded SQL, and how to select the best interface for your programming needs.">Get started with DB2 UDB CLI</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|