Syntax 2 For generating a result set using an EAServer Method As Stored Procedure
Description
Generates an EAServer result
set that can be returned from a PowerBuilder user object running
as a component on EAServer.
The result set is retrieved using a DataWindow control or DataStore
object whose data source is an EAServer component
method.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataStore object |
Syntax
[PowerBuilder]
1 |
<span>dwcontrol</span>.<span>GenerateResultSet</span> ( { <span>dwbuffer</span> } ) |
Argument |
Description |
---|---|
dwcontrol |
The DataWindow control or DataStore object |
dwbuffer (optional) |
A value of the dwBuffer enumerated datatype
|
Return Values
Returns 1 if it succeeds or one of the following negative
values if an error occurs:
-
-4
Value of dwbuffer or internal parameter
incorrect -
-10
Calling object not running on EAServer or EAServer API library could not
be loaded -
-11
Entry points in EAServer API
library not found -
-12
Internal error
Usage
The GenerateResultSet method allows you
to return a result set from a PowerBuilder custom class user object
that has been packaged as a component on EAServer using
the EAServer Method As Stored
Procedure (MASP) technique. For more information about MASP, see
the EAServer documentation.
GenerateResultSet does not return
a result set if the custom class user object is not running on EAServer.
To use GenerateResultSet, create a user
object function for the custom class user object that will be installed
on EAServer. The user object function
must not return a value. It connects to a database and retrieves data
into a DataStore object using the PowerBuilder Transaction object. The
call to GenerateResultSet uses column data in
the DataStore object to generate an EAServer result
set.
In the installed EAServer component,
the user object function runs as a method on EAServer. EAServer can return the generated
result set to any client that can interpret a Tabular Data Stream
(TDS) result set. To retrieve the result set from a PowerBuilder
client, create a DataWindow object whose data source is Stored Procedure
and select the method on EAServer as
the data source.
DataWindow datatypes map to CS-Library type constants in the
result set as follows:
DataWindow datatype |
Datatype in result set |
---|---|
Date |
CS_CHAR_TYPE |
DateTime |
CS_DATETIME_TYPE |
Decimal |
CS_DECIMAL_TYPE |
Long, Ulong |
CS_INT_TYPE |
Number |
CS_FLOAT_TYPE |
Real |
CS_REAL_TYPE |
String (length <= 244) |
CS_CHAR_TYPE |
String (length > 244) |
CS_LONGCHAR_TYPE |
Time |
CS_CHAR_TYPE |
The precision of all decimal datatypes in the result set will
be 16.
The sort order of the result set remains the same whether
or not the method running on EAServer performs
a sort operation on the DataStore object. If the result set is returned
to a PowerBuilder client, you can use the Sort and SetSort PowerScript
methods to sort the returned data.
If GenerateResultSet is called multiple
times within a single script, EAServer passes
multiple duplicate result sets back to the client.
Examples
The following is a user object function that runs
as a method on EAServer. The
function creates an instance of a DataStore object, connects to
a database, and retrieves data into the DataStore object. The call
to GenerateResultSet creates an EAServer result set that is returned
to the client from the data in the DataStore object.
1 |
// User object function: uf_gettraintimes |
1 |
// Set transaction object properties |
1 |
... |
1 |
// Open a log file for connect errors |
1 |
integer li_FileNum |
1 |
li_FileNum = FileOpen("C:SCHEDULESERRORS.TXT", & |
1 |
LineMode!, Write!, LockWrite!, Append!) |
1 |
1 |
// Connect to the database |
1 |
CONNECT using SQLCA; |
1 |
IF SQLCA.SQLCode <>0 THEN |
1 |
FileWrite(li_FileNum, & |
1 |
"Cannot connect to database " & |
1 |
+ SQLCA.SQLErrText) |
1 |
RETURN |
1 |
ELSE |
1 |
1 |
// Create a DataStore object and retrieve data |
1 |
   uo_ds_traintimes u_DataStore |
1 |
   u_DataStore = CREATE uo_ds_traintimes |
1 |
   u_DataStore.SetTransObject(sqlca) |
1 |
   u_DataStore.Retrieve() |
1 |
1 |
// Generate the result set |
1 |
   long ll_return |
1 |
   ll_return = & |
1 |
u_DataStore.GenerateResultSet(Primary!) |
1 |
   IF ll_return <> 1 THEN |
1 |
FileWrite(li_FileNum, & |
1 |
"GenerateResultSet return code: " & |
1 |
+ string(ll_return)) |
1 |
ELSE |
1 |
FileWrite(li_FileNum, "Result set generated") |
1 |
END IF |
1 |
1 |
FileClose(li_FileNum) |
1 |
DESTROY u_DataStore |
1 |
DISCONNECT using SQLCA; |
1 |
END IF |
To use the method above with a PowerBuilder client, start
PowerBuilder and connect with ODBC or with the SYC database interface
to EAServer where the user
object is installed. Create a new DataWindow object with Stored
Procedure as its data source and then select the component method from
the list of stored procedures. Define the result set to correspond
to the result set returned by the method on the server.
In the client application, use the Retrieve method
to retrieve data from the server:
1 |
// The data source for dw_traintimes is |
1 |
// PBPackage.PBServer.uf_gettraintimes |
1 |
dw_traintimes.Retrieve() |