CVOConnection::CVOConnection(LPCTSTR pcszProvider) : m_Conn(NULL)
{
if(!g_Init)
Initialize();
HRESULT hr;
if(pcszProvider == NULL)
{
pcszProvider = TEXT("edb");
hr = CoCreateInstance(g_ClsID, NULL, CLSCTX_INPROC_SERVER, IID__Connection, (LPVOID*) &m_Conn);
hr = m_Conn->put_Provider((LPTSTR)pcszProvider);
//hr = m_Conn->Open(TEXT(""),TEXT(""),TEXT(""),adOpenUnspecified);
}
else
{
m_strProvider = pcszProvider;
m_Conn = NULL;
}
}
CVOConnection::~CVOConnection()
{
if(m_Conn)
{
m_Conn->Close();
m_Conn->Release();
}
}
BOOL CVOConnection::Initialize()
{
if(FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
return FALSE;
HRESULT hr;
hr = CLSIDFromProgID(g_ProgID, &g_ClsID);
if(FAILED(hr))
return FALSE;
return TRUE;
}
BOOL CVOConnection::Execute(LPCTSTR pcszSQL)
{
CVORecordset rs(*this);
return rs.Open(pcszSQL, adOpenForwardOnly, adLockPessimistic);
}