[rygel] media-export,db: Add method to check for valid database



commit c1173e63ae3a96db320751ecb1dffd07564071d2
Author: Jens Georg <mail jensge org>
Date:   Wed Apr 20 22:48:39 2016 +0200

    media-export,db: Add method to check for valid database
    
    Signed-off-by: Jens Georg <mail jensge org>

 src/librygel-db/database.vala                      |   11 +++++++++++
 .../rygel-media-export-media-cache.vala            |    4 +---
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/librygel-db/database.vala b/src/librygel-db/database.vala
index 0be0257..aded52c 100644
--- a/src/librygel-db/database.vala
+++ b/src/librygel-db/database.vala
@@ -307,4 +307,15 @@ public class Rygel.Database.Database : Object, Initable {
                       error.message);
         }
     }
+
+    /**
+     * Check for an empty SQLite database.
+     * @return true if the file is an empty SQLite database, false otherwise
+     * @throws DatabaseError if the SQLite meta table does not exist which
+     * usually indicates that the file is not a databsae
+     */
+    public bool is_empty () throws DatabaseError {
+        return this.query_value ("SELECT count(type) FROM " +
+                                 "sqlite_master WHERE rowid = 1") == 0;
+    }
 }
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala 
b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 272e21d..c095d9b 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -676,9 +676,7 @@ public class Rygel.MediaExport.MediaCache : Object {
             debug ("Could not find schema version;" +
                    " checking for empty database...");
             try {
-                var rows = this.db.query_value ("SELECT count(type) FROM " +
-                                                "sqlite_master WHERE rowid=1");
-                if (rows == 0) {
+                if (this.db.is_empty ()) {
                     debug ("Empty database, creating new schema version %s",
                             SQLFactory.SCHEMA_VERSION);
                     if (!create_schema ()) {


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