Commit 21e426b9 authored by Ronan's avatar Ronan

fix(MainDb): use constexpr instead of define

parent cbb14ad1
......@@ -52,6 +52,34 @@ namespace {
constexpr unsigned int ModuleVersionFriends = makeVersion(1, 0, 0);
constexpr unsigned int ModuleVersionLegacyFriendsImport = makeVersion(1, 0, 0);
constexpr unsigned int ModuleVersionLegacyHistoryImport = makeVersion(1, 0, 0);
constexpr int LegacyFriendListColId = 0;
constexpr int LegacyFriendListColName = 1;
constexpr int LegacyFriendListColRlsUri = 2;
constexpr int LegacyFriendListColSyncUri = 3;
constexpr int LegacyFriendListColRevision = 4;
constexpr int LegacyFriendColFriendListId = 1;
constexpr int LegacyFriendColSipAddress = 2;
constexpr int LegacyFriendColSubscribePolicy = 3;
constexpr int LegacyFriendColSendSubscribe = 4;
constexpr int LegacyFriendColRefKey = 5;
constexpr int LegacyFriendColVCard = 6;
constexpr int LegacyFriendColVCardEtag = 7;
constexpr int LegacyFriendColVCardSyncUri = 8;
constexpr int LegacyFriendColPresenceReceived = 9;
constexpr int LegacyMessageColLocalAddress = 1;
constexpr int LegacyMessageColRemoteAddress = 2;
constexpr int LegacyMessageColDirection = 3;
constexpr int LegacyMessageColText = 4;
constexpr int LegacyMessageColState = 7;
constexpr int LegacyMessageColUrl = 8;
constexpr int LegacyMessageColDate = 9;
constexpr int LegacyMessageColAppData = 10;
constexpr int LegacyMessageColContentId = 11;
constexpr int LegacyMessageColContentType = 13;
constexpr int LegacyMessageColIsSecured = 14;
}
// -----------------------------------------------------------------------------
......@@ -1187,22 +1215,6 @@ static T getValueFromRow (const soci::row &row, int index, bool &isNull) {
// -----------------------------------------------------------------------------
#define LEGACY_FRIEND_LIST_COL_ID 0
#define LEGACY_FRIEND_LIST_COL_NAME 1
#define LEGACY_FRIEND_LIST_COL_RLS_URI 2
#define LEGACY_FRIEND_LIST_COL_SYNC_URI 3
#define LEGACY_FRIEND_LIST_COL_REVISION 4
#define LEGACY_FRIEND_COL_FRIEND_LIST_ID 1
#define LEGACY_FRIEND_COL_SIP_ADDRESS 2
#define LEGACY_FRIEND_COL_SUBSCRIBE_POLICY 3
#define LEGACY_FRIEND_COL_SEND_SUBSCRIBE 4
#define LEGACY_FRIEND_COL_REF_KEY 5
#define LEGACY_FRIEND_COL_V_CARD 6
#define LEGACY_FRIEND_COL_V_CARD_ETAG 7
#define LEGACY_FRIEND_COL_V_CARD_SYNC_URI 8
#define LEGACY_FRIEND_COL_PRESENCE_RECEIVED 9
void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
soci::session *inSession = inDbSession.getBackendSession();
soci::transaction tr(*dbSession.getBackendSession());
......@@ -1221,10 +1233,10 @@ void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
try {
set<string> names;
for (const auto &friendList : friendsLists) {
const string &name = friendList.get<string>(LEGACY_FRIEND_LIST_COL_NAME, "");
const string &rlsUri = friendList.get<string>(LEGACY_FRIEND_LIST_COL_RLS_URI, "");
const string &syncUri = friendList.get<string>(LEGACY_FRIEND_LIST_COL_SYNC_URI, "");
const int &revision = friendList.get<int>(LEGACY_FRIEND_LIST_COL_REVISION, 0);
const string &name = friendList.get<string>(LegacyFriendListColName, "");
const string &rlsUri = friendList.get<string>(LegacyFriendListColRlsUri, "");
const string &syncUri = friendList.get<string>(LegacyFriendListColSyncUri, "");
const int &revision = friendList.get<int>(LegacyFriendListColRevision, 0);
string uniqueName = name;
for (int id = 0; names.find(uniqueName) != names.end(); uniqueName = name + "-" + Utils::toString(id++));
......@@ -1233,7 +1245,7 @@ void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
*session << "INSERT INTO friends_list (name, rls_uri, sync_uri, revision) VALUES ("
" :name, :rlsUri, :syncUri, :revision"
")", soci::use(uniqueName), soci::use(rlsUri), soci::use(syncUri), soci::use(revision);
resolvedListsIds[friendList.get<int>(LEGACY_FRIEND_LIST_COL_ID)] = dbSession.getLastInsertId();
resolvedListsIds[friendList.get<int>(LegacyFriendListColId)] = dbSession.getLastInsertId();
}
} catch (const exception &e) {
lWarning() << "Failed to import legacy friends list: " << e.what() << ".";
......@@ -1245,19 +1257,19 @@ void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
for (const auto &friendInfo : friends) {
long long friendsListId;
{
auto it = resolvedListsIds.find(friendInfo.get<int>(LEGACY_FRIEND_COL_FRIEND_LIST_ID, -1));
auto it = resolvedListsIds.find(friendInfo.get<int>(LegacyFriendColFriendListId, -1));
if (it == resolvedListsIds.end())
continue;
friendsListId = it->second;
}
const long long &sipAddressId = insertSipAddress(friendInfo.get<string>(LEGACY_FRIEND_COL_SIP_ADDRESS, ""));
const int &subscribePolicy = friendInfo.get<int>(LEGACY_FRIEND_COL_SUBSCRIBE_POLICY, LinphoneSPAccept);
const int &sendSubscribe = friendInfo.get<int>(LEGACY_FRIEND_COL_SEND_SUBSCRIBE, 1);
const string &vCard = friendInfo.get<string>(LEGACY_FRIEND_COL_V_CARD, "");
const string &vCardEtag = friendInfo.get<string>(LEGACY_FRIEND_COL_V_CARD_ETAG, "");
const string &vCardSyncUri = friendInfo.get<string>(LEGACY_FRIEND_COL_V_CARD_SYNC_URI, "");
const int &presenceReveived = friendInfo.get<int>(LEGACY_FRIEND_COL_PRESENCE_RECEIVED, 0);
const long long &sipAddressId = insertSipAddress(friendInfo.get<string>(LegacyFriendColSipAddress, ""));
const int &subscribePolicy = friendInfo.get<int>(LegacyFriendColSubscribePolicy, LinphoneSPAccept);
const int &sendSubscribe = friendInfo.get<int>(LegacyFriendColSendSubscribe, 1);
const string &vCard = friendInfo.get<string>(LegacyFriendColVCard, "");
const string &vCardEtag = friendInfo.get<string>(LegacyFriendColVCardEtag, "");
const string &vCardSyncUri = friendInfo.get<string>(LegacyFriendColVCardSyncUri, "");
const int &presenceReveived = friendInfo.get<int>(LegacyFriendColPresenceReceived, 0);
*session << "INSERT INTO friend ("
" sip_address_id, friends_list_id, subscribe_policy, send_subscribe,"
......@@ -1269,7 +1281,7 @@ void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
soci::use(presenceReveived), soci::use(vCard), soci::use(vCardEtag), soci::use(vCardSyncUri);
bool isNull;
const string &data = getValueFromRow<string>(friendInfo, LEGACY_FRIEND_COL_REF_KEY, isNull);
const string &data = getValueFromRow<string>(friendInfo, LegacyFriendColRefKey, isNull);
if (!isNull)
*session << "INSERT INTO friend_app_data (friend_id, name, data) VALUES"
" (:friendId, 'legacy', :data)",
......@@ -1284,19 +1296,6 @@ void MainDbPrivate::importLegacyFriends (DbSession &inDbSession) {
lInfo() << "Successful import of legacy friends.";
}
#define LEGACY_MESSAGE_COL_LOCAL_ADDRESS 1
#define LEGACY_MESSAGE_COL_REMOTE_ADDRESS 2
#define LEGACY_MESSAGE_COL_DIRECTION 3
#define LEGACY_MESSAGE_COL_TEXT 4
#define LEGACY_MESSAGE_COL_STATE 7
#define LEGACY_MESSAGE_COL_URL 8
#define LEGACY_MESSAGE_COL_DATE 9
#define LEGACY_MESSAGE_COL_APP_DATA 10
#define LEGACY_MESSAGE_COL_CONTENT_ID 11
#define LEGACY_MESSAGE_COL_IMDN_MESSAGE_ID 12
#define LEGACY_MESSAGE_COL_CONTENT_TYPE 13
#define LEGACY_MESSAGE_COL_IS_SECURED 14
void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
soci::session *inSession = inDbSession.getBackendSession();
soci::transaction tr(*dbSession.getBackendSession());
......@@ -1312,27 +1311,27 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
soci::rowset<soci::row> messages = (inSession->prepare << "SELECT * FROM history");
try {
for (const auto &message : messages) {
const int direction = message.get<int>(LEGACY_MESSAGE_COL_DIRECTION);
const int direction = message.get<int>(LegacyMessageColDirection);
if (direction != 0 && direction != 1) {
lWarning() << "Unable to import legacy message with invalid direction.";
continue;
}
const int &state = message.get<int>(
LEGACY_MESSAGE_COL_STATE, static_cast<int>(ChatMessage::State::Displayed)
LegacyMessageColState, static_cast<int>(ChatMessage::State::Displayed)
);
if (state < 0 || state > static_cast<int>(ChatMessage::State::Displayed)) {
lWarning() << "Unable to import legacy message with invalid state.";
continue;
}
const tm &creationTime = Utils::getTimeTAsTm(message.get<int>(LEGACY_MESSAGE_COL_DATE, 0));
const tm &creationTime = Utils::getTimeTAsTm(message.get<int>(LegacyMessageColDate, 0));
bool isNull;
getValueFromRow<string>(message, LEGACY_MESSAGE_COL_URL, isNull);
getValueFromRow<string>(message, LegacyMessageColUrl, isNull);
const int &contentId = message.get<int>(LEGACY_MESSAGE_COL_CONTENT_ID, -1);
ContentType contentType(message.get<string>(LEGACY_MESSAGE_COL_CONTENT_TYPE, ""));
const int &contentId = message.get<int>(LegacyMessageColContentId, -1);
ContentType contentType(message.get<string>(LegacyMessageColContentType, ""));
if (!contentType.isValid())
contentType = contentId != -1
? ContentType::FileTransfer
......@@ -1342,7 +1341,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
continue;
}
const string &text = getValueFromRow<string>(message, LEGACY_MESSAGE_COL_TEXT, isNull);
const string &text = getValueFromRow<string>(message, LegacyMessageColText, isNull);
Content content;
content.setContentType(contentType);
......@@ -1358,7 +1357,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
continue;
}
const string appData = getValueFromRow<string>(message, LEGACY_MESSAGE_COL_APP_DATA, isNull);
const string appData = getValueFromRow<string>(message, LegacyMessageColAppData, isNull);
if (isNull) {
lWarning() << "Unable to import legacy file message without app data.";
continue;
......@@ -1373,14 +1372,14 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
soci::use(eventType), soci::use(creationTime);
const long long &eventId = dbSession.getLastInsertId();
const long long &localSipAddressId = insertSipAddress(message.get<string>(LEGACY_MESSAGE_COL_LOCAL_ADDRESS));
const long long &remoteSipAddressId = insertSipAddress(message.get<string>(LEGACY_MESSAGE_COL_REMOTE_ADDRESS));
const long long &localSipAddressId = insertSipAddress(message.get<string>(LegacyMessageColLocalAddress));
const long long &remoteSipAddressId = insertSipAddress(message.get<string>(LegacyMessageColRemoteAddress));
const long long &chatRoomId = insertOrUpdateImportedBasicChatRoom(
remoteSipAddressId,
localSipAddressId,
creationTime
);
const int &isSecured = message.get<int>(LEGACY_MESSAGE_COL_IS_SECURED, 0);
const int &isSecured = message.get<int>(LegacyMessageColIsSecured, 0);
*session << "INSERT INTO conference_event (event_id, chat_room_id)"
" VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId);
......
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