Ejemplo n.º 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;
}
Ejemplo n.º 2
0
//执行语句
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));
	}
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
//关闭连接
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));
	}
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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);
		}
	}
Ejemplo n.º 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"));
			}
		}
	}
Ejemplo n.º 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 = "";
	}