AdoImpl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*************************************************************
  2. /* Copyright (C), 2014-2020, lyfz. Co., Ltd.
  3. /* 文件名: AdoImpl.h
  4. /* 作者: Jeff.w
  5. /* 创建日期: 2014-08-16
  6. /* 版本号: V1.0
  7. /* 描述: 核心层底,数据库ADO编程
  8. /* 其它:
  9. /* 主要类模块:
  10. /* 历史修改记录:
  11. /* 作者 时间 版本 描述
  12. /* Jeff.w 14/08/18 1.0 创建这个模块
  13. ***************************************************************/
  14. #ifndef __ADO_IMPL_HEADER__
  15. #define __ADO_IMPL_HEADER__
  16. #pragma once
  17. #include "AdoDef.h"
  18. #include "ADODatabase.h"
  19. #include "ADORecordset.h"
  20. #include "ADOCommand.h"
  21. // 声明回调函数;
  22. typedef int (CALLBACK *RecordsetCallback)(IN const DWORD& dwCallBackType, IN LPVOID lpParamter, IN const int& nRecordCount, IN CADORecordset* pRet);
  23. // Jeff.一个数据库只有一个AdoImpl实例;
  24. // 该类使用线程,监测线程的作用是判断数据库是否断开并重连;
  25. // 未对二进制文件支持操作;
  26. class AdoImpl
  27. {
  28. CString m_strQuery;
  29. CString m_strLastError;
  30. DWORD m_dwLastError;
  31. inline CString GetQuery() {return m_strQuery;};
  32. inline void SetQuery(LPCSTR strQuery) {m_strQuery = strQuery;};
  33. private:
  34. CRITICAL_SECTION m_csAdo;
  35. TCHAR m_szConnectString[1024];// 暂使用1024魔数,后期升级再定义;
  36. CADODatabase *m_pADODatabase;
  37. BOOL OpenADORecordSet(IN CADORecordset *pRSet, IN LPCTSTR lpSQL, IN const int& nCursorLocation = adUseClient);
  38. void CloseADORecordSet(IN CADORecordset* pRSet);
  39. void DeleteADORecordSet(IN CADORecordset* pRSet);
  40. public:
  41. AdoImpl(void);
  42. virtual ~AdoImpl(void);
  43. void SetConnectString(
  44. IN const int &nType,
  45. IN LPCTSTR lpDataSource,
  46. IN LPCTSTR lpDatabaseTCPPort,
  47. IN LPCTSTR lpDatabaseAccount,
  48. IN LPCTSTR lpDatabasePassWord,
  49. IN LPCTSTR lpDatabaseName,
  50. IN LPCTSTR lpDatabaseFile = NULL);
  51. BOOL IsOpen();
  52. BOOL Opendatabase(IN LPCTSTR lpConnectString = NULL);
  53. void Closedatabase();
  54. int Execute(IN LPCTSTR lpSQL);//不返回记录集;
  55. bool GetADODateBaseStatus();
  56. CADODatabase *GetAdoDatabase(){return m_pADODatabase;};
  57. // 应用层接口;
  58. public:
  59. DWORD GetTableRecordCount(IN LPCTSTR lpTableName, IN LPCTSTR lpFilters); // 返回要查询的表的记录数;
  60. // 使用回调函数来处理具体的数据;
  61. int GetFieldValueList(IN LPCTSTR lpTableName, IN LPCTSTR lpFields, IN LPCTSTR lpFilters, IN const DWORD &dwCallBackType,IN LPVOID lpCallBack, IN OUT LPVOID lpParamter);
  62. int GetFieldValueListEx(IN LPCTSTR lpTableName, IN LPCTSTR lpFields, IN LPCTSTR lpFilters, IN const DWORD &dwCallBackType,IN LPVOID lpCallBack, IN OUT LPVOID lpParamter);
  63. BOOL AppenChunkFromFile(IN LPCTSTR lpTableName, IN LPCTSTR lpFieldName, IN LPCTSTR lpFileName);
  64. BOOL AppenChunkFromBuffer(IN LPCTSTR lpTableName, IN LPCTSTR lpFieldName, IN BYTE* lpBuffer, IN const int& nBuflen);
  65. };
  66. #endif