[glom] TreeModelDb: fill_values_if_necessary(): Avoid a crash.



commit c36403a4167ff2b4b52a7f04e69900d603492c7f
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Oct 6 13:34:27 2011 +0200

    TreeModelDb: fill_values_if_necessary(): Avoid a crash.
    
    * glom/mode_data/datawidget/treemodel_db.cc: Do not try to use a null
    GdaDataModel, which can happen if a SQL query fails.

 ChangeLog                                 |    7 +++++++
 glom/mode_data/datawidget/treemodel_db.cc |   18 +++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 94900de..b9c006d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-10-06  Murray Cumming  <murrayc murrayc com>
 
+	TreeModelDb: fill_values_if_necessary(): Avoid a crash.
+
+	* glom/mode_data/datawidget/treemodel_db.cc: Do not try to use a null
+	GdaDataModel, which can happen if a SQL query fails.
+
+2011-10-06  Murray Cumming  <murrayc murrayc com>
+
 	Document: get_data_layout_groups_default(): Simplify the default structure.
 
 	* glom/libglom/document/document.cc: Do not create the useless "main" 
diff --git a/glom/mode_data/datawidget/treemodel_db.cc b/glom/mode_data/datawidget/treemodel_db.cc
index 62e8777..424ea3c 100644
--- a/glom/mode_data/datawidget/treemodel_db.cc
+++ b/glom/mode_data/datawidget/treemodel_db.cc
@@ -106,16 +106,24 @@ void DbTreeModelRow::fill_values_if_necessary(DbTreeModel& model, int row)
 
       //Create default values, if necessary, of the correct types:
       //Examine the columns in the returned DataModel:
+      const Glib::RefPtr<const Gnome::Gda::DataModel> datamodel = model.m_gda_datamodel;
       for(guint col = 0; col < model.m_data_model_columns_count; ++col)
       {
         if(m_db_values.find(col) == m_db_values.end()) //If there is not already a value in the map for this column.
         {
-          Glib::RefPtr<Gnome::Gda::Column> column = model.m_gda_datamodel->describe_column(col);
+          if(!datamodel) //though this should not happen.
+          {
+            m_db_values[col] = Gnome::Gda::Value();
+          }
+          else
+          {
+            const Glib::RefPtr<const Gnome::Gda::Column> column = datamodel->describe_column(col);
 
-          //We don't just create a Gda::Value of the column's gda type,
-          //because we should use a NULL-type Gda::Value as the initial value for some fields:
-          const Field::glom_field_type glom_type = Field::get_glom_type_for_gda_type(column->get_g_type());
-          m_db_values[col] = Glom::Conversions::get_empty_value(glom_type);
+            //We don't just create a Gda::Value of the column's gda type,
+            //because we should use a NULL-type Gda::Value as the initial value for some fields:
+            const Field::glom_field_type glom_type = Field::get_glom_type_for_gda_type(column->get_g_type());
+            m_db_values[col] = Glom::Conversions::get_empty_value(glom_type);
+          }
         }
       }
     }



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