hd

OtlDB.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*************************************************************************
  2. 【文件名】 OtlDB.h
  3. 【功能模块和目的】 OTL数据库访问DLL接口定义类头文件
  4. 【开发者及日期】 SuFeng 2012.05.19
  5. 【版本】 1.0
  6. 【版权信息】 Copyright(C)2013 郑州鼎晟科技有限公司版权所有
  7. 【更改记录】
  8. *************************************************************************/
  9. #pragma once
  10. #include "OtlConnHost.h"
  11. #ifdef DBCTRL_EXPORTS
  12. #define INHERIT_OTL(base) base
  13. #define OTL_RECORD_SET IOtlRecordset
  14. #define OTL_STORED_PROC IOtlStoredProc
  15. #else
  16. #define INHERIT_OTL(base)
  17. #define OTL_RECORD_SET COtlRecordset
  18. #define OTL_STORED_PROC COtlStoredProc
  19. #endif
  20. class COtlRecordset;
  21. class COtlConnHost;
  22. class otl_stream;
  23. /*************************************************************************
  24. 【类名】 COtlConnection
  25. 【功能】 OTL连接控制类
  26. 【接口说明】
  27. 【开发者及日期】 郑石诺 2015/01/09
  28. 【版本】 V1.0.0
  29. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  30. 【更改记录】
  31. *************************************************************************/
  32. class COtlConnection INHERIT_OTL( : public IOtlConnection )
  33. {
  34. private:
  35. COtlConnHost* m_pOtlConnHost; // OTL连接管理类
  36. static COtlConnection * m_pInstence; // 数据库连接唯一实例
  37. private:
  38. COtlConnection(); // 私有构造
  39. virtual ~COtlConnection(); // 私有析构
  40. public:
  41. // 数据库实例控制
  42. static COtlConnection* GetOtlInstence(); // 获取数据实例
  43. // static void DestroyInst(); // 销毁数据库实例
  44. // 数据库连接控制
  45. BOOL Connect(); // 连接数据库(注册表中默认配置的数据库)
  46. BOOL Connect( LPCTSTR lpszConnString ); // 连接指定数据库
  47. BOOL ConnectTest( LPCTSTR lpszConnString, LPSTR lpErrInfo ); // 连接测试
  48. void Disconnect(); // 断开连接
  49. DB_TYPE GetDatabaseType(); // 获取数据库类型
  50. // 数据操作
  51. BOOL ExecCommand( LPCTSTR lpszSQL ); // 直接命令执行
  52. void DropTableCommand( LPCTSTR lpszSQL ); // 删除表命令函数
  53. BOOL InsertConstant( LPCTSTR lpszSQL ); // 恒量插入(单数据)
  54. BOOL GetSingleDataString( LPCTSTR lpszSQL, CHAR * lpValue ); // 获取字符串单值
  55. BOOL GetSingleDataText( LPCTSTR lpszSQL, CHAR * lpValue ); // 获取Text串单值
  56. BOOL GetSingleDataInt( LPCTSTR lpszSQL, LONG & nValue ); // 获取整型单值
  57. long GetSingleDataInt( LPCTSTR strSql ); // 获取整型单值
  58. CString GetSingleDataStr( LPCTSTR strSql ); // 获取字符串单值
  59. long GetSingleDataStr2Int( LPCTSTR strSql ); // 获取字符串单值并转化成整型返回
  60. OTL_RECORD_SET* QueryRecords( LPCTSTR lpszSQL ); // 查询记录集
  61. OTL_STORED_PROC* CallStoredProc( const CString & a_DeclareWord ); // 调用存储过程
  62. // 事务操作
  63. BOOL TransBegin(); // 开始事务
  64. BOOL TransCommit(); // 提交事务
  65. BOOL TransRollback(); // 回滚事务
  66. // 错误处理
  67. LPCTSTR GetLastError();
  68. };
  69. /*************************************************************************
  70. 【类名】 COtlRecordset
  71. 【功能】 OTL记录集访问类
  72. 【接口说明】
  73. 【开发者及日期】 郑石诺 2015/01/09
  74. 【版本】 V1.0.0
  75. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  76. 【更改记录】
  77. *************************************************************************/
  78. class COtlRecordset INHERIT_OTL( : public IOtlRecordset )
  79. {
  80. friend COtlConnection;
  81. friend COtlRecordset;
  82. public:
  83. #ifndef DBCTRL_EXPORTS
  84. static void DestroyInstance( COtlRecordset * pRecord );
  85. #endif
  86. // 数据控制
  87. BOOL IsEOF( void ); // 是否已遍历到记录保结尾
  88. BOOL MoveNextRow( void ); // 移动记录集到下一行
  89. BOOL GetValueInt( char *pColName, int &nValue ); // 获取当前行指定字段值 整形
  90. BOOL GetValueStr( char *pColName, char *pValue ); // 获取当前行指定字段值 字符串
  91. BOOL GetValueText( char *pColName, char *pValue ); // 获取当前行指定字段值 较大文本值
  92. BOOL GetValueFloat( char *pColName, float & Value ); // 获取当前行指定字段值 浮点
  93. int GetValueIntByIndex( int index ); // 通过字段ID获取整型记录
  94. int GetValueInt( CString FieldName ); // 通过字段名称获取整型记录
  95. CString GetValueStrByIndex( int index ); // 通过字段ID获取字符串记录
  96. CString GetValueStr( CString FieldName ); // 通过字段名称获取字符串记录
  97. BOOL GetValueFloatByIndex( int index, float & Value ); // 通过字段ID获取浮点记录
  98. // 错误处理
  99. LPCTSTR GetLastError( void );
  100. private:
  101. COtlRecordset( COtlConnHost * pConnHost ); // 私有构造
  102. virtual ~COtlRecordset( void )throw(); // 私有析构
  103. // 读取记录集初始数据
  104. BOOL __InitData( LPCTSTR lpszSQL );
  105. private:
  106. otl_stream* m_pStream; // OTL流
  107. COtlConnHost* m_pOtlConnHost; // OTL连接管理类
  108. OtlIterator m_Iterator; // OTL流迭代器
  109. };
  110. /*************************************************************************
  111. 【类名】 COtlStoredProc
  112. 【功能】 存储过程执行实体(仅供需返回值的存储过程或存储函数)
  113. 【接口说明】
  114. 【开发者及日期】 郑石诺 2015/01/09
  115. 【版本】 V1.0.0
  116. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  117. 【更改记录】
  118. *************************************************************************/
  119. class COtlStoredProc INHERIT_OTL( : public IOtlStoredProc )
  120. {
  121. friend COtlConnHost;
  122. public:
  123. #ifndef DBCTRL_EXPORTS
  124. static void DestroyInstance( COtlStoredProc * a_pProc );
  125. #endif
  126. // 添加存储过程输入参数(目前仅实现了两种重载,后续根据需要可自行添加)
  127. BOOL Input( LPCTSTR a_StrParam );
  128. BOOL Input( UINT a_UintParam );
  129. BOOL Input( int a_IntParam );
  130. // 存储过程执行完毕输出参数(目前仅实现了两种重载,后续根据需要可自行添加)
  131. BOOL Output( UINT & a_UintReturn );
  132. BOOL Output( int& a_IntParam );
  133. BOOL Output( LPTSTR a_StrParam );
  134. BOOL Output( float a_FloatParam );
  135. // 错误处理
  136. LPCTSTR GetLastError();
  137. private:
  138. COtlStoredProc( COtlConnHost * a_pConnHost, const CString & a_DeclareWord );
  139. virtual ~COtlStoredProc( void )throw();
  140. private:
  141. COtlConnHost* m_pOtlConnHost; // OTL连接管理类
  142. otl_stream m_Stream; // OTL流
  143. };