fix(MainDb): add a resolve id function (soci workaround)

This commit is contained in:
Ronan Abhamon 2017-11-27 15:30:21 +01:00
parent a63b6c7601
commit 049371e757
2 changed files with 24 additions and 17 deletions

View file

@ -26,6 +26,10 @@
// =============================================================================
namespace soci {
class row;
}
LINPHONE_BEGIN_NAMESPACE
class Content;
@ -35,6 +39,12 @@ public:
std::unordered_map<long long, std::weak_ptr<EventLog>> storageIdToEvent;
private:
// ---------------------------------------------------------------------------
// SOCI helpers.
// ---------------------------------------------------------------------------
long long resolveId (const soci::row &row, int col) const;
// ---------------------------------------------------------------------------
// Low level API.
// ---------------------------------------------------------------------------

View file

@ -119,6 +119,15 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
// -----------------------------------------------------------------------------
long long MainDbPrivate::resolveId (const soci::row &row, int col) const {
L_Q();
// See: http://soci.sourceforge.net/doc/master/backends/
// `row id` is not supported by soci on Sqlite3. It's necessary to cast id to int...
return q->getBackend() == AbstractDb::Sqlite3
? static_cast<long long>(row.get<int>(0))
: row.get<long long>(0);
}
long long MainDbPrivate::insertSipAddress (const string &sipAddress) {
L_Q();
soci::session *session = dbSession.getBackendSession<soci::session>();
@ -444,9 +453,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
if (contentType == ContentType::FileTransfer)
content = new FileTransferContent();
else if (contentType.isFile()) {
long long contentId = q->getBackend() == AbstractDb::Sqlite3
? static_cast<long long>(row.get<int>(0))
: row.get<long long>(0);
long long contentId = resolveId(row, 0);
string name;
int size;
@ -764,14 +771,10 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
}
void MainDbPrivate::invalidConferenceEventsFromQuery (const string &query, long long chatRoomId) {
L_Q();
soci::session *session = dbSession.getBackendSession<soci::session>();
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(chatRoomId));
for (const auto &row : rows) {
shared_ptr<EventLog> eventLog = getEventFromCache(
q->getBackend() == AbstractDb::Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0)
);
shared_ptr<EventLog> eventLog = getEventFromCache(resolveId(row, 0));
if (eventLog) {
const EventLogPrivate *dEventLog = eventLog->getPrivate();
L_ASSERT(dEventLog->dbKey.isValid());
@ -1267,7 +1270,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(d->selectChatRoomId(chatRoomId)), soci::use(lastNotifyId));
for (const auto &row : rows) {
long long eventId = getBackend() == Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0);
long long eventId = d->resolveId(row, 0);
shared_ptr<EventLog> eventLog = d->getEventFromCache(eventId);
events.push_back(eventLog ? eventLog : d->selectGenericConferenceEvent(
@ -1469,9 +1472,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::rowset<soci::row> rows = (session->prepare << query);
for (const auto &row : rows) {
// See: http://soci.sourceforge.net/doc/master/backends/
// `row id` is not supported by soci on Sqlite3. It's necessary to cast id to int...
long long eventId = getBackend() == Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0);
long long eventId = d->resolveId(row, 0);
shared_ptr<EventLog> event = d->getEventFromCache(eventId);
if (!event)
@ -1577,13 +1578,9 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
} else if (capabilities & static_cast<int>(ChatRoom::Capabilities::Conference)) {
list<shared_ptr<Participant>> participants;
long long dbChatRoomId = getBackend() == AbstractDb::Sqlite3
? static_cast<long long>(row.get<int>(0))
: row.get<long long>(0);
string query = "SELECT sip_address.value, is_admin"
" FROM sip_address, chat_room, chat_room_participant"
" WHERE chat_room.id = " + Utils::toString(dbChatRoomId) +
" WHERE chat_room.id = " + Utils::toString(d->resolveId(row, 0)) +
" AND sip_address.id = chat_room_participant.participant_sip_address_id"
" AND chat_room_participant.chat_room_id = chat_room.id";