CreateResultSet
Description
Creates a result set object using a pointer to an
IPB_ResultSetAccessor object.
Syntax
|
1 |
CreateResultSet (IPB_ResultSetAccessor* rs) |
|
Argument |
Description |
|---|---|
|
rs |
A pointer to an IPB_ResultSetAccessor |
Return value
pbobject.
Examples
This example loads the PBVM and calls the f_ret and f_in functions
in the custom class user object n_rs in the PBL pbrs.pbl. The
PowerScript for the functions is shown after the C++ code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include "stdafx.h" #include "windows.h" #include "pbni.h" #include "vector" using std::vector; void main(int argc, char* argv[]) { HINSTANCE hinst = LoadLibrary("pbvm.dll"); typedef PBXRESULT (*P_PB_GetVM)(IPB_VM** vm); P_PB_GetVM getvm = (P_PB_GetVM)GetProcAddress(hinst, "PB_GetVM"); IPB_VM* pbvm; getvm(&pbvm); IPB_Session* session = NULL; vector<LPCSTR> ll(1); ll[0] = "pbrs.pbl"; pbvm->CreateSession("pbrs", &ll[0], 1, &session); pbgroup group = session->FindGroup("n_rs", pbgroup_userobject); if (group == NULL) return; pbclass cls = session->FindClass(group, "n_rs"); if (cls == NULL) return; pbobject obj = session->NewObject(cls); if (obj == NULL) return; pbmethodID mid = session->GetMethodID(cls, "f_ret", PBRT_FUNCTION, "Cresultset."); PBCallInfo ci; session->InitCallInfo(cls, mid, &ci); session->InvokeObjectFunction(obj, mid, &ci); // Use the result set returned from f_ret to // create an IPB_ResultSetAccessor rsa pbobject rs = ci.returnValue->GetObject(); IPB_ResultSetAccessor* rsa = session->GetResultSetAccessor(rs); // Create a result set object from rsa pbobject rsobj = session->CreateResultSet(rsa); // Call the f_in method mid = session->GetMethodID(cls, "f_in", PBRT_FUNCTION, "IRCresultset."); PBCallInfo ci1; session->InitCallInfo(cls, mid, &ci1); // Set the result set object rsobj as the // argument for f_in ci1.pArgs->GetAt(0)->SetObject(rsobj); session->InvokeObjectFunction(obj, mid, &ci1); session->FreeCallInfo(&ci); session->FreeCallInfo(&ci1); } |
f_ret retrieves data from a database into a DataStore and
generates a result set:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
ResultSet rs DataStore ds Long sts Integer li_ret // Profile Demo Database V190 SQLCA.DBMS = "ODBC" SQLCA.AutoCommit = False SQLCA.DBParm = & "ConnectString='DSN=Demo Database V190;UID=dba;PWD=sql'" connect using sqlca; ds = Create DataStore ds.DataObject = "" ds.DataObject = "d_rs" ds.SetTransObject(sqlca) w_main.dw_1.SetTransObject(sqlca) long ll_ret, rows, rows2 ll_ret = ds.Retrieve() ll_ret = w_main.dw_1.Retrieve() //ds.sharedata(w_main.dw_1) rows = ds.RowCount() rows2 = w_main.dw_1.RowCount() messagebox("info from f_ret", " row count is " & + string(rows) + " or " + string(rows2)) sts = ds.GenerateResultSet(rs) Return rs |
f_in takes a result set, rs, as an argument and uses it to create
a DataStore:
|
1 2 3 4 5 6 7 8 |
DataStore ds Int cnt, li_ret ds = Create DataStore ds.CreateFrom(rs) cnt = ds.RowCount() messagebox("info from f_in", "row count is " + string(cnt)) Return cnt |
Usage
To use the IPB_ResultSetAccessor interface, load the PBVM, obtain
a result set from a PowerBuilder application, and call
GetResultSetAccessor on this result set to get an IPB_ResultSetAccessor
interface object. You can then call the methods of this object to get
information about the result set. You can also call CreateResultSet
using this object as an argument to create a result set that you can
return to PowerBuilder.
When you call CreateResultSet, the AddRef function of the
IPB_ResultSetAccessor interface is called on the rs argument implicitly
to add a reference to the interface pointer.
See also