202 lines
11 KiB
HTML
202 lines
11 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 xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="dc.language" scheme="rfc1766" 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. -->
|
||
|
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<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="keywords" content="COMMIT statement, COMMIT, SQL statements,
|
||
|
in COMMIT statement, WORK clause, unit of work, ending, commit point,
|
||
|
HOLD clause, locking" />
|
||
|
<title>COMMIT</title>
|
||
|
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="ic.css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
|
||
|
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
|
||
|
|
||
|
|
||
|
<a name="c4comit"></a>
|
||
|
<h2 id="c4comit"><a href="rbafzmst02.htm#ToC_816">COMMIT</a></h2><a id="idx1552" name="idx1552"></a><a id="idx1553" name="idx1553"></a><a id="idx1554" name="idx1554"></a><a id="idx1555" name="idx1555"></a><a id="idx1556" name="idx1556"></a><a id="idx1557" name="idx1557"></a><a id="idx1558" name="idx1558"></a>
|
||
|
<a name="comit"></a>
|
||
|
<p id="comit">The COMMIT statement ends a unit of work and commits the database changes
|
||
|
that were made by that unit of work.</p>
|
||
|
<a name="wq1156"></a>
|
||
|
<h3 id="wq1156"><a href="rbafzmst02.htm#ToC_817">Invocation</a></h3>
|
||
|
<p>This statement can be embedded in an application program or issued interactively.
|
||
|
It is an executable statement that can be dynamically prepared.</p>
|
||
|
<p>COMMIT is not allowed in a trigger if the trigger program and
|
||
|
the triggering program run under the same commitment definition. COMMIT is
|
||
|
not allowed in a procedure if the procedure is called on a connection
|
||
|
to a remote application server or if the procedure is defined as ATOMIC. COMMIT is
|
||
|
not allowed in a function.</p>
|
||
|
<a name="wq1157"></a>
|
||
|
<h3 id="wq1157"><a href="rbafzmst02.htm#ToC_818">Authorization</a></h3>
|
||
|
<p>None required.</p>
|
||
|
<a name="wq1158"></a>
|
||
|
<h3 id="wq1158"><a href="rbafzmst02.htm#ToC_819">Syntax</a></h3>
|
||
|
<a href="rbafzmstc4comit.htm#descomj"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn265.htm"
|
||
|
border="0" /></span><a href="#skipsyn-264"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a> .-WORK-.
|
||
|
>>-COMMIT--+------+--+------+----------------------------------><
|
||
|
'-HOLD-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-264" id="skipsyn-264"></a>
|
||
|
<a name="descomj"></a>
|
||
|
<h3 id="descomj"><a href="rbafzmst02.htm#ToC_820">Description</a></h3>
|
||
|
<p>The COMMIT statement ends the unit of work in which it is executed and
|
||
|
starts a new unit of work. It commits all changes made by SQL schema statements
|
||
|
(except DROP SCHEMA) and SQL data change statements during the unit of work.
|
||
|
For information on SQL schema statements and SQL data change statements see <a href="rbafzmststates.htm#schemastmt">Table 36</a> and <a href="rbafzmststates.htm#datachgstmt">Table 37</a>.</p>
|
||
|
<p>Connections in the release-pending state are ended. </p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">WORK </dt><a id="idx1559" name="idx1559"></a>
|
||
|
<dd>COMMIT WORK has the same effect as COMMIT.
|
||
|
</dd>
|
||
|
<dt class="bold">HOLD </dt><a id="idx1560" name="idx1560"></a><a id="idx1561" name="idx1561"></a>
|
||
|
<dd>Specifies a hold on resources. If specified, currently open cursors
|
||
|
are not closed and all resources acquired during the unit of work are held.
|
||
|
Locks on specific rows and objects implicitly acquired during the unit of
|
||
|
work are released.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>All implicitly acquired locks are released; except for object level locks
|
||
|
required for the cursors that are not closed.</p>
|
||
|
<p>All locators that are not held are released. For more information on held
|
||
|
locators, see <a href="rbafzmstholdloc.htm#holdloc">HOLD LOCATOR</a>.</p>
|
||
|
<a name="macomm"></a>
|
||
|
<h3 id="macomm"><a href="rbafzmst02.htm#ToC_821">Notes</a></h3>
|
||
|
<p><span class="bold">Recommended coding practices:</span> An explicit COMMIT
|
||
|
or ROLLBACK statement should be coded at the end of an application process.
|
||
|
Either an implicit commit or rollback operation will be performed at the end
|
||
|
of an application process depending on the application environment. Thus,
|
||
|
a portable application should explicitly execute a COMMIT or ROLLBACK before
|
||
|
execution ends in those environments where explicit COMMIT or ROLLBACK is
|
||
|
permitted.</p>
|
||
|
<p>An implicit COMMIT or ROLLBACK may be performed under the following circumstances.</p>
|
||
|
<ul>
|
||
|
<li>For the default activation group:
|
||
|
<ul>
|
||
|
<li>An implicit COMMIT is not performed when applications that run in the
|
||
|
default activation group end. Interactive SQL, Query Manager, and non-ILE
|
||
|
programs are examples of programs that run in the default activation group.</li>
|
||
|
<li>In order to commit work, you must issue a COMMIT.</li></ul></li>
|
||
|
<li>For non-default activation groups when the scope of the commitment definition
|
||
|
is to the activation group:
|
||
|
<ul>
|
||
|
<li>If the activation group ends normally, the commitment definition is implicitly
|
||
|
committed.</li>
|
||
|
<li>If the activation group ends abnormally, the commitment definition is
|
||
|
implicitly rolled back.</li></ul></li>
|
||
|
<li>Regardless of the type of activation group, if the scope of the commitment
|
||
|
definition is the job, an implicit commit is never performed.</li></ul>
|
||
|
<p><span class="bold">Effect of commit:</span> Commit without HOLD causes the
|
||
|
following to occur: </p>
|
||
|
<ul>
|
||
|
<li>Connections in the release-pending state are ended.
|
||
|
<p>For existing connections:
|
||
|
</p>
|
||
|
<ul>
|
||
|
<li>all open cursors that were declared with the WITH HOLD clause are preserved
|
||
|
and their current position is maintained, although a FETCH statement is required
|
||
|
before a Positioned UPDATE or Positioned DELETE statement can be executed.</li>
|
||
|
<li>all open cursors that were declared without the WITH HOLD clause are closed.</li></ul></li>
|
||
|
<li>All LOB locators are freed. Note that this is true even when the locators
|
||
|
are associated with LOB values retrieved via a cursor that has the WITH HOLD
|
||
|
property.</li>
|
||
|
<li>All locks acquired by the LOCK TABLE statement are released. All implicitly
|
||
|
acquired locks are released, except for those required for the cursors that
|
||
|
were not closed.</li></ul>
|
||
|
<p><span class="bold">Row lock limit:</span> A unit of work can include the processing
|
||
|
of up to 4 million rows, including rows retrieved during a SELECT or FETCH
|
||
|
statement<sup class="fn"><a href="rbafzmstc4comit.htm#fn25">61</a></sup>, and rows inserted, deleted, or updated as part
|
||
|
of INSERT, DELETE, and UPDATE statements.<sup class="fn"><a href="rbafzmstc4comit.htm#fn26">62</a></sup></p>
|
||
|
<p><span class="bold">Unaffected statements:</span> The commit and rollback operations
|
||
|
do not affect the DROP SCHEMA statement, and this statement is not, therefore,
|
||
|
allowed in an application program that also specifies COMMIT(*CHG), COMMIT(*CS),
|
||
|
COMMIT(*ALL), or COMMIT(*RR).</p>
|
||
|
<a name="cmtdef"></a>
|
||
|
<p id="cmtdef"><span class="bold">Commitment definition use:</span> The commitment
|
||
|
definition used by SQL is determined as follows: </p>
|
||
|
<ul>
|
||
|
<li>If the activation group of the program calling SQL is already using an
|
||
|
activation group level commitment definition, then SQL uses that commitment
|
||
|
definition.</li>
|
||
|
<li>If the activation group of the program calling SQL is using the job level
|
||
|
commitment definition, then SQL uses the job level commitment definition.</li>
|
||
|
<li>If the activation group of the program calling SQL is not currently using
|
||
|
a commitment definition but the job commitment definition is started, then
|
||
|
SQL uses the job commitment definition.</li>
|
||
|
<li>If the activation group of the program calling SQL is not currently using
|
||
|
a commitment definition and the job commitment definition is not started,
|
||
|
then SQL implicitly starts a commitment definition. SQL uses the Start Commitment
|
||
|
Control (STRCMTCTL) command with:
|
||
|
<ul>
|
||
|
<li>A CMTSCOPE(*ACTGRP) parameter</li>
|
||
|
<li>A LCKLVL parameter based on the COMMIT option specified on either the
|
||
|
CRTSQLxxx, STRSQL, or RUNSQLSTM commands. In REXX, the LCKLVL parameter is
|
||
|
based on the commit option in the SET OPTION statement.</li></ul></li></ul>
|
||
|
<a name="commitexamp"></a>
|
||
|
<h3 id="commitexamp"><a href="rbafzmst02.htm#ToC_822">Example</a></h3>
|
||
|
<p>In a C program, transfer a certain amount of commission (COMM) from one
|
||
|
employee (EMPNO) to another in the EMPLOYEE table. Subtract the amount from
|
||
|
one row and add it to the other. Use the COMMIT statement to ensure that no
|
||
|
permanent changes are made to the database until both operations are completed
|
||
|
successfully. </p>
|
||
|
<pre class="xmp">void main ()
|
||
|
{
|
||
|
|
||
|
EXEC SQL <span class="bold">BEGIN DECLARE SECTION</span>;
|
||
|
decimal(5,2) AMOUNT;
|
||
|
char FROM_EMPNO[7];
|
||
|
char TO_EMPNO[7];
|
||
|
EXEC SQL <span class="bold">END DECLARE SECTION</span>;
|
||
|
EXEC SQL <span class="bold">INCLUDE SQLCA</span>;
|
||
|
EXEC SQL <span class="bold">WHENEVER SQLERROR GOTO</span> SQLERR;
|
||
|
...
|
||
|
EXEC SQL <span class="bold">UPDATE</span> EMPLOYEE
|
||
|
<span class="bold">SET</span> COMM = COMM - :AMOUNT
|
||
|
<span class="bold">WHERE</span> EMPNO = :FROM_EMPNO;
|
||
|
EXEC SQL <span class="bold">UPDATE</span> EMPLOYEE
|
||
|
<span class="bold">SET</span> COMM = COMM + :AMOUNT
|
||
|
<span class="bold">WHERE</span> EMPNO = :TO_EMPNO;
|
||
|
FINISHED:
|
||
|
EXEC SQL <span class="bold">COMMIT WORK</span>;
|
||
|
return;
|
||
|
|
||
|
SQLERR:
|
||
|
...
|
||
|
EXEC SQL <span class="bold">WHENEVER SQLERROR CONTINUE</span>; /* continue if error on rollback */
|
||
|
EXEC SQL <span class="bold">ROLLBACK WORK</span>;
|
||
|
return;
|
||
|
}</pre><a id="idx1562" name="idx1562"></a><a id="idx1563" name="idx1563"></a>
|
||
|
<hr /><div class="fnnum"><a id="fn25" name="fn25">61</a>.</div>
|
||
|
<div class="fntext">This limit also includes:
|
||
|
<ul>
|
||
|
<li>Any rows accessed or changed through files opened under commitment control
|
||
|
through high-level language file processing</li>
|
||
|
<li>Any rows deleted, updated, or inserted as a result of a trigger or CASCADE,
|
||
|
SET NULL, or SET DEFAULT referential integrity delete rule.</li></ul></div><div class="fnnum"><a id="fn26" name="fn26">62</a>.</div>
|
||
|
<div class="fntext">Unless you specified COMMIT(*CHG) or COMMIT(*CS),
|
||
|
in which case these rows are not included in this total.</div>
|
||
|
<br />
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstcomnt.htm">Previous Page</a> | <a href="rbafzmstconj1.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
|
||
|
<a href="rbafzmstindex.htm#index">Index</a> ]
|
||
|
|
||
|
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
|
||
|
</body>
|
||
|
</html>
|