From f03ad848cbf8f6b580bac5bc9af312ee3259fd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 14 Jan 2021 15:32:20 +0100 Subject: [PATCH] Add support for `true` and `false` literals to be used with bool fields The lexer itself should be responsible for parsing those values but it will require a bigger refactoring. --- YACReaderLibrary/db/query_parser.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/YACReaderLibrary/db/query_parser.cpp b/YACReaderLibrary/db/query_parser.cpp index 2620a81b..5a45160b 100644 --- a/YACReaderLibrary/db/query_parser.cpp +++ b/YACReaderLibrary/db/query_parser.cpp @@ -55,8 +55,17 @@ int QueryParser::TreeNode::bindValues(QSqlQuery &selectQuery, int bindPosition) { if (t == "token") { std::string bind_string(":bindPosition" + std::to_string(++bindPosition)); - if (isIn(fieldType(children[0].t), { FieldType::numeric, FieldType::boolean, FieldType::booleanFolder })) { + if (isIn(fieldType(children[0].t), { FieldType::numeric })) { selectQuery.bindValue(QString::fromStdString(bind_string), std::stoi(children[1].t)); + } else if (isIn(fieldType(children[0].t), { FieldType::boolean, FieldType::booleanFolder })) { + auto value = toLower(children[1].t); + if (value == "true") { + selectQuery.bindValue(QString::fromStdString(bind_string), 1); + } else if (value == "false") { + selectQuery.bindValue(QString::fromStdString(bind_string), 0); + } else { + selectQuery.bindValue(QString::fromStdString(bind_string), std::stoi(value)); + } } else { selectQuery.bindValue(QString::fromStdString(bind_string), QString::fromStdString("%%" + children[1].t + "%%")); }