glom r1801 - in trunk: . glom glom/libglom/data_structure glom/mode_data glom/mode_design/fields glom/utility_widgets/db_adddel



Author: murrayc
Date: Fri Dec 12 23:05:23 2008
New Revision: 1801
URL: http://svn.gnome.org/viewvc/glom?rev=1801&view=rev

Log:
2008-12-12  Murray Cumming  <murrayc murrayc com>

* glom/libglom/data_structure/field.[h|cc]: Store the primary_key and
unique_key details as bools in the C++ class, because we cannot
easily get that from libgda-4.0, so we at least remember that
information from the document. If we can get it from the database
somehow then we can do that later.
* glom/mode_design/fields/dialog_fielddefinition.cc: get_field():
Store the primary_key and unique_key details in the C++ class.
We previously stored them info Gda::Column but that code was commented
out during the port to libgda-4.0.

There is also a crash workaround in Gda::Holder in libgdamm, but there
is still another unsolved crash.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/libglom/data_structure/field.cc
   trunk/glom/libglom/data_structure/field.h
   trunk/glom/mode_data/box_data_list.cc
   trunk/glom/mode_design/fields/box_db_table_definition.cc
   trunk/glom/mode_design/fields/dialog_fielddefinition.cc
   trunk/glom/utility_widgets/db_adddel/glom_db_treemodel.cc

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Fri Dec 12 23:05:23 2008
@@ -277,6 +277,7 @@
   return (iterFind != tables.end());
 }
 
