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

📄 ibmdb2query.h

📁 C++连接一写常用数据库的接口
💻 H
字号:
/* * DB2Query object defines the needed query 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 * */#ifndef __DB2_QUERY_H__#define __DB2_QUERY_H__#include <vector>#include "baseQuery.h"#include "ibmDB2Connection.h"#include "ibmDB2BindParam.h"#include "ibmDB2Value.h"#include "ibmDB2FieldDescription.h"
using namespace std;
#define FETCH_BLOCK_SIZE 10class DB2Query : public BaseQuery{private:     // Collection types that can be freed within this object   enum CollectionType   {      FIELD_INFORMATION,      FIELD_VALUES,      BIND_PARAMETERS   };   // DB2 Handles   SQLHANDLE        _hstmt;   DBULONG          _db2CurrentRow;   // Parameter collection.   DBULONG        _numParameters;   DB2BindParam **_parameters;   vector<string> _queryParameterNames;    // Holds all the parameter names that are in a query from left to right to allow binding correctly   // Field Information collection   DBULONG                _numFieldInformation;   DB2FieldDescription  **_fieldInformation;   // Field Value collection   DBULONG     _numRecordValues;   DB2Value  **_recordValues;      DB2Connection* _parentConnection;   int            _index;            // Index of the handle object   bool           _isTransaction;    // Is the object in a state of a transaction running.   /* Internal method to obtain the information     *   about the fields returned in a result set.    */   void   _db2GetFieldsInformation();   /* Internal method to obtain the data    *   for a row in a result set    */   void   _db2GetResultSetRow();   /* Internal method to return the dbConnect type for the IBM DB2 field    *    * @param type    The IBM DB2 field type to resolve to a dbConnect field type    *    * @return   Returns the dbConnect field type for the given IBM DB2 field type    */   FieldType   _db2ResolveFieldType(      SQLSMALLINT type);   /* Internal method to replace the parameters with ?    *    * @param originalSqlStatement  The sql statement with the bind parameters.    * @param bindParameters        The vector to hold the pointers to the bind parameters (left to right for the ?'s)    *    * @return   Returns the SQL that has bad its parameters replace with ?    */   string   _db2ParseBindParameters(         const string& originalSqlStatement,         vector<DB2BindParam*> &bindParameters);   /* Internal method to bind parameters with ? with the actual given parameter values    *    * @param resolvedSqlStatement  The sql statement with the ?'s?    * @param bindParameters        The vector with pointers to the bind parameters (left to right for the ?'s)    *    */   void   _db2BindParameters(         const string& resolvedSqlStatement,         vector<DB2BindParam*> &bindParameters);   /* Internal method to free internally allocated memory    *    * @param type    The type representing which value to deallocate.    *    */   void _freeCollection(      CollectionType type);public:   /* Constructor.    *    */   DB2Query(      DB2Connection* parentConnection,      int            index);   /* Destructor.    *    */   virtual    ~DB2Query();      /* Clears any bind parameters    *    */   void    clearBindParams();   /* Set the SQL / DDL command that will be used for bind     *  paramaters and the execute    *    * @param sqlStatement  Statement wanting to execute    *    */   void   command(      const string& sqlStatement);   /* Set the value for a parameter giving the parameter name.    *    * @param paramName      Name of the parameter.    *    * @return               Returns the parameter object for the position.    */   BaseValue*   bindParam(      const string& paramName);    /* Execute the sql statement set by command    *    */   void   execute();   /* Obtain the next row of data in the record set.    *    */   void   fetchNext();   /* Begin a transaction.    * Make virtual so a new driver can inherit and implement    *    */   virtual void   transBegin();         /* Commit a transaction.    * Make virtual so a new driver can inherit and implement    *    */   virtual void   commit();         /* Rollback a transaction.    * Make virtual so a new driver can inherit and implement    *    */   virtual void   rollback();      /* Returns the information about a field.    *    * @param    index     Index of the field.    *    * @return             Returns a pointer to the field information structure.    */   BaseFieldDescription*   getFieldInfoByColumn(      int index);   /* Returns the information about a field.    *    * @param    fieldName Name of the field.    *    * @return             Returns a pointer to the field information structure.    */   BaseFieldDescription*   getFieldInfoByName(      const string& fieldName);         /* Returns the value of a field.    *    * @param    index     Index of the field.    *    * @return   Returns a pointer to the value structure.    */   BaseValue*   getFieldByColumn(      int index);   /* Returns the value of a field.    *    * @param    fieldName Name of the field.    *    * @return   Returns a pointer to the value structure.    */   BaseValue*   getFieldByName(      const string& fieldName);};#endif

⌨️ 快捷键说明

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