[glom/feature_backup2] Saving from a backup: Now works.



commit c4b46839612fe3d2120ed13dbb102e8ed4d6aedd
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jul 22 11:46:48 2010 +0200

    Saving from a backup: Now works.
    
    * glom/application.[h|cc]: on_document_load(): Simplify the code to
      create from a backup, modifying the from-example code to handle it too,
      calling a new recreate_database_from_backup() method.
      That now creates the database and then adds the groups before trying
      to restore from the backup file.
    * glom/libglom/connectionpool_backends/backend.h: convert_backup():
    * glom/libglom/connectionpool_backends/postgres.[h|cc]: convert_backup():
    * glom/libglom/connectionpool_backends/sqlite.[h|cc]: convert_backup():
      Add a database_name_parameter. This now expects the database to exist
      already, though it should be empty. It should also already have the
      expected groups.
    * glom/libglom/connectionpool.[h|cc]: convert_backup(): Supply the
      database name. Also update the meta data so we know about the new tables.

 ChangeLog                                        |   18 ++
 glom/application.cc                              |  216 +++++++++++++++++-----
 glom/application.h                               |    1 +
 glom/libglom/connectionpool.cc                   |   17 ++-
 glom/libglom/connectionpool.h                    |   46 +++---
 glom/libglom/connectionpool_backends/backend.h   |   38 ++--
 glom/libglom/connectionpool_backends/postgres.cc |    8 +-
 glom/libglom/connectionpool_backends/postgres.h  |    2 +-
 glom/libglom/connectionpool_backends/sqlite.cc   |    2 +-
 glom/libglom/connectionpool_backends/sqlite.h    |    5 +-
 glom/libglom/document/document.cc                |    2 +-
 11 files changed, 256 insertions(+), 99 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ba912b8..bc2b7c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-07-22  Murray Cumming  <murrayc murrayc com>
+
+	Saving from a backup: Now works.
+
+	* glom/application.[h|cc]: on_document_load(): Simplify the code to
+  create from a backup, modifying the from-example code to handle it too,
+  calling a new recreate_database_from_backup() method.
+  That now creates the database and then adds the groups before trying
+  to restore from the backup file.
+	* glom/libglom/connectionpool_backends/backend.h: convert_backup():
+	* glom/libglom/connectionpool_backends/postgres.[h|cc]: convert_backup():
+	* glom/libglom/connectionpool_backends/sqlite.[h|cc]: convert_backup():
+  Add a database_name_parameter. This now expects the database to exist
+  already, though it should be empty. It should also already have the
+  expected groups.
+	* glom/libglom/connectionpool.[h|cc]: convert_backup(): Supply the
+  database name. Also update the meta data so we know about the new tables.
+
 2010-07-21  Murray Cumming  <murrayc murrayc com>
 
 	Small Business example: Add table privileges.
diff --git a/glom/application.cc b/glom/application.cc
index 9660490..5e2c90d 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -1109,6 +1109,7 @@ bool Application::on_document_load()
       {
         pDocument->set_modified(false);
         pDocument->set_is_new(true);
+        pDocument->set_allow_autosave(true); //Turn this back on.
         std::cout << "debug: user cancelled creating database" << std::endl;
         return false;
       }
@@ -1206,12 +1207,17 @@ bool Application::on_document_load()
         return false; //Failed. Close the document.
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
-      if(is_example)
+      if(is_example || is_backup)
       {
         //Create the example database:
         //connection_request_password_and_choose_new_database_name() has already change the database name to a new unused one:
         bool user_cancelled = false;
-        const bool test = recreate_database_from_example(user_cancelled);
+        bool test = false;
+        if(is_example)
+          test = recreate_database_from_example(user_cancelled);
+        else
+          test = recreate_database_from_backup(original_uri, user_cancelled);
+
         if(!test)
         {
           // TODO: Do we need to call connection_pool->cleanup() here, for
@@ -1236,53 +1242,10 @@ bool Application::on_document_load()
           const AppState::userlevels user_level = pDocument->get_userlevel();
           pDocument->set_userlevel(AppState::USERLEVEL_DEVELOPER);
           pDocument->set_modified(true);
+          pDocument->set_allow_autosave(true); //Turn this back on.
           pDocument->set_userlevel(user_level); //Change it back.
         }
       }
