rollback()

Read(2356) Label: rollback, database,

Here’s how to use rollback() function.

db.rollback()

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

=create(ID,NAME,GENDER,AGE).record([3, "AAA","F",14])

 

 

2

=connect@e("demo")

 

Establish a connection and use @e option to automatically control the commit and rollback operations.

3

=A2.savepoint("s1")

 

set the savepoint named s1.

4

>A2.execute@k(A1,"update STUDENTS2 set NAME=?,GENDER=?,AGE=? where ID=?",NAME,GENDER,AGE,ID)

 

Execute the sql statement, update table STYDENTS2 according to A1’s records, and use @k option to not to commit the transaction.

5

=A2.error()

 

Get the error code generated from the execution of the previous SQL statement.

6

if A5==0

>A2.commit()

Commit if there is not an error.

7

else

>A2.rollback("s1")

Roll back if there is an error.

8

>A2.close()

 

Close the connection.

Related function:

db.close()

db.error()

db.commit()

connect()

f.rollback()

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.