arc_mysql.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <kopano/ECConfig.h>
  18. #include <kopano/database.hpp>
  19. #include "arc_mysql.hpp"
  20. namespace KC {
  21. KCMDatabaseMySQL::~KCMDatabaseMySQL(void)
  22. {
  23. Close();
  24. }
  25. ECRESULT KCMDatabaseMySQL::Connect(ECConfig *lpConfig)
  26. {
  27. /* The max length of a group_concat function */
  28. static constexpr const unsigned int gcm = 32768;
  29. /*
  30. * Set auto reconnect. mysql < 5.0.4 default on, mysql 5.0.4 >
  31. * reconnection default off. Archiver always wants to reconnect.
  32. */
  33. return KDatabase::Connect(lpConfig, true, 0, gcm);
  34. }
  35. #define ZA_TABLEDEF_SERVERS \
  36. "CREATE TABLE `za_servers` ( \
  37. `id` int(11) unsigned NOT NULL auto_increment, \
  38. `guid` binary(16) NOT NULL, \
  39. PRIMARY KEY (`id`), \
  40. UNIQUE KEY `guid` (`guid`) \
  41. ) ENGINE=InnoDB"
  42. #define ZA_TABLEDEF_INSTANCES \
  43. "CREATE TABLE `za_instances` ( \
  44. `id` int(11) unsigned NOT NULL auto_increment, \
  45. `tag` smallint(6) unsigned NOT NULL, \
  46. PRIMARY KEY (`id`), \
  47. UNIQUE KEY `instance` (`id`, `tag`) \
  48. ) ENGINE=InnoDB"
  49. #define ZA_TABLEDEF_MAPPINGS \
  50. "CREATE TABLE `za_mappings` ( \
  51. `server_id` int(11) unsigned NOT NULL, \
  52. `val_binary` blob NOT NULL, \
  53. `tag` smallint(6) unsigned NOT NULL, \
  54. `instance_id` int(11) unsigned NOT NULL, \
  55. PRIMARY KEY (`server_id`, `val_binary`(64), `tag`), \
  56. UNIQUE KEY `instance` (`instance_id`, `tag`, `server_id`), \
  57. FOREIGN KEY (`server_id`) REFERENCES za_servers(`id`) ON DELETE CASCADE, \
  58. FOREIGN KEY (`instance_id`, `tag`) REFERENCES za_instances(`id`, `tag`) ON UPDATE RESTRICT ON DELETE CASCADE \
  59. ) ENGINE=InnoDB"
  60. static constexpr const struct sSQLDatabase_t kcmsql_tables[] = {
  61. {"servers", ZA_TABLEDEF_SERVERS},
  62. {"instances", ZA_TABLEDEF_INSTANCES},
  63. {"mappings", ZA_TABLEDEF_MAPPINGS},
  64. {nullptr, nullptr},
  65. };
  66. const struct sSQLDatabase_t *KCMDatabaseMySQL::GetDatabaseDefs(void)
  67. {
  68. return kcmsql_tables;
  69. }
  70. } /* namespace */