[glom] Fix distcheck.



commit 56c08e85a7d76f47c76f7b64d7adbdd9094447ce
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Apr 12 11:48:07 2011 +0200

    Fix distcheck.
    
    * Makefile.am: Distribute the .db file for the sqlite example.
    This fixes the discheck, because we use it in a test.
    * glom/libglom/connectionpool_backends/sqlite.cc: connect(): Give clues
    on stderr if the file is missing.
    * glom/libglom/utils.[h|cc]: Add a file_exists(Gio::File) override for use
    by those checks.

 ChangeLog                                      |   11 +++++
 Makefile.am                                    |    4 +-
 glom/libglom/connectionpool_backends/sqlite.cc |   57 ++++++++++++++---------
 glom/libglom/utils.cc                          |   24 +++++-----
 glom/libglom/utils.h                           |    1 +
 5 files changed, 63 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e65a595..b331add 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-04-12  Murray Cumming  <murrayc murrayc com>
+
+	Fix distcheck.
+
+	* Makefile.am: Distribute the .db file for the sqlite example.
+	This fixes the discheck, because we use it in a test.
+	* glom/libglom/connectionpool_backends/sqlite.cc: connect(): Give clues
+	on stderr if the file is missing.
+	* glom/libglom/utils.[h|cc]: Add a file_exists(Gio::File) override for use
+	by those checks.
+
 1.19.4:
 
 2011-04-11  Murray Cumming  <murrayc murrayc com>
diff --git a/Makefile.am b/Makefile.am
index 90b8243..a2d5dcb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -96,7 +96,9 @@ dist_example_DATA =				\
 	examples/example_smallbusiness.glom
 
 # We use += because we set this first in Makefile_tests.am:
-dist_noinst_DATA += examples/sqlite/test_sqlite_music/test_sqlite_music.glom
+dist_noinst_DATA += \
+	examples/sqlite/test_sqlite_music/test_sqlite_music.glom \
+	examples/sqlite/test_sqlite_music/glom_musiccollection21.db
 
 iconthemedir = $(datadir)/icons/hicolor
 appicon16dir = $(iconthemedir)/16x16/apps
diff --git a/glom/libglom/connectionpool_backends/sqlite.cc b/glom/libglom/connectionpool_backends/sqlite.cc
index e2ee9a0..ff9cf90 100644
--- a/glom/libglom/connectionpool_backends/sqlite.cc
+++ b/glom/libglom/connectionpool_backends/sqlite.cc
@@ -19,9 +19,8 @@
  */
 
 #include <libglom/libglom_config.h>
-
 #include <libglom/connectionpool_backends/sqlite.h>
-
+#include <libglom/utils.h>
 #include <giomm/file.h>
 
 #include <iostream>
