void CConnection::Connect(const CDBConnParams& params) { CHECK_NCBI_DBAPI(m_connection != 0, "Connection is already open"); CHECK_NCBI_DBAPI(m_ds == NULL, "m_ds is not initialized"); m_connection = m_ds->GetDriverContext()->MakeConnection(params); // Explicitly set member value ... m_database = m_connection? m_connection->DatabaseName(): string(); }
// New part IStatement* CConnection::GetStatement() { CHECK_NCBI_DBAPI(m_connection == 0, "No connection established"); CHECK_NCBI_DBAPI( m_connUsed, "CConnection::GetStatement(): Connection taken, cannot use this method" ); CStatement *stmt = new CStatement(this); AddListener(stmt); stmt->AddListener(this); return stmt; }
int CCallableStatement::GetReturnStatus() { CHECK_NCBI_DBAPI(!m_StatusIsAvailable, "Return status is not available yet."); /* if (!m_StatusIsAvailable) { ERR_POST_X(10, Warning << "Return status is not available yet."); } */ return m_status; }
CConnection* CConnection::Clone() { CHECK_NCBI_DBAPI(m_ds == NULL, "m_ds is not initialized"); CConnection *conn = new CConnection(CloneCDB_Conn(), m_ds); if( m_msgToEx ) conn->MsgToEx(true); ++m_connCounter; return conn; }
IConnection* CConnection::CloneConnection(EOwnership ownership) { CHECK_NCBI_DBAPI(m_ds == NULL, "m_ds is not initialized"); CDB_Connection *cdbConn = CloneCDB_Conn(); CConnection *conn = new CConnection(m_ds, ownership); conn->m_modeMask = this->GetModeMask(); conn->m_forceSingle = this->m_forceSingle; conn->m_database = this->GetDatabase(); conn->m_connection = cdbConn; if( m_msgToEx ) conn->MsgToEx(true); conn->AddListener(m_ds); m_ds->AddListener(conn); return conn; }
IDataSource* CDriverManager::MakeDs(const CDBConnParams& params, const string& tag) { string tagged_name = params.GetDriverName() + tag; CMutexGuard mg(m_Mutex); TDsContainer::iterator i_ds = m_ds_list.find(tagged_name); if (i_ds != m_ds_list.end()) { return (*i_ds).second; } I_DriverContext* ctx = MakeDriverContext(params); CHECK_NCBI_DBAPI( !ctx, "CDriverManager::CreateDs() -- Failed to get context for driver: " + params.GetDriverName() ); return RegisterDs(tagged_name, ctx); }
IDataSource* CDriverManager::CreateDs(const string& driver_name, const map<string, string>* attr, const string& tag) { string tagged_name = driver_name + tag; CMutexGuard mg(m_Mutex); TDsContainer::iterator i_ds = m_ds_list.find(tagged_name); if (i_ds != m_ds_list.end()) { return (*i_ds).second; } I_DriverContext* ctx = GetDriverContextFromMap( driver_name, attr ); CHECK_NCBI_DBAPI( !ctx, "CDriverManager::CreateDs() -- Failed to get context for driver: " + driver_name ); return RegisterDs(tagged_name, ctx); }
ICallableStatement* CConnection::GetCallableStatement(const string& proc) { CHECK_NCBI_DBAPI( m_connUsed, "CConnection::GetCallableStatement(): Connection taken, cannot use this method" ); /* if( m_cstmt != 0 ) { //m_cstmt->PurgeResults(); delete m_cstmt; } m_cstmt = new CCallableStatement(proc, this); AddListener(m_cstmt); m_cstmt->AddListener(this); return m_cstmt; */ CCallableStatement *cstmt = new CCallableStatement(proc, this); AddListener(cstmt); cstmt->AddListener(this); return cstmt; }
CConnection* CConnection::GetAuxConn() { if( m_connCounter < 0 ) return 0; CConnection *conn = this; CHECK_NCBI_DBAPI( m_connUsed && m_forceSingle, "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; }
CDB_Connection* CConnection::CloneCDB_Conn() { CHECK_NCBI_DBAPI(m_ds == NULL, "m_ds is not initialized"); CDBDefaultConnParams def_params( GetCDB_Connection()->ServerName(), GetCDB_Connection()->UserName(), GetCDB_Connection()->Password(), GetModeMask(), true ); const CCPPToolkitConnParams params(def_params); def_params.SetHost(GetCDB_Connection()->Host()); def_params.SetPort(GetCDB_Connection()->Port()); def_params.SetDatabaseName(GetDatabase()); def_params.SetParam("do_not_dispatch", "true"); def_params.SetParam("do_not_read_conf", "true"); I_DriverContext* dctx = m_ds->GetDriverContext(); CDB_Connection* tmp_conn = dctx->MakeConnection(params); // If the original connection was known to be in a transaction, // operations using the new one could block on its completion, // possibly yielding a deadlock. In such cases, ensure that the // new connection has a reasonable timeout. (MS SQL offers a // finer-grained LOCK_TIMEOUT setting, but that's not portable, // even to Sybase, which is more prone to such deadlocks in the // first place.) if (GetCDB_Connection()->HasTransaction() && dctx->GetTimeout() == 0) { tmp_conn->SetTimeout(5); } _TRACE("CDB_Connection " << (void*)GetCDB_Connection() << " cloned, new CDB_Connection: " << (void*)tmp_conn); return tmp_conn; }
CDB_Connection* CConnection::GetCDB_Connection() { CHECK_NCBI_DBAPI(m_connection == 0, "Database connection has not been initialized"); return m_connection; }