commit

Description

Ends a transaction, preserving changes made to the database during the transaction.

Syntax

exec sql [at connection_name]   
commit [transaction | tran | work] 
[transaction_name];

Parameters

transaction | trans | work

The keywords transaction, trans, and work are interchangeable in the rollback statement, except that only work is ANSI-compliant.

transaction_name

A name assigned to the transaction.

Examples

Example 1

/*
 ** Using chained transaction mode, 
 ** synchronize tables on two servers
 */
 exec sql begin declare section;
     char     title_id[7];
     int      num_sold;
 exec sql end declare section;
     long     SQLCODE;
     ...
 try_update:
 exec sql whenever sqlerror goto abort_tran;
 
 exec sql at connect1 select sum(qty)
     into :num_sold
     from salesdetail
     where title_id = :title_id;
 exec sql at connect2 update current_sales
     set num_sold = :num_sold
     where title_id = :title_id;
exec sql at connect2 commit work;
 exec sql at connect1 commit work;
 return;
abort_tran:
 printf("oops, should have used 2-phase commit\n");
 exec sql whenever sqlerror continue;
 exec sql at connect2 rollback work;
 exec sql at connect1 rollback work;
 goto try_update;

Usage

See also

begin transaction, commit work, rollback transaction, rollback work