[rygel] media-db: Fix upgrade from db v4 to v5



commit 5d1a5823ad7d5f3fc16632a7b16c76892a023f9d
Author: Jens Georg <mail jensge org>
Date:   Sat Apr 10 21:24:22 2010 +0200

    media-db: Fix upgrade from db v4 to v5

 src/rygel/rygel-media-db.vala |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/src/rygel/rygel-media-db.vala b/src/rygel/rygel-media-db.vala
index 774006f..c1f527f 100644
--- a/src/rygel/rygel-media-db.vala
+++ b/src/rygel/rygel-media-db.vala
@@ -660,6 +660,7 @@ public class Rygel.MediaDB : Object {
     }
 
     private void update_v4_v5 () {
+        Gee.Queue<string> queue = new LinkedList<string> ();
         try {
             db.begin ();
             db.exec ("DROP TRIGGER IF EXISTS trgr_delete_children");
@@ -669,7 +670,26 @@ public class Rygel.MediaDB : Object {
             db.exec ("CREATE TABLE Object AS SELECT * FROM _Object");
             db.exec ("DELETE FROM Object");
             db.exec (CREATE_CLOSURE_TRIGGER_STRING);
-            db.exec ("INSERT INTO Object SELECT * FROM _Object");
+            db.exec ("INSERT INTO _Object (upnp_id, type_fk, title, " +
+                     "timestamp) VALUES ('0', 0, 'Root', 0)");
+            db.exec ("INSERT INTO Object (upnp_id, type_fk, title, " +
+                     "timestamp) VALUES ('0', 0, 'Root', 0)");
+
+            queue.offer ("0");
+            while (!queue.is_empty) {
+                GLib.Value[] args = { queue.poll () };
+                db.exec ("SELECT upnp_id FROM _Object WHERE parent = ?",
+                         args,
+                         (statement) => {
+                            queue.offer (statement.column_text (0));
+
+                            return true;
+                         });
+
+                db.exec ("INSERT INTO Object SELECT * FROM _OBJECT " +
+                         "WHERE parent = ?",
+                         args);
+            }
             db.exec ("DROP TABLE Object");
             db.exec ("ALTER TABLE _Object RENAME TO Object");
             // the triggers created above have been dropped automatically



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]