ECDatabase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef ECDATABASE_H
  18. #define ECDATABASE_H
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/ECConfig.h>
  21. #include <kopano/database.hpp>
  22. #include <string>
  23. namespace KC {
  24. class ECConfig;
  25. class zcp_versiontuple;
  26. class _kc_export ECDatabase _kc_final : public KDatabase {
  27. public:
  28. ECDatabase(ECConfig *);
  29. virtual ~ECDatabase(void);
  30. static ECRESULT InitLibrary(const char *dir, const char *config_file);
  31. static void UnloadLibrary(void);
  32. virtual ECRESULT Begin(void) _kc_override;
  33. ECRESULT CheckExistColumn(const std::string &table, const std::string &column, bool *exist);
  34. ECRESULT CheckExistIndex(const std::string &table, const std::string &key, bool *exist);
  35. virtual ECRESULT Commit(void) _kc_override;
  36. ECRESULT Connect(void);
  37. ECRESULT CreateDatabase(void);
  38. virtual ECRESULT DoSelect(const std::string &query, DB_RESULT *result, bool stream_result = false) _kc_override;
  39. ECRESULT DoSelectMulti(const std::string &query);
  40. virtual ECRESULT DoDelete(const std::string &query, unsigned int *affected_rows = nullptr) _kc_override;
  41. virtual ECRESULT DoInsert(const std::string &query, unsigned int *insert_id = nullptr, unsigned int *affected_rows = nullptr) _kc_override;
  42. virtual ECRESULT DoSequence(const std::string &seqname, unsigned int ulCount, unsigned long long *first_id) _kc_override;
  43. virtual ECRESULT DoUpdate(const std::string &query, unsigned int *affected_rows = nullptr) _kc_override;
  44. ECRESULT FinalizeMulti(void);
  45. std::string FilterBMP(const std::string &to_filter);
  46. ECRESULT GetNextResult(DB_RESULT *);
  47. ECRESULT InitializeDBState(void);
  48. ECRESULT ValidateTables(void);
  49. virtual ECRESULT Rollback(void) _kc_override;
  50. bool SuppressLockErrorLogging(bool suppress);
  51. void ThreadEnd(void);
  52. void ThreadInit(void);
  53. ECRESULT UpdateDatabase(bool force_update, std::string &report);
  54. private:
  55. ECRESULT InitializeDBStateInner(void);
  56. virtual const struct sSQLDatabase_t *GetDatabaseDefs(void) _kc_override;
  57. ECRESULT GetDatabaseVersion(zcp_versiontuple *);
  58. ECRESULT GetFirstUpdate(unsigned int *lpulDatabaseRevision);
  59. ECRESULT IsUpdateDone(unsigned int ulDatabaseRevision, unsigned int ulRevision=0);
  60. ECRESULT UpdateDatabaseVersion(unsigned int ulDatabaseRevision);
  61. virtual ECRESULT Query(const std::string &q) _kc_override;
  62. std::string error;
  63. bool m_bForceUpdate = false, m_bFirstResult = false;
  64. ECConfig *m_lpConfig = nullptr;
  65. #ifdef DEBUG
  66. unsigned int m_ulTransactionState = 0;
  67. #endif
  68. // Function requires m_bForceUpdate variable
  69. friend ECRESULT UpdateDatabaseConvertToUnicode(ECDatabase *lpDatabase);
  70. };
  71. } /* namespace */
  72. #endif // ECDATABASE_H