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.
This commit is contained in:
Luis Ángel San Martín 2021-01-14 15:32:20 +01:00
parent f803b54f2e
commit f03ad848cb

View File

@ -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 + "%%"));
}