Example

The following example shows how you might synchronize DataWindows between a PowerBuilder client and an EAServer component. This example uses a stateless component.

Client window definition

Suppose the client has a window called w_employee that has buttons that allow the user to retrieve and update data. The Retrieve button on the client window has the following script:

// Global variable:
// connection myconnect
// Instance variable:
// uo_employee iuo_employee

blob lblb_data
long ll_rv

myconnect.CreateInstance(iuo_employee)
iuo_employee.RetrieveData(lblb_data)

ll_rv = dw_employee.SetFullState(lblb_data)

if ll_rv = -1 then
   MessageBox("Error", "SetFullState call failed!")
end if

The Update button on the client window has the following script:

blob lblb_data
long ll_rv

ll_rv = dw_employee.GetChanges(lblb_data)

if ll_rv = -1 then
   MessageBox("Error", "GetChanges call failed!")
else
   if iuo_employee.UpdateData(lblb_data) = 1 then &
      dw_employee.ResetUpdate()
end if

Server object definition

The server has an object called uo_employee that has the following functions:

Instance variables

The uo_employee object has these instance variables:

protected TransactionServer ts
protected DataStore ids_datastore

Activate

The Activate event for the uo_employee object instantiates the TransactionServer service. In addition, it connects to the database and creates the DataStore that will be used to access the database:

this.GetContextService("TransactionServer", ts)
SQLCA.DBMS="ODBC"
SQLCA.DBParm="ConnectString=
   'DSN=EAS Demo DB;UID=dba;PWD=sql',
   UseContextObject='Yes'"
CONNECT USING SQLCA;
IF SQLCA.SQLCode < 0 THEN
   //Handle the error
END IF
ids_datastore = CREATE datastore
ids_datastore.dataobject = "d_emplist"
ids_datastore.SetTransObject (SQLCA)

Script for the RetrieveData function

The RetrieveData function takes an argument called ablb_data, which is a Blob passed by reference. The function returns a Long value.

Here is the script for the RetrieveData function:

long ll_rv
ids_datastore.Retrieve()
ll_rv = ids_datastore.GetFullState(ablb_data)
ts.SetComplete()
return ll_rv

Script for the UpdateData function

The UpdateData function takes an argument called ablb_data, which is a Blob passed by reference. The function returns a Long value.

Here is the script for the UpdateData function:

long ll_rv
if ids_datastore.SetChanges(ablb_data) = 1 then
   ll_rv = ids_datastore.Update()
end if 
if ll_rv = 1 then
   ts.SetComplete()
else
   ts.SetAbort()
end if
return ll_rv

Deactivate

The Deactivate event for the uo_employee object destroys the DataStore and disconnects from the database:

DESTROY ids_datastore
DISCONNECT USING SQLCA;