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:
1 |
// Global variable:<br>// connection myconnect<br>// Instance variable:<br>// uo_employee iuo_employee<br> <br>blob lblb_data<br>long ll_rv<br> <br>myconnect.CreateInstance(iuo_employee)<br>iuo_employee.RetrieveData(lblb_data)<br> <br>ll_rv = dw_employee.SetFullState(lblb_data)<br> <br>if ll_rv = -1 then<br>   MessageBox("Error", "SetFullState call failed!")<br>end if |
The Update button on the client window has the following script:
1 |
blob lblb_data<br>long ll_rv<br> <br>ll_rv = dw_employee.GetChanges(lblb_data)<br> <br>if ll_rv = -1 then<br>   MessageBox("Error", "GetChanges call failed!")<br>else<br>   if iuo_employee.UpdateData(lblb_data) = 1 then &<br>      dw_employee.ResetUpdate()<br>end if |
Server object definition
The server has an object called uo_employee that
has the following functions:
-
RetrieveData
-
UpdateData
Instance variables
The uo_employee object has these
instance variables:
1 |
protected TransactionServer ts<br>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:
1 |
this.GetContextService("TransactionServer", ts)<br>SQLCA.DBMS="ODBC"<br>SQLCA.DBParm="ConnectString=<br>   'DSN=EAS Demo DB;UID=dba;PWD=sql',<br>   UseContextObject='Yes'"<br>CONNECT USING SQLCA;<br>IF SQLCA.SQLCode < 0 THEN<br>   //Handle the error<br>END IF<br>ids_datastore = CREATE datastore<br>ids_datastore.dataobject = "d_emplist"<br>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:
1 |
long ll_rv<br>ids_datastore.Retrieve()<br>ll_rv = ids_datastore.GetFullState(ablb_data)<br>ts.SetComplete()<br>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:
1 |
long ll_rv<br>if ids_datastore.SetChanges(ablb_data) = 1 then<br>   ll_rv = ids_datastore.Update()<br>end if <br>if ll_rv = 1 then<br>   ts.SetComplete()<br>else<br>   ts.SetAbort()<br>end if<br>return ll_rv |
Deactivate
The Deactivate event for the uo_employee object
destroys the DataStore and disconnects from the database:
1 |
DESTROY ids_datastore<br>DISCONNECT USING SQLCA; |