rollback()

Read(234) 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.

Parameters:

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 functions:

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()

Restore the unencrypted composite table file

f.rollback(p)

Restore the encrypted composite table file; parameter p is the write password

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.

Parameters:

f

A composite table file

p

Write password

Return value:

Boolean

Example:

 

A

 

1

=file("D:/ckv.ctx")

There is an eror about ckv.ctx in executing T.update(P), so error is reported when f.create() 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

3

=file("D:/ckv1.ctx")

Same as A1

4

=A2.rollback("!@#123")

Restore the encrypted composite table file ckv1.ctx to the state before update is performed