Catalog plugin: add count method
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 18 Nov 2009 12:16:25 +0000 (13:16 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 18 Nov 2009 14:36:49 +0000 (15:36 +0100)
src/plugins/catalog-sqlite.vala

index cc55361..653dc99 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;