|
The QMTxn() function starts, commits or aborts a transaction on the server.
The function takes a single argument, Mode, as the action to be performed. This may be:
| 1 | Start a transaction. Equivalent to use of the QMBasic TRANSACTION START statement. |
| 2 | Commit a durable transaction. Equivalent to use of the QMBasic TRANSACTION COMMIT statement. |
| 3 | Abort a transaction. Equivalent to use of the QMBasic TRANSACTION ABORT statement. |
| 4 | Commit a non-durable transaction. Equivalent to use of the QMBasic TRANSACTION COMMIT statement in a program compiled with the NON.DURABLE.TXN setting of the $MODE compiler directive. |
The example program fragments below read two records, apply an update such as transferring funds from one client to the other, and then write both records. By using a transaction, the two updates are applied together. A real program would include error handling.
QMTxn(Mode)
QMTxn(1);
Rec1 = QMReadu(fClients, Client1, TRUE, &Err);
Rec2 = QMReadu(fClients, Client2, TRUE, &Err);
...processing...
QMWrite(fClients, Client1, Rec1);
QMWrite(fClients, Client2, Rec2);
QMTxn(2);
QMFree(Rec);
QMFree(Rec2);
Note the use of QMFree() to release dynamically allocated memory in this example.
|
QMTxn(Mode as Integer)
QMTxn(1)
Rec1 = QMReadu(fClients, Client1, True, Err)
Rec2 = QMReadu(fClients, Client2, True, Err)
...processing...
QMWrite fClients, Client1, Rec1
QMWrite fClients, Client2, Rec2
QMTxn(2)
|
Txn(Mode)
session->Txn(1)
Rec1 = session->Readu(fClients, Client1, @true, Err)
Rec2 = session->Readu(fClients, Client2, @true, Err)
...processing...
session->Write(fClients, Client1, Rec1)
session->Write(fClients, Client2, Rec2)
session->Txn(2)
|
Txn(Mode)
qm.Txn(1);
Rec1 = qm.Readu(fClients, Client1, true);
Rec2 = qm.Readu(fClients, Client2, true);
...processing...
qm.Write(fClients, Client1, Rec1);
qm.Write(fClients, Client2, Rec2);
qm.Txn(2);
|
Txn(Mode)
qm.Txn(1)
Rec1 = qm.Readu(fClients, Client1, true)
Rec2 = qm.Readu(fClients, Client2, true)
...processing...
qm.Write(fClients, Client1, Rec1)
qm.Write(fClients, Client2, Rec2)
qm.Txn(2)
|
|