IMDb SQLite class: set rating to -1 to indicate a NULL value in the database
[cinaest] / src / imdb / imdb-sqlite.vala
index 2e13ef2..10065c0 100644 (file)
@@ -217,6 +217,29 @@ class IMDbSqlite : Object {
                return (count ("Plots") > 0);
        }
 
+       public string get_plot (string title) {
+               string sql = "SELECT Plot FROM Plots WHERE rowid in (SELECT rowid FROM Movies WHERE Title=\"%s\")".printf (title);
+               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 "";
+               }
+
+               do {
+                       rc = stmt.step ();
+                       if (rc == Sqlite.ROW) {
+                               return stmt.column_text (0).replace (""", "\"");
+                       }
+               } while (rc == Sqlite.ROW);
+
+               return "";
+       }
+
        public int clear () {
                int rc;
 
@@ -319,7 +342,11 @@ class IMDbSqlite : Object {
                        if (rc == Sqlite.ROW) {
                                int year = stmt.column_int (1);
                                string title = stmt.column_text (0);
-                               int rating = stmt.column_int (2);
+                               int rating;
+                               if (stmt.column_type (2) != Sqlite.NULL)
+                                       rating = stmt.column_int (2);
+                               else
+                                       rating = -1;
                                int genres = stmt.column_int (3);
                                string aka = null;
                                if (match != null && !(filter.matches_title (strip_year (title, year)))) {
@@ -335,7 +362,7 @@ class IMDbSqlite : Object {
                return n;
        }
 
-       private string movie_aka (string title, string match) {
+       private string? movie_aka (string title, string match) {
                string sql = "SELECT Aka FROM Akas WHERE (TitleID = (SELECT rowid FROM Movies WHERE Title = \"%s\") AND Aka %s) LIMIT 1;".printf (title, match);
                Statement stmt;
                int rc;