mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Use the query parser in the comic and folder model
This commit is contained in:
committed by
Luis Ángel San Martín
parent
5fa7da1e46
commit
673ee1f067
@ -9,6 +9,7 @@
|
||||
#include "qnaturalsorting.h"
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
#include "query_parser.h"
|
||||
|
||||
//ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read
|
||||
#include "QsLog.h"
|
||||
@ -607,40 +608,40 @@ void ComicModel::setupModelData(const SearchModifiers modifier, const QString &f
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
QSqlQuery selectQuery(db);
|
||||
|
||||
switch (modifier) {
|
||||
case YACReader::NoModifiers:
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"WHERE UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter) LIMIT :limit");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":limit", 500); //TODO, load this value from settings
|
||||
break;
|
||||
std::string queryString("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) LEFT JOIN folder f ON (f.id == c.parentId) WHERE ");
|
||||
|
||||
case YACReader::OnlyRead:
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"WHERE (UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter)) AND ci.read = 1 LIMIT :limit");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":limit", 500); //TODO, load this value from settings
|
||||
break;
|
||||
try {
|
||||
QueryParser parser;
|
||||
auto result = parser.parse(filter.toStdString());
|
||||
result.buildSqlString(queryString);
|
||||
|
||||
case YACReader::OnlyUnread:
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"WHERE (UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter)) AND ci.read = 0 LIMIT :limit");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":limit", 500); //TODO, load this value from settings
|
||||
break;
|
||||
switch (modifier) {
|
||||
case YACReader::NoModifiers:
|
||||
queryString += "LIMIT :limit";
|
||||
break;
|
||||
|
||||
default:
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
case YACReader::OnlyRead:
|
||||
queryString += "AND ci.read = 1 LIMIT :limit";
|
||||
break;
|
||||
|
||||
case YACReader::OnlyUnread:
|
||||
queryString += "AND ci.read = 0 LIMIT :limit";
|
||||
break;
|
||||
|
||||
default:
|
||||
queryString += "LIMIT :limit";
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
}
|
||||
selectQuery.prepare(QString(queryString.c_str()));
|
||||
selectQuery.bindValue(":limit", 500); //TODO, load this value from settings
|
||||
result.bindValues(selectQuery);
|
||||
} catch (const std::exception &e) {
|
||||
QLOG_ERROR() << "Unable to parse query: " << e.what();
|
||||
}
|
||||
|
||||
selectQuery.exec();
|
||||
|
||||
QLOG_DEBUG() << selectQuery.lastError() << "--";
|
||||
|
||||
setupModelData(selectQuery);
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
|
Reference in New Issue
Block a user