[glom/glom-1-28] DbUtils::drop_table(): Update the meta store too.



commit 9aef15a5a9459801e1edc0b70579bdff958d0ab1
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Feb 7 17:43:14 2016 +0100

    DbUtils::drop_table(): Update the meta store too.
    
    Otherwise, we still get the dropped table name when asking libgda
    for a list of tables. This caused Glom to complain that a
    previously-deleted table name already existed when the user tried to
    recreate it.
    Bug #754645 (m.rick.mac)

 glom/libglom/connectionpool.cc                 |   53 ++++++++++++++---------
 glom/libglom/connectionpool.h                  |    2 +
 glom/libglom/db_utils.cc                       |    6 ++-
 tests/test_selfhosting_new_then_alter_table.cc |    8 ++++
 4 files changed, 47 insertions(+), 22 deletions(-)
---
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 1aaa5c2..5cf9729 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -337,7 +337,7 @@ sharedptr<SharedConnection> ConnectionPool::connect()
 
       {
         //Allow get_meta_store_data() to succeed:
-        //Hopefully this (and the update_meta_store_for_table() calls) is all we need.
+        //Hopefully this (and the update_meta_store_table() calls) is all we need.
         //std::cout << "DEBUG: Calling update_meta_store_data_types() ..." << std::endl;
         try
         {
@@ -357,26 +357,8 @@ sharedptr<SharedConnection> ConnectionPool::connect()
 
         //std::cout << "DEBUG: Calling update_meta_store_table_names() ..." << std::endl;
 
-        try
-        {
-          //update_meta_store_table_names() has been known to throw an exception.
-          //Glom is mostly unusable when it fails, but that's still better than a crash.
-          //std::cout << G_STRFUNC << ": Before update_meta_store_table_name()" << std::endl;
-          const bool test = 
m_refGdaConnection->update_meta_store_table_names(m_backend->get_public_schema_name());
-          if(!test && !m_fake_connection)
-          {
-            std::cerr << G_STRFUNC << ": update_meta_store_table_names() failed without an exception." << 
std::endl;
-          }
-        }
-        catch(const Glib::Error& ex)
-        {
-          //If the connection was not opened, because it is a fake connection,
-          //then we should not be surprised that this fails,
-          //and a warning will only be useful later when get_meta_store_data() fails when used in 
get_table_names_from_database().
-          if(!m_fake_connection)
-          {
-            std::cerr << G_STRFUNC << ": update_meta_store_table_names() failed: " << ex.what() << std::endl;
-          }
+        if(!update_meta_store_for_table_names()) {
+          std::cerr << G_STRFUNC << ": update_meta_store_table_names() failed without an exception." << 
std::endl;
         }
         //std::cout << "DEBUG: ... update_meta_store_table_names() has finished." << std::endl;
 
@@ -1028,4 +1010,33 @@ void ConnectionPool::set_fake_connection()
   set_password("glom_fake_password");
 }
 
+bool ConnectionPool::update_meta_store_for_table_names()
+{
+  try
+  {
+    //update_meta_store_table_names() has been known to throw an exception.
+    //Glom is mostly unusable when it fails, but that's still better than a crash.
+    //std::cout << G_STRFUNC << ": Before update_meta_store_table_name()" << std::endl;
+    const bool test = m_refGdaConnection->update_meta_store_table_names(m_backend->get_public_schema_name());
+    if(!test && !m_fake_connection)
+    {
+      std::cerr << G_STRFUNC << ": update_meta_store_table_names() failed without an exception." << 
std::endl;
+      return false;
+    }
+  }
+  catch(const Glib::Error& ex)
+  {
+    //If the connection was not opened, because it is a fake connection,
+    //then we should not be surprised that this fails,
+    //and a warning will only be useful later when get_meta_store_data() fails when used in 
get_table_names_from_database().
+    if(!m_fake_connection)
+    {
+      std::cerr << G_STRFUNC << ": update_meta_store_table_names() failed: " << ex.what() << std::endl;
+      return false;
+    }
+  }
+
+  return true;
+}
+
 } //namespace Glom
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index e9fcfbd..6585866 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -279,6 +279,8 @@ public:
    */
   bool change_columns(const Glib::ustring& table_name, const type_vec_const_fields& old_fields, const 
type_vec_const_fields& fields) throw();
 
+  bool update_meta_store_for_table_names();
+
   /** Specify a callback that the ConnectionPool can call to get a pointer to the document.
    * This callback avoids Connection having to link to AppWindow,
    * and avoids us worrying about whether a previously-set document (via a set_document() method) is still 
valid.
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index 6ce47d9..3b84942 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -2018,7 +2018,11 @@ bool rename_table(const Glib::ustring& table_name, const Glib::ustring& new_tabl
 bool drop_table(const Glib::ustring& table_name)
 {
   //TODO: Escape the table names:
-  return DbUtils::query_execute_string( "DROP TABLE " + escape_sql_id(table_name));
+  if(!DbUtils::query_execute_string( "DROP TABLE " + escape_sql_id(table_name)))
+    return false;
+
+  ConnectionPool* connection_pool = ConnectionPool::get_instance();
+  return connection_pool->update_meta_store_for_table_names();
 }
 
 Glib::ustring escape_sql_id(const Glib::ustring& id)
diff --git a/tests/test_selfhosting_new_then_alter_table.cc b/tests/test_selfhosting_new_then_alter_table.cc
index 436dd02..ab5d031 100644
--- a/tests/test_selfhosting_new_then_alter_table.cc
+++ b/tests/test_selfhosting_new_then_alter_table.cc
@@ -59,6 +59,14 @@ static bool do_test(Glom::Document::HostingMode hosting_mode, const Glib::ustrin
     return false;
   }
 
+  const Glom::DbUtils::type_vec_strings table_names =
+    Glom::DbUtils::get_table_names_from_database();
+  if(std::find(table_names.begin(), table_names.end(), renamed_table_name)
+    != table_names.end()) {
+    std::cerr << G_STRFUNC << ": Failure: The dropped table seems to still exist." << std::endl;
+    return false;
+  }
+
   test_selfhosting_cleanup();
  
   return true; 


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