ADOCommand.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*************************************************************
  2. /* Copyright (C), 2014-2020, lyfz. Co., Ltd.
  3. /* 文件名: **.h
  4. /* 作者: Jeff.w
  5. /* 创建日期: 2014-08-16
  6. /* 版本号: V1.0
  7. /* 描述: 核心层底,数据库ADO编程
  8. /* 其它:
  9. /* 主要类模块:
  10. /* 历史修改记录:
  11. /* 作者 时间 版本 描述
  12. /* Jeff.w 14/08/16 1.0 创建这个模块
  13. ***************************************************************/
  14. #ifndef __ADO_COMMAND_HEADER__
  15. #define __ADO_COMMAND_HEADER__
  16. #pragma once
  17. #include "AdoDef.h"
  18. #include "ADODatabase.h"
  19. #include "ADOParameter.h"
  20. class CADOCommand
  21. {
  22. public:
  23. enum cadoCommandType
  24. {
  25. typeCmdText = adCmdText,
  26. typeCmdTable = adCmdTable,
  27. typeCmdTableDirect = adCmdTableDirect,
  28. typeCmdStoredProc = adCmdStoredProc,
  29. typeCmdUnknown = adCmdUnknown,
  30. typeCmdFile = adCmdFile
  31. };
  32. CADOCommand(CADODatabase* pAdoDatabase, CString strCommandText = _T(""), int nCommandType = typeCmdStoredProc);
  33. virtual ~CADOCommand()
  34. {
  35. ::SysFreeString(m_pCommand->CommandText);
  36. m_pCommand.Release();
  37. m_pCommand = NULL;
  38. m_strCommandText = _T("");
  39. }
  40. void SetTimeout(long nTimeOut){m_pCommand->PutCommandTimeout(nTimeOut);};
  41. void SetText(CString strCommandText);
  42. void SetType(int nCommandType);
  43. BOOL AddParameter(CADOParameter* pAdoParameter);
  44. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, int nValue);
  45. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, long lValue);
  46. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, double dblValue, int nPrecision = 0, int nScale = 0);
  47. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, CString strValue);
  48. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, COleDateTime time);
  49. BOOL AddParameter(CString strName, int nType, int nDirection, long lSize, _variant_t vtValue, int nPrecision = 0, int nScale = 0);
  50. // inline func;
  51. inline int GetType(){return m_nCommandType;};
  52. inline CString GetText(){return m_strCommandText;};
  53. BOOL Execute(int nCommandType = typeCmdStoredProc);
  54. int GetRecordsAffected(){return m_nRecordsAffected;};
  55. inline _CommandPtr GetCommand(){return m_pCommand;};
  56. protected:
  57. void dump_com_error(_com_error &e);
  58. protected:
  59. _CommandPtr m_pCommand;
  60. int m_nCommandType;
  61. int m_nRecordsAffected;
  62. CString m_strCommandText;
  63. CString m_strLastError;
  64. DWORD m_dwLastError;
  65. };
  66. #endif