1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[LocationCompleterModel] Simplify createQuery function

It is no longer needed to search for bookmarks in database
This commit is contained in:
nowrep 2014-02-09 17:35:43 +01:00
parent b3c4d5d8da
commit 9a5a795449

View File

@ -186,22 +186,17 @@ QString LocationCompleterModel::completeDomain(const QString &text)
QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const QString &orderBy, QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const QString &orderBy,
const QList<QUrl> &alreadyFound, int limit, bool exactMatch) const QList<QUrl> &alreadyFound, int limit, bool exactMatch)
{ {
// TODO: As bookmarks are no longer in database, replace table with "history"
QString table = "history";
QString query = QString("SELECT %1.id, %1.url, %1.title, history.count").arg(table);
QStringList searchList; QStringList searchList;
QString query = QLatin1String("SELECT id, url, title, count FROM history WHERE ");
query.append(QLatin1String(" FROM history "));
query.append(QLatin1String("WHERE "));
if (exactMatch) { if (exactMatch) {
query.append(QString("%1.title LIKE ? OR %1.url LIKE ? ").arg(table)); query.append(QLatin1String("title LIKE ? OR url LIKE ? "));
} }
else { else {
searchList = searchString.split(QLatin1Char(' '), QString::SkipEmptyParts); searchList = searchString.split(QLatin1Char(' '), QString::SkipEmptyParts);
const int slSize = searchList.size(); const int slSize = searchList.size();
for (int i = 0; i < slSize; ++i) { for (int i = 0; i < slSize; ++i) {
query.append(QString("(%1.title LIKE ? OR %1.url LIKE ?) ").arg(table)); query.append(QLatin1String("(title LIKE ? OR url LIKE ?) "));
if (i < slSize - 1) { if (i < slSize - 1) {
query.append(QLatin1String("AND ")); query.append(QLatin1String("AND "));
} }
@ -209,13 +204,13 @@ QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const
} }
for (int i = 0; i < alreadyFound.count(); i++) { for (int i = 0; i < alreadyFound.count(); i++) {
query.append(QString("AND (NOT %1.url=?) ").arg(table)); query.append(QLatin1String("AND (NOT url=?) "));
} }
query.append(QString("GROUP BY %1.url ").arg(table)); query.append(QLatin1String("GROUP BY url "));
if (!orderBy.isEmpty()) { if (!orderBy.isEmpty()) {
query.append("ORDER BY " + orderBy); query.append(QLatin1String("ORDER BY ") + orderBy);
} }
query.append(QLatin1String(" LIMIT ?")); query.append(QLatin1String(" LIMIT ?"));