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

📄 dhdbado.h

📁 ADO查看数据库工具的原码
💻 H
字号:
// DHDBAdo.h: interface for the CDHDBAdo class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DHDBADO_H__29FCF94C_DC6D_4B20_A668_D21796748E49__INCLUDED_)
#define AFX_DHDBADO_H__29FCF94C_DC6D_4B20_A668_D21796748E49__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "DHAdoField.h"
class CDHDBAdo  
{
public:
	void Reset();
	long GetMaxValue(char *pszTableName, char *pszFieldName);//获取指定表中指定字段的最大值
	//////////////////////////////
	void SetPageSize(long nPageSize);	//设置分页时每页包含记录数目
	BOOL SetCurPage(long nCurPage);		//设置当前页面编号
	long GetPageCount();				//获取页面总数
	long GetPageSize();					//获取分页时每页包含记录数目
	//////////////////////////////////
	CString GetLastError(); //获取最后一次错误的信息
	///////////////////////////////////////////////////
	BOOL SetConnectString(LPCTSTR   lpszCon); //设置连接字符串 并打开连接
	/*	查询数据库
	*	lpszSQL  用于查询的SQL语句
	*	CursorType	光标模式	
	*				adOpenForwardOnly	只向前存取 其他用户的操作不可见
	*				adOpenKeyset		支持各种方式的光标移动   其他用户的添加操作不可见	删除和修改可见	
	*				adOpenStatic		支持各种方式的光标移动	其他用户的操作不可见
	*				adOpenDynamic		支持各种方式的光标移动	其他用户的所有操作都可见
	*	LockType	数据锁定模式
	*				adLockReadOnly			只读模式
	*				adLockPessimistic		悲观锁
	*				adLockOptimistic		积极锁
	*				adLockBatchOptimistic	批量锁
	*	Options		命令类型
	*				adCmdText			文本SQL语句
	*				adCmdTable			表名
	*				adCmdStoredProc		存储过程
	*				adCmdUnknown		未定义类型
	*/
	BOOL Open (LPCTSTR lpszSQL="",enum CursorTypeEnum CursorType = adOpenStatic,enum LockTypeEnum LockType = adLockOptimistic,long Options = adCmdText); 
	BOOL Close();									//关闭记录集
	BOOL Requery();									//重新查询
	long DBExcuteSQL(LPCTSTR lpszSql);					//直接执行SQL语句并返回受影响的行数
	void SetSQLStatement(LPCTSTR lpszSQL);			//设置SQL语句
	LPCTSTR GetSQLStatement() const;				//获取当前SQL语句
	BOOL IsOpen();									//判断是否已打开记录集
	long CalcCount();								//获取当前记录集中记录的数目
	long GetOptions();								//获取当前命令类型
	int	 GetLockType();								//当前锁定类型
	int  GetCursorType();							//当前光标模式
	/////////////////////////////////////////////
	//在移动光标时 移动前的记录的修改自动保存到库中
	long GetFieldNum();								//获取当前记录集中记录的数目
	BOOL IsEOF();									//是否在记录集的末尾位置
	BOOL IsBOF();									//是否在记录集的开始位置
	BOOL MovePrev();								//光标前移一条记录
	BOOL MoveNext();								//光标后移一条记录
	BOOL MoveLast();								//光标移动到记录集末尾
	BOOL MoveFirst();								//光标移动到记录集头部
	BOOL MoveAbsolute(long nRows);					//移动到绝对的第nRows行
	BOOL Move(long nRows);							//以当前行为原点移动nRows行
	BOOL Delete();									//删除记录
	BOOL AddNew();									//增加新的记录
	BOOL IsAddNew();								//当前记录是否新增加的记录
	BOOL IsEdit();									//当前记录是否更新过
	BOOL Update();									//提交更改
	BOOL UpdateBatch(enum AffectEnum AffectRecords);//使用批量锁模式时 可选择性的更新修改过的记录
	BOOL CancelUpdate();							//取消对数据集的修改
	/////////////////////////////////////////////
	
	
	DWORD GetBinFieldLen(LPCTSTR szField);				//获取二进制字段的数据长度
	DWORD GetBinFieldLen(int nField);
	BOOL GetBinFieldData(LPCTSTR szField, void *pData); //获取二进制字段内容
	BOOL GetBinFieldData(int nField, void *pData);
	BOOL SetBinField(LPCTSTR szField, void *pData, DWORD dwLen);//设置二进制字段内容
	BOOL SetBinField(int nField, void *pData, DWORD dwLen);
	////////////////////////////////////////////
	
	CDHAdoField&	operator()( int nField );		//根据字段号取字段
	CDHAdoField&	Field(int nField);		
	CDHAdoField&	operator()( LPCTSTR szField );	//根据字段名取字段
	CDHAdoField&	Field(LPCTSTR szField);
	int		GetFieldID( LPCTSTR szField );			//通过字段名查询字段ID
	CString GetFieldName( int nField );				//获取字段名
	void	SetFieldNull(int nField);				//使字段值为空
	void	SetFieldNull(LPCTSTR szField);
	
