Convert Google plugin into a D-Bus service
[cinaest] / src / plugins / catalog-sqlite.vala
index cc55361..1e8d068 100644 (file)
@@ -81,6 +81,29 @@ class CatalogSqlite : Object {
                return 0;
        }
 
+       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 contains (string table, Movie movie) {
                string sql = "SELECT count(*) FROM %s WHERE Title=\"%s\" AND Year=%d".printf (table, movie.title, movie.year);
                Statement stmt;
@@ -155,7 +178,7 @@ class CatalogSqlite : Object {
                        sep = " AND ";
                }
                if (filter.rating_min > 0) {
-                       sql += sep + "Rating >= = %d".printf (filter.rating_min);
+                       sql += sep + "Rating >= %d".printf (filter.rating_min);
                        sep = " AND ";
                }
                if (filter.genres.field != 0) {