SetTrans

Description

Sets the values in the internal transaction object for a DataWindow control or DataStore to the values from the specified transaction object. The transaction object supplies connection settings, such as the database name.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control, DataWindowChild object, DataStore object


Syntax

PowerBuilder

integer dwcontrol.SetTrans ( transaction transaction )

Argument

Description

dwcontrol

A reference to a DataWindow control, DataStore, or child DataWindow in which you want to set the values of the internal transaction object

transaction

The name of the transaction object from which you want dwcontrol to get values


Return value

Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.

Usage

In most cases, use the SetTransObject method to specify the transaction object. It is more efficient and allows you to control when changes get committed to the database.

SetTrans copies the values from a specified transaction object to the internal transaction object for the DataWindow control or DataStore. When you use SetTrans in a script, the DataWindow uses its internal transaction object and automatically connects and disconnects as needed; any errors that occur cause an automatic rollback. With SetTrans, you do not specify SQL statements, such as CONNECT, COMMIT, and DISCONNECT. The DataWindow control connects and disconnects after each Retrieve or Update function.

Use SetTransObject with composite DataWindows

You must use SetTransObject with DataWindow objects that use the Composite presentation style. Composite DataWindows are containers for other DataWindow objects and do not have any internal transaction information of their own.

If you use SetTrans with each nested DataWindow in a composite DataWindow, disconnect does not occur until the PowerBuilder session ends.

Use SetTrans when you want PowerBuilder to manage the database connections automatically because you have a limited number of available connections or expect to use the application from a remote location. SetTrans is appropriate when you are only retrieving data and do not need to hold database locks on records the user is modifying. For better performance, however, you should use SetTransObject.

DBMS connection settings

You must set the parameters required to connect to your DBMS in the transaction object before you can use the transaction object to set the DataWindow's internal transaction object and connect to the database.

Updating more than one table

When you use SetTrans to specify the transaction object, you cannot update multiple DataWindow objects or multiple tables within one object.

Examples

This statement sets the values in the internal transaction object for dw_employee to the values in the default transaction object SQLCA:

dw_employee.SetTrans(SQLCA)

The following statements change the database type and password of dw_employee. The first two statements create the transaction object emp_TransObj. The next statement uses the GetTrans method to store the values of the internal transaction object for dw_employee in emp_TransObj. The next two statements change the database type and password. The SetTrans method assigns the revised values to dw_employee:

// Name the transaction object.
transaction emp_TransObj
 
// Create the transaction object.
emp_TransObj = CREATE transaction
 
// Fill the new object with the original values.
dw_employee.GetTrans(emp_TransObj)
// Change the database type.
emp_TransObj.DBMS ="Sybase"
// Change the password.
emp_TransObj.LogPass = "cam2"
 
// Put the revised values into the
// DataWindow transaction object.
dw_employee.SetTrans(emp_TransObj)

See also

GetTrans

SetTransObject