+//TODO_Performance: Avoid calling this so often.
 Base_DB::type_vecStrings Base_DB::get_table_names_from_database(bool ignore_system_tables) const
 {
   type_vecStrings result;
@@ -537,6 +538,7 @@
           ;//TODO_gda:field_info->set_unique_key( value_unique.get_boolean() );
         //TODO_gda:else if(field_info->get_primary_key()) //All primaries keys are unique, so force this.
           //TODO_gda:field_info->set_unique_key();
+
         //Get whether it is autoincrements
         /* libgda does not provide this yet.
         Gnome::Gda::Value value_autoincrement = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_AUTOINCREMENT, row);
@@ -1682,12 +1684,17 @@
   {
     //TODO_Performance: Cache this result?
     Document_Glom::type_vecFields fields = document->get_table_fields(table_name);
+    //std::cout << "Base_DB::get_field_primary_key_for_table(): table=" << table_name << ", fields count=" << fields.size() << std::endl;
     for(Document_Glom::type_vecFields::iterator iter = fields.begin(); iter != fields.end(); ++iter)
     {
-      if((*iter)->get_primary_key())
-      {
+      sharedptr<Field> field = *iter;
+      if(!field)
+        continue;
+
+      //std::cout << "  field=" << field->get_name() << std::endl;
+    
+      if(field->get_primary_key())
         return *iter;
-      }
     }
   }
 

Modified: trunk/glom/libglom/data_structure/field.cc
==============================================================================
--- trunk/glom/libglom/data_structure/field.cc	(original)
+++ trunk/glom/libglom/data_structure/field.cc	Fri Dec 12 23:05:23 2008
@@ -39,7 +39,9 @@
 Field::Field()
 : m_glom_type(TYPE_INVALID),
   m_field_info(Gnome::Gda::Column::create()),
-  m_visible(true)
+  m_visible(true),
+  m_primary_key(false),
+  m_unique_key(false)
 {
   m_translatable_item_type = TRANSLATABLE_TYPE_FIELD;
 }
@@ -70,6 +72,9 @@
 
   m_visible = src.m_visible;
 
+  m_primary_key = src.m_primary_key;
+  m_unique_key = src.m_unique_key;
+
   m_default_formatting = src.m_default_formatting;
 
   return *this;
@@ -85,6 +90,8 @@
          && (m_strLookupField == src.m_strLookupField)
          && (m_calculation == src.m_calculation)
          && (m_visible == src.m_visible)
+         && (m_primary_key == src.m_primary_key)
+         && (m_unique_key == src.m_unique_key)
          && (m_default_formatting == src.m_default_formatting);
 }
 
@@ -646,23 +653,25 @@
 bool Field::get_primary_key() const
 {
   //TODO_gda: return m_field_info->get_primary_key();
-  return false;
+  return m_primary_key;
 }
 
 void Field::set_primary_key(bool val)
 {
+  m_primary_key = val;
   //TODO_gda: m_field_info->set_primary_key(val);
 }
 
 bool Field::get_unique_key() const
 {
   //TODO_gda: return m_field_info->get_unique_key();
-  return false;
+  return m_unique_key;
 }
 
 void Field::set_unique_key(bool val)
 {
   //TODO_gda: m_field_info->set_unique_key(val);
+  m_unique_key = val;
 }
 
 Gnome::Gda::Value Field::get_default_value() const

Modified: trunk/glom/libglom/data_structure/field.h
==============================================================================
--- trunk/glom/libglom/data_structure/field.h	(original)
+++ trunk/glom/libglom/data_structure/field.h	Fri Dec 12 23:05:23 2008
@@ -248,6 +248,10 @@
   Glib::ustring m_strLookupField;
   Glib::ustring m_calculation;
   bool m_visible; //Whether it will be shown to the user.
+
+  //Things that libgda cannot easily tell us:
+  bool m_primary_key;
+  bool m_unique_key;
 };
 
 } //namespace Glom

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	Fri Dec 12 23:05:23 2008
@@ -465,10 +465,12 @@
     sharedptr<Field> field_primary_key = get_field_primary_key_for_table(m_table_name);
     if(!field_primary_key)
     {
-      //g_warning("%s: primary key not found.", __FUNCTION__);
+      std::cerr << "Box_Data_List::create_layout(): primary key not found." << std::endl;
     }
     else
     {
+      std::cout << "DEBUG: Box_Data_List::create_layout(): primary_key=" << field_primary_key->get_name() << std::endl;
+
       m_AddDel.set_key_field(field_primary_key);
  
       //This map of layout groups will also contain the field information from the database:

Modified: trunk/glom/mode_design/fields/box_db_table_definition.cc
==============================================================================
--- trunk/glom/mode_design/fields/box_db_table_definition.cc	(original)
+++ trunk/glom/mode_design/fields/box_db_table_definition.cc	Fri Dec 12 23:05:23 2008
@@ -415,11 +415,11 @@
     GType fieldType = Field::get_gda_type_for_glom_type(glom_type);
 
     //Unique:
-    const bool bUnique = m_AddDel.get_value_as_bool(row, m_colUnique);
+    //const bool bUnique = m_AddDel.get_value_as_bool(row, m_colUnique);
     //TODO_gda: fieldInfo->set_unique_key(bUnique);
 
     //Primary Key:
-    const bool bPrimaryKey = m_AddDel.get_value_as_bool(row, m_colPrimaryKey);
+    //const bool bPrimaryKey = m_AddDel.get_value_as_bool(row, m_colPrimaryKey);
     ///TODO_gda: fieldInfo->set_primary_key(bPrimaryKey);
 
     fieldInfo->set_g_type(fieldType);

Modified: trunk/glom/mode_design/fields/dialog_fielddefinition.cc
==============================================================================
--- trunk/glom/mode_design/fields/dialog_fielddefinition.cc	(original)
+++ trunk/glom/mode_design/fields/dialog_fielddefinition.cc	Fri Dec 12 23:05:23 2008
@@ -231,8 +231,6 @@
 
   fieldInfo->set_g_type( Field::get_gda_type_for_glom_type( m_pCombo_Type->get_field_type() ) );
 
-  //TODO_gda: fieldInfo->set_unique_key(m_pCheck_Unique->get_active());
-  //TODO_gda: fieldInfo->set_primary_key(m_pCheck_PrimaryKey->get_active());
   fieldInfo->set_auto_increment(m_pCheck_AutoIncrement->get_active());
 
   if(!fieldInfo->get_auto_increment()) //Ignore default_values for auto_increment fields - it's just some obscure postgres code.
@@ -264,6 +262,9 @@
 
   //Glom-specific details:
 
+  field->set_unique_key(m_pCheck_Unique->get_active());
+  field->set_primary_key(m_pCheck_PrimaryKey->get_active());
+
   field->set_title(m_pEntry_Title->get_text());
 
   //Formatting:

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	Fri Dec 12 23:05:23 2008
@@ -271,12 +271,19 @@
         for(int i = 0; i < cols_count; ++i)
         {
           Glib::RefPtr<Gnome::Gda::Holder> holder = iter->get_holder_for_field(i);
-          m_db_values[i] = holder->get_value();
+          if(holder)
+            m_db_values[i] = holder->get_value(); //TODO_gda: Why not just use get_value_at()?
+          else
+            std::cerr << "DbTreeModelRow::fill_values_if_necessary(): NULL Gnome::Gda::Holder for field=." << i << std::endl;
+
           //std::cout << "  debug: col=" << i << ", GType=" << m_db_values[i].get_value_type() << std::endl;
         }
 
         Glib::RefPtr<Gnome::Gda::Holder> holder = iter->get_holder_for_field(model.m_column_index_key);
-        m_key = holder->get_value();
+        if(holder)
+          m_key = holder->get_value();  //TODO_gda: Why not just use get_value_at()?
+        else
+          std::cerr << "DbTreeModelRow::fill_values_if_necessary(): NULL Gnome::Gda::Holder for key field" << std::endl;
 
         m_extra = false;
         m_removed = false;



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