glom r1569 - in trunk: . glom/mode_data



Author: murrayc
Date: Tue Apr 15 19:04:10 2008
New Revision: 1569
URL: http://svn.gnome.org/viewvc/glom?rev=1569&view=rev

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

* glom/mode_data/box_data.cc
* glom/mode_data/box_data.h: add_related_record_for_field():
Added a primary_key_value_used output parameter so that the caller nows 
what record was actually created.
* glom/mode_data/box_data_details.cc: on_flowtable_field_edited():
* glom/mode_data/box_data_list.cc: on_adddel_user_changed(): 
Use the new output parameter instead of calling get_entered_field_data(), 
so that automatically-created related records are really linked from the 
parent record even when the ID is not on the layout.
This fixes bug #526386 (Jani Monoses).

Modified:
   trunk/ChangeLog
   trunk/glom/mode_data/box_data.cc
   trunk/glom/mode_data/box_data.h
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/mode_data/box_data_list.cc

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 19:04:10 2008
@@ -691,7 +691,11 @@
   return result;
 }
 
-bool Box_Data::add_related_record_for_field(const sharedptr<const LayoutItem_Field>& layout_item_parent, const sharedptr<const Relationship>& relationship, const sharedptr<const Field>& primary_key_field, const Gnome::Gda::Value& primary_key_value_provided)
+bool Box_Data::add_related_record_for_field(const sharedptr<const LayoutItem_Field>& layout_item_parent, 
+  const sharedptr<const Relationship>& relationship, 
+  const sharedptr<const Field>& primary_key_field, 
+  const Gnome::Gda::Value& primary_key_value_provided,
+  Gnome::Gda::Value& primary_key_value_used)
 {
   Gnome::Gda::Value primary_key_value = primary_key_value_provided;
 
@@ -699,8 +703,12 @@
   if(related_record_exists)
   {
     //No problem, the SQL command below will update this value in the related table.
+    primary_key_value_used = primary_key_value; //Let the caller know what related record was created.
+    return true;
   }
-  else
+    
+
+  //TODO: Remove this useless {} scope. It is only still here to avoid whitespace changes in a patch diff.
   {
     //To store the entered data in the related field, we would first have to create a related record.
     if(!relationship->get_auto_create())
@@ -761,8 +769,11 @@
         }
 
         const Glib::ustring strQuery = "INSERT INTO \"" + relationship->get_to_table() + "\" (\"" + primary_key_field->get_name() + "\") VALUES (" + primary_key_field->sql(primary_key_value) + ")";
-        bool test = query_execute(strQuery, get_app_window());
-        if(test)
+        const bool test = query_execute(strQuery, get_app_window());
+        if(!test)
+          return false;
+
+        //TODO: Remove this useless {} scope. It is only still here to avoid whitespace changes in a patch diff.
         {
           if(key_is_auto_increment)
           {
@@ -775,7 +786,13 @@
 
             //Set it in the database too:
             sharedptr<Field> field_from_key = get_fields_for_table_one_field(relationship->get_from_table(), relationship->get_from_field()); //TODO_Performance.
-            if(field_from_key)
+            if(!field_from_key)
+            {
+              std::cerr << "Box_Data::add_related_record_for_field(): get_fields_for_table_one_field() failed." << std::endl;
+              return false;
+            }
+
+            //TODO: Remove this useless {} scope. It is only still here to avoid whitespace changes in a patch diff.
             {
               sharedptr<Field> parent_primary_key_field = get_field_primary_key();
               if(!parent_primary_key_field)
@@ -796,18 +813,20 @@
                   const Glib::ustring strQuery = "UPDATE \"" + relationship->get_from_table() + "\" SET \"" + relationship->get_from_field() + "\" = " + primary_key_field->sql(primary_key_value) +
                     " WHERE \"" + relationship->get_from_table() + "\".\"" + parent_primary_key_field->get_name() + "\" = " + parent_primary_key_field->sql(parent_primary_key_value);
                   const bool test = query_execute(strQuery, get_app_window());
-                  return test;
+                  if(!test)
+                    return false;
                 }
               }
             }
           }
+
+           primary_key_value_used = primary_key_value; //Let the caller know what related record was created.
+           return true;
         }
       }
     }
 
   }
-
-  return true;
 }
 
 void Box_Data::print_layout()

Modified: trunk/glom/mode_data/box_data.h
==============================================================================
--- trunk/glom/mode_data/box_data.h	(original)
+++ trunk/glom/mode_data/box_data.h	Tue Apr 15 19:04:10 2008
@@ -95,7 +95,7 @@
   virtual type_vecLayoutFields get_fields_to_show() const;
 
   virtual bool get_related_record_exists(const sharedptr<const Relationship>& relationship, const sharedptr<const Field>& key_field, const Gnome::Gda::Value& key_value);
-  virtual bool add_related_record_for_field(const sharedptr<const LayoutItem_Field>& layout_item_parent, const sharedptr<const Relationship>& relationship, const sharedptr<const Field>& primary_key_field, const Gnome::Gda::Value& primary_key_value_provided);
+  virtual bool add_related_record_for_field(const sharedptr<const LayoutItem_Field>& layout_item_parent, const sharedptr<const Relationship>& relationship, const sharedptr<const Field>& primary_key_field, const Gnome::Gda::Value& primary_key_value_provided, Gnome::Gda::Value& primary_key_value_used);
 
   type_vecLayoutFields get_table_fields_to_show(const Glib::ustring& table_name) const;
 

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 19:04:10 2008
@@ -704,12 +704,13 @@
           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);
+          Gnome::Gda::Value primary_key_value_used;
+          const bool test = add_related_record_for_field(layout_field, relationship, primary_key_field, primary_key_value, primary_key_value_used);
           if(!test)
             return;
 
           //Get the new primary_key_value if it has been created:
-          primary_key_value = get_entered_field_data(layout_item);
+          primary_key_value = primary_key_value_used;
 
           //Now that the related record exists, the following code to set the value of the other field in the related field can succeed.
         }

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 19:04:10 2008
@@ -444,12 +444,13 @@
             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);
+            Gnome::Gda::Value primary_key_value_used;
+            const bool test = add_related_record_for_field(layout_field, relationship, primary_key_field, primary_key_value, primary_key_value_used);
             if(!test)
               return;
 
             //Get the new primary_key_value if it has been created:
-            primary_key_value = get_entered_field_data(layout_item);
+            primary_key_value = primary_key_value_used;
 
             //Now that the related record exists, the following code to set the value of the other field in the related field can succeed.
           }



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