📄 adox.cpp
字号:
}
bool CADOXTable::Create(LPCTSTR lpstrTableName)
{
try
{
m_pTable->PutName(lpstrTableName);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXTable::AddField(LPCTSTR lpstrFieldName, enum DataType Type, int nLength)
{
try
{
m_pTable->Columns->Append(lpstrFieldName, (enum DataTypeEnum) Type, nLength);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXTable::AddIndex(CADOXIndex pIndex)
{
try
{
m_pTable->Indexes->Append(_variant_t((IDispatch *)pIndex.m_pIndex));
m_pCatalog->Tables->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXTable::DeleteField(LPCTSTR lpstrFieldName)
{
try
{
m_pTable->Columns->Delete(lpstrFieldName);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXTable::GetName(CString& strTableName)
{
_variant_t vName;
ASSERT(m_pTable != NULL);
vName = m_pTable->GetName();
strTableName = vName.bstrVal;
}
void CADOXTable::dump_com_error(_com_error &e)
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format( _T("CADOXTable Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n"),
e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCTSTR)bstrDescription );
#ifdef _DEBUG
AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
#endif
}
////////////////////////////////////////////////////////
//
// CADOXCAtalog Class
//
bool CADOXCatalog::CreateDatabase(LPCTSTR lpstrCreate)
{
try
{
m_pCatalog->Create(_bstr_t(lpstrCreate));
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::Open(LPCTSTR lpstrConnection)
{
HRESULT hr = S_OK;
TESTHR(hr = m_pConn.CreateInstance(__uuidof(ADODB::Connection)));
try
{
m_pConn->Open(lpstrConnection, "", "", NULL);
m_pCatalog->PutActiveConnection(variant_t((IDispatch *)m_pConn));
//m_pCatalog->PutActiveConnection(_bstr_t(lpstrConnection));
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::AddTable(CADOXTable pTable)
{
try
{
m_pCatalog->Tables->Append( _variant_t((IDispatch *)pTable.m_pTable));
m_pCatalog->Tables->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXCatalog::GetTableName(long nTableIndex, CString &strTableName)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nTableIndex >= 0 && nTableIndex < m_pCatalog->Tables->GetCount());
strTableName = (LPCTSTR)m_pCatalog->Tables->GetItem(nTableIndex)->GetName();
}
bool CADOXCatalog::DeleteTable(LPCTSTR lpstrTableName)
{
ASSERT(m_pCatalog != NULL);
try
{
m_pCatalog->Tables->Delete(lpstrTableName);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::DeleteTable(long nTableIndex)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nTableIndex >= 0 && nTableIndex < m_pCatalog->Tables->GetCount());
try
{
m_pCatalog->Tables->Delete(nTableIndex);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXCatalog::GetProcedureName(long nProcedure, CString &strProcedureName)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nProcedure >= 0 && nProcedure < m_pCatalog->Procedures->GetCount());
strProcedureName = (LPCTSTR)m_pCatalog->Procedures->GetItem(nProcedure)->GetName();
}
bool CADOXCatalog::DeleteProcedure(long nProcedure)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nProcedure >= 0 && nProcedure < m_pCatalog->Procedures->GetCount());
try
{
m_pCatalog->Procedures->Delete(nProcedure);
m_pCatalog->Procedures->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::DeleteProcedure(LPCTSTR lpstrProcedureName)
{
ASSERT(m_pCatalog != NULL);
try
{
m_pCatalog->Procedures->Delete(lpstrProcedureName);
m_pCatalog->Procedures->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
long CADOXCatalog::GetViewCount()
{
ASSERT(m_pCatalog != NULL);
try
{
return m_pCatalog->Views->GetCount();
}
catch(_com_error &e)
{
dump_com_error(e);
return -1;
}
}
void CADOXCatalog::GetViewName(long nViewIndex, CString &strViewName)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nViewIndex >= 0 && nViewIndex < m_pCatalog->Views->GetCount());
strViewName = (LPCTSTR)m_pCatalog->Views->GetItem(nViewIndex)->GetName();
}
bool CADOXCatalog::DeleteView(LPCTSTR lpstrViewName)
{
ASSERT(m_pCatalog != NULL);
try
{
m_pCatalog->Views->Delete(lpstrViewName);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::DeleteView(long nViewIndex)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nViewIndex >= 0 && nViewIndex < m_pCatalog->Views->GetCount());
try
{
m_pCatalog->Views->Delete(nViewIndex);
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXCatalog::GetGroupName(long nGroupIndex, CString &strGroupName)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nGroupIndex >= 0 && nGroupIndex < m_pCatalog->Groups->GetCount());
strGroupName = (LPCTSTR)m_pCatalog->Groups->GetItem(nGroupIndex)->GetName();
}
bool CADOXCatalog::DeleteGroup(LPCTSTR lpstrGroupName)
{
ASSERT(m_pCatalog != NULL);
try
{
m_pCatalog->Groups->Delete(lpstrGroupName);
m_pCatalog->Groups->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::DeleteGroup(long nGroupIndex)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nGroupIndex >= 0 && nGroupIndex < m_pCatalog->Groups->GetCount());
try
{
m_pCatalog->Groups->Delete(nGroupIndex);
m_pCatalog->Groups->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXCatalog::GetUserName(long nUserIndex, CString &strUserName)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nUserIndex >= 0 && nUserIndex < m_pCatalog->Users->GetCount());
strUserName = (LPCTSTR)m_pCatalog->Users->GetItem(nUserIndex)->GetName();
}
bool CADOXCatalog::DeleteUser(LPCTSTR lpstrUserName)
{
ASSERT(m_pCatalog != NULL);
try
{
m_pCatalog->Users->Delete(lpstrUserName);
m_pCatalog->Users->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::DeleteUser(long nUserIndex)
{
ASSERT(m_pCatalog != NULL);
ASSERT(nUserIndex >= 0 && nUserIndex < m_pCatalog->Users->GetCount());
try
{
m_pCatalog->Users->Delete(nUserIndex);
m_pCatalog->Users->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
bool CADOXCatalog::AddUser(CADOXUser pUser, LPCTSTR lpstrPassword)
{
try
{
m_pCatalog->Users->Append( _variant_t((IDispatch *)pUser.m_pUser), _bstr_t(lpstrPassword));
m_pCatalog->Users->Refresh();
return true;
}
catch(_com_error &e)
{
dump_com_error(e);
return false;
}
}
void CADOXCatalog::dump_com_error(_com_error &e)
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format( _T("CADOXCatalog Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n"),
e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCTSTR)bstrDescription );
#ifdef _DEBUG
AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -