Passing result sets

PowerBuilder provides two system objects to handle getting result sets from components running in EAServer and returning result sets from PowerBuilder user objects running as EAServer components. These system objects, ResultSet and ResultSets, are designed to simplify the conversion of transaction server result sets to and from DataStore objects and do not contain any state information. They are not designed to be used for database updates. You use the CreateFrom and GenerateResultSet functions on the DataStore object to convert the result sets stored in these objects to and from DataStore objects.

NoteAbout GenerateResultSet GenerateResultSet has an alternative syntax used for returning a Tabular Data Stream result set when using MASP (Method as Stored Procedure) with EAServer. For more information, see the DataWindow Reference.

Component methods that return result sets use the TabularResults module. Single result sets are returned as TabularResults::ResultSet structures. Multiple result sets are returned as a sequence of ResultSet structures using the TabularResults::ResultSets datatype.

Accessing result sets in EAServer components from PowerBuilder clients

When you generate an EAServer proxy object in PowerBuilder for an EAServer component method that returns TabularResults::ResultSet, the method on the proxy object returns a PowerBuilder ResultSet object. Methods that return multiple result sets return a PowerBuilder ResultSets object.

NoteViewing proxies in the Browser You can view the properties and methods of EAServer proxy objects on the Proxy tab in the PowerBuilder Browser.

For example, the Sybase Virtual University sample SVUBookstore component has several methods that return a TabularResults::ResultSet value. When you create an EAServer proxy object for the component, this is how the GetMajors method displays as a PowerBuilder user object function in the Browser:

SVUBookStore.GetMajors ( ) returns ResultSet

You can access the result set from a PowerBuilder client by creating an instance of the component, calling the method, and then using the result set to populate a DataStore object with the CreateFrom function.

This example creates an instance of the SVUBookstore component and calls the GetMajors method:

SVUBookstore lcst_mybookstore
resultset lrs_resultset
datastore ds_local
integer li_rc

// myconnect is a Connection object
li_rc = myconnect.CreateInstance(lcst_mybookstore)
IF li_rc <> 0 THEN
   MessageBox("Create Instance", string(li_rc) )
   myconnect.DisconnectServer()
   RETURN
END IF

lrs_resultset = lcst_mybookstore.GetMajors()
ds_local = CREATE datastore
ds_local.CreateFrom(lrs_resultset)

Returning result sets from EAServer components

To pass or return result sets from a PowerBuilder user object that will be deployed to EAServer, set the datatype of a function’s argument or return value to ResultSet (for a single result set) or ResultSets (for multiple result sets). When the user object is deployed as an EAServer component, the ResultSet and ResultSets return values are represented in the IDL interface of the component as TabularResults::ResultSet and TabularResults::ResultSets datatypes.

In this example, a DataStore object is created and data is retrieved into it, and then the GenerateResultSet function is used to create a result set that can be returned to a client:

datastore ds_datastore
resultset lrs_resultset
integer li_rc

ds_datastore = create datastore
ds_datastore.dataobject = "d_empdata"
ds_datastore.SetTransObject (SQLCA)
IF ds_datastore.Retrieve() = -1 THEN
   // report error and return
END IF
li_rc = ds_datastore.generateresultset(lrs_resultset)
IF li_rc <> 1 THEN
   // report error and return
END IF
return lrs_resultset