[glom/glom-1-18] Deleting tables: Remove all auto-increment rows.



commit 1d5cac98cbfa56ac41c0cd193be065fa67571959
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Oct 13 20:11:29 2011 +0200

    Deleting tables: Remove all auto-increment rows.
    
    * glom/navigation/box_tables.cc: Remove the autoincrement rows for all
    autoincrement fields.
    
    Conflicts:
    
    	glom/navigation/box_tables.cc

 ChangeLog                     |    7 +++++++
 glom/navigation/box_tables.cc |   36 +++++++++++++++++++++---------------
 2 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 898509c..b4d59c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-10-13  Murray Cumming  <murrayc murrayc com>
 
+	Deleting tables: Remove all auto-increment rows.
+
+	* glom/navigation/box_tables.cc: Remove the autoincrement rows for all 
+	autoincrement fields.
+
+2011-10-13  Murray Cumming  <murrayc murrayc com>
+
 	Deleting tables: Remove the auto-increment too.
 
 	* glom/libglom/db_utils.[h|cc]: Added remove_auto_increment().
diff --git a/glom/navigation/box_tables.cc b/glom/navigation/box_tables.cc
index e53eb9c..8fc77ac 100644
--- a/glom/navigation/box_tables.cc
+++ b/glom/navigation/box_tables.cc
@@ -312,11 +312,9 @@ void Box_Tables::on_adddel_Delete(const Gtk::TreeModel::iterator& rowStart, cons
           dialog.set_transient_for(*Application::get_application());
           const int iButtonClicked = dialog.run();
           
-          Glib::ustring primary_key_field_name; 
-          const sharedptr<const Field> primary_key_field = get_field_primary_key_for_table(table_name);
-          if(primary_key_field)
-            primary_key_field_name = primary_key_field->get_name();
-
+          //Get a list of autoincrementing fields in the table:
+          const Glom::Document::type_vec_fields fields = document->get_table_fields(table_name);
+ 
           //Delete the table:
           if(iButtonClicked == Gtk::RESPONSE_OK)
           {
@@ -325,21 +323,29 @@ void Box_Tables::on_adddel_Delete(const Gtk::TreeModel::iterator& rowStart, cons
               std::cerr << "Box_Tables::on_adddel_Delete(): DROP TABLE failed." << std::endl;
             else
             {
-              //Remove the auto-increment row.
-              //Otherwise it would not start at 0 if a table with the same name is added again later.
-              //TODO: Remove rows for other auto-increment fields too:
-              if(!primary_key_field_name.empty())
-                DbUtils::remove_auto_increment(table_name, primary_key_field_name);
-              else
-              {
-                std::cerr << G_STRFUNC << ": primary_key_field_name is empty" << std::endl;
-              }
-              
               //Forget about it in the document too.
               get_document()->remove_table(table_name);
               
               something_changed = true;
             }
+            
+            //Remove the auto-increment rows.
+            //Otherwise it would not start at 0 if a table with the same name, and same field, is added again later.
+            for(Glom::Document::type_vec_fields::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
+            {
+              const Glom::sharedptr<const Glom::Field> field = *iter;
+              if(!field || !field->get_auto_increment())
+                continue;
+                
+              const Glib::ustring field_name = field->get_name();
+            
+              if(!field_name.empty())
+                DbUtils::remove_auto_increment(table_name, field_name);
+              else
+              {
+                std::cerr << G_STRFUNC << ": field_name is empty" << std::endl;
+              }
+            }
           }
         }
       }



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