Condividi tramite


SQLCOMMIT( ) Function

Commits a transaction.

SQLCOMMIT(nStatementHandle)

Parameters

  • nStatementHandle
    Specifies the statement handle to the data source returned by SQLCONNECT( ).

Return Value

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

Remarks

If manual transactions are in effect (the SQLSETPROP( ) Transactions property is set to Manual), you can send multiple updates to remote tables and commit all the updates with SQLCOMMIT( ).

Updates can be rolled back with SQLROLLBACK( ).

Example

The following example assumes SQLCONNECT( ) is successfully issued, and its return value is stored to a memory variable named gnHandle. SQLSETPROP( ) is used to set the Transactions property to 2 (Manual), allowing you to use SQLCOMMIT( ) and SQLROLLBACK( ).

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

= SQLSETPROP(gnHandle, 'Transactions', 2)  && Manual transactions
= SQLEXEC(gnHandle, "INSERT INTO authors (au_id, au_lname);
   VALUES ('aupoe', 'Poe')")  && Modify the authors table
= SQLCOMMIT(gnHandle)  && Commit the changes

See Also

Reference

AERROR( ) Function

BEGIN TRANSACTION Command

END TRANSACTION Command

SQLCONNECT( ) Function

SQLROLLBACK( ) Function

SQLSETPROP( ) Function

SQL Commands and Functions

Other Resources

Language Reference (Visual FoxPro)