Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 7 - Control Statements / With Transaction Statements

With Transaction

With Transaction statements cause AppleScript to associate a single transaction ID with any events it sends to a target application as a result of executing commands in the body of the With Transaction statement.

with transaction [ session ] 
   [ statement ]...
end [ transaction ]

session is an object that specifies a specific session.

statement is any AppleScript statement.

This example uses a With Transaction statement to ensure that a record can be modified by one user without being modified by another user at the same time.

tell application "Small DB"
   with transaction
      set oldName to Field "Name"
      set oldAddress to Field "Address"
      set newName to display dialog �
         "Please type a new name" �
         default answer oldName
      set newAddress to display dialog �
         "Please type the new address" �
         default answer oldAddress
      set Field "Name" to newName
      set Field "Address" to newAddress
   end transaction
end tell
The Set statements obtain the current values of the Name and Address fields and invite the user to change them. Enclosing these Set statements in a single With Transaction statement informs the application that other users should not be allowed to access the same record at the same time.

With Transaction statements only work with applications that explicitly support them. Some applications only support With Transaction statements (like the one in the previous example) that do not take a session object as a parameter. Other applications support both With Transaction statements
that have no parameter and With Transaction statements that take a session parameter.

The following example demonstrates how to specify a session for a With Transaction statement.

tell application "Super DB"
	set mySession to make session with �
		data {user: "Bob", password: "Secret"}
	with transaction mySession
	end transaction
end tell 

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996