Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Advantage CA-Clipper Guide v5.5 - begin transaction http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 BEGIN TRANSACTION
 Indicates the beginning of a transaction
------------------------------------------------------------------------------

 Syntax

     BEGIN TRANSACTION

 Description

     This command marks the beginning of an Advantage TPS transaction.
     From the point in your application where the BEGIN TRANSACTION
     command is issued, every APPEND and REPLACE command issued before
     a corresponding COMMIT TRANSACTION or ROLLBACK TRANSACTION command
     is encountered will be considered one transaction.

     Important:  The currently selected work area must be using an
     Advantage RDD in order for the Advantage TPS commands or functions
     to work. If you issue an Advantage TPS command or function and are
     not in a work area using an Advantage RDD, you will receive an
     Advantage 6034, "Advantage work area required for transaction", error.

     Once a BEGIN TRANSACTION command is executed, any updates (REPLACEs
     and APPENDs) made to the database are tracked in a transaction log
     file. Other users sharing the same tables will not see any
     changes to the database until the transaction is committed. When the
     transaction is committed, the changes are written to the tables
     and indexes.

     For example, if you stopped the debugger on the COMMIT TRANSACTION
     statement in the code sample shown below, other users of the two
     tables cannot see the results of the APPENDs and REPLACEs
     until after the commit is executed. The pre-existing record would
     contain its original pre-transaction values. The appended records
     would not be visible at all.

     A transaction can only contain updates to tables which
     reside on the same file server.

 Example

     In this example, the code secures the necessary record lock it needs
     in the first table, CUSTOMER.DBF. If the lock succeeds, the
     code starts the transaction, which contains updates to two tables
     After the REPLACE commands are executed, the COMMIT TRANSACTION
     command physically writes the updates to the network OS,
     which subsequently writes the data to the physical hard disk.

     As mentioned earlier, the amount of code between the BEGIN
     TRANSACTION and COMMIT TRANSACTION statements should only contain
     REPLACE and APPEND commands. In this way, a "transaction" is clearly
     defined and executed. If a lot of other code is processed between
     the BEGIN TRANSACTION and COMMIT TRANSACTION statements, the chances
     are greater that the transaction will encounter an error which will
     require a transaction rollback.

     // Secure the Locks First and Append the necessary Records
     SELECT CUSTOMER
     IF !RLock()
        Alert( "Could not Lock Record in CUSTOMER for Transaction" )
        RETURN( .F. )
     ENDIF

     // Start the Transaction
     BEGIN TRANSACTION

        // Update the fields in the current record in CUSTOMER.DBF
        SELECT CUSTOMER
        REPLACE c_lname WITH cLastName
        REPLACE c_fname WITH cFirstName
        REPLACE c_add1 WITH cAdd1
        REPLACE c_city WITH cCity
        REPLACE c_state WITH cState
        REPLACE c_zip WITH cZip

        // Append 2 records to ORDER.DBF and update the appropriate order
        // information.
        APPEND BLANK
        REPLACE o_ordernum WITH cOrderNum
        REPLACE o_orddate WITH dOrdDate
        REPLACE o_sales WITH cSalesRep
        REPLACE o_terms WITH cTerms
        REPLACE o_amount WITH nAmount
        REPLACE o_salestax WITH nSalesTac

        APPEND BLANK
        REPLACE ol_ordernum WITH cOrderNum
        REPLACE ol_itemnum WITH cItemNum
        REPLACE ol_descr WITH cItemDescr
        REPLACE ol_cost WITH nCost
        REPLACE ol_numof WITH nNumItems
        REPLACE ol_subtotal WITH nSubTotal

     // End and Commit the Transaction
     COMMIT TRANSACTION


See Also: COMMIT TRANSACTION ROLLBACK TRANSACTION AX_Transaction()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson