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

📄 myconnection.h

📁 连接并使用Oracle。可以创建表、预览数据集、删除、修改数据集。将这些操作封装在类里
💻 H
字号:
// MyConnection.h: interface for the MyConnection class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYCONNECTION_H__703C60F4_CBD8_11D4_B3EE_000102574F1A__INCLUDED_)
#define AFX_MYCONNECTION_H__703C60F4_CBD8_11D4_B3EE_000102574F1A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//OCI头文件
#include "ocidem.h"
#include "oratypes.h"
#include "ocidfn.h"

//单引号替换
#define _R OciReplace
CString OciReplace(LPCSTR pstr);


//数据库连接类
class connection
{
	//cursor是connection的友员类
	friend class cursor;

public:
	connection();	//构造函数
	~connection();	//析构函数
	
	//连接数据库
	BOOL connect(char *username, char *password,char *sername);

	//断开数据库连接
	BOOL disconnect();
	
	//当前数据库连接状态
	BOOL IsConnected();
	
	//数据库连接操作错误显示
	void display_error() const;
	
private:
    Lda_Def lda;
    unsigned char hda[HDA_SIZE];
    enum conn_state
    {
		not_connected, //0-没有连接
		connected	   //1-连接成功
    };
	
    conn_state state;
}; 

//游标类
class cursor
{
public:
	cursor();	//构造函数
	~cursor();	//析构函数

	//打开游标
	BOOL open(connection *conn_param);
	
	//关闭游标
	BOOL close();

	//当前游标状态(是否打开)
	BOOL IsOpened();
	
	//解析SQL语句
	BOOL parse(const char *stmt);
	
	/* 绑定输入 */
	BOOL bind_by_position(int sqlvnum, void *progvar,int progvarlen, int datatype,short *indicator);
	
    /* 绑定输出 */
	BOOL define_by_position(int position, void *buf,int bufl, int datatype);                
	BOOL define_by_name(CString sqlname,void *buf,int bufl,  int datatype);
	
	//表描述信息
	BOOL describe(int position, long *dbsize, int *dbtype, 
				  void *cbuf, int *cbufl, long *dsize, int *prec,
				  int *scale, int *nullok);

	//执行SQL语句
	BOOL execute();

	//读取返回数据(一次一条记录)
	BOOL fetch();

	//读取返回数据(一次多条记录)
	int FetchMultiRow(int amount);

	//执行SQL语句(包含解析parse、执行execute)
	BOOL ExecuteSQL(char * stmt);
	
	//游标操作错误显示
	void display_error();
	
private:
	int  get_error_code();
    Cda_Def cda;
	connection *conn;  
	CString stmt;
	bool    Defined[50];
	
	enum cursor_state
    {
		not_opened,
			opened
    };
    
    cursor_state state;
}; 

#endif // !defined(AFX_MYCONNECTION_H__703C60F4_CBD8_11D4_B3EE_000102574F1A__INCLUDED_)

⌨️ 快捷键说明

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