Here’s how to use the commit() function.
Description:
Commit the database transaction manually.
Syntax:
db.commit()
Note:
The function commits the transaction manually, which is the same as commit() of the Connection class in Java.
Parameter:
| 
   db  | 
  
  
   Data source connection.  | 
  
 
Option:
| 
   @k  | 
  
  
   After the execution is completed, the transaction won't be committed. If this option is omitted, the transaction will be committed.  | 
  
 
Example:
| 
   
  | 
  
  
   A  | 
  
  
   B  | 
  
  
   
  | 
  
 
| 
   1  | 
  
  
   =create(ID,NAME,GENDER,AGE).record([3, "AAA","F",14])  | 
  
  
   
  | 
  
  
   
  | 
  
 
| 
   2  | 
  
  
   =connect@e("demo")  | 
  
  
   
  | 
  
  
   Create the connection and automatically control the commit and rollback operations through @e option.  | 
  
 
| 
   3  | 
  
  
   >A2.execute@k(A1,"update STUDENTS2 set NAME=?,GENDER=?,AGE=? where ID=?",NAME,GENDER,AGE,ID)  | 
  
  
   
  | 
  
  
   Execute the sql statement and update table STYDENTS2 according to A1’s records, during which @k option is used to not to commit the transaction.  | 
  
 
| 
   4  | 
  
  
   =A2.error()  | 
  
  
   
  | 
  
  
   Read the error code generated by the execution of the previous sql.  | 
  
 
| 
   5  | 
  
  
   if A4==0  | 
  
  
   >A2.commit()  | 
  
  
   Commit if there isn’t an error.  | 
  
 
| 
   6  | 
  
  
   else  | 
  
  
   >A2.rollback()  | 
  
  
   Roll back if there is an error.  | 
  
 
| 
   7  | 
  
  
   >A2.close()  | 
  
  
   
  | 
  
  
   Close the connection.  | 
  
 
Related function: