8000 expose `Results::is_valid` in the C API by nicola-cab · Pull Request #6407 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

expose Results::is_valid in the C API #6407

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

Merged
merged 2 commits into from
Mar 22, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Expose `Results::is_valid()` in the C API, in order to prevent to use an invalid Results. (PR [#6407](https://github.com/realm/realm-core/pull/6407))

### Fixed
* `SyncSession::pause()` could hold a reference to the database open after shutting down the sync session, preventing users from being able to delete the realm. ([#6372](https://github.com/realm/realm-core/issues/6372), since v13.3.0)
Expand Down
6 changes: 6 additions & 0 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,12 @@ RLM_API realm_results_t* realm_get_backlinks(realm_object_t* object, realm_class
*/
RLM_API bool realm_query_delete_all(const realm_query_t*);

/**
* Set the boolean passed as argument to true or false whether the realm_results passed is valid or not
* @return true/false if no exception has occured.
*/
RLM_API bool realm_results_is_valid(const realm_results_t*, bool*);

/**
* Count the number of results.
*
Expand Down
9 changes: 9 additions & 0 deletions src/realm/object-store/c_api/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ RLM_API realm_results_t* realm_get_backlinks(realm_object_t* object, realm_class
});
}

RLM_API bool realm_results_is_valid(const realm_results_t* results, bool* is_valid)
{
return wrap_err([&]() {
if (is_valid)
*is_valid = results->is_valid();
return true;
});
}

RLM_API bool realm_results_count(realm_results_t* results, size_t* out_count)
{
return wrap_err([&]() {
Expand Down
6 changes: 6 additions & 0 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,12 @@ TEST_CASE("C API", "[c_api]") {
auto r = cptr_checked(realm_query_find_all(q.get()));
CHECK(!realm_is_frozen(r.get()));

SECTION("realm_results_is_valid") {
bool valid;
CHECK(checked(realm_results_is_valid(r.get(), &valid)));
CHECK(valid);
}

SECTION("realm_results_count()") {
size_t count;
CHECK(checked(realm_results_count(r.get(), &count)));
Expand Down
0