📄 conn_impl.cpp
字号:
}void CConnection::FreeResources() { delete m_stmt; //m_stmt = 0; delete m_cstmt; //m_cstmt = 0; delete m_cursor; // m_cursor = 0; delete m_bulkInsert; //m_bulkInsert = 0; delete m_connection; m_connection = 0;}CConnection* CConnection::Clone(){ CConnection *conn = new CConnection(CloneCDB_Conn(), m_ds); //conn->AddListener(m_ds); //m_ds->AddListener(conn); conn->SetDbName(GetDatabase()); ++m_connCounter; return conn;}IConnection* CConnection::CloneConnection(){ CConnection *conn = new CConnection(m_ds); conn->m_modeMask = this->m_modeMask; conn->m_forceSingle = this->m_forceSingle; conn->m_connection = CloneCDB_Conn(); conn->m_database = this->m_database; conn->AddListener(m_ds); m_ds->AddListener(conn); return conn;}// New partIStatement* CConnection::GetStatement(){ if( m_connUsed ) throw CDbapiException("CConnection::GetStatement(): Connection taken, cannot use this method"); if( m_stmt == 0 ) { m_stmt = new CStatement(this); AddListener(m_stmt); m_stmt->AddListener(this); } return m_stmt;}ICallableStatement*CConnection::GetCallableStatement(const string& proc, int nofArgs){ if( m_connUsed ) throw CDbapiException("CConnection::GetCallableStatement(): Connection taken, cannot use this method"); if( m_cstmt != 0 ) { //m_cstmt->PurgeResults(); delete m_cstmt; } m_cstmt = new CCallableStatement(proc, nofArgs, this); AddListener(m_cstmt); m_cstmt->AddListener(this); return m_cstmt;}ICursor* CConnection::GetCursor(const string& name, const string& sql, int nofArgs, int batchSize){ if( m_connUsed ) throw CDbapiException("CConnection::GetCursor(): Connection taken, cannot use this method"); if( m_cursor != 0 ) { delete m_cursor; } m_cursor = new CCursor(name, sql, nofArgs, batchSize, this); AddListener(m_cursor); m_cursor->AddListener(this); return m_cursor;}IBulkInsert* CConnection::GetBulkInsert(const string& table_name, unsigned int nof_cols){ if( m_connUsed ) throw CDbapiException("CConnection::GetBulkInsert(): Connection taken, cannot use this method"); if( m_bulkInsert != 0 ) { delete m_bulkInsert; } m_bulkInsert = new CBulkInsert(table_name, nof_cols, this); AddListener(m_bulkInsert); m_bulkInsert->AddListener(this); return m_bulkInsert;}// New part endIStatement* CConnection::CreateStatement(){ if( m_stmt != 0 || m_cstmt != 0 || m_cursor != 0 || m_bulkInsert != 0 ) throw CDbapiException("CConnection::CreateStatement(): Get...() methods used"); CStatement *stmt = new CStatement(GetAuxConn()); AddListener(stmt); stmt->AddListener(this); return stmt;}ICallableStatement*CConnection::PrepareCall(const string& proc, int nofArgs){ if( m_stmt != 0 || m_cstmt != 0 || m_cursor != 0 || m_bulkInsert != 0 ) throw CDbapiException("CConnection::CreateCallableStatement(): Get...() methods used"); CCallableStatement *cstmt = new CCallableStatement(proc, nofArgs, GetAuxConn()); AddListener(cstmt); cstmt->AddListener(this); return cstmt;}ICursor* CConnection::CreateCursor(const string& name, const string& sql, int nofArgs, int batchSize){ if( m_stmt != 0 || m_cstmt != 0 || m_cursor != 0 || m_bulkInsert != 0 ) throw CDbapiException("CConnection::CreateCursor(): Get...() methods used"); CCursor *cur = new CCursor(name, sql, nofArgs, batchSize, GetAuxConn()); AddListener(cur); cur->AddListener(this); return cur;}IBulkInsert* CConnection::CreateBulkInsert(const string& table_name, unsigned int nof_cols){ if( m_stmt != 0 || m_cstmt != 0 || m_cursor != 0 || m_bulkInsert != 0 ) throw CDbapiException("CConnection::CreateBulkInsert(): Get...() methods used"); CBulkInsert *bcp = new CBulkInsert(table_name, nof_cols, GetAuxConn()); AddListener(bcp); bcp->AddListener(this); return bcp;}void CConnection::Action(const CDbapiEvent& e){ _TRACE(GetIdent() << " " << (void*)this << ": '" << e.GetName() << "' received from " << e.GetSource()->GetIdent()); if(dynamic_cast<const CDbapiClosedEvent*>(&e) != 0 ) { CStatement *stmt; CCallableStatement *cstmt; CCursor *cursor; CBulkInsert *bulkInsert; if( (cstmt = dynamic_cast<CCallableStatement*>(e.GetSource())) != 0 ) { if( cstmt == m_cstmt ) { _TRACE("CConnection: Clearing cached callable statement " << (void*)m_cstmt); m_cstmt = 0; } } else if( (stmt = dynamic_cast<CStatement*>(e.GetSource())) != 0 ) { if( stmt == m_stmt ) { _TRACE("CConnection: Clearing cached statement " << (void*)m_stmt); m_stmt = 0; } } else if( (cursor = dynamic_cast<CCursor*>(e.GetSource())) != 0 ) { if( cursor == m_cursor ) { _TRACE("CConnection: Clearing cached cursor " << (void*)m_cursor); m_cursor = 0; } } else if( (bulkInsert = dynamic_cast<CBulkInsert*>(e.GetSource())) != 0 ) { if( bulkInsert == m_bulkInsert ) { _TRACE("CConnection: Clearing cached bulkinsert " << (void*)m_bulkInsert); m_bulkInsert = 0; } } if( m_connCounter == 1 ) m_connUsed = false; } else if(dynamic_cast<const CDbapiAuxDeletedEvent*>(&e) != 0 ) { if( m_connCounter > 1 ) { --m_connCounter; _TRACE("Server: " << GetCDB_Connection()->ServerName() <<", connections left: " << m_connCounter); } else m_connUsed = false; } else if(dynamic_cast<const CDbapiDeletedEvent*>(&e) != 0 ) { RemoveListener(e.GetSource()); if(dynamic_cast<CDataSource*>(e.GetSource()) != 0 ) { delete this; } }}CConnection* CConnection::GetAuxConn(){ if( m_connCounter < 0 ) return 0; CConnection *conn = this; if( m_connUsed && m_forceSingle ) { throw CDbapiException("GetAuxConn(): Extra connections not permitted"); } if( m_connUsed ) { conn = Clone(); _TRACE("GetAuxConn(): Server: " << GetCDB_Connection()->ServerName() << ", open aux connection, total: " << m_connCounter); } else { m_connUsed = true; _TRACE("GetAuxconn(): server: " << GetCDB_Connection()->ServerName() << ", no aux connections necessary, using default..."); } return conn;}void CConnection::MsgToEx(bool v){ if( !v ) { // Clear the previous handlers if present GetCDB_Connection()->PopMsgHandler(GetHandler()); } else { GetCDB_Connection()->PushMsgHandler(GetHandler()); }}CToMultiExHandler* CConnection::GetHandler(){ if(m_multiExH == 0 ) { m_multiExH = new CToMultiExHandler; } return m_multiExH;}CDB_MultiEx* CConnection::GetErrorAsEx(){ return GetHandler()->GetMultiEx();}string CConnection::GetErrorInfo(){ CNcbiOstrstream out; CDB_UserHandler_Stream h(&out); h.HandleIt(GetHandler()->GetMultiEx()); return CNcbiOstrstreamToString(out);}/*void CConnection::DeleteConn(CConnection* conn){ if( m_connCounter > 1) { delete conn; --m_connCounter; } _TRACE("Connection deleted, total left: " << m_connCounter); return;}*/END_NCBI_SCOPE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -