Syntax 1Using values from an external transaction object
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.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataWindowChild object, DataStore |
Syntax
[PowerBuilder]
1 |
integer <span>dwcontrol</span>.<span>SetTrans</span> ( transaction <span>transaction </span>) |
Argument |
Description |
---|---|
dwcontrol |
A reference to a DataWindow control, |
transaction |
The name of the transaction object from |
Return Values
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.
If you use SetTrans for an EAServer component, you must
not set the UseContext Object database parameter to Yes.
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:
1 |
dw_employee.<span>SetTrans</span>(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:
1 |
// Name the transaction object. |
1 |
transaction emp_TransObj |
1 |
1 |
// Create the transaction object. |
1 |
emp_TransObj = CREATE transaction |
1 |
1 |
// Fill the new object with the original values. |
1 |
dw_employee.GetTrans(emp_TransObj) |
1 |
// Change the database type. |
1 |
emp_TransObj.DBMS ="Sybase" |
1 |
// Change the password. |
1 |
emp_TransObj.LogPass = "cam2" |
1 |
1 |
// Put the revised values into the |
1 |
// DataWindow transaction object. |
1 |
dw_employee.<span>SetTrans</span>(emp_TransObj) |