SQLStatementImpl.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef __SQL_STATEMENT_IMPL_HEADER__
  2. #define __SQL_STATEMENT_IMPL_HEADER__
  3. #pragma once
  4. enum SQLSTATEMENTKIND
  5. {
  6. KIND_INSERT = 1,
  7. KIND_UPDATE = 2
  8. };
  9. class CSQLStatementImpl
  10. {
  11. CSQLStatementImpl();
  12. protected:
  13. CString m_strSQL;
  14. CString m_strTableName;
  15. CString m_strFilter;
  16. int m_nStatementKind; // 1==Insert, 2==Update;
  17. int m_nCount;
  18. int m_nSzie;
  19. CStringArray m_saFields;
  20. CStringArray m_saValues;
  21. public:
  22. ~CSQLStatementImpl();
  23. inline static CSQLStatementImpl *GetInstancePtr()
  24. {
  25. static CSQLStatementImpl lInstance;
  26. return &lInstance;
  27. }
  28. inline void ReSetKind(LPCTSTR lpTableName,LPCTSTR lpFilter,const int &nStatementKind,const int &nSize)
  29. {
  30. m_nStatementKind = nStatementKind;
  31. //if(m_nStatementKind == KIND_UPDATE)
  32. m_strTableName = lpTableName;
  33. m_strFilter = lpFilter;
  34. m_nCount = 0;
  35. m_nSzie = nSize;
  36. // SetSize之后,必须调用RemoveAll,否则Add时元素位置是从m_nSize开始,而不是从0开始;
  37. m_saFields.SetSize(m_nSzie,256);
  38. m_saValues.SetSize(m_nSzie,256);
  39. m_saFields.RemoveAll();
  40. m_saValues.RemoveAll();
  41. }
  42. void AddElement(LPCTSTR lpField, LPCTSTR lpValue);
  43. void AddElement(LPCTSTR lpField, CONST INT &nValue);
  44. CString ReturnSQL();
  45. void ReturnSQL(CString &strSQL);
  46. };
  47. #endif