[glom] MySQL: Support MySQL in the command-line utiltiies.



commit 7869c9870cc6549acb40cc39678a0ac2905c40c7
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 13 14:16:06 2013 +0100

    MySQL: Support MySQL in the command-line utiltiies.
    
            * glom/glom_create_from_example.cc:
            * glom/glom_test_connection.cc: Add ifdefed code for MySQL.

 ChangeLog                        |    7 ++++
 glom/glom_create_from_example.cc |   47 +++++++++++++++++++++++-----
 glom/glom_test_connection.cc     |   63 +++++++++++++++++++++++++++++++------
 3 files changed, 98 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 70d4f1b..3c44aef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2013-01-13  Murray Cumming  <murrayc murrayc com>
 
+        MySQL: Support MySQL in the command-line utiltiies.
+
+        * glom/glom_create_from_example.cc:
+        * glom/glom_test_connection.cc: Add ifdefed code for MySQL.
+
+2013-01-13  Murray Cumming  <murrayc murrayc com>
+
         MySQL: Add comments about AppArmor stopping use of MySQL on Ubuntu.
 
         * glom/libglom/connectionpool_backends/mysql_self.cc:
diff --git a/glom/glom_create_from_example.cc b/glom/glom_create_from_example.cc
index 7cf67c6..226da2e 100644
--- a/glom/glom_create_from_example.cc
+++ b/glom/glom_create_from_example.cc
@@ -27,6 +27,8 @@
 #include <libglom/connectionpool.h>
 #include <libglom/connectionpool_backends/postgres_self.h>
 #include <libglom/connectionpool_backends/postgres_central.h>
+#include <libglom/connectionpool_backends/mysql_self.h>
+#include <libglom/connectionpool_backends/mysql_central.h>
 #include <libglom/init.h>
 #include <libglom/privs.h>
 #include <libglom/db_utils.h>
@@ -42,6 +44,8 @@
 
 #include <glibmm/i18n.h>
 
+#include "config.h"
+
 class GlomCreateOptionGroup : public Glib::OptionGroup
 {
 public:
@@ -59,12 +63,17 @@ public:
   double m_arg_server_port;
   Glib::ustring m_arg_server_username;
   Glib::ustring m_arg_server_password;
+
+#ifdef GLOM_ENABLE_MYSQL
+  bool m_arg_use_mysql;
+#endif //GLOM_ENABLE_MYSQL
 };
 
 GlomCreateOptionGroup::GlomCreateOptionGroup()
 : Glib::OptionGroup("glom_create_from_example", _("Glom options"), _("Command-line options")),
   m_arg_version(false),
-  m_arg_server_port(0)
+  m_arg_server_port(0),
+  m_arg_use_mysql(false)
 {
   Glib::OptionEntry entry;
   entry.set_long_name("input");
@@ -102,6 +111,13 @@ GlomCreateOptionGroup::GlomCreateOptionGroup()
   entry.set_short_name('u');
   entry.set_description(_("The username for the PostgreSQL server."));
   add_entry(entry, m_arg_server_username);
+
+#ifdef GLOM_ENABLE_MYSQL
+  entry.set_long_name("use-mysql");
+  entry.set_short_name('m');
+  entry.set_description(_("Use MySQL instead of PostgreSQL."));
+  add_entry(entry, m_arg_use_mysql);
+#endif //GLOM_ENABLE_MYSQL
 }
 
 static void on_initialize_progress()
@@ -385,17 +401,32 @@ int main(int argc, char* argv[])
 
   document.set_file_uri(file_uri);
 
-
   const bool self_hosting = group.m_arg_server_hostname.empty();
   if(self_hosting)
   {
-    std::cout << "Using self-hosting instead of a central PostgreSQL server." << std::endl;
-    document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_SELF);
+    std::cout << "Using self-hosting instead of a central database server." << std::endl;
+
+#if GLOM_ENABLE_MYSQL
+    if(group.m_arg_use_mysql)
+      document.set_hosting_mode(Glom::Document::HOSTING_MODE_MYSQL_SELF);
+    else
+#endif //GLOM_ENABLE_MYSQL
+    {
+      document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_SELF);
+    }
   }
   else
   {
-    std::cout << "Using the PostgreSQL server with host: " << group.m_arg_server_hostname << std::endl;
-    document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_CENTRAL);
+    std::cout << "Using the database server with host: " << group.m_arg_server_hostname << std::endl;
+
+#if GLOM_ENABLE_MYSQL
+    if(group.m_arg_use_mysql)
+      document.set_hosting_mode(Glom::Document::HOSTING_MODE_MYSQL_CENTRAL);
+    else
+#endif //GLOM_ENABLE_MYSQL
+    {
+      document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_CENTRAL);
+    }
   }
    
   document.set_is_example_file(false);
@@ -421,11 +452,11 @@ int main(int argc, char* argv[])
     //Other command-line utilities such as psql don't do this either.
     //TODO: Support alternatives such as using a file.
     const Glib::ustring prompt = Glib::ustring::compose(
-      _("Please enter the PostgreSQL server's password for the user %1: "), group.m_arg_server_username);
+      _("Please enter the database server's password for the user %1: "), group.m_arg_server_username);
 
 #ifdef G_OS_WIN32
     const char* password = "";
