Commit 5c0b416b authored by Ronan's avatar Ronan

feat(MainDb): supports correctly foreign keys, fix db schema, ...

parent f20bca4c
......@@ -43,7 +43,9 @@ bool AbstractDb::connect (Backend backend, const string &parameters) {
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<soci::session>();
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
......@@ -56,6 +56,8 @@ protected:
long long getLastInsertId () const;
void enableForeignKeys (bool status);
private:
L_DECLARE_PRIVATE(AbstractDb);
L_DISABLE_COPY(AbstractDb);
......
......@@ -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<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId (
const string &peerAddress,
unsigned int notifyId
) {
// TODO.
return list<shared_ptr<EventLog>>();
}
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<soci::session>();
*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<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId (
const string &peerAddress,
unsigned int notifyId
) {
return list<shared_ptr<EventLog>>();
}
int MainDb::getMessagesCount (const string &) const {
return 0;
}
......
......@@ -55,6 +55,11 @@ public:
int getEventsCount (FilterMask mask = NoFilter) const;
// Messages, calls and conferences.
std::list<std::shared_ptr<EventLog>> getHistorySinceNotifyId (
const std::string &peerAddress,
unsigned int notifyId
);
int getMessagesCount (const std::string &peerAddress = "") const;
int getUnreadMessagesCount (const std::string &peerAddress = "") const;
std::list<std::shared_ptr<EventLog>> getHistory (
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment