diff --git a/list.cpp b/list.cpp index a1229153..bddcd106 100644 --- a/list.cpp +++ b/list.cpp @@ -60,6 +60,11 @@ void List::remove(std::size_t row_ndx) { m_link_view->remove(row_ndx); } +Query List::get_query() { + verify_attached(); + return m_link_view->get_target_table().where(m_link_view); +} + void List::verify_valid_row(std::size_t row_ndx, bool insertion) { size_t size = m_link_view->size(); if (row_ndx > size || (!insertion && row_ndx == size)) { diff --git a/list.hpp b/list.hpp index 0440f003..cf43ece1 100644 --- a/list.hpp +++ b/list.hpp @@ -47,6 +47,8 @@ namespace realm { template void set(ContextType ctx, ValueType value, size_t list_ndx); + Query get_query(); + void verify_valid_row(std::size_t row_ndx, bool insertion = false); void verify_attached(); void verify_in_tranaction(); diff --git a/results.cpp b/results.cpp index 0839f1f5..c5334652 100644 --- a/results.cpp +++ b/results.cpp @@ -67,6 +67,17 @@ void Results::validate_write() const throw InvalidTransactionException("Must be in a write transaction"); } +void Results::set_live(bool live) +{ + if (!live && m_mode == Mode::Table) { + m_query = m_table->where(); + m_mode = Mode::Query; + } + + update_tableview(); + m_live = live; +} + size_t Results::size() { validate_read(); @@ -94,7 +105,7 @@ RowExpr Results::get(size_t row_ndx) case Mode::TableView: update_tableview(); if (row_ndx < m_table_view.size()) - return m_table_view.get(row_ndx); + return (!m_live && !m_table_view.is_row_attached(row_ndx)) ? RowExpr() : m_table_view.get(row_ndx); break; } @@ -148,7 +159,9 @@ void Results::update_tableview() m_mode = Mode::TableView; break; case Mode::TableView: - m_table_view.sync_if_needed(); + if (m_live) { + m_table_view.sync_if_needed(); + } break; } } diff --git a/results.hpp b/results.hpp index 6b017df1..acb797a0 100644 --- a/results.hpp +++ b/results.hpp @@ -74,6 +74,9 @@ public: // Get the object type which will be returned by get() StringData get_object_type() const noexcept { return get_object_schema().name; } + // Set whether the TableView should sync if needed before accessing results + void set_live(bool live); + // Get the size of this results // Can be either O(1) or O(N) depending on the state of things size_t size(); @@ -168,6 +171,7 @@ private: TableView m_table_view; Table* m_table = nullptr; SortOrder m_sort; + bool m_live = true; Mode m_mode = Mode::Empty;