From 47ff44b9235a71908076b3284ae12070e73cccd9 Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Tue, 13 Sep 2022 15:20:58 +0100 Subject: [PATCH 1/5] do not discard existing query for lists --- src/realm/object-store/c_api/query.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/realm/object-store/c_api/query.cpp b/src/realm/object-store/c_api/query.cpp index f6545d86573..d779098e94e 100644 --- a/src/realm/object-store/c_api/query.cpp +++ b/src/realm/object-store/c_api/query.cpp @@ -244,11 +244,15 @@ RLM_API realm_query_t* realm_query_parse_for_list(const realm_list_t* list, cons const realm_query_arg_t* args) { return wrap_err([&]() { + auto existing_query = list->get_query(); auto realm = list->get_realm(); auto table = list->get_table(); auto query = parse_and_apply_query(realm, table, query_string, num_args, args); - auto ordering = query.get_ordering(); - return new realm_query_t{std::move(query), std::move(ordering), realm}; + auto combined = existing_query.and_query(query); + auto ordering_copy = util::make_bind(); + if (auto ordering = query.get_ordering()) + ordering_copy->append(*ordering); + return new realm_query_t{std::move(query), std::move(ordering_copy), realm}; }); } From 588d5bed0db988f5edc4f268b6f4789e81093529 Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Tue, 13 Sep 2022 17:59:25 +0100 Subject: [PATCH 2/5] expose get_object_parent towards c api --- src/realm.h | 6 ++++++ src/realm/object-store/c_api/object.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/realm.h b/src/realm.h index b3eb6876c07..696e0012642 100644 --- a/src/realm.h +++ b/src/realm.h @@ -1408,6 +1408,12 @@ RLM_API bool realm_get_num_versions(const realm_t*, uint64_t* out_versions_count */ RLM_API realm_object_t* realm_get_object(const realm_t*, realm_class_key_t class_key, realm_object_key_t obj_key); +/** + * Get the parent object for the object passed as argument. + * @return A non-NULL pointer if the parent object exists. + */ +RLM_API bool realm_object_get_parent(const realm_object_t* object, realm_object_t* parent); + /** * Find an object with a particular primary key value. * diff --git a/src/realm/object-store/c_api/object.cpp b/src/realm/object-store/c_api/object.cpp index 560a4077d78..3fc2387b75b 100644 --- a/src/realm/object-store/c_api/object.cpp +++ b/src/realm/object-store/c_api/object.cpp @@ -28,6 +28,16 @@ RLM_API realm_object_t* realm_get_object(const realm_t* realm, realm_class_key_t }); } +RLM_API bool realm_object_get_parent(const realm_object_t* object, realm_object_t* parent) +{ + return wrap_err([&]() { + if (parent) + *parent = realm_object_t{realm::Object{object->get_realm(), object->obj().get_parent_object()}}; + return true; + }); +} + + RLM_API realm_object_t* realm_object_find_with_primary_key(const realm_t* realm, realm_class_key_t class_key, realm_value_t pk, bool* out_found) { From cabfa9cc21bdd4c840cbd682fa602bc7d63b6004 Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Tue, 13 Sep 2022 18:01:49 +0100 Subject: [PATCH 3/5] entry changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8544127573..9f3b0b271c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Enhancements * (PR [#????](https://github.com/realm/realm-core/pull/????)) * Convert object_store::Collection types into Results (PR [#5845](https://github.com/realm/realm-core/pull/5845)) +* Expose `realm_object_get_parent` in the C API (PR [#5851](https://github.com/realm/realm-core/pull/5851)) ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) From 7e8d9cea6da5135e9a55ce70ac48e9c17f203c0e Mon Sep 17 00:00:00 2001 From: nicola cabiddu Date: Wed, 14 Sep 2022 09:57:34 +0100 Subject: [PATCH 4/5] Update src/realm.h Co-authored-by: Yavor Georgiev --- src/realm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/realm.h b/src/realm.h index 696e0012642..2bff945cdfd 100644 --- a/src/realm.h +++ b/src/realm.h @@ -1409,8 +1409,8 @@ RLM_API bool realm_get_num_versions(const realm_t*, uint64_t* out_versions_count RLM_API realm_object_t* realm_get_object(const realm_t*, realm_class_key_t class_key, realm_object_key_t obj_key); /** - * Get the parent object for the object passed as argument. - * @return A non-NULL pointer if the parent object exists. + * Get the parent object for the object passed as argument. Only works for embedded objects. + * @return true, if no errors occurred. */ RLM_API bool realm_object_get_parent(const realm_object_t* object, realm_object_t* parent); From 930a9d469d4f5354191d4bd0de3913f7477a4b01 Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Wed, 14 Sep 2022 10:36:19 +0100 Subject: [PATCH 5/5] Revert "do not discard existing query for lists" This reverts commit 47ff44b9235a71908076b3284ae12070e73cccd9. --- src/realm/object-store/c_api/query.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/realm/object-store/c_api/query.cpp b/src/realm/object-store/c_api/query.cpp index d779098e94e..f6545d86573 100644 --- a/src/realm/object-store/c_api/query.cpp +++ b/src/realm/object-store/c_api/query.cpp @@ -244,15 +244,11 @@ RLM_API realm_query_t* realm_query_parse_for_list(const realm_list_t* list, cons const realm_query_arg_t* args) { return wrap_err([&]() { - auto existing_query = list->get_query(); auto realm = list->get_realm(); auto table = list->get_table(); auto query = parse_and_apply_query(realm, table, query_string, num_args, args); - auto combined = existing_query.and_query(query); - auto ordering_copy = util::make_bind(); - if (auto ordering = query.get_ordering()) - ordering_copy->append(*ordering); - return new realm_query_t{std::move(query), std::move(ordering_copy), realm}; + auto ordering = query.get_ordering(); + return new realm_query_t{std::move(query), std::move(ordering), realm}; }); }