mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Add new fields to the DB and make then available to be used in the apps
This commit is contained in:
@ -5,14 +5,17 @@
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
const std::map<QueryParser::FieldType, std::vector<std::string>> QueryParser::fieldNames {
|
||||
{ FieldType::numeric, { "numpages", "number", "count", "arcnumber", "arccount" } },
|
||||
{ FieldType::text, { "title", "volume", "storyarc", "genere", "writer", "penciller", "inker", "colorist", "letterer", "coverartist", "publisher", "format", "agerating", "synopsis", "characters", "notes" } },
|
||||
{ FieldType::boolean, { "isbis", "color", "read", "manga" } },
|
||||
{ FieldType::date, { "date" } },
|
||||
{ FieldType::numeric, { "numpages", "count", "arccount", "alternateCount" } },
|
||||
{ FieldType::text, { "number", "arcnumber", "title", "volume", "storyarc", "genere", "writer", "penciller", "inker", "colorist", "letterer", "coverartist", "publisher", "format", "agerating", "synopsis", "characters", "notes", "editor", "imprint", "teams", "locations", "series", "alternateSeries", "alternateNumber", "languageISO", "seriesGroup", "mainCharacterOrTeam", "review", "tags" } },
|
||||
{ FieldType::boolean, { "isbis", "color", "read" } },
|
||||
{ FieldType::date, { "date", "added", "lastTimeOpened" } },
|
||||
{ FieldType::filename, { "filename" } },
|
||||
{ FieldType::folder, { "folder" } },
|
||||
{ FieldType::booleanFolder, { "completed", "finished" } },
|
||||
{ FieldType::booleanFolder, { "completed", "finished" } }, // TODO_METADTA include new folder fields, e.g. type
|
||||
{ FieldType::enumField, { "type" } }
|
||||
};
|
||||
|
||||
int QueryParser::TreeNode::buildSqlString(std::string &sqlString, int bindPosition) const
|
||||
@ -26,7 +29,7 @@ int QueryParser::TreeNode::buildSqlString(std::string &sqlString, int bindPositi
|
||||
}
|
||||
sqlString += "UPPER(c.filename) LIKE UPPER(:bindPosition" + std::to_string(bindPosition) + ") OR ";
|
||||
sqlString += "UPPER(f.name) LIKE UPPER(:bindPosition" + std::to_string(bindPosition) + ")) ";
|
||||
} else if (isIn(fieldType(children[0].t), { FieldType::numeric, FieldType::boolean })) {
|
||||
} else if (isIn(fieldType(children[0].t), { FieldType::numeric, FieldType::boolean, FieldType::enumField })) {
|
||||
sqlString += "ci." + children[0].t + " = :bindPosition" + std::to_string(bindPosition) + " ";
|
||||
} else if (fieldType(children[0].t) == FieldType::filename) {
|
||||
sqlString += "(UPPER(c." + children[0].t + ") LIKE UPPER(:bindPosition" + std::to_string(bindPosition) + ")) ";
|
||||
@ -67,6 +70,24 @@ int QueryParser::TreeNode::bindValues(QSqlQuery &selectQuery, int bindPosition)
|
||||
} else {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), std::stoi(value));
|
||||
}
|
||||
} else if ((isIn(fieldType(children[0].t), { FieldType::enumField }))) {
|
||||
auto enumType = children[0].t;
|
||||
auto value = toLower(children[1].t);
|
||||
if (enumType == "type") {
|
||||
if (value == "comic") {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), 0);
|
||||
} else if (value == "manga") {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), 1);
|
||||
} else if (value == "westernmanga") {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), 2);
|
||||
} else if (value == "webcomic" || value == "web") {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), 3);
|
||||
} else if (value == "4koma" || value == "yonkoma") {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), 4);
|
||||
}
|
||||
} else {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), std::stoi(children[1].t));
|
||||
}
|
||||
} else {
|
||||
selectQuery.bindValue(QString::fromStdString(bind_string), QString::fromStdString("%%" + children[1].t + "%%"));
|
||||
}
|
||||
@ -232,6 +253,7 @@ QueryParser::TreeNode QueryParser::baseToken()
|
||||
return TreeNode("token", { TreeNode("all", {}), TreeNode(token(true), {}) });
|
||||
}
|
||||
|
||||
// TODO ":" should come from the lexer as a token
|
||||
auto words(split(token(true), ':'));
|
||||
|
||||
if (words.size() > 1 && fieldType(words[0].toStdString()) != FieldType::unknown) {
|
||||
|
Reference in New Issue
Block a user