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

📄 ibmdb2connection.h

📁 C++连接一写常用数据库的接口
💻 H
字号:
/* * DB2Connection object defines the needed connection functions for the dbConnect IBM DB2 driver * Copyright (C) 2003 Johnathan Ingram, jingram@rogueware.org * * This library is free software; you can redistribute it and/or *   modify it under the terms of the GNU Lesser General Public *   License as published by the Free Software Foundation; either *   version 2.1 of the License, or (at your option) any later version. * *   This library is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *   Lesser General Public License for more details. * *   You should have received a copy of the GNU Lesser General Public *   License along with this library; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US * * Notes: *  1)   * */#ifndef __DB2_CONNECTION_H__#define __DB2_CONNECTION_H__#define DB2_DRIVERNAME    "DB2"#include <string>#include <time.h>#include "dbconnectTypes.h"#include "baseConnection.h"#include "baseException.h"#include "simpleThreads.h"#include "sqlcli1.h"using namespace std;class DB2Handle : public BaseHandle{public:   // IBM DB2 Connection Handles;   SQLHANDLE   _hdbc;   void        *queryObject;   // Query Object bound to the connection   // Constructor   DB2Handle()    :      _hdbc(SQL_NULL_HDBC),      queryObject(NULL)    { };};class DB2Connection : public BaseConnection{private:      // Collection types that can be freed within this object   enum CollectionType   {      CONNECTION_HANDLES   };   // Thread mutexes   SimpleThread_Mutex classMutex;         // Handles used by the driver   SQLHANDLE    _henv;          // Environment handle      DBULONG      _numHandles;   DB2Handle  **_handles;   /* Internal method to connect the handle to an IBM DB2 database.    *    * @param handleIndex     Index to the connection handle that must be connected.    */   void    _db2Connect(         int index);      /* Internal method to disconnect the handle from an IBM DB2 database.    *    * @param handleIndex     Index to the connection handle that must be disconnected.    */   void    _db2Disconnect(         int index);         /* Internal method to make sure the connection handle is still alive and reconnect if timed out.    *    * @param handleIndex     Index to the connection handle that must be pinged.    */   void    _db2Ping(         int index);   /* Internal method to free internally allocated memory    *    * @param type    The type representing which value to deallocate.    *    */   void _freeCollection(         CollectionType type);   public:   /* Constructor.    *    */   DB2Connection(         int argc,          const char** argv);   /* Destructor.    *    */   ~DB2Connection();   /* Create connections to the database.    *    * @param username         Database username.    * @param password         Password used for username.    * @param databaseName     Name of the database connecting to.    * @param host             Host the database resides on. Default "localhost"    * @param maxConnections   Maximum number of connections the object can pool at any one time. Default 1    * @param optParam1        Optional parameter that can be used by the driver.    * @param optParam2        Optional parameter that can be used by the driver.    *    */   void    connect(         const string &username,          const string &password="",          const string &databaseName="",          const string &host="localhost",          int          maxConnections=1,         int          minConnections=1,         const string &optParam1="",         const string &optParam2="");   /* Destroy all connections to the database.    *    * @param timeout          Timeout in seconds to wait for connections to become idle. Default 120.    */   void    disconnect(         time_t timeout=120);        /* Obtain a connection that is attached to a query object.    *    * @param timeout     Interval in seconds that the function should block for before throwing an exception.    *    * @return            Returns a void pointer to a BaseQuery object. (The pointer needs to be type casted.    */   void*   requestQueryConnection();      /* release a connection that is attached to a query object.    *    * @param queryConnection   Pointer of the query connection to release.    *    */   void   releaseQueryConnection(         void* queryObject);      friend class DB2Query;};#endif

⌨️ 快捷键说明

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