nemiver r910 - in trunk: . src/common src/persp/dbgperspective



Author: dodji
Date: Thu Aug 21 22:01:33 2008
New Revision: 910
URL: http://svn.gnome.org/viewvc/nemiver?rev=910&view=rev

Log:
Fix #523377 - first-run prints sql-related errors to console

	* src/common/nmv-conf-manager.cc,h:
	  (ConfManager::user_config_dir_exists()): New entry point.
	  (ConfManager::get_user_config_dir_path()): Likewise.
	* src/persp/dbgperspective/nmv-sess-mgr.cc:
	  (struct SessMgr::Priv::get_db_file_path()): New entry point.
	  (struct SessMgr::Priv::db_file_path_exists): Likewise.
	  (struct SessMgr::Priv::create_db ): Do access the connection only
	  using its accessor. It guarantees that the connection is
	  instantiated when we need it.
	  (struct SessMgr::Priv::drop_db): Likewise.
	  (struct SessMgr::Priv::init_db): Don't try to drop the database
	  tables if it is obvious that no database exists yet. Create
	  the databases tables straight away instead.


Modified:
   trunk/ChangeLog
   trunk/src/common/nmv-conf-manager.cc
   trunk/src/common/nmv-conf-manager.h
   trunk/src/persp/dbgperspective/nmv-sess-mgr.cc

Modified: trunk/src/common/nmv-conf-manager.cc
==============================================================================
--- trunk/src/common/nmv-conf-manager.cc	(original)
+++ trunk/src/common/nmv-conf-manager.cc	Thu Aug 21 22:01:33 2008
@@ -36,6 +36,10 @@
 #include "nmv-conf-manager.h"
 #include "nmv-env.h"
 
+static const char *NEMIVER_CONFIG_TOP_DIR_NAME = ".nemiver";
+static const char *NEMIVER_CONFIG_DIR_NAME = "config";
+static const char *NEMIVER_CONFIG_FILE_NAME = "nemiver.conf";
+
 using namespace std ;
 using namespace Glib ;
 
@@ -261,8 +265,8 @@
     string home_dir = get_home_dir () ;
     vector<string> path_elems ;
     path_elems.push_back (home_dir) ;
-    path_elems.push_back (".nemiver") ;
-    path_elems.push_back ("config") ;
+    path_elems.push_back (NEMIVER_CONFIG_TOP_DIR_NAME) ;
+    path_elems.push_back (NEMIVER_CONFIG_DIR_NAME) ;
     string user_config_path = build_filename (path_elems) ;
 
     if (!file_test (user_config_path, FILE_TEST_IS_DIR))
@@ -270,7 +274,7 @@
                        (user_config_path.c_str (), S_IRWXU) == 0) ;
 
     string user_config_file = build_filename
-                              (user_config_path, "nemiver.conf") ;
+                              (user_config_path, NEMIVER_CONFIG_FILE_NAME) ;
 
     if (!file_test (user_config_file, FILE_TEST_EXISTS)
         && a_create_if_not_exists) {
@@ -281,6 +285,28 @@
     return get_config () ;
 }
 
+bool
+ConfManager::user_config_dir_exists ()
+{
+    if (file_test (get_user_config_dir_path (), FILE_TEST_EXISTS)) {
+        return true;
+    }
+    return false;
+}
+
+const string&
+ConfManager::get_user_config_dir_path ()
+{
+    static string user_config_dir;
+    if (user_config_dir.empty ()) {
+        vector<string> path_elems ;
+        path_elems.push_back (get_home_dir ()) ;
+        path_elems.push_back (NEMIVER_CONFIG_TOP_DIR_NAME) ;
+        user_config_dir = build_filename (path_elems) ;
+    }
+    LOG_DD ("user_config_dir: " << user_config_dir);
+    return user_config_dir;
+}
 
 void
 ConfManager::create_default_config_file (const UString a_path)

