示例#1
0
文件: ADO.cpp 项目: cdecl/GlassLib
//////////////////////////////////////////////////////////////////////
// Query Excute
long ADOComm::Execute(const _bstr_t &bstrSql, const long lCommandTimeout, bool bPrepared)
{
	ADODB::_CommandPtr pCommand;
	pCommand.CreateInstance(__uuidof(Command));

	// CommandTimeout  
	if (lCommandTimeout >= 0) {
		pCommand->PutCommandTimeout(lCommandTimeout);
	}

	pCommand->PutCommandType(ADODB::adCmdText);
	pCommand->PutCommandText(bstrSql);
	pCommand->PutPrepared(bPrepared ? VARIANT_TRUE : VARIANT_FALSE);
	
	_variant_t varRecordsAffected;
	pCommand->PutRefActiveConnection(pConnection_);
	pCommand->Execute(&varRecordsAffected, &vtMissing, ADODB::adExecuteNoRecords); // NoRecords
	pCommand->PutRefActiveConnection(NULL);

	return (long)varRecordsAffected;
}
示例#2
0
文件: ADO.cpp 项目: cdecl/GlassLib
//////////////////////////////////////////////////////////////////////
// Recordset Open
void ADOComm::OpenRs(const _bstr_t &bstrSql, CursorLocationEnum adCursorLocation, const long lCommandTimeout, bool bPrepared)
{
	ADODB::_CommandPtr pCommand;
	pCommand.CreateInstance(__uuidof(Command));

	pCommand->PutCommandType(ADODB::adCmdText);
	pCommand->PutCommandText(bstrSql);
	pCommand->PutPrepared(bPrepared ? VARIANT_TRUE : VARIANT_FALSE);
	
	if (lCommandTimeout >= 0) {
		pCommand->PutCommandTimeout(lCommandTimeout);
	}

	pCommand->PutRefActiveConnection(pConnection_);
	pConnection_->PutCursorLocation(adCursorLocation);

	_variant_t varRecordsAffected;
	pRecordset_ = pCommand->Execute(&varRecordsAffected, &vtMissing, ADODB::adCmdText);
	pCommand->PutRefActiveConnection(NULL);

	if (adCursorLocation != adUseServer) {
		pRecordset_->PutRefActiveConnection(NULL); 
	}
}