Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCORE-1994 Fix passing a double as argument to query on Decimal128 #7387

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Fix a performance regression when reading values from Bson containers and revert some breaking changes to the Bson API ([PR #7377](https://github.com/realm/realm-core/pull/7377), since v14.0.0)
* List KVO information was being populated for non-list collections ([PR #7378](https://github.com/realm/realm-core/pull/7378), since v14.0.0)
* Setting a Mixed property to an ObjLink equal to its existing value would remove the existing backlinks and then exit before re-adding them, resulting in later assertion failures due to the backlink state being invalid ([PR #7384](https://github.com/realm/realm-core/pull/7384), since v14.0.0).
* Passing a double as argument for a Query on Decimal128 did not work ([#7386](https://github.com/realm/realm-core/issues/7386), since v14.0.0)
* Opening file with file format 23 in read-only mode will crash ([#7388](https://github.com/realm/realm-core/issues/7388), since v14.0.0)
* Querying a dictionary over a link would sometimes result in out-of-bounds memory reads ([PR #7382](https://github.com/realm/realm-core/pull/7382), since v14.0.0).

Expand Down
7 changes: 5 additions & 2 deletions src/realm/parser/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,12 @@ std::unique_ptr<Subexpr> ConstantNode::visit(ParserDriver* drv, DataType hint)
case type_Float:
ret = std::make_unique<Value<float>>(float(double_val));
break;
case type_Decimal:
ret = std::make_unique<Value<Decimal128>>(Decimal128(text));
case type_Decimal: {
// If not argument, try decode again to get full precision
Decimal128 dec = (type == Type::ARG) ? Decimal128(double_val) : Decimal128(text);
ret = std::make_unique<Value<Decimal128>>(dec);
break;
}
case type_Int: {
int64_t int_val = int64_t(double_val);
// Only return an integer if it precisely represents val
Expand Down
5 changes: 3 additions & 2 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4675,10 +4675,11 @@ TEST(Parser_Decimal128)
verify_query(test_context, table, "dec >= -infinity", table->size() - num_nans);

// argument substitution checks
std::any args[] = {Decimal128("0"), Decimal128("123"), realm::null{}};
size_t num_args = 3;
std::any args[] = {Decimal128("0"), Decimal128("123"), realm::null{}, 123.0};
size_t num_args = 4;
verify_query_sub(test_context, table, "dec == $0", args, num_args, 1);
verify_query_sub(test_context, table, "dec == $1", args, num_args, 1);
verify_query_sub(test_context, table, "dec == $3", args, num_args, 1);
verify_query_sub(test_context, table, "dec == $2", args, num_args, 0);
verify_query_sub(test_context, table, "nullable_dec == $2", args, num_args, 1);

Expand Down
Loading