-      else if(is_backup)
-      {
-        std::string original_dir_path;
-
-        Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(original_uri);
-        if(gio_file)
-        {
-          Glib::RefPtr<Gio::File> parent = gio_file->get_parent();
-          if(parent)
-          {
-            try
-            {
-              original_dir_path = Glib::filename_from_uri(parent->get_uri());
-            }
-            catch(const Glib::Error& ex)
-            {
-              std::cerr << G_STRFUNC << ": Glib::filename_from_uri() failed: " << ex.what() << std::endl;
-            }
-          }
-        }
-
-        if(original_dir_path.empty())
-        {
-          std::cerr << G_STRFUNC << ": original_dir_path is empty." << std::endl;
-          return false;
-        }
-
-        //Restore the database from the backup:
-        std::cout << "DEBUG: original_dir_path=" << original_dir_path << std::endl;
-        const bool restored = connection_pool->convert_backup(
-          sigc::mem_fun(*this, &Application::on_connection_convert_backup_progress), original_dir_path);
-
-        if(m_dialog_progess_convert_backup)
-        {
-          delete m_dialog_progess_convert_backup;
-          m_dialog_progess_convert_backup = 0;
-        }
-
-        if(!restored)
-        {
-          std::cerr << G_STRFUNC << ": Restore failed." << std::endl;
-          return false;
-        }
-      }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
       //Switch to operator mode when opening new documents:
@@ -1863,6 +1826,167 @@ bool Application::recreate_database_from_example(bool& user_cancelled)
 
   return true; //All tables created successfully.
 }
