ActiveX methods return row results using the IJagServerResults interface. Both a custom (native C++) and IDispatch version of the interface are available, as documented in these chapters of the the EAServer API Reference:
To use these methods in your component, you must first register the jagaxwrap.dll programmable object on your machine. If you are developing on a machine that has EAServer installed on it, jagaxwrap.dll is already registered.
The following sections describe the two methods for returning result sets:
“Forwarding a result set with ResultsPassthrough” describes how to forward an ODBC or Client-Library result set to the client. Use this method when you want to send query results as-is.
“Sending results row-by-row” describes the sequence of calls to define a result set’s columns and send the result set row-by-row. Use this method when you must manufacture a result set from scratch. You can also use this method to filter rows or columns from the results of a remote-database query.
You cannot send a result set unless the IDL definition
of the component method returns TabularResults::ResultSet or TabularResults::ResultSets.
You can call the ResultsPassthrough method after you have sent a remote-database query with ODBC or Client-Library calls. This method passes either the current result set or all the result sets on the connection (or command). See the ResultsPassthrough reference page for examples.
The steps below describe the call sequence for sending a result set from scratch.
Instantiate an IJagServerResults interface pointer.
Call BeginResults, specifying the number of columns in the result set.
For each column, call DescribeCol to describe the column number, column name, length of the column name, datatype, precision, and size of the column. If a column represents a cash value, call ColAttributes to set the “COLUMN_MONEY” attribute.
This step and the next step may be combined; you can describe columns and bind them in the same loop.
For each column, call BindCol, specifying the size and location of the variable where the column’s data value and length can be read.
For each row, update the variables containing the column’s data value and length, then call SendData to send the row to the client.
Call EndResults after all rows have been sent.
The C++ fragment below shows an ActiveX method implementation that returns a result set:
// EAServer includes #include <stdio.h> #include <sql.h> #include <jagctx.h> #include <JagAxWrap.h> #include <JagAxWrap_i.c> #include <jagpublic.h>
STDMETHODIMP CAXRSDemo::SendRows() { HRESULT hr; IJagServerResults *p_ijsrs; CLSID clsid_jsrs;
BSTR colName; BSTR SQLType; VARIANTARG bindVar; long rowCount;
LONG intCol; short intColInd = 0; BSTR strCol; short strColInd = 0; DOUBLE doubleCol; short doubleColInd = 0;
// Create an IJagServerResults interface pointer hr = CLSIDFromProgID( L"Jaguar.JagServerResults.1", &clsid_jsrs); // ... Deleted error checking ...
hr = CoCreateInstance(clsid_jsrs, NULL, CLSCTX_INPROC_SERVER, IID_IJagServerResults, (void**)&p_ijsrs); // ... Deleted error checking ...
// Result set has three columns. hr = p_ijsrs->BeginResults(3); // ... Deleted error checking ...
// // First column has datatype SQL_INTEGER, // has name "one", and can be NULL. // colName = SysAllocString(L"one"); SQLType = SysAllocString(L"SQL_INTEGER");
hr = p_ijsrs->DescribeCol( 1, colName, SQLType, sizeof(intCol), 0, 0, VARIANT_TRUE);
// ... Deleted error checking ...
// // Bind first column to intCol // VariantInit(&bindVar); bindVar.vt = VT_I4 | VT_BYREF; bindVar.plVal = &intCol; hr = p_ijsrs->BindCol( 1, bindVar, sizeof(intCol), &intColInd); // ... Deleted error checking ...
// // Second column has datatype SQL_VARCHAR, // maximum length 32, name "two", and can // be null. // hr = SysReAllocString(&colName, L"two"); // ... Deleted error checking ...
hr = SysReAllocString(&SQLType, L"SQL_VARCHAR"); // ... Deleted error checking ...
hr = p_ijsrs->DescribeCol( 2, colName, SQLType, 32, 0, 0, VARIANT_TRUE); // ... Deleted error checking ...
// // Allocate a BSTR and bind the second column // to it. Later, we’ll use SysReAllocString() to set // values for transfer. // strCol = SysAllocString(L"");
VariantInit(&bindVar); bindVar.vt = VT_BSTR | VT_BYREF; bindVar.pbstrVal = &strCol;
// ... Deleted error checking ...
// // Third column has datatype SQL_DECIMAL with // precision of 5 and scale of 3 // Column name is "three", and the column can be null. // hr = SysReAllocString(&colName, L"three"); // ... Deleted error checking ...
hr = SysReAllocString(&SQLType, L"SQL_DECIMAL"); // ... Deleted error checking ...
hr = p_ijsrs->DescribeCol( 3, colName, SQLType, 0, 5, 3, VARIANT_TRUE); // ... Deleted error checking ...
// // Bind the third column to doubleCol. //
VariantInit(&bindVar); bindVar.vt = VT_R8 | VT_BYREF; bindVar.pdblVal = &doubleCol;
// ... Deleted error checking ...
// // Now send the rows. //
rowCount = 0;
// First row: 1, "uno", 3.141
intCol = 1;
hr = SysReAllocString(&strCol, L"uno"); // ... Deleted error checking ...
doubleCol = 3.141;
hr = p_ijsrs->SendData(); // ... Deleted error checking ...
++rowCount;
// Second row: 2, "dos", 6.282
intCol = 2;
hr = SysReAllocString(&strCol, L"dos"); // ... Deleted error checking ...
doubleCol = 6.282;
hr = p_ijsrs->SendData(); // ... Deleted error checking ...
++rowCount;
// Third row: 3, "tres", 9.423
intCol = 3;
hr = SysReAllocString(&strCol, L"tres"); // ... Deleted error checking ...
doubleCol = 9.423;IJagServerResults
hr = p_ijsrs->SendData(); // ... Deleted error checking ...
++rowCount;
// // Done sending rows. // hr = p_ijsrs->EndResults(rowCount); // ... Deleted error checking ...
return S_OK;
}
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |