Freigeben über


SQLROLLBACK( ) Function

Cancels any changes made during the current transaction.

SQLROLLBACK(nConnectionHandle)

Return Values

Numeric

Parameters

  • nConnectionHandle
    Specifies the connection handle to the data source returned by SQLCONNECT( ).

Remarks

SQLROLLBACK( ) returns 1 if the transaction is successfully rolled back; otherwise, it returns -1. If SQLROLLBACK( ) returns -1, you can use AERROR( ) to determine why the transaction could not be rolled back.

If manual transactions are in effect (the SQLSETPROP( ) transaction property is set to manual), you can send multiple updates to remote tables. The updates can all be rolled back with SQLROLLBACK( ).

Updates can be committed with SQLCOMMIT( ).

Example

The following example assumes SQLCONNECT( ) is successfully issued, and its return value is stored to a memory variable named gnConnHandle. SQLSETPROP( ) is used to set the Transactions property to 2 (manual), making it possible for you to use SQLCOMMIT( ) and SQLROLLBACK( ).

The authors table is modified with SQLEXEC( ), and the changes to the table are cancelled with SQLROLLBACK( ).

= SQLSETPROP(gnConnHandle, 'Transactions', 2)  && manual
= SQLEXEC(gnConnHandle, "INSERT INTO authors (au_id, au_lname);
   VALUES ('aupoe', 'Poe')")
= SQLROLLBACK(gnConnHandle)

See Also

AERROR( ) | SQLCOMMIT( ) | SQLCONNECT( ) | SQLSETPROP( )