glom r1857 - in trunk: . glom/libglom/data_structure glom/mode_design/fields glom/utility_widgets/db_adddel



Author: arminb
Date: Sat Jan 24 14:26:25 2009
New Revision: 1857
URL: http://svn.gnome.org/viewvc/glom?rev=1857&view=rev

Log:
2009-01-24  Armin Burgmeier  <armin openismus com>

	* glom/libglom/data_structure/fieldtypes.cc (constructor): Added
	GdaBlob as a fallback type for GdaBinary, so that
	Field::set_field_info() sets the correct glom type if the GType is
	GDA_TYPE_BLOB.

	* glom/libglom/data_structure/glomconversions.cc
	(get_pixbuf_for_gda_value): Allow the value having type
	GDA_TYPE_BLOB, and handle this appropriately. These changes fix images
	in SQLite with libgda4, requiring libgda trunk.

	* glom/utility_widgets/db_adddel/glom_db_treemodel.cc
	(refresh_from_database): Use STATEMENT_MODEL_RANDOM_ACCESS to create
	the data model when using SQLite, because of bug #567891.

	* glom/mode_design/fields/box_db_table_definition.cc (fill_field): Use
	the field's glom type directly, instead of guessing it from the
	field's GType.


Modified:
   trunk/ChangeLog
   trunk/glom/libglom/data_structure/field.cc
   trunk/glom/libglom/data_structure/fieldtypes.cc
   trunk/glom/libglom/data_structure/glomconversions.cc
   trunk/glom/mode_design/fields/box_db_table_definition.cc
   trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc

Modified: trunk/glom/libglom/data_structure/field.cc
==============================================================================
--- trunk/glom/libglom/data_structure/field.cc	(original)
+++ trunk/glom/libglom/data_structure/field.cc	Sat Jan 24 14:26:25 2009
@@ -718,6 +718,9 @@
 
 GType Field::get_gda_g_type() const
 {
+  // TODO: Can't we just do this here? armin.
+  // return get_field_info()->get_g_type();
+
   switch(m_glom_type)
   {
     case TYPE_NUMERIC:

Modified: trunk/glom/libglom/data_structure/fieldtypes.cc
==============================================================================
--- trunk/glom/libglom/data_structure/fieldtypes.cc	(original)
+++ trunk/glom/libglom/data_structure/fieldtypes.cc	Sat Jan 24 14:26:25 2009
@@ -86,9 +86,9 @@
             Glib::ustring type_string = value_gdatype.get_string();
             const GType gdatype = gda_g_type_from_string(type_string.c_str());
 
-            //Save it for later:
             //std::cout << "debug: schema_type_string=" << schema_type_string << ", gda type=" << gdatype << "(" << g_type_name(gdatype) << ")" << std::endl;
-            
+
+            //Save it for later:
             m_mapSchemaStringsToGdaTypes[schema_type_string] = gdatype;
 
             Glib::ustring gdatypestring = gda_g_type_to_string(gdatype); // TODO: What is this actually used for?
@@ -104,6 +104,7 @@
     }
   }
 
+  m_mapFallbackTypes[GDA_TYPE_BINARY] = GDA_TYPE_BLOB;
   m_mapFallbackTypes[GDA_TYPE_NUMERIC] = G_TYPE_DOUBLE;
   m_mapFallbackTypes[GDA_TYPE_TIME] = G_TYPE_STRING;
   m_mapFallbackTypes[G_TYPE_DATE] = G_TYPE_STRING;

Modified: trunk/glom/libglom/data_structure/glomconversions.cc
==============================================================================
--- trunk/glom/libglom/data_structure/glomconversions.cc	(original)
+++ trunk/glom/libglom/data_structure/glomconversions.cc	Sat Jan 24 14:26:25 2009
@@ -21,6 +21,8 @@
 
 #include "config.h" // For HAVE_STRPTIME
 
+#include <libgda/gda-blob-op.h> // For gda_blob_op_read_all()
+
 #include "glomconversions.h"
 #include <glom/libglom/connectionpool.h>
 #include <glom/libglom/utils.h>
