description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CDynamicParameterAccessor Class |
CDynamicParameterAccessor Class |
02/14/2018 |
|
|
5f22626e-e80d-491f-8b3b-cedc50331960 |
Similar to CDynamicAccessor but obtains parameter information to be set by calling the ICommandWithParameters interface.
class CDynamicParameterAccessor : public CDynamicAccessor
Header: atldbcli.h
Name | Description |
---|---|
CDynamicParameterAccessor | The constructor. |
GetParam | Retrieves the parameter data from the buffer. |
GetParamCount | Retrieves the number of parameters in the accessor. |
GetParamIO | Determines whether the specified parameter is an input or output parameter. |
GetParamLength | Retrieves the length of the specified parameter stored in the buffer. |
GetParamName | Retrieves the name of a specified parameter. |
GetParamStatus | Retrieves the status of the specified parameter stored in the buffer. |
GetParamString | Retrieves the string data of the specified parameter stored in the buffer. |
GetParamType | Retrieves the data type of a specified parameter. |
SetParam | Sets the buffer using the parameter data. |
SetParamLength | Sets the length of the specified parameter stored in the buffer. |
SetParamStatus | Sets the status of the specified parameter stored in the buffer. |
SetParamString | Sets the string data of the specified parameter stored in the buffer. |
The provider must support ICommandWithParameters
for the consumer to use this class.
The parameter information is stored in a buffer created and managed by this class. Obtain parameter data from the buffer by using GetParam and GetParamType.
For an example demonstrating how to use this class to execute a SQL Server stored procedure and get the output parameter values, see the DynamicConsumer sample code in the Microsoft VCSamples repository on GitHub.
The constructor.
typedef CDynamicParameterAccessor _ParamClass;
CDynamicParameterAccessor(
DBBLOBHANDLINGENUM eBlobHandling = DBBLOBHANDLING_DEFAULT,
DBLENGTH nBlobSize = 8000 )
: CDynamicAccessor(eBlobHandling, nBlobSize )
eBlobHandling
Specifies how the BLOB data is to be handled. The default value is DBBLOBHANDLING_DEFAULT. See CDynamicAccessor::SetBlobHandling for a description of the DBBLOBHANDLINGENUM values.
nBlobSize
The maximum BLOB size in bytes; column data over this value is treated as a BLOB. The default value is 8,000. See CDynamicAccessor::SetBlobSizeLimit for details.
See the CDynamicAccessor::CDynamicAccessor constructor for more information on BLOB handling.
Retrieves the nonstring data for a specified parameter from the parameter buffer.
template <class ctype>bool GetParam(DBORDINAL nParam,
ctype* pData) const throw();
template <class ctype> bool GetParam(TCHAR* pParamName,
ctype* pData) const throw();
void* GetParam(DBORDINAL nParam) const throw();
void* GetParam(TCHAR* pParamName) const throw();
ctype
A templated parameter that is the data type.
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pParamName
[in] The parameter name.
pData
[out] The pointer to the memory containing the data retrieved from the buffer.
For nontemplated versions, points to the memory containing the data retrieved from the buffer. For templated versions, returns true
on success or false
on failure.
Use GetParam
to retrieve nonstring parameter data from the buffer. Use GetParamString to retrieve string parameter data from the buffer.
Retrieves the number of parameters stored in the buffer.
DB_UPARAMS GetParamCount() const throw();
The number of parameters.
Determines whether the specified parameter is an input or output parameter.
bool GetParamIO(DBORDINAL nParam,
DBPARAMIO* pParamIO) const throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pParamIO
A pointer to the variable containing the DBPARAMIO
type (input or output) of the specified parameter. It is defined as follows:
typedef DWORD DBPARAMIO;
enum DBPARAMIOENUM {
DBPARAMIO_NOTPARAM = 0,
DBPARAMIO_INPUT = 0x1,
DBPARAMIO_OUTPUT = 0x2
};
Returns true
on success or false
on failure.
Retrieves the length of the specified parameter stored in the buffer.
bool GetParamLength(DBORDINAL nParam,
DBLENGTH* pLength);
DBLENGTH* GetParamLength(DBORDINAL nParam) const throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pLength
[out] A pointer to the variable containing the length in bytes of the specified parameter.
The first override returns true
on success or false
on failure. The second override points to the memory containing the length of the parameter.
Retrieves the name of the specified parameter.
LPOLESTR GetParamName(DBORDINAL nParam) const throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
The name of the specified parameter.
Retrieves the status of the specified parameter stored in the buffer.
bool GetParamStatus(DBORDINAL nParam,
DBSTATUS* pStatus);
DBSTATUS* GetParamStatus(DBORDINAL nParam) const throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pStatus
[out] A pointer to the variable containing the DBSTATUS status of the specified parameter. For information on DBSTATUS values, see Status in the OLE DB Programmer's Reference, or search for DBSTATUS in oledb.h.
The first override returns true
on success or false
on failure. The second override points to the memory containing the status of the specified parameter.
Retrieves the string data of the specified parameter stored in the buffer.
bool GetParamString(DBORDINAL nParam,
CSimpleStringA& strOutput) throw();
bool GetParamString(DBORDINAL nParam,
CSimpleStringW& strOutput) throw();
bool GetParamString(DBORDINAL nParam,
CHAR* pBuffer,
size_t* pMaxLen) throw();
bool GetParamString(DBORDINAL nParam,
WCHAR* pBuffer,
size_t* pMaxLen) throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
strOutput
[out] The ANSI (CSimpleStringA
) or Unicode (CSimpleStringW
) string data of the specified parameter. You should pass a parameter of type CString
, for example:
[!code-cppNVC_OLEDB_Consumer#9]
pBuffer
[out] A pointer to the ANSI (CHAR) or Unicode (WCHAR) string data of the specified parameter.
pMaxLen
[out] A pointer to the size of the buffer pointed to by pBuffer (in characters, including the terminating NULL).
Returns true
on success or false
on failure.
If pBuffer is NULL, this method will set the required buffer size in the memory pointed to by pMaxLen and return true
without copying the data.
This method will fail if the buffer pBuffer is not large enough to contain the whole string.
Use GetParamString
to retrieve string parameter data from the buffer. Use GetParam to retrieve nonstring parameter data from the buffer.
Retrieves the data type of a specified parameter.
bool GetParamType(DBORDINAL nParam,
DBTYPE* pType) const throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pType
[out] A pointer to the variable containing the data type of the specified parameter.
Returns true
on success or false
on failure.
Sets the parameter buffer using the specified (non-string) data.
template <class ctype>
bool SetParam(DBORDINAL nParam,
constctype* pData,
DBSTATUS status = DBSTATUS_S_OK) throw();
template <class ctype>
bool SetParam(TCHAR* pParamName,
const ctype* pData,
DBSTATUS status = DBSTATUS_S_OK) throw();
ctype
A templated parameter that is the data type.
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. For example:
[!code-cppNVC_OLEDB_Consumer#8]
pParamName
[in] The parameter name.
pData
[in] The pointer to the memory containing the data to be written to the buffer.
status
[in] The DBSTATUS column status. For information on DBSTATUS values, see Status in the OLE DB Programmer's Reference, or search for DBSTATUS in oledb.h.
Returns true
on success or false
on failure.
Use SetParam
to set nonstring parameter data in the buffer. Use SetParamString to set string parameter data in the buffer.
Sets the length of the specified parameter stored in the buffer.
bool SetParamLength(DBORDINAL nParam,
DBLENGTH length);
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
length
[in] The length in bytes of the specified parameter.
Returns true
on success or false
on failure.
Sets the status of the specified parameter stored in the buffer.
bool SetParamStatus(DBORDINAL nParam,
DBSTATUS status);
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
status
[in] The DBSTATUS status of the specified parameter. For information on DBSTATUS values, see Status in the OLE DB Programmer's Reference, or search for DBSTATUS in oledb.h.
Returns true
on success or false
on failure.
Sets the string data of the specified parameter stored in the buffer.
bool SetParamString(DBORDINAL nParam,
constCHAR* pString,
DBSTATUS status = DBSTATUS_S_OK) throw();bool SetParamString(DBORDINAL nParam,
constWCHAR* pString,
DBSTATUS status = DBSTATUS_S_OK) throw();
nParam
[in] The parameter number (offset from 1). Parameter 0 is reserved for return values. The parameter number is the index of the parameter based on its order in the SQL or stored procedure call. See SetParam for an example.
pString
[in] A pointer to the ANSI (CHAR) or Unicode (WCHAR) string data of the specified parameter. See DBSTATUS in oledb.h.
status
[in] The DBSTATUS status of the specified parameter. For information on DBSTATUS values, see Status in the OLE DB Programmer's Reference, or search for DBSTATUS in oledb.h.
Returns true
on success or false
on failure.
SetParamString
will fail if you try to set a string that is larger than the maximum size specified for pString.
Use SetParamString
to set string parameter data in the buffer. Use SetParam to set nonstring parameter data in the buffer.
OLE DB Consumer Templates
OLE DB Consumer Templates Reference
CAccessor Class
CDynamicAccessor Class
CManualAccessor Class