glom r1567 - in trunk: . glom/libglom/data_structure glom/mode_data glom/utility_widgets/db_adddel



Author: murrayc
Date: Tue Apr 15 18:24:11 2008
New Revision: 1567
URL: http://svn.gnome.org/viewvc/glom?rev=1567&view=rev

Log:
2008-04-15  Murray Cumming  <murrayc murrayc com>

* glom/mode_data/box_data.cc:
get_related_record_exists(): Don't bother looking for a record 
with the key NULL, because that is not something we want to related 
records by.
* glom/mode_data/box_data_list.cc: on_adddel_user_changed(): Get 
full field details for the related field, to ensure that this works 
properly.
* glom/utility_widgets/db_adddel/glom_db_treemodel.cc
fill_values_if_necessary(): Use Conversions::get_empty_value() instead 
of just creating a Gda::Value of the expected type, so we get a NULL 
GdaValue initially for appropriate field types.

This fixes the automatic creation of related records, at least when 
the from field is on the layout, partially fixing bug #526386
(Jani Monoses).

Modified:
   trunk/ChangeLog
   trunk/glom/libglom/data_structure/glomconversions.cc
   trunk/glom/mode_data/box_data.cc
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/mode_data/box_data_list.cc
   trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc

Modified: trunk/glom/libglom/data_structure/glomconversions.cc
==============================================================================
--- trunk/glom/libglom/data_structure/glomconversions.cc	(original)
+++ trunk/glom/libglom/data_structure/glomconversions.cc	Tue Apr 15 18:24:11 2008
@@ -691,7 +691,7 @@
     case(G_TYPE_STRING):
       return value.get_string().empty();
     default:
-      return false; //None of the other types can be empty. (An empty numeric, date, or time type shows up as a null.
+      return false; //None of the other types can be empty. (An empty numeric, date, or time type shows up as a NULL).
   }
 }
 

Modified: trunk/glom/mode_data/box_data.cc
==============================================================================
--- trunk/glom/mode_data/box_data.cc	(original)
+++ trunk/glom/mode_data/box_data.cc	Tue Apr 15 18:24:11 2008
@@ -280,8 +280,7 @@
           }
           */
 
-          Glib::ustring strFieldValue = field->sql(value);
-
+          const Glib::ustring strFieldValue = field->sql(value);
           if(!strFieldValue.empty())
           {
             if(!strNames.empty())
@@ -668,6 +667,10 @@
 
   bool result = false;
 
+  //Don't try doing a NULL=NULL or ""="" relationship:
+  if(Glom::Conversions::value_is_empty(key_value))
+    return false;
+
   //TODO_Performance: It's very possible that this is slow.
   //We don't care how many records there are, only whether there are more than zero.
   const Glib::ustring to_field = relationship->get_to_field();

Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc	(original)
+++ trunk/glom/mode_data/box_data_details.cc	Tue Apr 15 18:24:11 2008
@@ -703,6 +703,7 @@
 
           primary_key_value = get_entered_field_data(layout_item);
 
+          //Note: This just uses an existing record if one already exists:
           const bool test = add_related_record_for_field(layout_field, relationship, primary_key_field, primary_key_value);
           if(!test)
             return;

Modified: trunk/glom/mode_data/box_data_list.cc
==============================================================================
--- trunk/glom/mode_data/box_data_list.cc	(original)
+++ trunk/glom/mode_data/box_data_list.cc	Tue Apr 15 18:24:11 2008
@@ -439,10 +439,11 @@
           {
             //Get the value of the corresponding key in the current table (that identifies the record in the table that we will change)
             sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
-            layout_item->set_name(relationship->get_from_field());
+            layout_item->set_full_field_details( document->get_field(relationship->get_from_table(), relationship->get_from_field()) );
 
             primary_key_value = get_entered_field_data(layout_item);
 
+            //Note: This just uses an existing record if one already exists:
             const bool test = add_related_record_for_field(layout_field, relationship, primary_key_field, primary_key_value);
             if(!test)
               return;

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	Tue Apr 15 18:24:11 2008
@@ -304,9 +304,11 @@
         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);
-          Gnome::Gda::Value value;
-          value.init(column->get_g_type());
-          m_db_values[col] = value;
+
+          //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]