db.rollback()

Read(1256) Label: rollback, database,

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