+
+bool Application::recreate_database_from_backup(const Glib::ustring& backup_uri, bool& user_cancelled)
+{
+  //Create a database, based on the information in the current document:
+  Document* pDocument = static_cast<Document*>(get_document());
+  if(!pDocument)
+    return false;
+
+  ConnectionPool* connection_pool = ConnectionPool::get_instance();
+  if(!connection_pool)
+    return false; //Impossible anyway.
+
+  //Check whether the database exists already.
+  const Glib::ustring db_name = pDocument->get_connection_database();
+  if(db_name.empty())
+    return false;
+
+  connection_pool->set_database(db_name);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+#else
+  std::auto_ptr<std::exception> error;
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+  {
+    connection_pool->set_ready_to_connect(); //This has succeeded already.
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    sharedptr<SharedConnection> sharedconnection = connection_pool->connect();
+#else
+    sharedptr<SharedConnection> sharedconnection = connection_pool->connect(error);
+    if(!error.get())
+    {
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+      g_warning("Application::recreate_database_from_example(): Failed because database exists already.");
+
+      return false; //Connection to the database succeeded, because no exception was thrown. so the database exists already.
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+    }
+#endif // !GLIBMM_EXCEPTIONS_ENABLED
+  }
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  catch(const ExceptionConnection& ex)
+  {
+#else
+  if(error.get())
+  {
+    const ExceptionConnection* exptr = dynamic_cast<ExceptionConnection*>(error.get());
+    if(exptr)
+    {
+      const ExceptionConnection& ex = *exptr;
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+      if(ex.get_failure_type() == ExceptionConnection::FAILURE_NO_SERVER)
+      {
+        user_cancelled = true; //Eventually, the user will cancel after retrying.
+        g_warning("Application::recreate_database_from_example(): Failed because connection to server failed, without specifying a database.");
+        return false;
+      }
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+    }
+#endif // !GLIBMM_EXCEPTIONS_ENABLED
+
+    //Otherwise continue, because we _expected_ connect() to fail if the db does not exist yet.
+  }
+
+  //Show the user that something is happening, because the INSERTS might take time.
+  //TOOD: This doesn't actually show up until near the end, even with Gtk::Main::instance()->iteration().
+  Dialog_ProgressCreating* dialog_progress_temp = 0;
+  Utils::get_glade_widget_derived_with_warning(dialog_progress_temp);
+  dialog_progress_temp->set_message(_("Creating Glom Database"), _("Creating Glom database from backup file."));
+  std::auto_ptr<Dialog_ProgressCreating> dialog_progress(dialog_progress_temp); //Put the dialog in an auto_ptr so that it will be deleted (and hidden) when the current function returns.
+
+  dialog_progress->set_transient_for(*this);
+  dialog_progress->show();
+
+  //Ensure that the dialog is shown, instead of waiting for the application to be idle:
+  while(Gtk::Main::instance()->events_pending())
+    Gtk::Main::instance()->iteration();
+
+  dialog_progress->pulse();
+
+  //Create the database: (This will show a connection dialog)
+  connection_pool->set_database( Glib::ustring() );
+  try
+  {
+    ConnectionPool::get_instance()->create_database(db_name);
+  }
+  catch(const Glib::Exception& ex) // libgda does not set error domain
+  {
+    std::cerr << G_STRFUNC << ": Gnome::Gda::Connection::create_database(" << db_name << ") failed: " << ex.what() << std::endl;
+
+    //Tell the user:
+    Gtk::Dialog* dialog = 0;
+    Utils::get_glade_widget_with_warning("glom_developer.glade", "dialog_error_create_database", dialog);
+    dialog->set_transient_for(*this);
+    Glom::Utils::dialog_run_with_help(dialog, "dialog_error_create_database");
+    delete dialog;
+
+    return false;
+  }
+
+  connection_pool->set_database(db_name); //Specify the new database when connecting from now on.
+
+  //Create the developer group, and make this user a member of it:
+  dialog_progress->pulse();
+  bool test = m_pFrame->add_standard_groups();
+  if(!test)
+    return false;
+
+  //Add any extra groups from the example file:
+  dialog_progress->pulse();
+  test = m_pFrame->add_groups_from_document();
+  if(!test)
+    return false;
+
+  //dialog_progress->pulse();
+  //m_pFrame->add_standard_tables(); //Add internal, hidden, tables.
+
+  //Restore the backup into the database:
+  std::string original_dir_path;
+
+  Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(backup_uri);
+  if(gio_file)
+  {
+    Glib::RefPtr<Gio::File> parent = gio_file->get_parent();
+    if(parent)
+    {
+      try
+      {
+        original_dir_path = Glib::filename_from_uri(parent->get_uri());
+      }
+      catch(const Glib::Error& ex)
+      {
+        std::cerr << G_STRFUNC << ": Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+      }
+    }
+  }
+
+  if(original_dir_path.empty())
+  {
+    std::cerr << G_STRFUNC << ": original_dir_path is empty." << std::endl;
+    return false;
+  }
+
+  //Restore the database from the backup:
+  std::cout << "DEBUG: original_dir_path=" << original_dir_path << std::endl;
+  const bool restored = connection_pool->convert_backup(
+    sigc::mem_fun(*this, &Application::on_connection_convert_backup_progress), original_dir_path);
+
+  if(m_dialog_progess_convert_backup)
+  {
+    delete m_dialog_progess_convert_backup;
+    m_dialog_progess_convert_backup = 0;
+  }
+
+  if(!restored)
+  {
+    std::cerr << G_STRFUNC << ": Restore failed." << std::endl;
+    return false;
+  }
+
+  return true; //Restore successfully.
+}
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
 AppState::userlevels Application::get_userlevel() const
diff --git a/glom/application.h b/glom/application.h
index f61f524..12104ee 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -182,6 +182,7 @@ private:
   Document* on_connection_pool_get_document();
 
   bool recreate_database_from_example(bool& user_cancelled); //return indicates success.
+  bool recreate_database_from_backup(const Glib::ustring& backup_uri, bool& user_cancelled); //return indicates success.
   void stop_self_hosting_of_document_database();
 
   void on_connection_avahi_begin();
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index ade26a5..3a4cca8 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -451,7 +451,22 @@ bool ConnectionPool::convert_backup(const SlotProgress& slot_progress, const std
     path_dir_to_use = Glib::build_filename(path_dir, "glom_postgres_data");
   }
 
-  return m_backend->convert_backup(slot_progress, path_dir_to_use, m_user, m_password);
+  const bool result = m_backend->convert_backup(slot_progress, path_dir_to_use, m_user, m_password, m_database);
+  if(!result)
+    return false;
+
+  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.
+    m_refGdaConnection->update_meta_store_table_names(m_backend->get_public_schema_name());
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "ConnectionPool::connect(): update_meta_store_table_names() failed: " << ex.what() << std::endl;
+  }
+
+  return result;
 }
 
 void ConnectionPool::set_password(const Glib::ustring& value)
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 67737a3..7073a4d 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -89,7 +89,7 @@ private:
   //ConnectionPool(const ConnectionPool& src);
   virtual ~ConnectionPool();
   //ConnectionPool& operator=(const ConnectionPool& src);
