DB_START_TRANSACTION()

Starts a transaction level.

Syntax

DB_START_TRANSACTION()
  RETURNING result INTEGER

Usage

This function encapsulates the BEGIN WORK instruction to start a transaction, in order to implement nested transactions.
Note: The transaction encapsulation functions are provided for special cases, when several nested functions of your program implement SQL instructions that must be committed in a unique transaction. In general, you should not need those functions and simply use the standard BEGIN WORK / COMMIT WORK / ROLLBACK WORK instructions.

On most database engines, you can only have a unique transaction, that you start with BEGIN WORK and you end with COMMIT WORK or ROLLBACK WORK. But in a complex program, you may have nested function calls doing several SQL transactions.

The transaction management functions execute a real transaction instruction only if the number of subsequent start/end calls of these functions matches.

DEFINE s INTEGER

MAIN
  DATABASE mydb
  LET s = DB_START_TRANSACTION() -- real BEGIN WORK
  CALL do_update()
  LET s = DB_FINISH_TRANSACTION(TRUE) -- real COMMIT WORK
END MAIN

FUNCTION do_update()
  LET s = DB_START_TRANSACTION()
  UPDATE customer SET cust_status = 'X'
  LET s = DB_FINISH_TRANSACTION(TRUE)
END FUNCTION