@@ -48,26 +47,40 @@ Glib::RefPtr<Gnome::Gda::Connection> Sqlite::connect(const Glib::ustring& databa
   Glib::RefPtr<Gio::File> db_dir = Gio::File::create_for_uri(m_database_directory_uri);
   Glib::RefPtr<Gio::File> db_file = db_dir->get_child(database + ".db");
 
-
-  if(db_file->query_file_type() == Gio::FILE_TYPE_REGULAR)
+  const bool file_exists = Glom::Utils::file_exists(db_file);
+  if(!file_exists)
   {
-    // Convert URI to path, for GDA connection string
-    const std::string database_directory = db_dir->get_path();
-
-    const Glib::ustring cnc_string = "DB_DIR=" + database_directory + ";DB_NAME=" + database;
-    const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
-    
-    connection = Gnome::Gda::Connection::open_from_string("SQLite", 
-      cnc_string, auth_string,
-      Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+    std::cerr << G_STRFUNC << ": The db file does not exist at path: " << db_file->get_uri() << std::endl;
+  }
+  else
+  {
+    if(db_file->query_file_type() != Gio::FILE_TYPE_REGULAR)
+    {
+      std::cerr << G_STRFUNC << ": The db file is not a regular file at path: " << db_file->get_uri() << std::endl;
+    }
+    else
+    {
+      // Convert URI to path, for GDA connection string
+      const std::string database_directory = db_dir->get_path();
+
+      const Glib::ustring cnc_string = "DB_DIR=" + database_directory + ";DB_NAME=" + database;
+      const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
+
+      connection = Gnome::Gda::Connection::open_from_string("SQLite",
+        cnc_string, auth_string,
+        Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+    }
   }
 
   if(!connection)
   {
     // If the database directory is valid, then only the database (file) is
     // missing, otherwise we pretend the "server" is not running.
-    if(db_dir->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
+    if(Glom::Utils::file_exists(db_dir) &&
+      (db_dir->query_file_type() == Gio::FILE_TYPE_DIRECTORY))
+    {
       throw ExceptionConnection(ExceptionConnection::FAILURE_NO_DATABASE);
+    }
     else
       throw ExceptionConnection(ExceptionConnection::FAILURE_NO_SERVER);
   }
@@ -84,8 +97,8 @@ bool Sqlite::create_database(const Glib::ustring& database_name, const Glib::ust
   const std::string database_directory = file->get_path();
   const Glib::ustring cnc_string = Glib::ustring::compose("DB_DIR=%1;DB_NAME=%2", database_directory, database_name);
 
-  Glib::RefPtr<Gnome::Gda::Connection> cnc = 
-    Gnome::Gda::Connection::open_from_string("SQLite", 
+  Glib::RefPtr<Gnome::Gda::Connection> cnc =
+    Gnome::Gda::Connection::open_from_string("SQLite",
       cnc_string, "",
       Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
 
@@ -262,7 +275,7 @@ bool Sqlite::recreate_table(const Glib::RefPtr<Gnome::Gda::Connection>& connecti
     if(removed_iter == fields_removed.end())
     {
       add_column_to_server_operation(operation, field, i++);
-      
+
       if(!trans_fields.empty())
         trans_fields += ',';
       Gnome::Gda::Value default_value = field->get_default_value();
@@ -298,21 +311,21 @@ bool Sqlite::recreate_table(const Glib::RefPtr<Gnome::Gda::Connection>& connecti
     std::cerr << G_STRFUNC << ": Could not begin transaction: exception=" << ex.what() << std::endl;
     return false;
   }
-  
+
   //Do everything in one big try/catch block,
   //reverting the transaction if anything fail:
   try
   {
     connection->get_provider()->perform_operation(connection, operation);
-  
+
     if(!trans_fields.empty())
     {
       connection->statement_execute_non_select(Glib::ustring("INSERT INTO \"") + TEMPORARY_TABLE_NAME + "\" SELECT " + trans_fields + " FROM \"" + table_name + "\"");
       connection->statement_execute_non_select("DROP TABLE " + table_name);
       connection->statement_execute_non_select(Glib::ustring("ALTER TABLE \"") + TEMPORARY_TABLE_NAME + "\" RENAME TO \"" + table_name + "\"");
-    
+
       connection->commit_transaction(TRANSACTION_NAME);
-    
+
       return true;
     }
   }
@@ -320,7 +333,7 @@ bool Sqlite::recreate_table(const Glib::RefPtr<Gnome::Gda::Connection>& connecti
   {
     std::cerr << G_STRFUNC << ": exception=" << ex.what() << std::endl;
     std::cerr << G_STRFUNC << ": Reverting the transaction." << std::endl;
-    
+
     try
     {
       connection->rollback_transaction(TRANSACTION_NAME);
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 6d33559..03a5ac8 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -953,18 +953,20 @@ bool Utils::file_exists(const Glib::ustring& uri)
      return false;
 
   //Check whether file exists already:
-  {
-    // Try to examine the input file.
-    Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+  // Try to examine the input file.
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+  return file_exists(file);
+}
 
-    try
-    {
-      return file->query_exists();
-    }
-    catch(const Gio::Error& /* ex */)
-    {
-      return false; //Something went wrong. It does not exist.
-    }
+bool Utils::file_exists(const Glib::RefPtr<Gio::File>& file)
+{
+  try
+  {
+    return file->query_exists();
+  }
+  catch(const Gio::Error& /* ex */)
+  {
+    return false; //Something went wrong. It does not exist.
   }
 }
 
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index 498721b..4efd0b0 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -172,6 +172,7 @@ Glib::ustring string_trim(const Glib::ustring& str, const Glib::ustring& to_remo
 Glib::ustring string_remove_suffix(const Glib::ustring& str, const Glib::ustring& suffix, bool case_sensitive = true);
 
 bool file_exists(const Glib::ustring& uri);
+bool file_exists(const Glib::RefPtr<Gio::File>& file);
 
 /** Delete a directory, if it exists, and its contents.
  * Unlike g_file_delete(), this does not fail if the directory is not empty.



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