Modified: trunk/src/common/nmv-conf-manager.h
==============================================================================
--- trunk/src/common/nmv-conf-manager.h	(original)
+++ trunk/src/common/nmv-conf-manager.h	Thu Aug 21 22:01:33 2008
@@ -76,6 +76,10 @@
 
     static Config& parse_user_config_file (bool a_create_if_not_exist=true) ;
 
+    static bool user_config_dir_exists ();
+
+    static const std::string& get_user_config_dir_path ();
+
     static void create_default_config_file (const UString a_path) ;
 
     static void create_default_config_file (std::ostream &a_ostream) ;

Modified: trunk/src/persp/dbgperspective/nmv-sess-mgr.cc
==============================================================================
--- trunk/src/persp/dbgperspective/nmv-sess-mgr.cc	(original)
+++ trunk/src/persp/dbgperspective/nmv-sess-mgr.cc	Thu Aug 21 22:01:33 2008
@@ -28,6 +28,7 @@
 #include "common/nmv-tools.h"
 #include "common/nmv-transaction.h"
 #include "common/nmv-sql-statement.h"
+#include "common/nmv-conf-manager.h"
 #include "nmv-ui-utils.h"
 #include "nmv-sess-mgr.h"
 
@@ -40,6 +41,7 @@
 using nemiver::common::SQLStatement;
 
 static const char *REQUIRED_DB_SCHEMA_VERSION = "1.3";
+static const char *DB_FILE_NAME = "nemivercommon.db";
 
 NEMIVER_BEGIN_NAMESPACE (nemiver)
 
@@ -89,7 +91,7 @@
     ConnectionSafePtr connection ()
     {
         if (!conn) {
-            conn= ConnectionManager::create_db_connection ();
+            conn = ConnectionManager::create_db_connection ();
         }
         THROW_IF_FAIL (conn);
         return conn;
@@ -114,12 +116,34 @@
         return Glib::locale_to_utf8 (path);
     }
 
+    const string& get_db_file_path () const
+    {
+        static string db_file_path;
+        if (db_file_path.empty ()) {
+            vector<string> path_elems;
+            path_elems.push_back (ConfManager::get_user_config_dir_path ());
+            path_elems.push_back (DB_FILE_NAME);
+            db_file_path = Glib::build_filename (path_elems);
+        }
+        LOG_DD ("db_file_path: " << db_file_path);
+        return db_file_path;
+    }
+
+    bool db_file_path_exists () const
+    {
+        if (Glib::file_test (get_db_file_path (), Glib::FILE_TEST_EXISTS)) {
+            LOG_DD ("could not find file: " << get_db_file_path ());
+            return true;
+        }
+        return false;
+    }
+
     bool create_db ()
     {
         LOG_FUNCTION_SCOPE_NORMAL_DD;
 
         UString path_to_script = path_to_create_tables_script ();
-        Transaction transaction (*conn);
+        Transaction transaction (*connection ());
         return tools::execute_sql_command_file
                                         (path_to_script,
                                          transaction,
@@ -131,7 +155,7 @@
         LOG_FUNCTION_SCOPE_NORMAL_DD;
 
         UString path_to_script = path_to_drop_tables_script ();
-        Transaction transaction (*conn);
+        Transaction transaction (*connection ());
         return tools::execute_sql_command_file
                                         (path_to_script,
                                          transaction,
@@ -163,9 +187,14 @@
         LOG_FUNCTION_SCOPE_NORMAL_DD;
 
         NEMIVER_TRY
-        //if the db version is not what we expect, create
-        //a new db with the schema we expect.
-        if (!check_db_version ()) {
+
+        // If there is not db, create a new one with 
+        // the schema we expect.
+        if (!db_file_path_exists ()) {
+            THROW_IF_FAIL (create_db ());
+        } else if (!check_db_version ()) {
+            // If the db version is not what we expect, create
+            // a new db with the schema we expect.
             drop_db ();
             THROW_IF_FAIL (create_db ());
         }



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