From 1e5d97753829f51bef13edc97adf49ffd45f7dcf Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Thu, 1 Oct 2009 19:08:41 +0200 Subject: [PATCH] core: get rid off "get_table" function --- src/rygel/rygel-database.vala | 23 --------- src/rygel/rygel-media-db.vala | 110 +++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 83 deletions(-) diff --git a/src/rygel/rygel-database.vala b/src/rygel/rygel-database.vala index 01d675e..34bfc4d 100644 --- a/src/rygel/rygel-database.vala +++ b/src/rygel/rygel-database.vala @@ -115,29 +115,6 @@ internal class Rygel.Database : Object { return statement; } - // compatibility wrapper for transition - public weak string errmsg () { - return this.db.errmsg (); - } - - public int get_table (string sql, out weak string[] schema_info, out int - nrows, out int ncolumns, void * foo) { - weak string[] _schema_info; - int _nrows; - int _ncolumns; - var ret = this.db.get_table (sql, - out _schema_info, - out _nrows, - out _ncolumns, - null); - - schema_info = _schema_info; - nrows = _nrows; - ncolumns = _ncolumns; - - return ret; - } - public int changes () { return this.db.changes (); } diff --git a/src/rygel/rygel-media-db.vala b/src/rygel/rygel-media-db.vala index 3cf5aca..957004e 100644 --- a/src/rygel/rygel-media-db.vala +++ b/src/rygel/rygel-media-db.vala @@ -273,74 +273,64 @@ public class Rygel.MediaDB : Object { private void open_db (string name) { this.db = new Rygel.Database (name); - weak string[] schema_info; - int nrows; - int ncolumns; - // FIXME error message causes segfault - var rc = db.get_table ("SELECT version FROM schema_info;", - out schema_info, - out nrows, - out ncolumns, - null); - - if (rc == Sqlite.OK) { - if (nrows == 1 && ncolumns == 1) { - if (schema_info[1] == schema_version) { - debug ("Media DB schema has current version"); - } else { - int old_version = schema_info[1].to_int(); - int current_version = schema_version.to_int(); - if (old_version < current_version) { - debug ("Older schema detected. Upgrading..."); - switch (old_version) { - case 3: - update_v3_v4 (); - break; - case 4: - update_v4_v5 (); - break; - default: - warning ("Cannot upgrade"); - db = null; - break; - } - } else { - warning ("The version \"%d\" of the detected database" + - " is newer than our supported version \"%d\"", - old_version, current_version); - db = null; + int old_version = -1; + + try { + this.db.exec ("SELECT version FROM schema_info", + null, + (stmt) => { + old_version = stmt.column_int (0); + return false; + }); + int current_version = schema_version.to_int(); + if (old_version == current_version) { + debug ("Media DB schema has current version"); + } else { + if (old_version < current_version) { + debug ("Older schema detected. Upgrading..."); + switch (old_version) { + case 3: + update_v3_v4 (); + break; + case 4: + update_v4_v5 (); + break; + default: + warning ("Cannot upgrade"); + db = null; + break; } + } else { + warning ("The version \"%d\" of the detected database" + + " is newer than our supported version \"%d\"", + old_version, current_version); + db = null; } - } else { - warning ("Incompatible schema... cannot proceed"); - db = null; - return; } - } else { + } catch (DatabaseError err) { debug ("Could not find schema version; checking for empty database..."); - rc = db.get_table ("SELECT * FROM sqlite_master", - out schema_info, - out nrows, - out ncolumns, - null); - if (rc != Sqlite.OK) { - warning ("Something weird going on: %s", - db.errmsg ()); - this.db = null; - return; - } - - if (nrows == 0) { - debug ("Empty database, creating new schema version %s", - schema_version); - if (!create_schema ()) { + try { + int rows = -1; + this.db.exec ("SELECT count(*) FROM sqlite_master", + null, + (stmt) => { + rows = stmt.column_int (0); + }); + if (rows == 0) { + debug ("Empty database, creating new schema version %s", + schema_version); + if (!create_schema ()) { + this.db = null; + return; + } + } else { + warning ("Incompatible schema... cannot proceed"); this.db = null; return; } - } else { - warning ("Incompatible schema... cannot proceed"); + } catch (DatabaseError err2) { + warning ("Something weird going on: %s", err2.message); this.db = null; - return; } } } -- 2.7.4