| OLE DB Programmer's Reference |
Returns the next in a series of multiple results from the provider.
HRESULT GetResult( IUnknown *pUnkOuter, DBRESULTFLAG lResultFlag, REFIID riid, DBROWCOUNT *pcRowsAffected, IUnknown **ppRowset);
Parameters
| Enum | Description |
|---|---|
| DBRESULTFLAG_DEFAULT | The type of the returned object is defined by riid or by properties set on the command object. If this is ambiguous, the provider should return a rowset. Prior to OLE DB 2.6, providers were required to return E_INVALIDARG when lResultFlag was not zero. Consumers should not pass nonzero values unless the provider is a 2.6 or later provider and has added support for lResultFlag. |
| DBRESULTFLAG_ROWSET | The consumer explicitly requests a rowset object. |
| DBRESULTFLAG_ROW | The consumer explicitly requests a row object. |
Providers that support the return of row objects from ICommand::Execute and also support multiple results should support returning row objects from calls to IMultipleResults::GetResult, as described by the flag values in the preceding table.
As in ICommand::Execute, when returning a row object from IMultipleResults::GetResult, if the statement would have returned multiple rows, the provider is encouraged, but not required, to return DB_S_NOTSINGLETON.
If lResultFlag is not zero and the riid does not match the requested object type, the provider should return E_NOINTERFACE.
If lResultFlag is not zero and a command property (for example, DBPROP_IRow or DBPROP_IRowset) conflicts with the requested object type, the provider should return DB_S_ERRORSOCCURRED with a suitable DBPROPSTATUS value, such as DBPROPSTATUS_CONFLICTING if the property is optional, or DB_E_ERRORSOCCURRED if the property is required.
If this is IID_NULL, ppRowset is ignored and no rowset is returned, even if one exists.
Some providers do not support returning individual counts of rows but instead return an overall count of the total rows affected by the call to ICommand::Execute, or they do not return row counts at all. Such providers set *pcRowsAffected to DB_COUNTUNAVAILABLE when the count of affected rows is not available.
If ppRowset is a null pointer, no rowset is created.
Return Code
This return code takes precedence over DB_S_ERRORSOCCURRED. That is, if the conditions described here and those described in DB_S_ERRORSOCCURRED both occur, the provider returns this code. When the consumer receives this return code, it should also check for the conditions described in DB_S_ERRORSOCCURRED.
The rowset was not returned because one or more propertiesfor which the dwOptions element of the DBPROP structure was DBPROPOPTIONS_REQUIRED or an invalid valuecould not be satisfied.
pUnkOuter was not a null pointer, and riid was not IID_IUnknown.
Comments
IMultipleResults::GetResult returns the next in a series of multiple results from the provider. A result is returned for each separate statement in the command text or from each set of parameters passed to a command. If the next result is the result of a row-returning command or operation, such as an SQL SELECT statement, the result of this method is a rowset over the result rows. If no rows match the command, the rowset is still created. The resulting rowset is fully functional and can be used, for example, to insert new rows or determine column metadata. If the next result is the result of a non-row-returning command, such as an SQL INSERT statement, *ppRowset is set to NULL and *pcRowsAffected is set to the count of rows affected, if applicable.
Rowsets returned by IMultipleResults::GetResult have the properties set as defined by the command that created the multiple results object. These properties are identical for each result set. There is no way to set different properties for results of a multiple result.
Providers will generally be able to process only one result at a time. For maximum interoperability, consumers should free any rowset obtained by a previous call to IMultipleResults::GetResult before requesting the next result.
If ICommand::Execute is called multiple times for a single command, with or without changes to the command text, the outcome may reflect changes in the underlying stored data, depending on the isolation level specified for the surrounding transaction.
When executing a command whose command text is a sequence of subcommands and also requesting a multiple results object, the provider must ensure that subcommands are executed in the order they appear in the command text and that any command whose results have been retrieved via IMultipleResults::GetResult has been executed.
It is provider-specific whether each of the subcommands is executed at ICommand::Execute or just-in-time for IMultipleResults::GetResult, and it is also provider-specific whether subcommands whose results have not been obtained have been executed.
Providers may check the entire command text for errors at execute time or may check the command text associated with each result when that result is retrieved. Therefore, the syntax errors returned by ICommand::Execute can also be returned by IMultipleResults::GetResult. In this case, the next call to IMultipleResults::GetResult moves on to the next result or returns DB_S_NORESULT if no more results are available.
When IMultipleResults::GetResult returns an error, its behavior depends on the error that occurred, as in the following scenarios:
The following example shows how a consumer might process multiple results:
hr = pICommandText->Execute(pUnkOuter, IID_IMultipleResults, pParams, &cRowsAffected,(IUnknown**)&pIMultipleResults); if (pIMultipleResults) { while(hr != DB_S_NORESULT) { if(SUCCEEDED(hr = pIMultipleResults->GetResult(pUnkOuter, 0, IID_IRowset, &cRowsAffected, &pIRowset))) { if(pIRowset) { // The next result is a rowset. Process the rowset. pIRowset->Release(); } else { // The next result is not a rowset. Process the // nonrowset result. } } else { // Process error from GetResult. break; } } pIMultipleResults->Release(); } ICommand::Execute
1998-2001 Microsoft Corporation. All rights reserved.