[glom/glom-1-18] Related Records: Fix bug with a blank row when there is only one row.



commit 23eec4a5a52b805911bc9ad947c99f653be69c21
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Sep 28 11:17:05 2011 +0200

    Related Records: Fix bug with a blank row when there is only one row.
    
    	* glom/libglom/connectionpool.[h|cc]: Added get_backend_supports_cursor().
    	* glom/mode_data/datawidget/treemodel_db.cc: refresh_from_database():
    	Call that method, so we can avoid using GdaDataAccessWrapper unless
    	necessary. That avoids an apparent bug with GdaDataAccessWrapper returned
    	a row of all-nulls if there is only one row. See libgda bug #660344 .
    	This is probably a performance improvement anyway.

 ChangeLog                                          |   11 +++++++++++
 glom/libglom/connectionpool.cc                     |    8 +++++++-
 glom/libglom/connectionpool.h                      |    6 ++++++
 .../utility_widgets/db_adddel/glom_db_treemodel.cc |    8 +++++---
 4 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 85f311a..d942b0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-09-28  Murray Cumming  <murrayc murrayc com>
+
+	Related Records: Fix bug with a blank row when there is only one row. 
+
+	* glom/libglom/connectionpool.[h|cc]: Added get_backend_supports_cursor().
+	* glom/mode_data/datawidget/treemodel_db.cc: refresh_from_database():
+	Call that method, so we can avoid using GdaDataAccessWrapper unless 
+	necessary. That avoids an apparent bug with GdaDataAccessWrapper returned 
+	a row of all-nulls if there is only one row. See libgda bug #660344 .
+	This is probably a performance improvement anyway.
+
 2011-09-27  Murray Cumming  <murrayc murrayc com>>
 
   libglom::LayoutItem_Portal: Added get_suitable_table_to_view_details().
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index f7f628a..926854e 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -208,7 +208,13 @@ const ConnectionPool::Backend* ConnectionPool::get_backend() const
   return m_backend.get();
 }
 
-
+bool ConnectionPool::get_backend_supports_cursor() const
+{
+  //TODO: Is there a generic libgda way to discover this?
+  const ConnectionPoolBackends::Sqlite* sqlite_backend =
+    dynamic_cast<const ConnectionPoolBackends::Sqlite*>(get_backend());
+  return !sqlite_backend;
+}
 
 //static:
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 88a7550..2ebda8e 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -128,6 +128,12 @@ public:
 
   Backend* get_backend();
   const Backend* get_backend() const;
+  
+  /** Discover whether the backend can create GdaDataModels that can be iterated,
+   * by creating them with the GDA_STATEMENT_MODEL_CURSOR_FORWARD flag.
+   * If not (with sqlite, for instance), the GdaDataAccessWrapper model can provide that API, without the performance.
+   */
+  bool get_backend_supports_cursor() const;
 
   /** This method will return a SharedConnection, either by opening a new connection or returning an already-open connection.
    * When that SharedConnection is destroyed, or when SharedConnection::close() is called, then the ConnectionPool will be informed.
diff --git a/glom/utility_widgets/db_adddel/glom_db_treemodel.cc b/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
index 30a3eff..9fdfd9d 100644
--- a/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
+++ b/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
@@ -287,7 +287,7 @@ bool DbTreeModel::refresh_from_database(const FoundSet& found_set)
     }
     else
     {
-      // Use a DataAccessWrapper to allow random access. This is necessary
+      // If using the sqlite backed, then use a DataAccessWrapper to allow random access. This is necessary
       // since we use move_to_row() on a created iterator in
       // fill_values_if_necessary(), which does not work if the iterator
       // does not support it (for example the one for Sqlite recordsets does
@@ -296,8 +296,10 @@ bool DbTreeModel::refresh_from_database(const FoundSet& found_set)
       // a) make this code dependent on the database backend used.
       // b) fetch rows we perhaps don't need, if only the first few rows of
       // a table are accessed.
-      // TODO_Performance: The unnecessary (for PostgreSQL) extra indirection might theoretically make this slower.
-      m_gda_datamodel = Gnome::Gda::DataAccessWrapper::create(m_gda_datamodel);
+      // See See libgda bug https://bugzilla.gnome.org/show_bug.cgi?id=660344
+      ConnectionPool* connection = ConnectionPool::get_instance();
+      if(connection && !connection->get_backend_supports_cursor())
+        m_gda_datamodel = Gnome::Gda::DataAccessWrapper::create(m_gda_datamodel);
 
       //This doesn't work with cursor-based models: const int count = m_gda_datamodel->get_n_rows();
       //because rows count is -1 until we have iterated to the last row.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]