glom r1531 - in branches/glom-1-6: . glom/mode_design/fields



Author: murrayc
Date: Mon Apr  7 17:32:04 2008
New Revision: 1531
URL: http://svn.gnome.org/viewvc/glom?rev=1531&view=rev

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

* glom/mode_design/fields/box_db_table_definition.cc
  check_field_change(): Refuse to change a field name to one that 
already exists.


Modified:
   branches/glom-1-6/ChangeLog
   branches/glom-1-6/glom/mode_design/fields/box_db_table_definition.cc

Modified: branches/glom-1-6/glom/mode_design/fields/box_db_table_definition.cc
==============================================================================
--- branches/glom-1-6/glom/mode_design/fields/box_db_table_definition.cc	(original)
+++ branches/glom-1-6/glom/mode_design/fields/box_db_table_definition.cc	Mon Apr  7 17:32:04 2008
@@ -251,30 +251,44 @@
 
     dialog.run();
 
-    result = false;
+    return false;
   }
-  else
+
+  //Refuse to set a second primary key:
+  //bool bcontinue = true;
+  if(field_new->get_primary_key() && !field_old->get_primary_key()) //Was the primary key column checked?
   {
-    //Refuse to set a second primary key:
-    //bool bcontinue = true;
-    if(field_new->get_primary_key() && !field_old->get_primary_key()) //Was the primary key column checked?
-    {
-      //Is there an existing primary key?
-      sharedptr<Field> existing_primary_key = get_field_primary_key_for_table(m_table_name);
-      if(existing_primary_key)
-      {
-        //Warn the user and refuse to make the change:
-        Gtk::MessageDialog dialog(Bakery::App_Gtk::util_bold_message(_("Too many primary keys")), true);
-        dialog.set_secondary_text(_("You may not specify more than one field as the primary key."));
-        if(parent_window)
-          dialog.set_transient_for(*parent_window);
-        dialog.run();
+    //Is there an existing primary key?
+    sharedptr<Field> existing_primary_key = get_field_primary_key_for_table(m_table_name);
+    if(existing_primary_key)
+    {
+      //Warn the user and refuse to make the change:
+      Gtk::MessageDialog dialog(Bakery::App_Gtk::util_bold_message(_("Too many primary keys")), true);
+      dialog.set_secondary_text(_("You may not specify more than one field as the primary key."));
+      if(parent_window)
+        dialog.set_transient_for(*parent_window);
+      dialog.run();
 
-        result = false;
-      }
+      return false;
     }
   }
 
+  //Refuse to change a field name to the same as an existing one:
+  if( (field_new->get_name() != field_old->get_name()) &&
+      (get_field_exists_in_database(m_table_name, field_new->get_name())) )
+  {
+    std::cout << "get_field_exists_in_database(" << m_table_name << ", " << field_new->get_name() << ") returned true" << std::endl;
+
+    //Warn the user and refuse to make the change:
+    Gtk::MessageDialog dialog(Bakery::App_Gtk::util_bold_message(_("Field Name Already Exists")), true);
+    dialog.set_secondary_text(_("This field already exists. Please choose a different field name"));
+    if(parent_window)
+      dialog.set_transient_for(*parent_window);
+    dialog.run();
+
+    return false;
+  }
+
   return result;
 }
 



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