f2s_esql_start_transaction¶

Applies to: Oracle, MS SQL, MySql/MariaDB, PostgreSQL Drivers

Syntax

f2s_esql_start_transaction

Description

This command is used to start a SQL transaction. Inside of a transaction, there can be any number of SQL statements, none of which will be executed until f2s_esql_commit_transaction is called. Note that transactions are generally only needed when a table is being altered.

A transaction is a single unit of work. When the transaction is successful, the modifications made inside the transaction are committed and become a permanent part of the database. If a transaction encounters errors and must be canceled or rolled back, then all of the data modifications are erased.

Example

f2s_esql_start_transaction Command using SQL Server
     String sSQL
     String sCustName
     String sCustAddress
     String sCustCity
     String sCustState
     String sCustZip
     String sCustPhone_Number
     Number nCreditLimit nMaximumAllowedCreditLimit
     Move 250.00 to nMaximumAllowedCreditLimit
     Move "Test Name" to sCustName
     Move "123 Test Address" to sCustAddress
     Move "Miami" to sCustCity
     Move "FL" to sCustState
     Move "33308" to sCustZip
     Move "305 555-5555" to sCustPhone_Number
     Move 1000.00 to nCreditLimit
     Move "Insert into CUSTOMER ([Name], [Address], [City], [State], [Zip], [Phone_Number],[Credit_Limit]) Values(?,?,?,?,?,?,?)" to sSQL

     //Start a Transaction
     f2s_esql_start_transaction

     //Create the SQL Statement
     f2s_esql_create_stmt sSQL

     // Prepare the SQL Statement
     f2s_esql_prepare_stmt

     // Set the parameter values for the SQL Statement
     f2s_esql_set_param 1 to sCustName
     f2s_esql_set_param 2 to sCustAddress
     f2s_esql_set_param 3 to sCustCity
     f2s_esql_set_param 4 to sCustState
     f2s_esql_set_param 5 to sCustZip
     f2s_esql_set_param 6 to sCustPhone_Number
     f2s_esql_set_param 7 to nCreditLimit

     //Execute the SQL Statement
     f2s_esql_execute_stmt

     //Check  Business rule for new customers with a high Credit Limit
     If (nCreditLimit > nMaximumAllowedCreditLimit) Begin
         Showln "Credit Limit is too high!  Rolling back the transaction."
         f2s_esql_rollback_transaction
     End
     Else Begin
         Showln "Successful - Committing the Transaction"
         f2s_esql_commit_transaction
     End
     f2s_esql_close_stmt
     inkey WindowIndex

Related Commands

  • f2s_esql_rollback_transaction

  • f2s_esql_commit_transaction

Replaces: Command SQL_START_TRANSACTION_STMT