glom r1835 - in trunk: . glom glom/mode_design/fields



Author: murrayc
Date: Mon Jan  5 14:15:33 2009
New Revision: 1835
URL: http://svn.gnome.org/viewvc/glom?rev=1835&view=rev

Log:
2009-01-05  Murray Cumming  <murrayc murrayc com>

* glom/base_db.[h|cc]: Added update_gda_metastore_for_table().
* glom/mode_design/fields/box_db_table_definition.cc
  on_adddel_add(), on_adddel_delete(), postgres_change_column(): 
Call it, but it does not seem to work.
New fields are immedietaly reported as not found (on the command line) 
and field type changes are reverted when reopening the dialog.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/base_db.h
   trunk/glom/base_db_table.h
   trunk/glom/mode_design/fields/box_db_table_definition.cc

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Mon Jan  5 14:15:33 2009
@@ -1174,25 +1174,6 @@
     {
       document->add_table(table_info);
       document->set_table_fields(table_info->get_name(), fields);
-
-      // Update meta store, so that get_fields_for_table_from_database
-      // returns the fields correctly for the new table.
-      sharedconnection->get_gda_connection()->update_meta_store();
-
-      // Don't do full update_meta_store() here because that's too slow.
-      // TODO: Maybe we should create the table directly via libgda instead of
-      // executing an SQL query ourselves, so that libgda has the chance to
-      // do this meta store update automatically.
-      // TODO: This doesn't work:
-#if 0
-      GdaMetaContext context;
-      context.table_name = const_cast<char*>(table_name.c_str());
-      context.size = 0;
-      context.column_names = NULL;
-      context.column_values = NULL;
-
-      gda_connection_update_meta_store(sharedconnection->get_gda_connection()->gobj(), &context, NULL);
-#endif
     }
   }
 
@@ -1260,6 +1241,18 @@
     table_creation_succeeded = false;
   }
 
+  if(table_creation_succeeded)
+  {
+    // Update the libgda meta store, so that get_fields_for_table_from_database()
+    // returns the fields correctly for the new table.
+    update_gda_metastore_for_table(table_info->get_name());
+
+    // TODO: Maybe we should create the table directly via libgda instead of
+    // executing an SQL query ourselves, so that libgda has the chance to
+    // do this meta store update automatically.
+    // (Yes, generally it would be nice to use libgda API instead of generating SQL. murrayc)
+  }
+
   return table_creation_succeeded;
 }
 
@@ -2982,5 +2975,31 @@
     found_set.m_where_clause = "\"" + where_clause_to_table_name + "\".\"" + relationship->get_to_field() + "\" = " + where_clause_to_key_field->sql(foreign_key_value);
 }
 
+void Base_DB::update_gda_metastore_for_table(const Glib::ustring& table_name) const
+{
+  sharedptr<SharedConnection> sharedconnection = connect_to_server(App_Glom::get_application());
+  if(!sharedconnection)
+  {
+    std::cerr << "Base_DB_Table::update_gda_metastore_for_table(): No connection." << std::endl;
+    return;
+  }
+
+  Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
+  if(!gda_connection)
+  {
+    std::cerr << "Base_DB_Table::update_gda_metastore_for_table(): No gda_connection." << std::endl;
+    return;
+  }
+
+  if(table_name.empty())
+  {
+    std::cerr << "Base_DB_Table::update_gda_metastore_for_table(): table_name is empty." << std::endl;
+    return;
+  }
+
+  std::cout << "DEBUG: Base_DB_Table::update_gda_metastore_for_table(): Calling Gda::Connection::update_meta_store_table() ..." << std::endl;
+  gda_connection->update_meta_store_table(table_name);
+  std::cout << "DEBUG: Base_DB_Table::update_gda_metastore_for_table(): ... Finished calling Gda::Connection::update_meta_store_table()" << std::endl;
+}
 
 } //namespace Glom

Modified: trunk/glom/base_db.h
==============================================================================
--- trunk/glom/base_db.h	(original)
+++ trunk/glom/base_db.h	Mon Jan  5 14:15:33 2009
@@ -348,6 +348,13 @@
    */
   void set_found_set_where_clause_for_portal(FoundSet& found_set, const sharedptr<LayoutItem_Portal>& portal, const Gnome::Gda::Value& foreign_key_value);
 
