⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: connection.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:20:09  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== *//* $Id: connection.cpp,v 1000.1 2004/06/01 19:20:09 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Vladimir Soussov * * File Description:  DBLib connection * */#include <ncbi_pch.hpp>#ifndef USE_MS_DBLIB#  include <dbapi/driver/dblib/interfaces.hpp>#  include <dbapi/driver/dblib/interfaces_p.hpp>#else#  include <dbapi/driver/msdblib/interfaces.hpp>#  include <dbapi/driver/msdblib/interfaces_p.hpp>#endif#include <string.h>BEGIN_NCBI_SCOPECDBL_Connection::CDBL_Connection(CDBLibContext* cntx, DBPROCESS* con,                                 bool reusable, const string& pool_name) :    m_Link(con), m_Context(cntx), m_Pool(pool_name), m_Reusable(reusable),    m_BCPAble(false), m_SecureLogin(false), m_ResProc(0){    dbsetuserdata(m_Link, (BYTE*) this);}bool CDBL_Connection::IsAlive(){    return DBDEAD(m_Link) == FALSE;}CDB_LangCmd* CDBL_Connection::LangCmd(const string& lang_query,                                      unsigned int nof_parms){    CDBL_LangCmd* lcmd = new CDBL_LangCmd(this, m_Link, lang_query, nof_parms);    m_CMDs.Add(lcmd);    return Create_LangCmd(*lcmd);}CDB_RPCCmd* CDBL_Connection::RPC(const string& rpc_name, unsigned int nof_args){    CDBL_RPCCmd* rcmd = new CDBL_RPCCmd(this, m_Link, rpc_name, nof_args);    m_CMDs.Add(rcmd);    return Create_RPCCmd(*rcmd);}CDB_BCPInCmd* CDBL_Connection::BCPIn(const string& tab_name,                                     unsigned int nof_cols){    if (!m_BCPAble) {        throw CDB_ClientEx(eDB_Error, 210003, "CDBL_Connection::BCPIn",                           "No bcp on this connection");    }    CDBL_BCPInCmd* bcmd = new CDBL_BCPInCmd(this, m_Link, tab_name, nof_cols);    m_CMDs.Add(bcmd);    return Create_BCPInCmd(*bcmd);}CDB_CursorCmd* CDBL_Connection::Cursor(const string& cursor_name,                                       const string& query,                                       unsigned int nof_params,                                       unsigned int){    CDBL_CursorCmd* ccmd = new CDBL_CursorCmd(this, m_Link, cursor_name,                                              query, nof_params);    m_CMDs.Add(ccmd);    return Create_CursorCmd(*ccmd);}CDB_SendDataCmd* CDBL_Connection::SendDataCmd(I_ITDescriptor& descr_in,                                              size_t data_size, bool log_it){    if (data_size < 1) {        throw CDB_ClientEx(eDB_Fatal, 210092,                           "CDBL_Connection::SendDataCmd",                           "wrong (zero) data size");    }    I_ITDescriptor* p_desc= 0;    // check what type of descriptor we've got    if(descr_in.DescriptorType() != #ifndef MS_DBLIB_IN_USE		CDBL_ITDESCRIPTOR_TYPE_MAGNUM#else		CMSDBL_ITDESCRIPTOR_TYPE_MAGNUM#endif		) {	// this is not a native descriptor	p_desc= x_GetNativeITDescriptor(dynamic_cast<CDB_ITDescriptor&> (descr_in));	if(p_desc == 0) return false;    }        C_ITDescriptorGuard d_guard(p_desc);    CDBL_ITDescriptor& desc = p_desc? dynamic_cast<CDBL_ITDescriptor&> (*p_desc) : 	dynamic_cast<CDBL_ITDescriptor&> (descr_in);    if (dbwritetext(m_Link,                    (char*) desc.m_ObjName.c_str(),                    desc.m_TxtPtr_is_NULL ? 0 : desc.m_TxtPtr,                    DBTXPLEN,                    desc.m_TimeStamp_is_NULL ? 0 : desc.m_TimeStamp,                    log_it ? TRUE : FALSE,                    (DBINT) data_size, 0) != SUCCEED ||        dbsqlok(m_Link) != SUCCEED ||        //        dbresults(m_Link) == FAIL) {        x_Results(m_Link) == FAIL) {        throw CDB_ClientEx(eDB_Error, 210093, "CDBL_Connection::SendDataCmd",                           "dbwritetext/dbsqlok/dbresults failed");    }    CDBL_SendDataCmd* sd_cmd = new CDBL_SendDataCmd(this, m_Link, data_size);    m_CMDs.Add(sd_cmd);    return Create_SendDataCmd(*sd_cmd);}bool CDBL_Connection::SendData(I_ITDescriptor& desc,                               CDB_Image& img, bool log_it){    return x_SendData(desc, dynamic_cast<CDB_Stream&> (img), log_it);}bool CDBL_Connection::SendData(I_ITDescriptor& desc,                               CDB_Text&  txt, bool log_it) {    return x_SendData(desc, dynamic_cast<CDB_Stream&> (txt), log_it);}bool CDBL_Connection::Refresh(){    // close all commands first    while (m_CMDs.NofItems()) {        CDB_BaseEnt* pCmd = static_cast<CDB_BaseEnt*> (m_CMDs.Get(0));        delete pCmd;        m_CMDs.Remove((int) 0);    }    // cancel all pending commands    if (dbcancel(m_Link) != CS_SUCCEED)        return false;    // check the connection status    return DBDEAD(m_Link) == FALSE;}const string& CDBL_Connection::ServerName() const{    return m_Server;}const string& CDBL_Connection::UserName() const{    return m_User;}const string& CDBL_Connection::Password() const{    return m_Passwd;}I_DriverContext::TConnectionMode CDBL_Connection::ConnectMode() const{    I_DriverContext::TConnectionMode mode = 0;    if ( m_BCPAble ) {        mode |= I_DriverContext::fBcpIn;    }    if ( m_SecureLogin ) {        mode |= I_DriverContext::fPasswordEncrypted;    }    return mode;}bool CDBL_Connection::IsReusable() const{    return m_Reusable;}const string& CDBL_Connection::PoolName() const{    return m_Pool;}I_DriverContext* CDBL_Connection::Context() const{    return const_cast<CDBLibContext*> (m_Context);}void CDBL_Connection::PushMsgHandler(CDB_UserHandler* h){    m_MsgHandlers.Push(h);}void CDBL_Connection::PopMsgHandler(CDB_UserHandler* h){    m_MsgHandlers.Pop(h);}CDB_ResultProcessor* CDBL_Connection::SetResultProcessor(CDB_ResultProcessor* rp){    CDB_ResultProcessor* r= m_ResProc;    m_ResProc= rp;    return r;}void CDBL_Connection::Release(){    m_BR = 0;    // close all commands first    while(m_CMDs.NofItems() > 0) {        CDB_BaseEnt* pCmd = static_cast<CDB_BaseEnt*> (m_CMDs.Get(0));        delete pCmd;        m_CMDs.Remove((int) 0);    }}CDBL_Connection::~CDBL_Connection(){    Refresh();    dbclose(m_Link);}void CDBL_Connection::DropCmd(CDB_BaseEnt& cmd){    m_CMDs.Remove(static_cast<TPotItem> (&cmd));}bool CDBL_Connection::x_SendData(I_ITDescriptor& descr_in,                                 CDB_Stream& stream, bool log_it){    size_t size = stream.Size();    if (size < 1)        return false;    I_ITDescriptor* p_desc= 0;    // check what type of descriptor we've got    if(descr_in.DescriptorType() !=#ifndef MS_DBLIB_IN_USE		CDBL_ITDESCRIPTOR_TYPE_MAGNUM#else		CMSDBL_ITDESCRIPTOR_TYPE_MAGNUM#endif		){	// this is not a native descriptor	p_desc= x_GetNativeITDescriptor(dynamic_cast<CDB_ITDescriptor&> (descr_in));	if(p_desc == 0) return false;    }        C_ITDescriptorGuard d_guard(p_desc);    CDBL_ITDescriptor& desc = p_desc? dynamic_cast<CDBL_ITDescriptor&> (*p_desc) : 	dynamic_cast<CDBL_ITDescriptor&> (descr_in);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -