IPB_Session interface:
CreateResultSet method
Description
Creates a result set object using a pointer to an IPB_ResultSetAccessor
object.
Syntax
CreateResultSet (IPB_ResultSetAccessor* rs)
Argument
|
Description
|
rs
|
A pointer to an IPB_ResultSetAccessor
object
|
Return Values
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:
#include "stdafx.h"
#include "windows.h"
#include "pbni.h"
#include "vector"
using std::vector;
void main(int argc, char* argv[])
{
HINSTANCE hinst = LoadLibrary("pbvm170.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:
ResultSet rs
DataStore ds
Long sts
Integer li_ret
// Profile PB Demo DB V170
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = &
"ConnectString='DSN=PB
Demo DB V170;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:
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