-  
+
 public:
   typedef ConnectionPoolBackends::Backend Backend;
   typedef Backend::type_vec_const_fields type_vec_const_fields;
@@ -106,17 +106,17 @@ public:
 
   /// Delete the singleton so it doesn't show up as leaked memory in, for instance, valgrind.
   static void delete_instance();
-  
+
   typedef sigc::slot<void> type_void_slot;
-  
+
 #ifndef G_OS_WIN32
-  /** Set callbacks that will be called to show UI while starting to advertise 
+  /** Set callbacks that will be called to show UI while starting to advertise
    * on the network via Avahi.
    *
    * @param slot_begin Show an explanatory message.
    * @param slot_progress Show a pulse progress and/or keep the UI updating.
    * @param slot_done Stop showing the message.
-   */ 
+   */
   void set_avahi_publish_callbacks(const type_void_slot& slot_begin, const type_void_slot& slot_progress, const type_void_slot& slot_done);
 #endif
 
@@ -167,12 +167,15 @@ public:
    * This backup can later be used to recreate the database,
    * for instance with a later version of PostgreSQL.
    * See @convert_backup().
+   *
    * @param path_dir The top-level directory for the backup file, using the normal directory structure.
-   * 
+   *
    */
   bool save_backup(const SlotProgress& slot_progress, const std::string& path_dir);
-  
-  /** Use a backup of the database in a tarball to create a new database.
+
+  /** Use a backup of the database in a tarball to create tables and data in an existing empty database.
+   * The database (server) should already have the necessary groups and users.
+   *
    * @param path_dir The top-level directory for the backup file, using the normal directory structure.
    * See save_backup().
    */
@@ -189,15 +192,15 @@ public:
   Field::sql_format get_sql_format() const;
   const FieldTypes* get_field_types() const;
   Glib::ustring get_string_find_operator() const;
- 
+
   typedef Backend::InitErrors InitErrors;
-  
+
   /** Do one-time initialization, such as  creating required database
    * files on disk for later use by their own  database server instance.
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    * @param parent_window A parent window to use as the transient window when displaying errors.
    */
   InitErrors initialize(const SlotProgress& slot_progress, bool network_shared = false);
@@ -207,8 +210,8 @@ public:
   /** Start a database server instance for the existing database files.
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    * @param parent_window The parent window (transient for) of any dialogs shown during this operation.
    * @result Whether the operation was successful.
    */
@@ -221,15 +224,15 @@ public:
    */
   bool cleanup(const SlotProgress& slot_progress);
 
-  /** Change the database server's configration to allow or prevent access from 
+  /** Change the database server's configration to allow or prevent access from
    * other users on the network.
    *
-   * For current backends, you may use this only before startup(), 
+   * For current backends, you may use this only before startup(),
    * or after cleanup().
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    */
   virtual bool set_network_shared(const SlotProgress& slot_progress, bool network_shared = true);
 
@@ -260,8 +263,8 @@ public:
   /** Specify a callback that the ConnectionPool can call to get a pointer to the document.
    * This callback avoids Connection having to link to Application,
    * and avoids us worrying about whether a previously-set document (via a set_document() method) is still valid.
-   */ 
-  typedef sigc::slot<Document*> SlotGetDocument; 
+   */
+  typedef sigc::slot<Document*> SlotGetDocument;
   void set_get_document_func(const SlotGetDocument& slot);
 
 #ifndef G_OS_WIN32
@@ -279,7 +282,7 @@ public:
 private:
   void on_sharedconnection_finished();
 
-  /** We call this when we know that the current connection will no longer work, 
+  /** We call this when we know that the current connection will no longer work,
    * for instance after we have stopped the server.
    */
   void invalidate_connection();
@@ -322,4 +325,3 @@ private:
 } //namespace Glom
 
 #endif //GLOM_CONNECTIONPOOL_H
-
diff --git a/glom/libglom/connectionpool_backends/backend.h b/glom/libglom/connectionpool_backends/backend.h
index 2a51d84..c72cd99 100644
--- a/glom/libglom/connectionpool_backends/backend.h
+++ b/glom/libglom/connectionpool_backends/backend.h
@@ -76,7 +76,7 @@ public:
      INITERROR_COULD_NOT_START_SERVER,
      INITERROR_OTHER
   };
