Here’s how to use rollback() function.
Description:
Roll back a database transaction.
Syntax:
db.rollback (spn)
Note:
The function rolls back the transaction to the specified savepoint. Rollback all transactions when the parameter is omitted.
Parameter:
db |
Database connection |
spn |
Savepoint name |
Example:
|
A |
B |
|
1 |
=file("D://files//student.txt") |
|
|
2 |
=A1.import@t() |
|
|
3 |
=connect@e("demo") |
|
Establish a connection and automatically control the commit and rollback operations |
4 |
>A3.execute@k(A2,"update STUDENTS2 set NAME=?,GENDER=?,AGE=? where ID=?",NAME,GENDER,AGE,ID) |
|
The transaction is not committed |
5 |
=A3.error() |
|
Get the error code generated from the execution of the previous SQL statement |
6 |
if A5==0 |
>A3.commit() |
Commit if there is not an error |
7 |
else |
>A3.rollback() |
Roll back if there is an error |
8 |
>A3.close() |
|
Close the connection |
Related function:
Description:
Restore a composite table file to the previous state when update error happens.
Syntax:
f.rollback() |
Note:
The function restores a composite table file’s entity table to the previous state when an error happens during adding, deleting, and modifying data.
Note: When error happens at the update of a composite table file, a file error prompt will appear if you use f.open() to open the composite table file. In this case rollback() is needed to do a rollback action. Different from the rollback operation on an ordinary database, there isn’t a special rollback mechanism for composite tables, users need to call f.rollback() function to to do the rollback manually.
Parameter:
f |
A composite table file or a homo-name files group |
Return value:
Boolean
Example:
|
A |
|
1 |
=file("D:/ckv.ctx") |
There is an error about ckv.ctx in executing T.update(P:D), so error is reported when f.open() is used: Error about ckv.ctx, call f.rollback() to restore. |
2 |
=A1.rollback() |
Restore composite table file ckv.ctx to the state before update is performed |