Team LiB   Previous Section   Next Section
with transaction [session object] end [transaction]

Syntax

With transaction

   (* code statements here *)

end transaction

Description

with transaction is designed to group together its enclosed statements and commands by assigning each of them a single transaction id. If a database application supports with transaction, for instance, than it knows which Apple events or commands share a transaction and can initiate an appropriate response, such as locking the particular table from other users until the transaction is complete. What is a transaction? A transaction gathers together a group of operations and declares, in essence, that, "we're all in this together—if one of us fails, then we all fail. We won't signal a successful completion until we all succeed."

The with transaction statement itself, beyond assigning the transaction id, does not have any other transactional-related capabilities such as rolling back all of the statements if one of the statements (e.g., a statement that updates or alters a database file) within the transaction fails. Any behavior that commits or rolls back database changes that are part of a single transaction would have to be initiated by the database system itself (the database program that AppleScript is scripting). with transaction only works with the database programs that support this statement.

Examples

To show what the with transaction statement looks like, the following AppleScript requests the first database record from an open FileMaker database. It encloses this request in a with transaction block:

tell application "FileMaker Pro"

    with transaction

        get the first record in the database named "Mydatabase" 

    end transaction

end tell

In this case, if you watch the Script Editor Event Log window as you run the script, FileMaker converts the with transaction statement to its own begin transaction command. This command returns an integer, the transaction id, such as 2812565. You can include an optional session-object parameter with the with transaction block, but not all applications support it. If you want to use AppleScript, transactions, and databases, then you have to evaluate the particular database system's support for with transaction.

    Team LiB   Previous Section   Next Section