-  
+
   enum StartupErrors
   {
     STARTUPERROR_NONE, /*< The database is ready for use. */
@@ -84,7 +84,7 @@ public:
     STARTUPERROR_FAILED_NO_DATA_HAS_BACKUP_DATA, /*< There is no data for the database, but there is a backup file instead. */
     STARTUPERROR_FAILED_UNKNOWN_REASON /*< Something else failed. */
   };
-  
+
 protected:
   /** Helper functions for backend implementations to use, so that these don't
    * need to worry whether glibmm was compiled with exceptions or not.
@@ -131,29 +131,29 @@ protected:
    */
   void set_database_directory_uri(const std::string& directory_uri);
   std::string get_database_directory_uri() const;
-  
+
   /** This callback should show UI to indicate that work is still happening.
    * For instance, a pulsing ProgressBar.
    */
   typedef sigc::slot<void> SlotProgress;
-  
+
   /** This method is called for one-time initialization of the database
    * storage. There is no need to implement this function if the data is centrally
    * hosted rather than hosted by Glom.
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    */
   virtual InitErrors initialize(const SlotProgress& slot_progress, const Glib::ustring& initial_username, const Glib::ustring& password, bool network_shared = false);
-  
+
   /** This method is called before the backend is used otherwise. This can
    * be used to start a self-hosted database server. There is no need to implement
    * this function if there is no need for extra startup code.
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    */
   virtual StartupErrors startup(const SlotProgress& slot_progress, bool network_shared = false);
 
@@ -165,15 +165,15 @@ protected:
    */
   virtual bool cleanup(const SlotProgress& slot_progress);
 
-  /** Change the database server's configration to allow or prevent access from 
+  /** Change the database server's configration to allow or prevent access from
    * other users on the network.
    *
-   * For current backends, you may use this only before startup(), 
+   * For current backends, you may use this only before startup(),
    * or after cleanup().
    *
    * @param slot_progress A callback to call while the work is still happening.
-   * @param network_shared Whether the database (and document) should be available to other users over the network, 
-   * if possible. 
+   * @param network_shared Whether the database (and document) should be available to other users over the network,
+   * if possible.
    */
   virtual bool set_network_shared(const SlotProgress& slot_progress, bool network_shared = true);
 
@@ -196,18 +196,19 @@ protected:
   /** This method is called to create a new database on the
    * database server. */
   virtual bool create_database(const Glib::ustring& database_name, const Glib::ustring& username, const Glib::ustring& password, std::auto_ptr<Glib::Error>& error) = 0;
-  
+
   /** Save a backup of the database in a tarball.
    * This backup can later be used to recreate the database,
    * for instance with a later version of PostgreSQL.
    */
   virtual bool save_backup(const SlotProgress& slot_progress, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name) = 0;
-  
-  /** Use a backup of the database in a tarball to create a new database.
+
+  /** Use a backup of the database in a tarball to create the tables and data in an existing empty database.
+   * The database (server) should already have the necessary groups and users.
    * See save_backup().
    */
-  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory_uri, const Glib::ustring& username, const Glib::ustring& password) = 0;
-  
+  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory_uri, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name) = 0;
+
 protected:
   std::string m_database_directory_uri;
 };
@@ -217,4 +218,3 @@ protected:
 } //namespace Glom
 
 #endif // GLOM_BACKEND_BACKEND_H
-
diff --git a/glom/libglom/connectionpool_backends/postgres.cc b/glom/libglom/connectionpool_backends/postgres.cc
index 20e0ec0..91db725 100644
--- a/glom/libglom/connectionpool_backends/postgres.cc
+++ b/glom/libglom/connectionpool_backends/postgres.cc
@@ -659,7 +659,7 @@ bool Postgres::save_backup(const SlotProgress& slot_progress, const Glib::ustrin
   return result;
 }
 
