glom r1804 - in trunk: . glom glom/libglom/connectionpool_backends



Author: jhs
Date: Mon Dec 15 11:34:36 2008
New Revision: 1804
URL: http://svn.gnome.org/viewvc/glom?rev=1804&view=rev

Log:
2008-12-15  Johannes Schmid  <jhs Obelix>

	* glom/frame_glom.cc:
	Fixed a warning (actually avoided a sprintf completely...)
	
	* glom/libglom/connectionpool_backends/postgres_central.cc:
	* glom/libglom/connectionpool_backends/postgres_central.h:
	* glom/libglom/connectionpool_backends/postgres_self.cc:
	Fixed creating of databases. Database is no created though things break
	at a latter stage.

Modified:
   trunk/ChangeLog
   trunk/glom/frame_glom.cc
   trunk/glom/libglom/connectionpool_backends/postgres_central.cc
   trunk/glom/libglom/connectionpool_backends/postgres_central.h
   trunk/glom/libglom/connectionpool_backends/postgres_self.cc

Modified: trunk/glom/frame_glom.cc
==============================================================================
--- trunk/glom/frame_glom.cc	(original)
+++ trunk/glom/frame_glom.cc	Mon Dec 15 11:34:36 2008
@@ -1743,8 +1743,7 @@
     else
     {
       //Create a new database name by appending a number to the original name:
-      char pchExtraNum[10];
-      sprintf(pchExtraNum, "%d", extra_num);
+      Glib::ustring pchExtraNum = Glib::ustring::compose("%1", extra_num);
       database_name_possible = (database_name + pchExtraNum);
     }
     ++extra_num;

Modified: trunk/glom/libglom/connectionpool_backends/postgres_central.cc
==============================================================================
--- trunk/glom/libglom/connectionpool_backends/postgres_central.cc	(original)
+++ trunk/glom/libglom/connectionpool_backends/postgres_central.cc	Mon Dec 15 11:34:36 2008
@@ -130,7 +130,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
+    Glib::ustring auth_string = create_auth_string(username, password);
     connection = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string);
     
     connection->statement_execute_non_select("SET DATESTYLE = 'ISO'");
@@ -140,10 +140,9 @@
   {
 #else
   std::auto_ptr<Glib::Error> error;
-  Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
+  Glib::ustring auth_string = create_auth_string(username, password);
   connection = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string, Gnome::Gda::CONNECTION_OPTIONS_NONE, error);
   
-  Glib::RefPtr<Gnome::Gda::SqlParser> parser = connection->create_parser();
   if(!error)
       connection->statement_execute_non_select("SET DATESTYLE = 'ISO'", error);
 
@@ -162,7 +161,7 @@
 
     Glib::ustring cnc_string = cnc_string_main + ";DB_NAME=" + default_database;
     Glib::RefPtr<Gnome::Gda::Connection> temp_conn;
-    const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
+    Glib::ustring auth_string = create_auth_string(username, password);
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
     try
     {
@@ -269,16 +268,12 @@
 #ifndef GLOM_ENABLE_CLIENT_ONLY
 bool PostgresCentralHosted::create_database(const Glib::ustring& database_name, const Glib::ustring& username, const Glib::ustring& password, std::auto_ptr<Glib::Error>& error)
 {
-  const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
-  const Glib::ustring cnc_string = Glib::ustring::compose("HOST=%1;PORT=%2", get_host(), get_port());
-  Glib::RefPtr<Gnome::Gda::Set> set = Gnome::Gda::Set::create();
-  Glib::RefPtr<Gnome::Gda::Connection> cnc;
   Glib::RefPtr<Gnome::Gda::ServerOperation> op;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-     cnc = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string);
-     op = cnc->create_operation(Gnome::Gda::SERVER_OPERATION_CREATE_DB, set);
+    op = Gnome::Gda::ServerOperation::prepare_create_database("PostgreSQL",
+                                                              database_name);
   }
   catch(const Glib::Error& ex)
   {
@@ -286,8 +281,10 @@
     return false;
   }
 #else
-  cnc = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string, 
-                                                 Gnome::Gda::CONNECTION_OPTIONS_NONE, error);
+  std::auto_ptr<Glib::Error> error;
+  op = Gnome::Gda::ServerOperation::prepare_create_database("PostgreSQL",
+                                                            database_name,
+                                                            error);
   if(error)
     return false;
 
@@ -299,12 +296,11 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    op->set_value_at("/DB_DEF_P/DB_NAME", database_name);
     op->set_value_at("/SERVER_CNX_P/HOST", get_host());
     op->set_value_at("/SERVER_CNX_P/PORT", port_as_string(m_port));
     op->set_value_at("/SERVER_CNX_P/ADM_LOGIN", username);
     op->set_value_at("/SERVER_CNX_P/ADM_PASSWORD", password);
