[glom/mysql] MySQL: Startup and shutdown now work



commit 6668bd0d5e77b7be3ae4c78e8fb45d48497c5f2a
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jan 3 21:08:48 2013 +0100

    MySQL: Startup and shutdown now work

 glom/libglom/connectionpool_backends/mysql_self.cc |   19 ++++++++++++++-----
 glom/libglom/privs.cc                              |    2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/glom/libglom/connectionpool_backends/mysql_self.cc b/glom/libglom/connectionpool_backends/mysql_self.cc
index 3d18cb5..df076b9 100644
--- a/glom/libglom/connectionpool_backends/mysql_self.cc
+++ b/glom/libglom/connectionpool_backends/mysql_self.cc
@@ -30,6 +30,7 @@
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/stringutils.h>
+#include <glibmm/timer.h>
 #include <glibmm/regex.h>
 #include <glibmm/main.h>
 #include <glibmm/shell.h>
@@ -212,7 +213,7 @@ Backend::InitErrors MySQLSelfHosted::initialize(const SlotProgress& slot_progres
     }
     else
     {
-      if(cleanup(slot_progress) != STARTUPERROR_NONE)
+      if(!cleanup(slot_progress))
       {
         std::cerr << "Error while attempting to create self-hosting MySQL database, while shutting down, after setting the initial username and password." << std::endl;
         return INITERROR_OTHER;
@@ -277,7 +278,10 @@ static Glib::ustring build_query_change_username(const Glib::RefPtr<Gnome::Gda::
   //Query OK, 0 rows affected (0.00 sec)
   const Glib::ustring user = connection->quote_sql_identifier(old_username) + "@localhost";
 
-  return "RENAME USER " + user + " TO " + connection->quote_sql_identifier(new_username);
+  //Login will fail after restart if we don't specify @localhost here too:
+  const Glib::ustring new_user = connection->quote_sql_identifier(new_username) + "@localhost";
+
+  return "RENAME USER " + user + " TO " + new_user;
 }
 
 Backend::StartupErrors MySQLSelfHosted::startup(const SlotProgress& slot_progress, bool network_shared)
@@ -402,7 +406,7 @@ Backend::StartupErrors MySQLSelfHosted::startup(const SlotProgress& slot_progres
     m_saved_password = m_initial_password_to_set;
 
     const std::string query = build_query_change_username(gda_connection, "root", m_initial_username_to_set);
-    //std::cout << G_STRFUNC << std::cout << "  DEBUG: rename user query=" << query << std::endl;
+    std::cout << G_STRFUNC << std::cout << "  DEBUG: rename user query=" << query << std::endl;
 
     try
     {
@@ -516,9 +520,14 @@ bool MySQLSelfHosted::cleanup(const SlotProgress& slot_progress)
   // CreateProcess() API used on Windows does not support single quotes.
   const std::string command_mysql_stop = get_mysqladmin_command(m_saved_username, m_saved_password)
     + " shutdown";
-  std::cout << "DEBUGcleanup before shutdown: command=" << command_mysql_stop << std::endl;
+  //std::cout << "DEBUGcleanup before shutdown: command=" << command_mysql_stop << std::endl;
   const bool result = Glom::Spawn::execute_command_line_and_wait(command_mysql_stop, slot_progress);
-  std::cout << "DEBUGcleanup after shutdown" << std::endl;
+
+  //Give it time to succeed, because mysqladmin shutdown does not wait when using protocol=tcp.
+  //TODO: Wait for a second command, such as myadmin ping, though its error message is less precise in this case.
+  Glib::usleep(5000 * 1000);
+
+  //std::cout << "DEBUGcleanup after shutdown: result=" << result << std::endl;
 
   if(!result)
   {
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index a41a76a..5f475ef 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -92,7 +92,7 @@ bool Privs::get_developer_user_exists_with_password(Document::HostingMode hostin
 
 Glib::ustring Privs::get_default_developer_user_name(Glib::ustring& password, Document::HostingMode hosting_mode)
 {
-  password = "glom_default_developer_password";
+  password = "testpw";
 
   if((hosting_mode == Document::HOSTING_MODE_MYSQL_CENTRAL) ||
    (hosting_mode == Document::HOSTING_MODE_MYSQL_SELF))



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