| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /*************************************************************************
- 【文件名】 OtlDB.h
- 【功能模块和目的】 OTL数据库访问DLL接口定义类头文件
- 【开发者及日期】 SuFeng 2012.05.19
- 【版本】 1.0
- 【版权信息】 Copyright(C)2013 郑州鼎晟科技有限公司版权所有
- 【更改记录】
- *************************************************************************/
- #pragma once
- #include "OtlConnHost.h"
- #ifdef DBCTRL_EXPORTS
- #define INHERIT_OTL(base) base
- #define OTL_RECORD_SET IOtlRecordset
- #define OTL_STORED_PROC IOtlStoredProc
- #else
- #define INHERIT_OTL(base)
- #define OTL_RECORD_SET COtlRecordset
- #define OTL_STORED_PROC COtlStoredProc
- #endif
- class COtlRecordset;
- class COtlConnHost;
- class otl_stream;
- /*************************************************************************
- 【类名】 COtlConnection
- 【功能】 OTL连接控制类
- 【接口说明】
- 【开发者及日期】 郑石诺 2015/01/09
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- class COtlConnection INHERIT_OTL( : public IOtlConnection )
- {
- private:
- COtlConnHost* m_pOtlConnHost; // OTL连接管理类
- static COtlConnection * m_pInstence; // 数据库连接唯一实例
- private:
- COtlConnection(); // 私有构造
- virtual ~COtlConnection(); // 私有析构
- public:
- // 数据库实例控制
- static COtlConnection* GetOtlInstence(); // 获取数据实例
- // static void DestroyInst(); // 销毁数据库实例
- // 数据库连接控制
- BOOL Connect(); // 连接数据库(注册表中默认配置的数据库)
- BOOL Connect( LPCTSTR lpszConnString ); // 连接指定数据库
- BOOL ConnectTest( LPCTSTR lpszConnString, LPSTR lpErrInfo ); // 连接测试
- void Disconnect(); // 断开连接
- DB_TYPE GetDatabaseType(); // 获取数据库类型
- // 数据操作
- BOOL ExecCommand( LPCTSTR lpszSQL ); // 直接命令执行
- void DropTableCommand( LPCTSTR lpszSQL ); // 删除表命令函数
- BOOL InsertConstant( LPCTSTR lpszSQL ); // 恒量插入(单数据)
- BOOL GetSingleDataString( LPCTSTR lpszSQL, CHAR * lpValue ); // 获取字符串单值
- BOOL GetSingleDataText( LPCTSTR lpszSQL, CHAR * lpValue ); // 获取Text串单值
- BOOL GetSingleDataInt( LPCTSTR lpszSQL, LONG & nValue ); // 获取整型单值
- long GetSingleDataInt( LPCTSTR strSql ); // 获取整型单值
- CString GetSingleDataStr( LPCTSTR strSql ); // 获取字符串单值
- long GetSingleDataStr2Int( LPCTSTR strSql ); // 获取字符串单值并转化成整型返回
- OTL_RECORD_SET* QueryRecords( LPCTSTR lpszSQL ); // 查询记录集
- OTL_STORED_PROC* CallStoredProc( const CString & a_DeclareWord ); // 调用存储过程
- // 事务操作
- BOOL TransBegin(); // 开始事务
- BOOL TransCommit(); // 提交事务
- BOOL TransRollback(); // 回滚事务
- // 错误处理
- LPCTSTR GetLastError();
- };
- /*************************************************************************
- 【类名】 COtlRecordset
- 【功能】 OTL记录集访问类
- 【接口说明】
- 【开发者及日期】 郑石诺 2015/01/09
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- class COtlRecordset INHERIT_OTL( : public IOtlRecordset )
- {
- friend COtlConnection;
- friend COtlRecordset;
- public:
- #ifndef DBCTRL_EXPORTS
- static void DestroyInstance( COtlRecordset * pRecord );
- #endif
- // 数据控制
- BOOL IsEOF( void ); // 是否已遍历到记录保结尾
- BOOL MoveNextRow( void ); // 移动记录集到下一行
- BOOL GetValueInt( char *pColName, int &nValue ); // 获取当前行指定字段值 整形
- BOOL GetValueStr( char *pColName, char *pValue ); // 获取当前行指定字段值 字符串
- BOOL GetValueText( char *pColName, char *pValue ); // 获取当前行指定字段值 较大文本值
- BOOL GetValueFloat( char *pColName, float & Value ); // 获取当前行指定字段值 浮点
- int GetValueIntByIndex( int index ); // 通过字段ID获取整型记录
- int GetValueInt( CString FieldName ); // 通过字段名称获取整型记录
- CString GetValueStrByIndex( int index ); // 通过字段ID获取字符串记录
- CString GetValueStr( CString FieldName ); // 通过字段名称获取字符串记录
- BOOL GetValueFloatByIndex( int index, float & Value ); // 通过字段ID获取浮点记录
- // 错误处理
- LPCTSTR GetLastError( void );
- private:
- COtlRecordset( COtlConnHost * pConnHost ); // 私有构造
- virtual ~COtlRecordset( void )throw(); // 私有析构
- // 读取记录集初始数据
- BOOL __InitData( LPCTSTR lpszSQL );
- private:
- otl_stream* m_pStream; // OTL流
- COtlConnHost* m_pOtlConnHost; // OTL连接管理类
- OtlIterator m_Iterator; // OTL流迭代器
- };
- /*************************************************************************
- 【类名】 COtlStoredProc
- 【功能】 存储过程执行实体(仅供需返回值的存储过程或存储函数)
- 【接口说明】
- 【开发者及日期】 郑石诺 2015/01/09
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- class COtlStoredProc INHERIT_OTL( : public IOtlStoredProc )
- {
- friend COtlConnHost;
- public:
- #ifndef DBCTRL_EXPORTS
- static void DestroyInstance( COtlStoredProc * a_pProc );
- #endif
- // 添加存储过程输入参数(目前仅实现了两种重载,后续根据需要可自行添加)
- BOOL Input( LPCTSTR a_StrParam );
- BOOL Input( UINT a_UintParam );
- BOOL Input( int a_IntParam );
- // 存储过程执行完毕输出参数(目前仅实现了两种重载,后续根据需要可自行添加)
- BOOL Output( UINT & a_UintReturn );
- BOOL Output( int& a_IntParam );
- BOOL Output( LPTSTR a_StrParam );
- BOOL Output( float a_FloatParam );
- // 错误处理
- LPCTSTR GetLastError();
- private:
- COtlStoredProc( COtlConnHost * a_pConnHost, const CString & a_DeclareWord );
- virtual ~COtlStoredProc( void )throw();
- private:
- COtlConnHost* m_pOtlConnHost; // OTL连接管理类
- otl_stream m_Stream; // OTL流
- };
|