IMDb SQLite: add count and has_plots methods
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 9 Jan 2010 13:12:49 +0000 (14:12 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 9 Jan 2010 13:14:47 +0000 (14:14 +0100)
src/imdb/imdb-sqlite.vala

index 5cf2154..2e13ef2 100644 (file)
@@ -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;