本文整理汇总了C++中CDatabase::IsOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ CDatabase::IsOpen方法的具体用法?C++ CDatabase::IsOpen怎么用?C++ CDatabase::IsOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDatabase
的用法示例。
在下文中一共展示了CDatabase::IsOpen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
CDatabase *CCachedDBConnections::GetConnection(const CString &strConnect, BOOL bAutoOpen)
{
CCacheMap::CPair *pKeyValPair = m_DBCache.PLookup(strConnect);
CDatabase *pDB = NULL;
if (pKeyValPair != NULL)
{
pDB = pKeyValPair->value;
}
if (NULL == pDB)
{
try { pDB = new CDatabase; }
catch (...) { pDB = NULL; }
}
if (pDB != NULL && !pDB->IsOpen() && bAutoOpen)
{
ATLVERIFY(pDB->OpenEx(strConnect,
CDatabase::useCursorLib | CDatabase::noOdbcDialog));
}
if (NULL == pKeyValPair)
{
m_DBCache[strConnect] = pDB;
}
return pDB;
}
示例2: ODBCCmdSQL
bool EVUtil::ODBCCmdSQL( CString szDBName,CString sql )
{
CDatabase db;
CString strConnect;
strConnect.Format(_T("ODBC;DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)};UID=sa;PWD=;DBQ=%s"), szDBName);
db.Open(NULL, FALSE, FALSE, strConnect,FALSE);
if(db.IsOpen())
{
//连接数据库成功
CRecordset rs(&db); //SQL语句
try
{
db.ExecuteSQL(sql);
}
catch (...)
{
db.Close();
return false;
}
db.Close();
return true;
}
return false;
}
示例3: GetMinMax
bool CGUIDialogMediaFilter::GetMinMax(const std::string &table, const std::string &field, int &min, int &max, const CDatabase::Filter &filter /* = CDatabase::Filter() */)
{
if (table.empty() || field.empty())
return false;
CDatabase *db = NULL;
CDbUrl *dbUrl = NULL;
if (m_mediaType == "movies" || m_mediaType == "tvshows" || m_mediaType == "episodes" || m_mediaType == "musicvideos")
{
CVideoDatabase *videodb = new CVideoDatabase();
if (!videodb->Open())
{
delete videodb;
return false;
}
db = videodb;
dbUrl = new CVideoDbUrl();
}
else if (m_mediaType == "artists" || m_mediaType == "albums" || m_mediaType == "songs")
{
CMusicDatabase *musicdb = new CMusicDatabase();
if (!musicdb->Open())
{
delete musicdb;
return false;
}
db = musicdb;
dbUrl = new CMusicDbUrl();
}
if (db == NULL || !db->IsOpen() || dbUrl == NULL)
{
delete db;
delete dbUrl;
return false;
}
CDatabase::Filter extFilter = filter;
std::string strSQLExtra;
if (!db->BuildSQL(m_dbUrl->ToString(), strSQLExtra, extFilter, strSQLExtra, *dbUrl))
{
delete db;
delete dbUrl;
return false;
}
std::string strSQL = "SELECT %s FROM %s ";
min = static_cast<int>(strtol(db->GetSingleValue(db->PrepareSQL(strSQL, std::string("MIN(" + field + ")").c_str(), table.c_str()) + strSQLExtra).c_str(), NULL, 0));
max = static_cast<int>(strtol(db->GetSingleValue(db->PrepareSQL(strSQL, std::string("MAX(" + field + ")").c_str(), table.c_str()) + strSQLExtra).c_str(), NULL, 0));
db->Close();
delete db;
delete dbUrl;
return true;
}
示例4: mrd
//定义的向数据库存储新的基本信息的函数
_declspec(dllexport) int WINAPI putmsg(void *res)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
whichtab=0;
bmsg bt;
if(res==NULL)
return 1; //error
memset((void*)&bt,0,sizeof(bt));
memcpy((void*)&bt,res,sizeof(bt));
CString str;
crt_conn(str);
CDatabase db;
if(db.IsOpen())
db.Close();
try
{db.Open(NULL,false,false,str);}
catch(CDBException *ep)
{
MessageBox(NULL,ep->m_strError,"from dll",0);
return 1;
}
myrecord mrd(&db);
if(mrd.IsOpen())
mrd.Close();
try
{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM base_msg");}
catch(CDBException *ep)
{
db.Close();
MessageBox(NULL,ep->m_strError,"from dll",0);
return 1;
}
mrd.AddNew();
// memset((void*)&mrd.bsd,0,sizeof(mrd.bsd));
// memcpy((void*)&mrd.bsd,bt,sizeof(mrd.bsd));
/*2015-6-15 不使用整个结构拷贝,而是逐个字段赋值的方法可以避免自动增量字段的人为改变。
这里还有一个微软认可的bug,就是在调试模式时,就会出现一个CRecordset的成员地址改变的傻逼断言,
该断言好像在dbrfx.cpp文件中(line560),通过查看dbrfx.cpp文件发现,这个断言是在#ifdef _DEBUG的判断下
执行的,所以在release版本下不会有错误,但是在调式模式下会出现断言错误。
*/
mrd.bsd.code=bt.code;
mrd.bsd.gmax=bt.gmax;
mrd.bsd.gstd=bt.gstd;
mrd.bsd.gtimes=bt.gtimes;
mrd.bsd.gtype=bt.gtype;
mrd.bsd.gwatch=bt.gwatch;
memcpy((void *)&(mrd.bsd.name),(void*)&(bt.name),60);
mrd.bsd.gcycle=bt.gcycle;
mrd.bsd.gdecay=bt.gdecay;
mrd.Update();
mrd.Close();
db.Close();
return 0;
};
示例5: Connect
bool COleDBConnectionProp::Connect(CDatabase& database, bool bShowDialog)
{
CWaitCursor cursor;
if(m_strDSN.IsEmpty())
{
ShowError("Empty ODBC Source");
return false;
}
if(m_strLoginName.IsEmpty())
{
ShowError("Empty Login Name");
return false;
}
CString ConnectString =
"DSN=" + m_strDSN + ";";
if(!m_strDatabaseName.IsEmpty())
{
ConnectString +=
"DATABASE=" + m_strDatabaseName + ";";
}
ConnectString +=
"UID=" + m_strLoginName + ";" +
"PWD=" + m_strPassword + ";"
;
try
{
DWORD dwOptions = CDatabase::useCursorLib;
if(!bShowDialog)
dwOptions |= CDatabase::noOdbcDialog;
if(database.IsOpen())
database.Close();
if(!database.OpenEx(ConnectString,dwOptions))
{
return false;
}
}
catch( CDBException* pExc)
{
pExc->ReportError();
pExc->Delete();
return false;
}
return true;
}
示例6: CloseConnection
int CMyDatabase::CloseConnection( CDatabase &m_Database)
{
try
{
if ( m_Database.IsOpen() )
m_Database.Close();
}
catch( CDBException *e)
{
char Message[255] = {0};
sprintf(Message,"CMyDatabase::CloseConnection(%s)",e->m_strError);
WriteLog(Message,"");
e->Delete();
}
return 0;
}
示例7: RemoveConnection
void CCachedDBConnections::RemoveConnection(const CString &strConnect)
{
CCacheMap::CPair *pKeyValPair = m_DBCache.PLookup(strConnect);
if (pKeyValPair != NULL)
{
CDatabase *pDB = NULL;
std::swap(pDB, pKeyValPair->value);
if (pDB != NULL)
{
if (pDB->IsOpen())
{
pDB->Close();
}
delete pDB;
pDB = NULL;
}
m_DBCache.RemoveKey(strConnect);
}
}
示例8: CloseSocket
BOOL CServerSocet::CloseSocket(CString* sMessage)
{
if(SocWin != NULL)
if(SocWin->m_hWnd != NULL)
SocWin->DestroyWindow();
if (sokClientSocket!= NULL)
{
int i;
for(i=0;i<iMaxCol;i++)
{
if(sokClientSocket[i]!=NULL)
{
CDatabase* dBase;
if(sokClientSocket[i]->dBase != NULL)
{
try
{
dBase = sokClientSocket[i]->dBase;
if(dBase!=NULL)
{
if(dBase->IsOpen())
{
dBase->Close();
}
}
}
catch(...)
{
}
delete(dBase);
sokClientSocket[i]->dBase = NULL;
}
if(sokClientSocket[i]->hThread != NULL)
{
TerminateThread(sokClientSocket[i]->hThread,0);
}
sokClientSocket[i]->hThread = NULL;
delete(sokClientSocket[i]);
sokClientSocket[i] = NULL;
}
}
delete(sokClientSocket);
sokClientSocket = NULL;
}
CString S;
S.Format(_T("Закрытие сокета"));
if(sMessage != NULL)
{
*sMessage = *sMessage + S;
}
if(bCreateSocket)
closesocket(sokServerSocket);
bCreateSocket = FALSE;
if(sMessage != NULL)
*sMessage = *sMessage + _T("\tвыполненно\n");
bStatus = FALSE;
return TRUE;
}
示例9: ExportData
UINT CNav_ExportCustomsDlg::ExportData(LPVOID p)
{
HRESULT hRes;
Excel::_ApplicationPtr appExcel;
hRes = appExcel.CreateInstance( _T("Excel.Application"));
CNav_ExportCustomsDlg *Dialog;
Dialog = (CNav_ExportCustomsDlg*)p;
if(Dialog != NULL)
{
CString sStart, sEnd;
Dialog->m_EndDate.GetWindowText(sEnd);
Dialog->m_StartDate.GetWindowText(sStart);
CString sGTD;
Dialog->m_EdGTDNUMBER.GetWindowText(sGTD);
COleDateTime datStart,datEnd, cDate;
datStart.ParseDateTime(sStart);
datEnd.ParseDateTime(sEnd);
CString sConnect;
CString sServer, sDatabase;
sServer = sReadFromIni(_T("DB"),_T("SERVER"),_T("svbyminssq3"));
//sWriteToIni(_T("DB"),_T("SERVER"),sServer);
sDatabase = sReadFromIni(_T("DB"),_T("DATABASE"),_T("SHATE-M-8"));
//sWriteToIni(_T("DB"),_T("DATABASE"),sDatabase);
Excel::WorkbooksPtr ExcelBooks;
Excel::_WorkbookPtr ExcelBook;
Excel::_WorksheetPtr ExcelSheet;
Excel::RangePtr range;
VARIANT bTRUE;
bTRUE.vt = 11;
bTRUE.boolVal = TRUE;
appExcel->Visible[0] = FALSE;
ExcelBook= appExcel->Workbooks->Add();
ExcelSheet = ExcelBook->Worksheets->Item[1];
sConnect.Format(_T("DRIVER=SQL Server;SERVER=%s;UID=;WSID=%s;Trusted_Connection=Yes;DATABASE=%s;LANGUAGE=русский"),sServer,GetWinUserName(),sDatabase);
CDatabase* dBase;
dBase = NULL;
try
{
dBase = new(CDatabase);
dBase->SetQueryTimeout(600);
dBase->OpenEx(sConnect,CDatabase::noOdbcDialog);
sConnect.Format(_T("EXEC [sp_setapprole] '%s', '%s', 'none', 0, 0"),_T("$ndo$shadow"),_T("FF5EC4E40F67BD4EDF3D04F8B84364DAD0"));
dBase->ExecuteSQL(sConnect);
}
catch(CDBException *exsept)
{
appExcel->Visible[0] = TRUE;
Dialog->m_stState.SetWindowTextW(exsept->m_strError);
exsept->Delete();
if(dBase != NULL)
{
if(dBase->IsOpen())
{
dBase->Close();
}
delete(dBase);
}
dBase = NULL;
Dialog->m_BtOK.ShowWindow(1);
Dialog->SecondThread = NULL;
return 0;
}
CString sSQL;
try
{
CRecordset Query(dBase);
int iField;
CDBVariant dbValue;
Dialog->m_stState.SetWindowTextW(_T("Формирование"));
sGTD = sGTD + _T("'");
sSQL = _T("select distinct SIH.[Posting Date],(SIL.[TTN Series]+SIL.[TTN Number]) AS TTN,SIL.[Item No_ 2], SIH.[Bill-to Name] ");
sSQL = sSQL + _T(" from [")+sDatabase;
sSQL = sSQL + _T("$Sales Invoice Header] as SIH join [");
sSQL = sSQL + sDatabase;
sSQL = sSQL + _T("$Sales Invoice Line] as SIL on SIL.[Document No_] = SIH.[No_] and SIL.[No_] is not null and SIL.[No_] <> '' and SIL.[TTN Series] <> '' and SIL.[TTN Number] <> '' join [");
sSQL = sSQL + sDatabase;
sSQL = sSQL + _T("$Custom Declaration Relation] as CDR on CDR.[Item No_] = SIL.[No_] and CDR.[Document Type] = 5 and CDR.[CD No_] = '") + sGTD;
sSQL = sSQL + _T(" where [Sales Process Type Code] = 'Б/Н_ДОСТАВКА' and Left(CONVERT ( nchar , SIH.[Posting Date], 112),8) >= '")+ datStart.Format(_T("%Y%m%d"))+_T("'");
sSQL = sSQL + _T(" and Left(CONVERT ( nchar , SIH.[Posting Date], 112),8) <= '")+ datEnd.Format(_T("%Y%m%d"))+_T("'");
//sSQL = sSQL + _T(" and CDR.[CD No_] = '") + sGTD;
//.........这里部分代码省略.........