-    cnc->perform_operation(op);
+    op->perform_create_database("PostgreSQL");
   }
   catch(const Glib::Error& ex)
   {
@@ -312,14 +308,13 @@
     return false;
   }
 #else
-  op->set_value_at("/DB_DEF_P/DB_NAME", database_name, error);
   op->set_value_at("/SERVER_CNX_P/HOST", get_host(), error);
   op->set_value_at("/SERVER_CNX_P/PORT", port_as_string(m_port), error);
   op->set_value_at("/SERVER_CNX_P/ADM_LOGIN", username, error);
   op->set_value_at("/SERVER_CNX_P/ADM_PASSWORD", password, error);
 
-  if(error.get() != NULL)
-    cnc->perform_operation(op, error);
+  if(error.get() == 0)
+    op->perform_create_database("PostgreSQL");
   else
     return false;
 #endif
@@ -362,6 +357,11 @@
   return true;
 }
 
+Glib::ustring PostgresCentralHosted::create_auth_string (const Glib::ustring& username, const Glib::ustring& password)
+{
+  return "USERNAME=" + username + ";PASSWORD=" + password;
+}
+
 }
 
 }

Modified: trunk/glom/libglom/connectionpool_backends/postgres_central.h
==============================================================================
--- trunk/glom/libglom/connectionpool_backends/postgres_central.h	(original)
+++ trunk/glom/libglom/connectionpool_backends/postgres_central.h	Mon Dec 15 11:34:36 2008
@@ -86,6 +86,8 @@
   bool m_try_other_ports;
 
   float m_postgres_server_version;
+  
+  static Glib::ustring create_auth_string(const Glib::ustring& username, const Glib::ustring& password);
 };
 
 } //namespace ConnectionPoolBackends

Modified: trunk/glom/libglom/connectionpool_backends/postgres_self.cc
==============================================================================
--- trunk/glom/libglom/connectionpool_backends/postgres_self.cc	(original)
+++ trunk/glom/libglom/connectionpool_backends/postgres_self.cc	Mon Dec 15 11:34:36 2008
@@ -481,17 +481,12 @@
 #ifndef GLOM_ENABLE_CLIENT_ONLY
 bool PostgresSelfHosted::create_database(const Glib::ustring& database_name, const Glib::ustring& username, const Glib::ustring& password, std::auto_ptr<Glib::Error>& error)
 {
-  const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
-  const Glib::ustring cnc_string = Glib::ustring::compose("HOST=localhost;PORT=%1;DB_NAME=%2", m_port, database_name);
-  Glib::RefPtr<Gnome::Gda::Set> set = Gnome::Gda::Set::create();
-  Glib::RefPtr<Gnome::Gda::Connection> cnc;
   Glib::RefPtr<Gnome::Gda::ServerOperation> op;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    cnc = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string);
-    cnc = Gnome::Gda::Connection::create();
-    op = cnc->create_operation(Gnome::Gda::SERVER_OPERATION_CREATE_DB, set);
+    op = Gnome::Gda::ServerOperation::prepare_create_database("PostgreSQL",
+                                                              database_name);
   }
   catch(const Glib::Error& ex)
   {
@@ -499,8 +494,10 @@
     return false;
   }
 #else
-  cnc = Gnome::Gda::Connection::open_from_string("PostgreSQL", cnc_string, auth_string, 
-                                                 Gnome::Gda::CONNECTION_OPTIONS_NONE, error);
+  std::auto_ptr<Glib::Error> error;
+  op = Gnome::Gda::ServerOperation::prepare_create_database("PostgreSQL",
+                                                            database_name,
+                                                            error);
   if(error)
     return false;
 
@@ -512,12 +509,11 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    op->set_value_at("/DB_DEF_P/DB_NAME", database_name);
     op->set_value_at("/SERVER_CNX_P/HOST", "localhost");
     op->set_value_at("/SERVER_CNX_P/PORT", port_as_string(m_port));
     op->set_value_at("/SERVER_CNX_P/ADM_LOGIN", username);
     op->set_value_at("/SERVER_CNX_P/ADM_PASSWORD", password);
-    cnc->perform_operation(op);
+    op->perform_create_database("PostgreSQL");
   }
   catch(const Glib::Error& ex)
   {
@@ -525,14 +521,13 @@
     return false;
   }
 #else
-  op->set_value_at("/DB_DEF_P/DB_NAME", database_name, error);
   op->set_value_at("/SERVER_CNX_P/HOST", "localhost", error);
   op->set_value_at("/SERVER_CNX_P/PORT", port_as_string(m_port), error);
   op->set_value_at("/SERVER_CNX_P/ADM_LOGIN", username, error);
   op->set_value_at("/SERVER_CNX_P/ADM_PASSWORD", password, error);
 
-  if(error.get() != NULL)
-    cnc->perform_operation(op, error);
+  if(error.get() == 0)
+    op->perform_create_database("PostgreSQL");
   else
     return false;
 #endif



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