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

📄 csqlocilibrary.h

📁 很好用的数据库连接组件
💻 H
字号:
#ifndef CSQL_ORACLE_H#define CSQL_ORACLE_H#include "stdafx.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include "oci.h"#include "oci1.h"#include "assert.h"#include "CSqlDriver.h"#include "CSqlResult.h"using namespace std;struct CColumn{	CVariant::Type columnType;	ub2    dbType ;	string columnName;	ub2 columnSize;	void * data;	sb2 ind;	ub2 fetchLength;	ub2 retCode;};//CSqlResult 的 Oracle 实现class CORACLEResult:public CSqlResult{friend class CORACLEDriver;	//CORACLEResult 以 CORACLEDriver 为友员类public:	CORACLEResult (const CORACLEDriver * db);	//以db为驱动构建查询结果集	~CORACLEResult ();protected:	CVariant data (int field);	//返回CVariant类型的当前列信息	int      intData (int field);	//返回CVariant类型的当前列信息	char*    stringData (int field);	//返回CVariant类型的当前列信息	bool isNull (int field);	//判断当前列是否为空(后续版本实现)	//将buf绑定到查询结果集输出上	bool bind (char (*buf)[256], int len = 0);	bool reset (const string & query);	//提交查询	bool multi_reset (const string & query);	//提交查询	int  get_result();	int  get_columns();	bool fetch ();		//索取下一行数据	bool cancel(bool bAll);	int size ();			//大小(后续版本实现)	int numRowsAffected ();	//影响的行数(后续版本实现)private:	CORACLEDriver* connection;	OCIStmt * stmthp;	OCIError * errorhp;	ub4 columnCount;	CColumn * columnInfo;	bool	m_valid;};//CSqlBcpResult 的 sybase实现class CORACLEBcpResult:public CSqlBcpResult{friend class CORACLEDriver;	//CORACLEBcpResult 以 CORACLEDriver 为友员类public:	CORACLEBcpResult (const CORACLEDriver * db);	//以db为驱动构建bcp结果集	~CORACLEBcpResult ();protected:	int fCheckTable (const string & tableName);	//检查表是否存在	bool fCheckPoint ();		//启动检查点	//将buf绑定到bcp结果集上	bool fBind (char (*buf)[256], int len);	bool fSend ();		//发起一次bcp	bool fStart (const string & tableName);	//启动相应表的bcp	bool fEnd (bool all = true);	//进行一次提交(批提交 或 全部提交)	bool reset();private:	CORACLEDriver* connection;	int m_nowRow ;	int m_BatchRows ;	char (*m_buf)[256];	char* m_buffer ;	int m_bufferLen ;	int   m_pos ;	CColumn *columnInfo  ;	ub4                 nrow_ctl;            /* number of rows in column array */	ub2                 ncol_ctl;         /* number of columns in column array */	OCIEnv             *envhp_ctl;                       /* environment handle */	OCIServer          *srvhp_ctl;                            /* server handle */	OCIError           *errorhp;                             /* error handle */	OCIError           *errhp2_ctl;                    /* another error handle */	OCISvcCtx          *svchp_ctl;                          /* service context */	OCISession         *authp_ctl;                   /* authentication context */	OCIParam           *colLstDesc_ctl;        /* column list parameter handle */	OCIDirPathCtx      *dpctx_ctl;                      /* direct path context */	OCIDirPathColArray *dpca_ctl;           /* direct path column array handle */	OCIDirPathStream   *dpstr_ctl;                /* direct path stream handle */	ub1                *buf_ctl;    /* pre-alloc'd buffer for out-of-line data */	ub4                 bufsz_ctl;                 /* size of buf_ctl in bytes */	ub4                 bufoff_ctl; /* offset into buf_ctl which is not in use */	ub4                *otor_ctl;                  /* Offset to Recnum mapping */	ub1                *inbuf_ctl;                 /* buffer for input records */};//CSqlDriver 的 Oracle实现class CORACLEDriver:public CSqlDriver{friend class CORACLEResult;friend class CORACLEBcpResult;public:	CORACLEDriver ();	~CORACLEDriver ();	enum InternalType{		ORAVARCHAR2=1,ORANUMBER=2,ORALONG=8,ORAROWID=11,ORADATE=12,		ORARAW=23,ORALANGRAW=24,ORACHAR=96,ORAREF=111,ORACLOB=112,		ORABLOB=113,ORAUROWID=208	};	//打开一个驱动联接	bool open (const string & db = "",			const string & user = "",			const string & password = "",			const string & host = "",			const string & appname = "", int port = -1);	void close ();		//关闭联接	CSqlQuery createQuery () const;	//返回基于此驱动的查询类	CSqlBcp createBcp () const;	//返回基于此驱动的bcp类	bool useDb (const string & db) const;	//应用db 数据库	bool _exec(const string& sql  );private:	void reset(sb4 ORAERRCODE);	OCIError           *errhp2_ctl;   	OCISession         *authp_ctl;    	OCIEnv * envhp;	OCIError * errorhp;	OCIServer * srvhp ;	OCISvcCtx * svcctxhp;};#endif

⌨️ 快捷键说明

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