	//根据字段名取值
	bool			GetBool( LPCTSTR szField );
	unsigned char	GetChar( LPCTSTR szField );
	short			GetShort( LPCTSTR szField );
	int				GetInt( LPCTSTR szField );
	long			GetLong( LPCTSTR szField );
	float			GetFloat( LPCTSTR szField );
	double			GetDouble( LPCTSTR szField );
	COleDateTime	GetDate( LPCTSTR szField );
	CString			GetString( LPCTSTR szField );
	CLongBinary*	GetBinary( LPCTSTR szField );
	//根据字段号取值
	bool			GetBool( int nField );
	unsigned char	GetChar( int nField );
	short			GetShort( int nField );
	int				GetInt( int nField );
	long			GetLong( int nField );
	float			GetFloat( int nField );
	double			GetDouble( int nField );
	COleDateTime	GetDate( int nField );
	CString			GetString( int nField );
	CLongBinary*	GetBinary( int nField );
	CDHDBAdo();
	virtual ~CDHDBAdo();
protected:
	void	ResetField();
	int		OnSQLErr(char *pNote, _com_error* e=NULL);
	int		OnSQLErr(char *pNote,CException* e);
	BOOL LoadFieldNamesMap();
	//用于查询数据的数据库连接
	_ConnectionPtr m_Con;
	//查询得到的记录集
	_RecordsetPtr	m_Rst;
	//连接字符串
	CString			m_strCon;
	//最近错误信息
	CString			m_strLastError;
	//最近错误代码
	int m_nLastErrorCode;			
	//创建记录集的SQL查询语句
	CString			m_strCmd;
	//是否有设置了SQL语句
	BOOL			m_bHasSQL;					
	//保存名字到ID的映射
	CMapStringToPtr		m_mapNameIdx;
	//数据集中当前行数据包含的字段集
	CPtrArray 	m_pFields;
	//数据集中当前行数据包含的字段树木
	int			m_nField;	
	//当前光标模式
	enum CursorTypeEnum m_CursorType;
	//当前锁定模式
	enum LockTypeEnum m_LockType;
	//命令类型
	long	m_Options;
	//默认每页记录数目
	long	m_nPageSize;
private:
	BOOL OpenConnection(); //打开数据库连接

};
////////////////////////////////////////////////////////////////
//	根据字段名称取字段值
inline	bool	CDHDBAdo::GetBool( LPCTSTR szField ) {
	return	Field( szField ).AsBool();
}
inline	unsigned char	CDHDBAdo::GetChar( LPCTSTR szField ) {
	return	Field( szField ).AsChar();
}
inline	short	CDHDBAdo::GetShort( LPCTSTR szField ) {
	return	Field( szField ).AsShort();
}
inline	int		CDHDBAdo::GetInt( LPCTSTR szField ) {
	return	Field( szField ).AsInt();
}
inline	long	CDHDBAdo::GetLong( LPCTSTR szField ) {
	return	Field( szField ).AsLong();
}
inline	float	CDHDBAdo::GetFloat( LPCTSTR szField ) {
	return	Field( szField ).AsFloat();
}
inline	double	CDHDBAdo:: GetDouble( LPCTSTR szField ) {
	return	Field( szField ).AsDouble();
}
inline	COleDateTime	CDHDBAdo::GetDate( LPCTSTR szField ) {
	return	Field( szField ).AsDate();
}
inline	CString	CDHDBAdo::GetString( LPCTSTR szField ) {
	return	Field( szField ).AsString();
}
inline	CLongBinary*	CDHDBAdo::GetBinary( LPCTSTR szField ) {
	return	Field( szField ).AsBinary();
}

////////////////////////////////////////////////////////////////
// 根据字段号取字段值
inline	bool	CDHDBAdo::GetBool( int nField ) {
	return	Field( nField ).AsBool();
}
inline	unsigned char	CDHDBAdo::GetChar( int nField ) {
	return	Field( nField ).AsChar();
}
inline	short	CDHDBAdo::GetShort( int nField ) {
	return	Field( nField ).AsShort();
}
inline	int		CDHDBAdo::GetInt( int nField ) {
	return	Field( nField ).AsInt();
}
inline	long	CDHDBAdo::GetLong( int nField ) {
	return	Field( nField ).AsLong();
}
inline	float	CDHDBAdo::GetFloat( int nField ) {
	return	Field( nField ).AsFloat();
}
inline	double	CDHDBAdo:: GetDouble( int nField ) {
	return	Field( nField ).AsDouble();
}
inline	COleDateTime	CDHDBAdo::GetDate( int nField ) {
	return	Field( nField ).AsDate();
}
inline	CString	CDHDBAdo::GetString( int nField ) {
	return	Field( nField ).AsString();
}
inline	CLongBinary*	CDHDBAdo::GetBinary( int nField ) {
	return	Field( nField ).AsBinary();
}
//////////////////////////////////////////
inline void CDHDBAdo::SetSQLStatement(LPCTSTR lpszSQL)
{
	m_strCmd.Format("%s", lpszSQL);
}

inline LPCTSTR CDHDBAdo::GetSQLStatement() const
{
	return m_strCmd;
}
/////////////////////////////////////////////
inline	CDHAdoField&	CDHDBAdo::operator()( LPCTSTR szField ) {
	return	Field( szField );
}

inline	CDHAdoField&	CDHDBAdo::operator()( int nField ) {
	return	Field( nField );
}
#endif // !defined(AFX_DHDBADO_H__29FCF94C_DC6D_4B20_A668_D21796748E49__INCLUDED_)

⌨️ 快捷键说明

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