From 34961c2a4fc18a7936fedb1c38e76dd9809980e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Fri, 2 Oct 2020 14:59:05 +0200 Subject: [PATCH] Correctly update case insensitive queries on indexed string columns --- CHANGELOG.md | 2 +- src/realm/query_engine.cpp | 1 + test/test_query.cpp | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ff61a8d5c..92b0ba28751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) -* None. +* If you make a case insignificant query on an indexed string column, it may fail in a way that results in a "No such key" exception. ([#6830](https://github.com/realm/realm-cocoa/issues/6830), since v6.0.0) ### Breaking changes * None. diff --git a/src/realm/query_engine.cpp b/src/realm/query_engine.cpp index 4193d9e5904..df36ac17580 100644 --- a/src/realm/query_engine.cpp +++ b/src/realm/query_engine.cpp @@ -367,6 +367,7 @@ std::string StringNode::describe(util::serializer::SerialisationState& st void StringNode::_search_index_init() { auto index = ParentNode::m_table->get_search_index(ParentNode::m_condition_column_key); + m_index_matches.clear(); index->find_all(m_index_matches, StringData(StringNodeBase::m_value), true); m_results_start = 0; m_results_ndx = 0; diff --git a/test/test_query.cpp b/test/test_query.cpp index be95a63c8db..63ae82e4040 100644 --- a/test/test_query.cpp +++ b/test/test_query.cpp @@ -2556,7 +2556,9 @@ TEST(Query_StrIndexUpdating) auto col = t->add_column(type_String, "value"); t->add_search_index(col); TableView tv = t->where().equal(col, "").find_all(); + TableView tv_ins = t->where().equal(col, "", false).find_all(); CHECK_EQUAL(tv.size(), 0); + CHECK_EQUAL(tv_ins.size(), 0); group->commit_and_continue_as_read(); // Queries on indexes have different codepaths for 0, 1, and multiple results, @@ -2570,7 +2572,9 @@ TEST(Query_StrIndexUpdating) t->create_object(); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 1); + CHECK_EQUAL(tv_ins.size(), 1); // 1 -> multiple results group->promote_to_write(); @@ -2578,7 +2582,9 @@ TEST(Query_StrIndexUpdating) t->create_object(); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 3); + CHECK_EQUAL(tv_ins.size(), 3); // multiple -> 1 group->promote_to_write(); @@ -2586,14 +2592,18 @@ TEST(Query_StrIndexUpdating) t->remove_object(tv.get_key(1)); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 1); + CHECK_EQUAL(tv_ins.size(), 1); // 1 -> 0 group->promote_to_write(); t->remove_object(tv.get_key(0)); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 0); + CHECK_EQUAL(tv_ins.size(), 0); // 0 -> multiple group->promote_to_write(); @@ -2601,7 +2611,9 @@ TEST(Query_StrIndexUpdating) t->create_object(); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 2); + CHECK_EQUAL(tv_ins.size(), 2); // multiple -> 0 group->promote_to_write(); @@ -2609,7 +2621,9 @@ TEST(Query_StrIndexUpdating) t->remove_object(tv.get_key(1)); group->commit_and_continue_as_read(); tv.sync_if_needed(); + tv_ins.sync_if_needed(); CHECK_EQUAL(tv.size(), 0); + CHECK_EQUAL(tv_ins.size(), 0); } TEST(Query_GA_Crash)