📄 dbcursor.h
字号:
//the class of CDBCursor
#ifndef _DBCURSOR_H_
#define _DBCURSOR_H_
#include "mydblib.h"
/*////////////////////////////////////////////////////////////
说明:使用游标的方法
1、构造游标对象,把相应的数据库过程作为参数传入对象
2、用OpenDBCursor()打开游标
3、用GetCursorInfo()函数获得结果集的信息
4、GetCursorColNameInfo()函数取得字段列名
5、DBCursorBind()函数绑定数据列到程序变量中
6、DBCursorFetch()函数取出一定行数的数据
*/////////////////////////////////////////////////////////////
class CDBCursor
{
public:
CDBCursor();
CDBCursor(PDBPROCESS dbproc);
~CDBCursor();
//数据库的游标操作
protected:
//data fields
PDBPROCESS m_cursorDBProc; //当前游标对应的数据库过程
PDBCURSOR m_dbCursor; //由dbcursoropen()返回的值
int m_KeysetCols; //结果集的列数
long int m_KeysetRows;//结果集的行数
UINT m_cursorRows ;//每次取出的记录数
DBINT * m_pStatus;// = new DBINT[CursorRows];
char * m_ppResultCharData;//取出的数据集合指针
LPDBINT m_ppResultCharLength;//Is a pointer to an array of DBINT elements
private:
int m_fetchCount; //游标移动的次数—私有变量
public:
/*函数名:OpenDBCursor
功能: 打开游标
参数: strSQL--要执行的SQL语句
scrollopt--游标的滚动类型
concuropt--游标的读取类型
nrows --每次移动游标取出的记录数
*/
PDBCURSOR OpenDBCursor(LPCSTR strSQL, int scrollopt,
int concuropt, int nrows);
//绑定数据列
BOOL DBCursorBind();
//从数据库中读取记录,fetchtype指定游标类型,rownum一般取0
//具体的参数可参考MSDN—dbcursorfetch函数的说明
BOOL DBCursorFetch(int fetchtype, int rownum );
//设置与游标相关的数据库过程
void SetDBCursorProc(PDBPROCESS proc){m_cursorDBProc = proc;}
//得到当前操作表中的记录数
int GetRowsNumber() {return (m_dbCursor!=NULL)?m_KeysetRows:-1;}
//得到当前操作表的列数
int GetColsNumber() { return (m_dbCursor!=NULL)?m_KeysetCols:-1;}
//得到结果集的列信息并写入colInfoList中
BOOL GetCursorColNameInfo(CStringList &colNameList);
//得到数据指针
char * GetDataPointer() const { return m_ppResultCharData; }
//获得游标句柄
PDBCURSOR GetDBCursor() const { return m_dbCursor;}
//获得二维表中指定行和列(以0为基数)的数据(转化为字符)
CString GetCellText(int row, int col);
//关闭游标
void CloseDBCursor();
protected:
//得到游标的行和列的数目
BOOL GetCursorInfo();
//释放申请的空间
void ReleaseBuffer();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -