Skip to content

Commit

Permalink
Added workaround for a bug in Qt5.10.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzard4591 committed Dec 13, 2017
1 parent 54ab1ec commit 5efe597
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/database/DatabaseMessageCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,44 @@ namespace openmittsu {
sortOrderSign = QStringLiteral("<");
}

#if defined(QT_VERSION) && (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
// Check in two steps to mitigate a cool bug in the query engine.
QSqlQuery query(m_database.database);
query.prepare(QStringLiteral("SELECT `apiid`, `uid`, `sort_by` FROM `%1` WHERE (%2) AND (((`sort_by` = :sortByValue) AND (`uid` %3 :uid))) ORDER BY `sort_by` %4, `uid` %4 LIMIT 1;").arg(getTableName()).arg(getWhereString()).arg(sortOrderSign).arg(sortOrder));
bindWhereStringValues(query);
query.bindValue(QStringLiteral(":sortByValue"), QVariant(m_sortByValue));
query.bindValue(QStringLiteral(":uid"), QVariant(m_uid));

if (!query.exec() || !query.isSelect()) {
throw openmittsu::exceptions::InternalErrorException() << "Could not execute message iteration query for table " << getTableName().toStdString() << ". Query error: " << query.lastError().text().toStdString();
}

if (query.next()) {
m_isMessageIdValid = true;
m_messageId = openmittsu::protocol::MessageId(query.value(QStringLiteral("apiid")).toString());
m_uid = query.value(QStringLiteral("uid")).toString();
m_sortByValue = query.value(QStringLiteral("sort_by")).toLongLong();
return true;
} else {
query.prepare(QStringLiteral("SELECT `apiid`, `uid`, `sort_by` FROM `%1` WHERE (%2) AND ((`sort_by` %3 :sortByValue)) ORDER BY `sort_by` %4, `uid` %4 LIMIT 1;").arg(getTableName()).arg(getWhereString()).arg(sortOrderSign).arg(sortOrder));
bindWhereStringValues(query);
query.bindValue(QStringLiteral(":sortByValue"), QVariant(m_sortByValue));

if (!query.exec() || !query.isSelect()) {
throw openmittsu::exceptions::InternalErrorException() << "Could not execute message iteration query for table " << getTableName().toStdString() << ". Query error: " << query.lastError().text().toStdString();
}

if (query.next()) {
m_isMessageIdValid = true;
m_messageId = openmittsu::protocol::MessageId(query.value(QStringLiteral("apiid")).toString());
m_uid = query.value(QStringLiteral("uid")).toString();
m_sortByValue = query.value(QStringLiteral("sort_by")).toLongLong();
return true;
} else {
return false;
}
}
#else
QSqlQuery query(m_database.database);
query.prepare(QStringLiteral("SELECT `apiid`, `uid`, `sort_by` FROM `%1` WHERE %2 AND ((`sort_by` %3 :sortByValue) OR ((`sort_by` = :sortByValue) AND (`uid` %3 :uid))) ORDER BY `sort_by` %4, `uid` %4 LIMIT 1;").arg(getTableName()).arg(getWhereString()).arg(sortOrderSign).arg(sortOrder));
bindWhereStringValues(query);
Expand All @@ -109,6 +147,7 @@ namespace openmittsu {
} else {
return false;
}
#endif
}

bool DatabaseMessageCursor::getFirstOrLastMessageId(bool first) {
Expand Down

1 comment on commit 5efe597

@tiket18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile, an update arrived Qt 5.10.1 and again everything broke

Please sign in to comment.