-bool Postgres::convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password)
+bool Postgres::convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name)
 {
 /* TODO:
   if(m_network_shared && !running)
@@ -694,8 +694,6 @@ bool Postgres::convert_backup(const SlotProgress& slot_progress, const std::stri
     return false;
   }
 
-  //TODO: Save the password to .pgpass
-
   //Make sure the path exists:
   const std::string path_backup = get_self_hosting_backup_path(base_directory);
   if(path_backup.empty() || !file_exists_filepath(path_backup))
@@ -704,7 +702,7 @@ bool Postgres::convert_backup(const SlotProgress& slot_progress, const std::stri
     return false;
   }
 
-  // Save the password to ~/.pgpass, because this is the only wayt to use
+  // Save the password to ~/.pgpass, because this is the only way to use
   // pg_dump without it asking for the password:
   std::string pgpass_backup, pgpass_original;
   const bool pgpass_created = save_password_to_pgpass(username, password, pgpass_backup, pgpass_original);
@@ -717,7 +715,7 @@ bool Postgres::convert_backup(const SlotProgress& slot_progress, const std::stri
   // Make sure to use double quotes for the executable path, because the
   // CreateProcess() API used on Windows does not support single quotes.
   const std::string command_restore = "\"" + get_path_to_postgres_executable("pg_restore") + "\"" +
-    " --create -d template1 " +
+    " -d " + database_name +
     " --host=\"" + m_host + "\"" +
     " --port=" + port_as_string(m_port) +
     " --username=\"" + username + "\"" +
diff --git a/glom/libglom/connectionpool_backends/postgres.h b/glom/libglom/connectionpool_backends/postgres.h
index 37829af..8cb4fec 100644
--- a/glom/libglom/connectionpool_backends/postgres.h
+++ b/glom/libglom/connectionpool_backends/postgres.h
@@ -56,7 +56,7 @@ public:
    */
   virtual bool save_backup(const SlotProgress& slot_progress, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name);
 
-  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password);
+  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name);
 
   static std::string get_path_to_postgres_executable(const std::string& program);
 
diff --git a/glom/libglom/connectionpool_backends/sqlite.cc b/glom/libglom/connectionpool_backends/sqlite.cc
index dc2bad4..642254f 100644
--- a/glom/libglom/connectionpool_backends/sqlite.cc
+++ b/glom/libglom/connectionpool_backends/sqlite.cc
@@ -394,7 +394,7 @@ bool Sqlite::save_backup(const SlotProgress& /* slot_progress */, const Glib::us
   return false;
 }
 
-bool Sqlite::convert_backup(const SlotProgress& /* slot_progress */, const std::string& /* base_directory */, const Glib::ustring& /* username */, const Glib::ustring& /* password */)
+bool Sqlite::convert_backup(const SlotProgress& /* slot_progress */, const std::string& /* base_directory */, const Glib::ustring& /* username */, const Glib::ustring& /* password */, const Glib::ustring& /* database_name */)
 {
   //TODO:
   std::cerr << G_STRFUNC << ": Not implemented.";
diff --git a/glom/libglom/connectionpool_backends/sqlite.h b/glom/libglom/connectionpool_backends/sqlite.h
index 06a86fe..d4ae24b 100644
--- a/glom/libglom/connectionpool_backends/sqlite.h
+++ b/glom/libglom/connectionpool_backends/sqlite.h
@@ -61,9 +61,9 @@ private:
   /** Creates a new database.
    */
   virtual bool create_database(const Glib::ustring& database_name, const Glib::ustring& username, const Glib::ustring& password, std::auto_ptr<Glib::Error>& error);
-  
+
   virtual bool save_backup(const SlotProgress& slot_progress, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name);
-  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password);
+  virtual bool convert_backup(const SlotProgress& slot_progress, const std::string& base_directory, const Glib::ustring& username, const Glib::ustring& password, const Glib::ustring& database_name);
 };
 
 } //namespace ConnectionPoolBackends
@@ -71,4 +71,3 @@ private:
 } //namespace Glom
 
 #endif //GLOM_BACKEND_SQLITE_H
-
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 3023a19..3b778b8 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -823,7 +823,7 @@ Document::type_vec_fields Document::get_table_fields(const Glib::ustring& table_
     {
       if(iterFind->second.m_fields.empty())
       {
-         g_warning("Document::get_table_fields: table found, but m_fields is empty");
+         std::cerr << G_STRFUNC << ": table found, but m_fields is empty. table_name=" << table_name << std::endl;
       }
 
       return iterFind->second.m_fields;



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