From: Philipp Zabel Date: Sat, 9 Jan 2010 13:12:49 +0000 (+0100) Subject: IMDb SQLite: add count and has_plots methods X-Git-Tag: v0.0.10~14 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=2c46416f0ee3685871b552d7e6a4511a54aada27;p=cinaest IMDb SQLite: add count and has_plots methods --- diff --git a/src/imdb/imdb-sqlite.vala b/src/imdb/imdb-sqlite.vala index 5cf2154..2e13ef2 100644 --- a/src/imdb/imdb-sqlite.vala +++ b/src/imdb/imdb-sqlite.vala @@ -190,6 +190,33 @@ class IMDbSqlite : Object { return false; } + public int count (string table) { + string sql = "SELECT count(*) FROM %s".printf (table); + Statement stmt; + int rc; + int count = 0; + + rc = db.prepare_v2 (sql, -1, out stmt); + if (rc != Sqlite.OK) { + stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ()); + db.progress_handler (0, null); + return 0; + } + + do { + rc = stmt.step (); + if (rc == Sqlite.ROW) { + count = stmt.column_int (0); + } + } while (rc == Sqlite.ROW); + + return count; + } + + public bool has_plots () { + return (count ("Plots") > 0); + } + public int clear () { int rc;