add dlna fields to video table.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 30 Aug 2013 15:28:58 +0000 (12:28 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 30 Aug 2013 15:49:03 +0000 (12:49 -0300)
Add new fields dlna_profile and dlna_mime to provide simple
information for applications that use it.

src/lib/lightmediascanner_db.h
src/lib/lightmediascanner_db_video.c

index c7d4fba..0459171 100644 (file)
@@ -156,6 +156,8 @@ extern "C" {
         int64_t id;
         struct lms_string_size title;
         struct lms_string_size artist;
+        struct lms_string_size dlna_profile;
+        struct lms_string_size dlna_mime;
         unsigned int length;
         struct lms_stream *streams;
     };
index 30775fc..06cd8a5 100644 (file)
@@ -111,6 +111,18 @@ _db_table_updater_videos_2(sqlite3 *db, const char *table,
     char *errmsg = NULL;
     int r;
 
+    r = sqlite3_exec(
+        db, "BEGIN TRANSACTION;"
+        "ALTER TABLE videos ADD COLUMN dlna_profile TEXT DEFAULT NULL;"
+        "ALTER TABLE videos ADD COLUMN dlna_mime TEXT DEFAULT NULL;"
+        "COMMIT;",
+        NULL, NULL, &errmsg);
+    if (r != SQLITE_OK) {
+        fprintf(stderr, "ERROR: could add columns to videos table: %s\n",
+                errmsg);
+        sqlite3_free(errmsg);
+    }
+
     /* Video streams */
     r = sqlite3_exec(db,
                      "CREATE TABLE IF NOT EXISTS videos_videos ("
@@ -309,8 +321,9 @@ lms_db_video_start(lms_db_video_t *ldv)
         return 0;
 
     ldv->insert = lms_db_compile_stmt(ldv->db,
-        "INSERT OR REPLACE INTO videos (id, title, artist, length) "
-        "VALUES (?, ?, ?, ?)");
+        "INSERT OR REPLACE INTO videos (id, title, artist, length, "
+        "dlna_profile, dlna_mime) "
+        "VALUES (?, ?, ?, ?, ?, ?)");
     if (!ldv->insert)
         return -2;
 
@@ -516,6 +529,15 @@ _db_insert(lms_db_video_t *ldv, const struct lms_video_info *info)
     if (ret != 0)
         goto done;
 
+    ret = lms_db_bind_text(stmt, 5, info->dlna_profile.str,
+                           info->dlna_profile.len);
+    if (ret != 0)
+        goto done;
+
+    ret = lms_db_bind_text(stmt, 6, info->dlna_mime.str, info->dlna_mime.len);
+    if (ret != 0)
+        goto done;
+
     r = sqlite3_step(stmt);
     if (r != SQLITE_DONE) {
         fprintf(stderr, "ERROR: could not insert video info: %s\n",