diff --git a/src/db/abstract/abstract-db.cpp b/src/db/abstract/abstract-db.cpp index 3f58b5251..1193720d4 100644 --- a/src/db/abstract/abstract-db.cpp +++ b/src/db/abstract/abstract-db.cpp @@ -123,6 +123,20 @@ string AbstractDb::primaryKeyRefStr (const string &type) const { return ""; } +string AbstractDb::timestampType () const { + L_D(); + + switch (d->backend) { + case Mysql: + return " TIMESTAMP"; + case Sqlite3: + return " DATE"; + } + + L_ASSERT(false); + return ""; +} + long long AbstractDb::getLastInsertId () const { long long id = 0; diff --git a/src/db/abstract/abstract-db.h b/src/db/abstract/abstract-db.h index 9987d9647..2d1ab1020 100644 --- a/src/db/abstract/abstract-db.h +++ b/src/db/abstract/abstract-db.h @@ -54,6 +54,8 @@ protected: std::string primaryKeyStr (const std::string &type = "INT") const; std::string primaryKeyRefStr (const std::string &type = "INT") const; + std::string timestampType () const; + long long getLastInsertId () const; void enableForeignKeys (bool status); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 61a623279..9ed69e167 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -1006,7 +1006,7 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), "CREATE TABLE IF NOT EXISTS event (" " id" + primaryKeyStr("BIGINT UNSIGNED") + "," " type TINYINT UNSIGNED NOT NULL," - " creation_time TIMESTAMP NOT NULL" + " creation_time" + timestampType() + " NOT NULL" ") " + charset; *session << @@ -1019,10 +1019,10 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), " local_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL," // Dialog creation time. - " creation_time TIMESTAMP NOT NULL," + " creation_time" + timestampType() + " NOT NULL," // Last event time (call, message...). - " last_update_time TIMESTAMP NOT NULL," + " last_update_time" + timestampType() + " NOT NULL," // ConferenceChatRoom, BasicChatRoom, RTT... " capabilities TINYINT UNSIGNED NOT NULL," @@ -1149,7 +1149,7 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), " from_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL," " to_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL," - " time TIMESTAMP," + " time" + timestampType() + " ," // See: https://tools.ietf.org/html/rfc5438#section-6.3 " imdn_message_id VARCHAR(255) NOT NULL,"