diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index f04940132..ce64805ae 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -43,7 +43,9 @@ bool AbstractDb::connect (Backend backend, const string ¶meters) { if (d->dbSession) { try { + enableForeignKeys(false); init(); + enableForeignKeys(true); } catch (const exception &e) { lWarning() << "Unable to init database: " << e.what(); @@ -133,4 +135,19 @@ long long AbstractDb::getLastInsertId () const { return id; } +void AbstractDb::enableForeignKeys (bool status) { + #ifdef SOCI_ENABLED + L_D(); + soci::session *session = d->dbSession.getBackendSession(); + switch (d->backend) { + case Mysql: + *session << string("SET FOREIGN_KEY_CHECKS = ") + (status ? "1" : "0"); + break; + case Sqlite3: + *session << string("PRAGMA foreign_keys = ") + (status ? "ON" : "OFF"); + break; + } + #endif // ifdef SOCI_ENABLED +} + LINPHONE_END_NAMESPACE diff --git a/src/db/abstract/abstract-db.h b/src/db/abstract/abstract-db.h index 2386c384e..9987d9647 100644 --- a/src/db/abstract/abstract-db.h +++ b/src/db/abstract/abstract-db.h @@ -56,6 +56,8 @@ protected: long long getLastInsertId () const; + void enableForeignKeys (bool status); + private: L_DECLARE_PRIVATE(AbstractDb); L_DISABLE_COPY(AbstractDb); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index d09d85de3..23ab4e17d 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -607,7 +607,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { "CREATE TABLE IF NOT EXISTS conference_subject_event (" " event_id" + primaryKeyStr("BIGINT") + "," - " subject VARCHAR(255)," + " subject VARCHAR(255) NOT NULL," " FOREIGN KEY (event_id)" " REFERENCES conference_notified_event(event_id)" @@ -629,7 +629,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { " is_secured BOOLEAN NOT NULL," " FOREIGN KEY (event_id)" - " REFERENCES conference_event(id)" + " REFERENCES conference_event(event_id)" " ON DELETE CASCADE," " FOREIGN KEY (local_sip_address_id)" " REFERENCES sip_address(id)" @@ -842,6 +842,14 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { return count; } + list> MainDb::getHistorySinceNotifyId ( + const string &peerAddress, + unsigned int notifyId + ) { + // TODO. + return list>(); + } + int MainDb::getMessagesCount (const string &peerAddress) const { L_D(); @@ -1067,7 +1075,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); - *session << "DELETE FROM chat_room WHERE peer_sip_address_id IN (" + *session << "DELETE FROM chat_room WHERE peer_sip_address_id = (" " SELECT id FROM sip_address WHERE value = :peerAddress" ")", soci::use(peerAddress); @@ -1247,6 +1255,13 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { return 0; } + list> MainDb::getHistorySinceNotifyId ( + const string &peerAddress, + unsigned int notifyId + ) { + return list>(); + } + int MainDb::getMessagesCount (const string &) const { return 0; } diff --git a/src/db/main-db.h b/src/db/main-db.h index af06cdcda..71889472b 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -55,6 +55,11 @@ public: int getEventsCount (FilterMask mask = NoFilter) const; // Messages, calls and conferences. + std::list> getHistorySinceNotifyId ( + const std::string &peerAddress, + unsigned int notifyId + ); + int getMessagesCount (const std::string &peerAddress = "") const; int getUnreadMessagesCount (const std::string &peerAddress = "") const; std::list> getHistory ( diff --git a/tester/db/linphone.db b/tester/db/linphone.db index 6fb3f9ab6..9b76ebd67 100644 Binary files a/tester/db/linphone.db and b/tester/db/linphone.db differ