-    std::cerr << _("Error: getpass() is not implemented in the Windows build. The connection will fail.") << std::endl;
+    std::cerr << "Error: getpass() is not implemented in the Windows build. The connection will fail." << std::endl;
 #else
     const char* password = ::getpass(prompt.c_str());
 #endif
diff --git a/glom/glom_test_connection.cc b/glom/glom_test_connection.cc
index 0978449..f54dc81 100644
--- a/glom/glom_test_connection.cc
+++ b/glom/glom_test_connection.cc
@@ -25,6 +25,7 @@
 
 #include <libglom/connectionpool.h>
 #include <libglom/connectionpool_backends/postgres_central.h>
+#include <libglom/connectionpool_backends/mysql_central.h>
 #include <libglom/init.h>
 #include <libglom/privs.h>
 #include <libglom/utils.h>
@@ -49,12 +50,17 @@ public:
   Glib::ustring m_arg_server_username;
   Glib::ustring m_arg_server_password;
   Glib::ustring m_arg_server_database;
+
+#ifdef GLOM_ENABLE_MYSQL
+  bool m_arg_use_mysql;
+#endif //GLOM_ENABLE_MYSQL
 };
 
 GlomCreateOptionGroup::GlomCreateOptionGroup()
 : Glib::OptionGroup("glom_create_from_example", _("Glom options"), _("Command-line options")),
   m_arg_version(false),
-  m_arg_server_port(0)
+  m_arg_server_port(0),
+  m_arg_use_mysql(false)
 {
   Glib::OptionEntry entry;
 
@@ -83,6 +89,14 @@ GlomCreateOptionGroup::GlomCreateOptionGroup()
   entry.set_short_name('d');
   entry.set_description(_("The specific database on the PostgreSQL server (Optional)."));
   add_entry(entry, m_arg_server_database);
+
+
+#ifdef GLOM_ENABLE_MYSQL
+  entry.set_long_name("use-mysql");
+  entry.set_short_name('m');
+  entry.set_description(_("Use MySQL instead of PostgreSQL."));
+  add_entry(entry, m_arg_use_mysql);
+#endif //GLOM_ENABLE_MYSQL
 }
 
 static void print_options_hint()
@@ -167,7 +181,7 @@ int main(int argc, char* argv[])
 
 #ifdef G_OS_WIN32
   const char* password = "";
-  std::cerr << _("Error: getpass() is not implemented in the Windows build. The connection will fail.") << std::endl;
+  std::cerr << "Error: getpass() is not implemented in the Windows build. The connection will fail." << std::endl;
 #else
   const char* password = ::getpass(prompt.c_str());
 #endif
@@ -177,19 +191,46 @@ int main(int argc, char* argv[])
 
   //Specify the backend and backend-specific details to be used by the connectionpool.
   //This is usually done by ConnectionPool::setup_from_document():
-  Glom::ConnectionPoolBackends::PostgresCentralHosted* backend = 
-    new Glom::ConnectionPoolBackends::PostgresCentralHosted;
-  backend->set_host(group.m_arg_server_hostname);
-
-  //Use a specified port, or try all suitable ports:
-  if(group.m_arg_server_port)
+#ifdef GLOM_ENABLE_MYSQL
+  Glom::ConnectionPoolBackends::Backend* backend = 0;
+  if(group.m_arg_use_mysql)
   {
-    backend->set_port(group.m_arg_server_port);
-    backend->set_try_other_ports(false);
+    //TODO: Move some of the *CentralHosted API into a multiply-inherited Server base class,
+    //to avoid the duplication?
+    Glom::ConnectionPoolBackends::MySQLCentralHosted* derived_backend = new Glom::ConnectionPoolBackends::MySQLCentralHosted;
+
+    //Use a specified port, or try all suitable ports:
+    if(group.m_arg_server_port)
+    {
+      derived_backend->set_port(group.m_arg_server_port);
+      derived_backend->set_try_other_ports(false);
+    }
+    else
+    {
+      derived_backend->set_try_other_ports(true);
+    }
+
+    derived_backend->set_host(group.m_arg_server_hostname);
+    backend = derived_backend;
   }
   else
+#endif //GLOM_ENABLE_MYSQL
   {
-    backend->set_try_other_ports(true);
+    Glom::ConnectionPoolBackends::PostgresCentralHosted* derived_backend = new Glom::ConnectionPoolBackends::PostgresCentralHosted;
+
+    //Use a specified port, or try all suitable ports:
+    if(group.m_arg_server_port)
+    {
+      derived_backend->set_port(group.m_arg_server_port);
+      derived_backend->set_try_other_ports(false);
+    }
+    else
+    {
+      derived_backend->set_try_other_ports(true);
+    }
+
+    derived_backend->set_host(group.m_arg_server_hostname);
+    backend = derived_backend;
   }
 
   connection_pool->set_user(group.m_arg_server_username);



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