[glom] DbUtils::drop_table(): Update the meta store too.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] DbUtils::drop_table(): Update the meta store too.
- Date: Sun, 7 Feb 2016 21:14:35 +0000 (UTC)
commit c987d018e83e2784eb8e8cc54702e9cc54c216ad
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 | 6 +++
4 files changed, 45 insertions(+), 22 deletions(-)
---
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 4efa75b..bfda345 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -324,7 +324,7 @@ std::shared_ptr<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
{
@@ -344,26 +344,8 @@ std::shared_ptr<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 auto 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;
@@ -1012,4 +994,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 auto 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 475b5e1..70f4b70 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -284,6 +284,8 @@ public:
*/
bool change_columns(const Glib::ustring& table_name, const type_vec_const_fields& old_fields, const
type_vec_const_fields& fields) noexcept;
+ 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 6a1f113..ca6b81f 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -2008,7 +2008,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;
+
+ auto 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 7dba31b..172fde2 100644
--- a/tests/test_selfhosting_new_then_alter_table.cc
+++ b/tests/test_selfhosting_new_then_alter_table.cc
@@ -59,6 +59,12 @@ static bool do_test(Glom::Document::HostingMode hosting_mode, const Glib::ustrin
return false;
}
+ const auto table_names = Glom::DbUtils::get_table_names_from_database();
+ if(Glom::Utils::find_exists(table_names, renamed_table_name)) {
+ 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]