Skip to content

Commit b4e1075

Browse files
committed
Fix query for non-existing key in nested dictionary
1 parent eef7fcf commit b4e1075

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/realm/collection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void Collection::get_any(QueryCtrlBlock& ctrl, Mixed val, size_t index)
168168
ctrl.matches.back().push_back(k);
169169
});
170170
}
171-
else {
171+
else if (end_of_path) {
172172
ctrl.matches.back().push_back(Mixed());
173173
}
174174
return;

src/realm/query_expression.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,18 +2065,18 @@ class Columns<Mixed> : public SimpleQuerySupport<Mixed> {
20652065
}
20662066
else {
20672067
if (index.initialize()) {
2068-
Value<Mixed> destination;
2069-
destination.init(false, 1);
2070-
SimpleQuerySupport::evaluate(index, destination);
2068+
Value<Mixed> dest;
2069+
dest.init(false, 1);
2070+
SimpleQuerySupport::evaluate(index, dest);
20712071

20722072
m_ctrl.matches.clear();
2073-
if (auto sz = destination.size()) {
2073+
if (auto sz = dest.size()) {
20742074
for (size_t i = 0; i < sz; i++) {
2075-
Collection::get_any(m_ctrl, destination.get(i), 0);
2075+
Collection::get_any(m_ctrl, dest.get(i), 0);
20762076
}
20772077
}
20782078
if (!index.set_size(m_ctrl.matches.size())) {
2079-
destination.init(true, 0);
2079+
dest.init(true, 0);
20802080
return;
20812081
}
20822082
}

test/test_parser.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5353,6 +5353,12 @@ TEST(Parser_NestedMixedDictionaryList)
53535353
list_george.add(2);
53545354
list_george.add(3);
53555355

5356+
Obj ringo = persons->create_object_with_primary_key("Ringo");
5357+
ringo.set(col_self, ringo.get_key());
5358+
ringo.set_collection(col, CollectionType::Dictionary);
5359+
auto dict_ringo = ringo.get_dictionary(col);
5360+
dict_ringo.insert("Foo", "Bar");
5361+
53565362
auto q = persons->column<Mixed>(col).path({"instruments", 0, "strings"}) == 6;
53575363
CHECK_EQUAL(q.count(), 1);
53585364

@@ -5369,15 +5375,16 @@ TEST(Parser_NestedMixedDictionaryList)
53695375
verify_query(test_context, persons, "properties[*] == {3, 2, 1}", 0);
53705376
verify_query(test_context, persons, "properties[*] == {1, 2, 3}", 1);
53715377
verify_query(test_context, persons, "ANY properties[*] == 2", 1);
5372-
verify_query(test_context, persons, "NONE properties[*] == 2", 2);
5378+
verify_query(test_context, persons, "NONE properties[*] == 2", 3);
53735379
verify_query(test_context, persons, "properties.@keys == 'instruments'", 2);
53745380
verify_query(test_context, persons, "properties.@keys == 'pets'", 2);
53755381
verify_query(test_context, persons, "properties.@keys == 'tickets'", 1);
53765382
verify_query(test_context, persons, "properties.@size == 3", 2);
53775383
verify_query(test_context, persons, "properties.instruments.@size == 2", 1);
5378-
verify_query(test_context, persons, "properties.@type == 'object'", 2);
5384+
verify_query(test_context, persons, "properties.@type == 'object'", 3);
53795385
verify_query(test_context, persons, "properties.@type == 'array'", 1);
5380-
verify_query(test_context, persons, "properties.@type == 'collection'", 3);
5386+
verify_query(test_context, persons, "properties.@type == 'collection'", 4);
5387+
verify_query(test_context, persons, "properties.Foo == 'Bar'", 1);
53815388
}
53825389

53835390
TEST(Parser_NestedDictionaryDeep)

0 commit comments

Comments
 (0)