Commit fde89d36 authored by Ronan's avatar Ronan

feat(MainDb): supports MySql types and rowid from sqlite

parent a9418e19
......@@ -77,21 +77,38 @@ void AbstractDb::init () {
// -----------------------------------------------------------------------------
string AbstractDb::primaryKeyAutoIncrementStr (const string &type) const {
string AbstractDb::primaryKeyStr (const string &type) const {
L_D();
switch (d->backend) {
case Mysql:
return type + "UNSIGNED PRIMARY KEY AUTO_INCREMENT";
return type + " PRIMARY KEY AUTO_INCREMENT";
case Sqlite3:
return " INTEGER PRIMARY KEY AUTOINCREMENT";
// See: ROWIDs and the INTEGER PRIMARY KEY
// https://www.sqlite.org/lang_createtable.html
return " INTEGER PRIMARY KEY ASC";
}
L_ASSERT(false);
return "";
}
long AbstractDb::getLastInsertId () const {
long result = 0;
string AbstractDb::primaryKeyRefStr (const string &type) const {
L_D();
switch (d->backend) {
case Mysql:
return " " + type;
case Sqlite3:
return " INTEGER";
}
L_ASSERT(false);
return "";
}
long long AbstractDb::getLastInsertId () const {
long long id = 0;
#ifdef SOCI_ENABLED
L_D();
......@@ -110,10 +127,10 @@ long AbstractDb::getLastInsertId () const {
}
soci::session *session = d->dbSession.getBackendSession<soci::session>();
*session << sql, soci::into(result);
*session << sql, soci::into(id);
#endif // ifdef SOCI_ENABLED
return result;
return id;
}
LINPHONE_END_NAMESPACE
......@@ -51,9 +51,10 @@ protected:
virtual void init ();
std::string primaryKeyAutoIncrementStr (const std::string &type = "INT") const;
std::string primaryKeyStr (const std::string &type = "INT") const;
std::string primaryKeyRefStr (const std::string &type = "INT") const;
long getLastInsertId () const;
long long getLastInsertId () const;
private:
L_DECLARE_PRIVATE(AbstractDb);
......
......@@ -39,74 +39,74 @@ private:
// Low level API.
// ---------------------------------------------------------------------------
long insertSipAddress (const std::string &sipAddress);
void insertContent (long messageEventId, const Content &content);
long insertContentType (const std::string &contentType);
long insertChatRoom (long sipAddressId, int capabilities, const tm &date);
void insertChatRoomParticipant (long chatRoomId, long sipAddressId, bool isAdmin);
void insertChatMessageParticipant (long messageEventId, long sipAddressId, int state);
long long insertSipAddress (const std::string &sipAddress);
void insertContent (long long messageEventId, const Content &content);
long long insertContentType (const std::string &contentType);
long long insertChatRoom (long long sipAddressId, int capabilities, const tm &date);
void insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin);
void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state);
// ---------------------------------------------------------------------------
// Events API.
// ---------------------------------------------------------------------------
std::shared_ptr<EventLog> selectGenericConferenceEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceCallEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceChatMessageEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceParticipantEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceParticipantDeviceEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
std::shared_ptr<EventLog> selectConferenceSubjectEvent (
long eventId,
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
) const;
long insertEvent (const EventLog &eventLog);
long insertConferenceEvent (const EventLog &eventLog, long *chatRoomId = nullptr);
long insertConferenceCallEvent (const EventLog &eventLog);
long insertConferenceChatMessageEvent (const EventLog &eventLog);
long insertConferenceNotifiedEvent (const EventLog &eventLog);
long insertConferenceParticipantEvent (const EventLog &eventLog);
long insertConferenceParticipantDeviceEvent (const EventLog &eventLog);
long insertConferenceSubjectEvent (const EventLog &eventLog);
long long insertEvent (const EventLog &eventLog);
long long insertConferenceEvent (const EventLog &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceCallEvent (const EventLog &eventLog);
long long insertConferenceChatMessageEvent (const EventLog &eventLog);
long long insertConferenceNotifiedEvent (const EventLog &eventLog);
long long insertConferenceParticipantEvent (const EventLog &eventLog);
long long insertConferenceParticipantDeviceEvent (const EventLog &eventLog);
long long insertConferenceSubjectEvent (const EventLog &eventLog);
L_DECLARE_PUBLIC(MainDb);
};
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
class EventLogPrivate : public BaseObjectPrivate {
public:
long storageId = -1;
long long storageId = -1;
private:
EventLog::Type type = EventLog::Type::None;
......
No preview for this file type
......@@ -54,21 +54,21 @@ static void get_messages_count () {
MainDb mainDb;
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
BC_ASSERT_EQUAL(mainDb.getMessagesCount(), 4976, int, "%d");
BC_ASSERT_EQUAL(mainDb.getMessagesCount("sip:test-7@sip.linphone.org"), 3, int, "%d");
BC_ASSERT_EQUAL(mainDb.getMessagesCount("sip:test-39@sip.linphone.org"), 3, int, "%d");
}
static void get_unread_messages_count () {
MainDb mainDb;
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
BC_ASSERT_EQUAL(mainDb.getUnreadMessagesCount(), 2, int, "%d");
BC_ASSERT_EQUAL(mainDb.getUnreadMessagesCount("sip:test-7@sip.linphone.org"), 0, int, "%d");
BC_ASSERT_EQUAL(mainDb.getUnreadMessagesCount("sip:test-39@sip.linphone.org"), 0, int, "%d");
}
static void get_history () {
MainDb mainDb;
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
BC_ASSERT_EQUAL(
mainDb.getHistory("sip:test-7@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
mainDb.getHistory("sip:test-39@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
3,
int,
"%d"
......
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