예제 #1
0
bool CDBAdo::ExecuteCommand(bool bIsRecordset)
{
	try 
	{
		//关闭记录集
		CloseRecordset();
		//执行命令
		if(bIsRecordset)
		{
			m_ptrRecordset->PutRefSource(m_ptrCommand);
			m_ptrRecordset->CursorLocation	= adUseClient;
			DetectResult(m_ptrRecordset->Open((IDispatch*)m_ptrCommand, vtMissing, adOpenForwardOnly, adLockReadOnly, adOptionUnspecified));
		}else 
		{
			m_ptrConnection->CursorLocation	= adUseClient;
			DetectResult(m_ptrCommand->Execute(NULL, NULL, adExecuteNoRecords));
		}
		return	true;
	}
	catch(_com_error& comError)
	{
		RecordErrorMsg(comError);
	}

	return	false;
}
예제 #2
0
파일: DataBase.cpp 프로젝트: anyboo/project
//执行语句
VOID __cdecl CDataBase::ExecuteProcess(LPCTSTR pszSPName, bool bRecordset)
{
	ASSERT(pszSPName != NULL);
	try
	{
		//关闭记录集
		CloseRecordset();

		m_DBCommand->CommandText = pszSPName;

		//执行命令
		if (bRecordset == true)
		{
			m_DBRecordset->PutRefSource(m_DBCommand);
			m_DBRecordset->CursorLocation = adUseClient;
			EfficacyResult(m_DBRecordset->Open((IDispatch *)m_DBCommand, vtMissing, adOpenForwardOnly, adLockReadOnly, adOptionUnspecified));
		}
		else
		{
			m_DBConnection->CursorLocation = adUseClient;
			EfficacyResult(m_DBCommand->Execute(NULL, NULL, adExecuteNoRecords));
		}
	}
	catch (CComError & ComError)
	{
		if (IsConnectError() == true)	TryConnectAgain(false, &ComError);
		else SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}
}
예제 #3
0
//执行命令
bool __cdecl CDataBase::ExecuteCommand(bool bRecordset)
{
	try 
	{
		//关闭记录集
		CloseRecordset();

		//执行命令
		if (bRecordset==true)
		{
			m_DBRecordset->PutRefSource(m_DBCommand);
			m_DBRecordset->CursorLocation=adUseClient;
			EfficacyResult(m_DBRecordset->Open((IDispatch *)m_DBCommand,vtMissing,adOpenForwardOnly,adLockReadOnly,adOptionUnspecified));
		}
		else 
		{
			m_DBConnection->CursorLocation=adUseClient;
			EfficacyResult(m_DBCommand->Execute(NULL,NULL,adExecuteNoRecords));
		}
		return true;
	}
	catch (CComError & ComError) 
	{ 
		if (IsConnectError()==true)	TryConnectAgain(false,&ComError);
		else SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError));
	}

	return false;
}
예제 #4
0
파일: DataBase.cpp 프로젝트: anyboo/project
//关闭连接
VOID __cdecl CDataBase::CloseConnection()
{
	try
	{
		CloseRecordset();
		if ((m_DBConnection != NULL) && (m_DBConnection->GetState() != adStateClosed))
		{
			EfficacyResult(m_DBConnection->Close());
		}
	}
	catch (CComError & ComError)
	{
		SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}
}
예제 #5
0
//关闭连接
bool __cdecl CDataBase::CloseConnection()
{
	try
	{
		CloseRecordset();
		if ((m_DBConnection!=NULL)&&(m_DBConnection->GetState()!=adStateClosed))
		{
			EfficacyResult(m_DBConnection->Close());
		}
		return true;
	}
	catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }

	return false;
}
예제 #6
0
bool CDBAdo::CloseConnection()
{
	try
	{
		CloseRecordset();
		if((m_ptrConnection!=NULL)&&(m_ptrConnection->GetState()!=adStateClosed))
			DetectResult(m_ptrConnection->Close());

		return true;
	}
	catch(_com_error& comError)
	{
		RecordErrorMsg(comError);
	}

	return false;
}
예제 #7
0
bool CDBAdo::OpenRecordset(char* szSQL)
{
	try
	{
		//关闭记录集
		CloseRecordset();

		m_ptrRecordset->Open(szSQL, m_ptrConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);

		return true;
	}
	catch(_com_error& comError)
	{
		RecordErrorMsg(comError);
	}

	return	false;
}
예제 #8
0
	void CVLDatabase::OpenRecordset(CursorTypeEnum cursorType, bool bind,
		LockTypeEnum lockType, CursorLocationEnum cursorLocation)
	{
		CloseRecordset();
		recordset->CursorLocation = cursorLocation;
		recordset->Open((_bstr_t)recordsetName.c_str(), _variant_t((IDispatch*)connection, true),
			cursorType, lockType, adCmdTableDirect);
		opened = true;
		if (bind)
		{
			HRESULT hr = S_OK;
			hr = recordset->QueryInterface(__uuidof(IADORecordBinding), (LPVOID*)&recordBinding);
			if (FAILED(hr)) _com_raise_error(hr);

			hr = recordBinding->BindToRecordset(&record);
			if (FAILED(hr)) _com_raise_error(hr);
		}
	}
예제 #9
0
	void CVLDatabase::Clear()
	{
		ClearItems();
		if (opened)
		{
			try
			{
				CloseRecordset();
				connection->Execute(Format(TEXT("DELETE FROM %s"), (LPCTSTR)recordsetName.c_str()).c_str(),
					NULL, adCmdText | adExecuteNoRecords);
				OpenRecordset();
			}
			catch(_com_error &e)
			{
				ComErrorToException(e, string("Can not clear database"));
			}
		}
	}
예제 #10
0
	void CVLDatabase::Close()
	{
		ClearItems();
		try
		{
			CloseRecordset();
			recordset = NULL;
			if (connected)
			{
				connection->Close();
				connected = false;
			}
			connection = NULL;
		}
		catch (_com_error &e)
		{
			ComErrorToException(e, string("Can not close database"));
		}
		provider = "";
		dataSource = "";
	}