+  /** Update GDA's information about the table structure, such as the 
+   * field list and their types.
+   * Call this whenever changing the table structure, for instance with an ALTER query.
+   * This may take a few seconds to return.
+   */
+  void update_gda_metastore_for_table(const Glib::ustring& table_name) const;
+
 
   static bool get_field_primary_key_index_for_fields(const type_vecFields& fields, guint& field_column);
   static bool get_field_primary_key_index_for_fields(const type_vecLayoutFields& fields, guint& field_column);

Modified: trunk/glom/base_db_table.h
==============================================================================
--- trunk/glom/base_db_table.h	(original)
+++ trunk/glom/base_db_table.h	Mon Jan  5 14:15:33 2009
@@ -42,8 +42,7 @@
 
   Glib::ustring get_table_name() const;
 
-protected:
-    
+protected:    
   Glib::ustring m_table_name;
 };
 

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	Mon Jan  5 14:15:33 2009
@@ -171,6 +171,7 @@
       //Show the new field (fill in the other cells):
 
       //Update our list of database fields.
+      update_gda_metastore_for_table(m_table_name);
       fill_fields();
 
       //fill_from_database(); //We cannot change the structure in a cell renderer signal handler.
@@ -209,6 +210,8 @@
       const bool test = query_execute( "ALTER TABLE \"" + m_table_name + "\" DROP COLUMN \"" + name + "\"", get_app_window());
       if(test)
       {
+        update_gda_metastore_for_table(m_table_name);
+
         //Remove it from all layouts, reports, etc:
         get_document()->remove_field(m_table_name, name);
       }
@@ -325,7 +328,7 @@
     //Get DB field info: (TODO: This might be unnecessary).
     type_vecFields::const_iterator iterFind = std::find_if( m_vecFields.begin(), m_vecFields.end(), predicate_FieldHasName<Field>(strFieldNameBeingEdited) );
     if(iterFind == m_vecFields.end()) //If it was not found:
-      std::cerr << "Box_DB_Table_Definition::on_adddel_changed(): field not found." << std::endl;
+      std::cerr << "Box_DB_Table_Definition::on_adddel_changed(): field not found: " << strFieldNameBeingEdited << std::endl;
     else
     {
       sharedptr<const Field> constfield = *iterFind;
@@ -589,12 +592,14 @@
 
 void Box_DB_Table_Definition::fill_fields()
 {
+  std::cout << "DEBUG: Box_DB_Table_Definition::fill_fields()" << std::endl;
   //Update the fields (also checking the actual database):
   m_vecFields = get_fields_for_table(m_table_name);
 }
 
 sharedptr<Field> Box_DB_Table_Definition::postgres_change_column(const sharedptr<const Field>& field_old, const sharedptr<const Field>& field)
 {
+  //std::cout << "DEBUG: Box_DB_Table_Definition::postgres_change_column()" << std::endl;
   const Glib::RefPtr<const Gnome::Gda::Column> field_info = field->get_field_info();
   const Glib::RefPtr<const Gnome::Gda::Column> field_info_old = field_old->get_field_info();
 
@@ -602,12 +607,15 @@
   if(field_info->get_g_type() != field_info_old->get_g_type() )
   {
     postgres_change_column_type(field_old, field); //This will also change everything else at the same time.
+    update_gda_metastore_for_table(m_table_name);
     return glom_sharedptr_clone(field);
   }
   else
   {
     //Change other stuff, without changing the type:
-    return GlomPostgres::postgres_change_column_extras(m_table_name, field_old, field);
+    sharedptr<Field> result = GlomPostgres::postgres_change_column_extras(m_table_name, field_old, field);
+    update_gda_metastore_for_table(m_table_name);
+    return result;
   }
 }
 
@@ -790,6 +798,8 @@
 
     if(!new_column_created) //We don't need to change anything else if everything was already correctly set as a new column:
       GlomPostgres::postgres_change_column_extras(m_table_name, field_old, field);
+
+    //Callers should call this: update_gda_metastore_for_table();
   }
 }
 



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