📄 interfaces.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: interfaces.hpp,v $ * PRODUCTION Revision 1000.1 2004/04/21 14:47:31 gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.7 * PRODUCTION * =========================================================================== */#ifndef DBAPI_DRIVER_ODBC___INTERFACES__HPP#define DBAPI_DRIVER_ODBC___INTERFACES__HPP/* $Id: interfaces.hpp,v 1000.1 2004/04/21 14:47:31 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: Driver for MS-SQL server (odbc version) * */#include <dbapi/driver/public.hpp>#include <dbapi/driver/util/parameters.hpp>#ifdef NCBI_OS_MSWIN#include <windows.h>#endif#include <sql.h>#include <sqlext.h>#include <sqltypes.h>BEGIN_NCBI_SCOPEclass CODBCContext;class CODBC_Connection;class CODBC_LangCmd;class CODBC_RPCCmd;class CODBC_CursorCmd;class CODBC_BCPInCmd;class CODBC_SendDataCmd;class CODBC_RowResult;class CODBC_ParamResult;class CODBC_ComputeResult;class CODBC_StatusResult;///////////////////////////////////////////////////////////////////////////////// CODBC_Reporter:://class NCBI_DBAPIDRIVER_ODBC_EXPORT CODBC_Reporter{public: CODBC_Reporter(CDBHandlerStack* hs, SQLSMALLINT ht, SQLHANDLE h) : m_HStack(hs), m_HType(ht), m_Handle(h) {} void ReportErrors(); void SetHandlerStack(CDBHandlerStack* hs) { m_HStack= hs; } void SetHandle(SQLHANDLE h) { m_Handle= h; } void SetHandleType(SQLSMALLINT ht) { m_HType= ht; }private: CODBC_Reporter(); CDBHandlerStack* m_HStack; SQLHANDLE m_Handle; SQLSMALLINT m_HType;};///////////////////////////////////////////////////////////////////////////////// CODBCContext:://class NCBI_DBAPIDRIVER_ODBC_EXPORT CODBCContext : public I_DriverContext{ friend class CDB_Connection;public: CODBCContext(SQLINTEGER version = SQL_OV_ODBC3, bool use_dsn= false); // // GENERIC functionality (see in <dbapi/driver/interfaces.hpp>) // virtual bool SetLoginTimeout (unsigned int nof_secs = 0); virtual bool SetTimeout (unsigned int nof_secs = 0); virtual bool SetMaxTextImageSize(size_t nof_bytes); virtual CDB_Connection* Connect(const string& srv_name, const string& user_name, const string& passwd, TConnectionMode mode, bool reusable = false, const string& pool_name = kEmptyStr); virtual bool IsAbleTo(ECapability cpb) const {return false;} virtual ~CODBCContext(); // // ODBC specific functionality // // the following methods are optional (driver will use the default values // if not called), the values will affect the new connections only virtual void ODBC_SetPacketSize(SQLUINTEGER packet_size); virtual SQLHENV ODBC_GetContext() const;private: SQLHENV m_Context; SQLUINTEGER m_PacketSize; SQLUINTEGER m_LoginTimeout; SQLUINTEGER m_Timeout; SQLUINTEGER m_TextImageSize; CODBC_Reporter m_Reporter; bool m_UseDSN; SQLHDBC x_ConnectToServer(const string& srv_name, const string& usr_name, const string& passwd, TConnectionMode mode); void xReportConError(SQLHDBC con);};///////////////////////////////////////////////////////////////////////////////// CODBC_Connection:://class NCBI_DBAPIDRIVER_ODBC_EXPORT CODBC_Connection : public I_Connection{ friend class CODBCContext; friend class CDB_Connection; friend class CODBC_LangCmd; friend class CODBC_RPCCmd; friend class CODBC_CursorCmd; friend class CODBC_BCPInCmd; friend class CODBC_SendDataCmd;protected: CODBC_Connection(CODBCContext* cntx, SQLHDBC con, bool reusable, const string& pool_name); virtual bool IsAlive(); virtual CDB_LangCmd* LangCmd (const string& lang_query, unsigned int nof_params = 0); virtual CDB_RPCCmd* RPC (const string& rpc_name, unsigned int nof_args); virtual CDB_BCPInCmd* BCPIn (const string& table_name, unsigned int nof_columns); virtual CDB_CursorCmd* Cursor (const string& cursor_name, const string& query, unsigned int nof_params, unsigned int batch_size = 1); virtual CDB_SendDataCmd* SendDataCmd (I_ITDescriptor& desc, size_t data_size, bool log_it = true); virtual bool SendData(I_ITDescriptor& desc, CDB_Image& img, bool log_it = true); virtual bool SendData(I_ITDescriptor& desc, CDB_Text& txt, bool log_it = true); virtual bool Refresh(); virtual const string& ServerName() const; virtual const string& UserName() const; virtual const string& Password() const; virtual I_DriverContext::TConnectionMode ConnectMode() const; virtual bool IsReusable() const; virtual const string& PoolName() const; virtual I_DriverContext* Context() const; virtual void PushMsgHandler(CDB_UserHandler* h); virtual void PopMsgHandler (CDB_UserHandler* h); virtual CDB_ResultProcessor* SetResultProcessor(CDB_ResultProcessor* rp); virtual void Release(); virtual ~CODBC_Connection(); void ODBC_SetTimeout(SQLUINTEGER nof_secs); void ODBC_SetTextImageSize(SQLUINTEGER nof_bytes); void DropCmd(CDB_BaseEnt& cmd); CODBC_LangCmd* xLangCmd(const string& lang_query, unsigned int nof_params = 0);private: bool x_SendData(SQLHSTMT cmd, CDB_Stream& stream, CODBC_Reporter& rep); SQLHDBC m_Link; CODBCContext* m_Context; CPointerPot m_CMDs; CDBHandlerStack m_MsgHandlers; string m_Server; string m_User; string m_Passwd; string m_Pool; CODBC_Reporter m_Reporter; bool m_Reusable; bool m_BCPable; bool m_SecureLogin; CDB_ResultProcessor* m_ResProc;};///////////////////////////////////////////////////////////////////////////////// CODBC_LangCmd:://class NCBI_DBAPIDRIVER_ODBC_EXPORT CODBC_LangCmd : public I_LangCmd{ friend class CODBC_Connection; friend class CODBC_CursorCmd; friend class CODBC_CursorResult;protected: CODBC_LangCmd(CODBC_Connection* conn, SQLHSTMT cmd, const string& lang_query, unsigned int nof_params); virtual bool More(const string& query_text); virtual bool BindParam(const string& param_name, CDB_Object* param_ptr); virtual bool SetParam(const string& param_name, CDB_Object* param_ptr); virtual bool Send(); virtual bool WasSent() const; virtual bool Cancel(); virtual bool WasCanceled() const; virtual CDB_Result* Result(); virtual bool HasMoreResults() const; virtual bool HasFailed() const; virtual int RowCount() const; virtual void DumpResults(); virtual void Release(); virtual ~CODBC_LangCmd();private: bool x_AssignParams(string& cmd, CMemPot& bind_guard, SQLINTEGER* indicator); bool xCheck4MoreResults(); CODBC_Connection* m_Connect; SQLHSTMT m_Cmd; string m_Query; CDB_Params m_Params; CODBC_RowResult* m_Res; CODBC_Reporter m_Reporter; int m_RowCount; bool m_hasResults; bool m_WasSent; bool m_HasFailed;};///////////////////////////////////////////////////////////////////////////////// CODBC_RPCCmd:://class NCBI_DBAPIDRIVER_ODBC_EXPORT CODBC_RPCCmd : public I_RPCCmd{ friend class CODBC_Connection;protected: CODBC_RPCCmd(CODBC_Connection* con, SQLHSTMT cmd, const string& proc_name, unsigned int nof_params);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -