本文整理汇总了C++中CComQIPtr::CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ CComQIPtr::CreateCommand方法的具体用法?C++ CComQIPtr::CreateCommand怎么用?C++ CComQIPtr::CreateCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComQIPtr
的用法示例。
在下文中一共展示了CComQIPtr::CreateCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Open
BOOL COledbRecordset::Open(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
_ASSERTE(m_pDb==NULL || m_pDb->IsOpen());
_ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
HRESULT Hr;
// Close old recordset
Close();
m_nRowsAffected = 0;
// Create a new recordset
CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
if( spCreate == NULL ) return FALSE;
CComPtr<ICommand> spCommand;
Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
if( FAILED(Hr) ) return _Error(Hr);
// Set type
COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
// Set SQL
CComQIPtr<ICommandText> spText = spCommand;
_ASSERTE(spText);
USES_CONVERSION;
Hr = spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
if( FAILED(Hr) ) return _Error(Hr);
// Execute...
Hr = spText->Execute(NULL, IID_IRowset, NULL, &m_nRowsAffected, (LPUNKNOWN*) &m_spRowset);
if( FAILED(Hr) ) return _Error(Hr);
// Bind columns
if( !_BindColumns() ) return FALSE;
return MoveNext();
}
示例2: Create
BOOL COledbCommand::Create(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
_ASSERTE(m_pDb->IsOpen());
_ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
HRESULT Hr;
Close();
// Open the command
CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
if( spCreate == NULL ) return FALSE;
CComPtr<ICommand> spCommand;
Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
if( FAILED(Hr) ) return _Error(Hr);
COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
m_spText = spCommand;
_ASSERTE(m_spText);
USES_CONVERSION;
Hr = m_spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
if( FAILED(Hr) ) return _Error(Hr);
// Prepare the command
if( (lOptions & DB_OPTION_PREPARE) != 0 ) {
CComQIPtr<ICommandPrepare> spPrepare = m_spText;
_ASSERTE(spPrepare);
if( spPrepare ) {
Hr = spPrepare->Prepare(0);
if( FAILED(Hr) ) return _Error(Hr);
}
}
// Create parameter bindings memory area
long cbAlloc = MAX_PARAMS * sizeof(DBBINDING);
m_rgBindings = (DBBINDING*) ::CoTaskMemAlloc(cbAlloc);
if( m_rgBindings == NULL ) return FALSE;
::ZeroMemory(m_rgBindings, cbAlloc);
m_pData = ::CoTaskMemAlloc(MAX_PARAMBUFFER_SIZE);
_ASSERTE(m_pData);
if( m_pData == NULL ) return FALSE;
::ZeroMemory(m_pData, MAX_PARAMBUFFER_SIZE);
m_nParams = 0;
m_dwBindOffset = 0L;
return TRUE;
}
示例3: ExecuteSQL
BOOL COledbDatabase::ExecuteSQL(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/, DWORD* pdwRowsAffected/*= NULL*/)
{
USES_CONVERSION;
HRESULT Hr;
if( pdwRowsAffected ) *pdwRowsAffected = 0;
CComQIPtr<IDBCreateCommand> spCreate = m_spSession;
if( spCreate == NULL ) return FALSE;
CComPtr<ICommand> spCommand;
Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
if( FAILED(Hr) ) return _Error(Hr);
_SetRecordsetType(spCommand, lType, lOptions);
CComQIPtr<ICommandText> spText = spCommand;
_ASSERTE(spText);
Hr = spText->SetCommandText(DBGUID_DBSQL, T2CW(pstrSQL));
if( FAILED(Hr) ) return _Error(Hr);
CComPtr<IRowset> spRowset;
Hr = spText->Execute(NULL, IID_IRowset, NULL, (LONG*) pdwRowsAffected, (LPUNKNOWN*) &spRowset);
if( FAILED(Hr) ) return _Error(Hr);
return TRUE;
}