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. |