From f32de945ad8e15d4ba5127991d11f82ee98c5234 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Wed, 9 Dec 2015 14:06:25 -0800 Subject: [PATCH 1/2] Update to Realm Core 0.95.5 --- impl/transact_log_handler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/impl/transact_log_handler.cpp b/impl/transact_log_handler.cpp index 2deba2fd..ac74b515 100644 --- a/impl/transact_log_handler.cpp +++ b/impl/transact_log_handler.cpp @@ -293,10 +293,12 @@ public: // Things that just mark the field as modified bool set_int(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); } + bool set_int_unique(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); } bool set_bool(size_t col, size_t row, bool) { return mark_dirty(row, col); } bool set_float(size_t col, size_t row, float) { return mark_dirty(row, col); } bool set_double(size_t col, size_t row, double) { return mark_dirty(row, col); } bool set_string(size_t col, size_t row, StringData) { return mark_dirty(row, col); } + bool set_string_unique(size_t col, size_t row, StringData) { return mark_dirty(row, col); } bool set_binary(size_t col, size_t row, BinaryData) { return mark_dirty(row, col); } bool set_date_time(size_t col, size_t row, DateTime) { return mark_dirty(row, col); } bool set_table(size_t col, size_t row) { return mark_dirty(row, col); } From 0286dea7a4dbebb8739554a4ceeb510653a1e85e Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Fri, 20 Nov 2015 14:05:18 -0800 Subject: [PATCH 2/2] Add methods to create snapshot of List and Results The Results class was updated to match the style of List and include a flag (m_live) that determines if it should sync updates. If an object in the static Results is deleted, then it will return null. --- list.cpp | 5 +++++ list.hpp | 2 ++ results.cpp | 17 +++++++++++++++-- results.hpp | 4 ++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/list.cpp b/list.cpp index 1cbafb8d..80d07bc4 100644 --- a/list.cpp +++ b/list.cpp @@ -59,6 +59,11 @@ void List::remove(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(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 fdde4c62..85ec6221 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(size_t row_ndx, bool insertion = false); void verify_attached(); void verify_in_tranaction(); diff --git a/results.cpp b/results.cpp index b2a63789..45578796 100644 --- a/results.cpp +++ b/results.cpp @@ -64,6 +64,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(); @@ -91,7 +102,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; } @@ -147,7 +158,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 115ca636..7d8563ff 100644 --- a/results.hpp +++ b/results.hpp @@ -60,6 +60,9 @@ public: // Get the object type which will be returned by get() StringData get_object_type() const noexcept { return 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(); @@ -153,6 +156,7 @@ private: TableView m_table_view; Table* m_table = nullptr; SortOrder m_sort; + bool m_live = true; Mode m_mode = Mode::Empty;