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

📄 db2lib.h

📁 访问db2数据库的VC封装
💻 H
字号:
////////////////////////////////////////////////////////////////////////
//db2lib.h: interface for the CDb2lib class.
//
// class CDb2lib for access IBM DB2 DATABASE by DB2 CLI
// Written by Yank
// Modified 2001/05/18
////////////////////////////////////////////////////////////////////////

#ifndef __DB2LIB_H
#define __DB2LIB_H

#define DBNTWIN32

#ifdef __BORLANDC__
#include "windows.h"
#else
#include "stdafx.h"
#endif

#include <sqlcli1.h>
#include <sqlcli.h>
#include <sqlsystm.h>


#define MAXCOLS 255
#define MAXCOLNAMELEN 255
#define SQLMAXCHAR 256
#define MAXSERVERNAME 30
#define MAX_PARAMNUM 255
#define MAX_PARAMLEN 256
#ifndef max
#define max(a,b) (a > b ? a : b)
#endif


typedef struct
{
    SQLCHAR  Name[MAXCOLNAMELEN+1];				//列名
    SQLSMALLINT NameLen;						//列名长度
    SQLSMALLINT Type;							//列类型
    SQLUINTEGER MaxLength;						//列长度
    SQLSMALLINT  Precision;						//精度
} SDBCOL;



typedef struct
{
    SQLCHAR     ErrorMsg[SQL_MAX_MESSAGE_LENGTH + 1] ;			
    SQLCHAR     SqlState[SQL_SQLSTATE_SIZE + 1] ;
    SQLINTEGER  SqlCode ;
    SQLSMALLINT Length;
} CDbErrorInfo;

typedef struct
{
    SQLCHAR ServerName[SQL_MAX_DSN_LENGTH + 1];
	SQLCHAR Description[256];
} CServerList;


class CDb2lib
{
public:

public:

    CDb2lib();
    virtual ~CDb2lib();

    bool Open(const char *servername, const char *loginID, const char *passWord);
	bool Run(const char *CommandStr, char *Param[], int ParamNum);
	bool Run20(const char *CommandStr, char *Param[], int ParamNum);

	bool Run20Error(const char *CommandStr, char *Param[], int ParamNum);
	bool Run20Message(const char *CommandStr, char *Param[], int ParamNum);
    bool MoveNext();
    bool Cancel();
    bool Close();

private:
    bool Init();
    bool Login(const char *servername, const char *loginID, const char *passWord);
    bool Bind();
	SQLRETURN terminate( SQLHANDLE henv, SQLRETURN rc);
    SQLRETURN handle_error( SQLSMALLINT htype, SQLHANDLE hndl, SQLRETURN frc);
	SQLRETURN DBconnect( SQLHANDLE henv, SQLHANDLE * hdbc, SQLCHAR *servername, SQLCHAR *loginID, SQLCHAR *passWord) ;
	bool EndTran();


private:
    int m_errorCode;
    char m_errorMsg[256];

	SQLHANDLE m_henv;								//环境句柄
	SQLHANDLE m_hdbc;								//连接句柄
	SQLHANDLE m_hstmt;								//执行句柄
	SQLRETURN m_rc ;						
	SQLCHAR m_stmt[2000];							

    
	
	bool m_loginOK;
    SQLSMALLINT m_colCount;							//列数
    SQLINTEGER m_rowCount;							//行数
    CDbErrorInfo m_dbErrorInfo;

    SDBCOL m_colInfo[MAXCOLS];						//列信息
    SQLCHAR m_data[MAXCOLS][SQLMAXCHAR];			//行数据
    char m_serverName[MAXSERVERNAME + 1];			//数据库名
    char m_loginID[MAXSERVERNAME + 1];				//用户
    char m_passWord[MAXSERVERNAME + 1];				//密码


public:
    const char * GetServerName();
    const char * GetLoginID();
    USHORT GetColCount();
    const SDBCOL * GetColInfo(int);
    const SDBCOL * GetColInfo(const char *);
    char * GetColData(int);
    char * GetColData(const char *);
    ULONG GetRowCount();
    int GetErrorCode();
    const char * GetErrorMsg();
    const CDbErrorInfo * GetDbErrorInfo();
    USHORT GetServerList(CServerList * serverList);


};

inline const char * CDb2lib::GetServerName()
{
    return (const char *)m_serverName;
}

inline const char * CDb2lib::GetLoginID()
{
    return (const char *)m_loginID;
}

inline USHORT CDb2lib::GetColCount()
{
    return m_colCount;
}

inline ULONG CDb2lib::GetRowCount()
{
    return m_rowCount;
}


#endif

⌨️ 快捷键说明

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