Movie list, plugins: detect if there are more results than the limit
[cinaest] / src / imdb / imdb-sqlite.vala
index 7371725..5cf2154 100644 (file)
@@ -271,7 +271,7 @@ class IMDbSqlite : Object {
                if (filter.genres.field != 0) {
                        sql += sep + "Genres&%d = %d".printf (filter.genres.field, filter.genres.field);
                }
-               sql += " ORDER BY Votes DESC LIMIT %d;".printf (limit);
+               sql += " ORDER BY Votes DESC LIMIT %d;".printf (limit + 1);
 
                stdout.printf("SQL: \"%s\"\n", sql);
 
@@ -279,10 +279,13 @@ class IMDbSqlite : Object {
                if (rc != Sqlite.OK) {
                        stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
                        db.progress_handler (0, null);
-                       return 1;
+                       return 0;
                }
 
+               int n = 0;
                do {
+                       if (++n > limit)
+                               break;
                        Idle.add (query.callback);
                        yield;
                        rc = stmt.step ();
@@ -302,7 +305,7 @@ class IMDbSqlite : Object {
                } while (rc == Sqlite.ROW);
 
                db.progress_handler (0, null);
-               return 0;
+               return n;
        }
 
        private string movie_aka (string title, string match) {