Commit b51fd2e4 authored by Ronan's avatar Ronan
Browse files

fix(MainDb): use transactions in unsafe functions

parent 30389fd9
......@@ -2010,12 +2010,16 @@ static constexpr string &blobToString (string &in) {
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
d->invalidConferenceEventsFromQuery(query, dbChatRoomId);
soci::session *session = d->dbSession.getBackendSession<soci::session>();
*session << "DELETE FROM event WHERE id IN (" + query + ")", soci::use(dbChatRoomId);
tr.commit();
L_END_LOG_EXCEPTION
}
......@@ -2044,6 +2048,7 @@ static constexpr string &blobToString (string &in) {
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
soci::rowset<soci::row> rows = (session->prepare << query);
for (const auto &row : rows) {
......@@ -2152,6 +2157,8 @@ static constexpr string &blobToString (string &in) {
chatRooms.push_back(chatRoom);
}
tr.commit();
return chatRooms;
L_END_LOG_EXCEPTION
......@@ -2200,6 +2207,9 @@ static constexpr string &blobToString (string &in) {
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
d->invalidConferenceEventsFromQuery(
......@@ -2207,9 +2217,10 @@ static constexpr string &blobToString (string &in) {
dbChatRoomId
);
soci::session *session = d->dbSession.getBackendSession<soci::session>();
*session << "DELETE FROM chat_room WHERE id = :chatRoomId", soci::use(dbChatRoomId);
tr.commit();
L_END_LOG_EXCEPTION
}
......@@ -2229,13 +2240,13 @@ static constexpr string &blobToString (string &in) {
L_BEGIN_LOG_EXCEPTION
const long long &dbChatRoomId = d->selectChatRoomId(basicChatRoom->getChatRoomId());
// TODO: Update events and chat messages. (Or wait signals.)
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(basicChatRoom->getChatRoomId());
const ChatRoomId &newChatRoomId = clientGroupChatRoom->getChatRoomId();
const long long &peerSipAddressId = d->insertSipAddress(newChatRoomId.getPeerAddress().asString());
const long long &localSipAddressId = d->insertSipAddress(newChatRoomId.getLocalAddress().asString());
......@@ -2282,9 +2293,11 @@ static constexpr string &blobToString (string &in) {
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
soci::session *session = d->dbSession.getBackendSession<soci::session>();
int capabilities = 0;
*session << "SELECT capabilities FROM chat_room WHERE id = :chatRoomId",
soci::use(dbChatRoomId), soci::into(capabilities);
......@@ -2295,6 +2308,8 @@ static constexpr string &blobToString (string &in) {
*session << "UPDATE chat_room SET capabilities = :capabilities WHERE id = :chatRoomId",
soci::use(capabilities), soci::use(dbChatRoomId);
tr.commit();
L_END_LOG_EXCEPTION
}
......
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