@@ -1214,10 +1216,29 @@
 {
   Glib::RefPtr<Gdk::Pixbuf> result;
 
-  if(value.get_value_type() == GDA_TYPE_BINARY)
+  if(value.get_value_type() == GDA_TYPE_BINARY || value.get_value_type() == GDA_TYPE_BLOB)
   {
-    glong buffer_binary_length = 0;
-    gconstpointer buffer_binary = value.get_binary(buffer_binary_length);
+    glong buffer_binary_length;
+    gconstpointer buffer_binary;
+    if(value.get_value_type() == GDA_TYPE_BLOB)
+    {
+      const GdaBlob* blob = value.get_blob();
+      if(gda_blob_op_read_all(blob->op, const_cast<GdaBlob*>(blob)))
+      {
+        buffer_binary_length = blob->data.binary_length;
+        buffer_binary = blob->data.data;
+      }
+      else
+      {
+        buffer_binary_length = 0;
+        buffer_binary = NULL;
+        g_warning("Conversions::get_pixbuf_for_gda_value(): Failed to read BLOB data");
+      }
+    }
+    else
+    {
+      buffer_binary = value.get_binary(buffer_binary_length);
+    }
 
     /* Note that this is regular binary data, not escaped text representing the binary data: */
     if(buffer_binary && buffer_binary_length)

Modified: trunk/glom/mode_design/fields/box_db_table_definition.cc
==============================================================================
--- trunk/glom/mode_design/fields/box_db_table_definition.cc	(original)
+++ trunk/glom/mode_design/fields/box_db_table_definition.cc	Sat Jan 24 14:26:25 2009
@@ -103,7 +103,11 @@
   m_AddDel.set_value(iter, m_colTitle, title);
 
   //Type:
-  Field::glom_field_type fieldType = Field::get_glom_type_for_gda_type(field->get_field_info()->get_g_type()); //Could be TYPE_INVALID if the gda type is not one of ours.
+  //Field::glom_field_type fieldType = Field::get_glom_type_for_gda_type(field->get_field_info()->get_g_type()); //Could be TYPE_INVALID if the gda type is not one of ours.
+  // TODO: Why was this done by converting the field's gtype to a glom type
+  // instead of using the glom type directly? This breaks numerical types in
+  // sqlite which we store as double.
+  Field::glom_field_type fieldType = field->get_glom_type();
 
   const Glib::ustring strType = Field::get_type_name_ui( fieldType );
   m_AddDel.set_value(iter, m_colType, strType);

Modified: trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
==============================================================================
--- trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc	(original)
+++ trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc	Sat Jan 24 14:26:25 2009
@@ -22,6 +22,7 @@
 #include "glom_db_treemodel.h"
 
 #include <glom/libglom/connectionpool.h>
+#include <glom/libglom/connectionpool_backends/sqlite.h> //For checking whether we are using SQLite or not
 #include <glom/libglom/data_structure/glomconversions.h> //For util_build_sql
 #include <glom/libglom/utils.h>
 
@@ -479,8 +480,18 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
     try
     {
-      //Specify the STATEMENT_MODEL_CURSOR, so that libgda only gets the rows that we actually use.   
-      m_gda_datamodel = m_connection->get_gda_connection()->statement_execute_select(stmt, Gnome::Gda::STATEMENT_MODEL_CURSOR);
+      //Specify the STATEMENT_MODEL_CURSOR, so that libgda only gets the rows that we actually use.
+      // TODO: CURSOR mode does not properly work with SQLite, because when 
+      // requesting a second iterator from the data model, it points to the
+      // same row as the previous iterator (not to the first row), and there
+      // is no way to do backwards iteration. I don't think there is API in
+      // libgda to find this out, se we are currently hardcoding this for the
+      // SQLite case. See also
+      // http://bugzilla.gnome.org/show_bug.cgi?id=567891.
+      Gnome::Gda::StatementModelUsage usage = Gnome::Gda::STATEMENT_MODEL_CURSOR_FORWARD;
+      if(dynamic_cast<ConnectionPoolBackends::Sqlite*>(connection_pool->get_backend()))
+        usage = Gnome::Gda::STATEMENT_MODEL_RANDOM_ACCESS;
+      m_gda_datamodel = m_connection->get_gda_connection()->statement_execute_select(stmt, usage);
 
       if(app && app->get_show_sql_debug())
         std::cout << "  Debug: DbTreeModel::refresh_from_database(): The query execution has finished." << std::endl;



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