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



commit 1259a7f27e257b96a91df3185bbc4bf913372e81
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 ++++++
 glom/mode_data/datawidget/treemodel_db.cc |    8 +++++---
 4 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d328894..7c09482 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>
 
 	Require the latest gtkmm.
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index b4f4b41..e83ea48 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -203,7 +203,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:
 sharedptr<SharedConnection> ConnectionPool::get_and_connect()
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 84338a4..5678ec6 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -132,6 +132,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/mode_data/datawidget/treemodel_db.cc b/glom/mode_data/datawidget/treemodel_db.cc
index b37ba08..62e8777 100644
--- a/glom/mode_data/datawidget/treemodel_db.cc
+++ b/glom/mode_data/datawidget/treemodel_db.cc
@@ -337,7 +337,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
@@ -346,8 +346,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]