Transaction Processing Considerations

Example:

Building Up a Multiple-Statement Transaction Request

Describing a Transaction

Although many asynchronous requests contain one SQL statement or an isolated stored procedure call, application programs are free to submit requests of arbitrary complexity. Whether a request consists of one or many statements, it constitutes a single UOW. Application programs define transaction boundaries by invoking EDASQL build, EDARPC, and EDASQL execute in various combinations.

The application signals the beginning of a transaction by calling EDASQL or EDARPC when the outgoing message buffer associated with the controlling connection SCB is empty. The buffer is empty immediately after a server connection is made and immediately after a message has been transmitted.

Applications signal end-of-transaction and transmit messages by calling EDASQL with the execute parameter set to EDA_EXECUTE_EXECUTE. When the API receives an end-of-transaction signal, it appends data (if any) to its request buffer and deposits the contents of the buffer in an outgoing message queue. Since each such message represents a single transaction or UOW, EDA_EXECUTE_EXECUTE can be taken to mean "COMMIT WORK."


Top of page

Example: Building Up a Multiple-Statement Transaction Request

The following example demonstrates how to build up a three-statement transaction request.

.
.
.
xcode = EDA_EXECUTE_BUILD; /* Accumulate two statement strings. */
EDASQL (&scb1, &stmt1, &slen1, &est1, &est2, &passwd, &plen, &xcode);
if (scb1.status != EDA_SUCCESS) process_error(&scb1);
EDASQL (&scb1, &stmt2, &slen1, &est1, &est2, &passwd, &plen, &xcode);
if (scb1.status != EDA_SUCCESS) process_error(&scb1);
xcode = EDA_EXECUTE_EXECUTE; /* This time, execute the string; commit
the transaction. */
EDASQL (&scb1, &stmt3, &slen1, &est1, &est2, &passwd, &plen, &xcode);
if (scb1.status != EDA_SUCCESS) process_error(&scb1);

EDARPC can build, but not transmit, transaction requests.


Top of page

Example: Describing a Transaction

The following example shows a transaction composed of a query, a stored procedure call, and an EDASQL call with a null statement parameter to transmit the message.

.
.
.
xcode = EDA_APPEND_TO_MSG; /* Build the string. */
EDASQL (&scb1, &stmt1, &slen1, &est1, &est2, &passwd, &plen, &xcode);
/* Add the query */
if (scb1.status != EDA_SUCCESS) process_error(&scb1);
EDARPC (&scb1, &procname, &lnprocname, &parms, &lnparms);
/* Add the RPC */
if (scb1.status != EDA_SUCCESS) process_error(&scb1);
xcode = EDA_EXECUTE_EXECUTE; /* This time, execute the string; commit
the transaction. */
zero = 0;
EDASQL (&scb1, NULL, &zero, &est1, &est2, &passwd, &plen, &xcode);
/* Add the query */
if (scb1.status != EDA_SUCCESS) process_error(&scb1);

iWay Software