core: Add function to get list of child ids
authorJens Georg <mail@jensge.org>
Sun, 28 Jun 2009 19:02:41 +0000 (21:02 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 9 Sep 2009 13:46:27 +0000 (16:46 +0300)
src/rygel/rygel-media-db.vala

index 5fa2edf..595e759 100644 (file)
@@ -186,6 +186,9 @@ public class Rygel.MediaDB : Object {
     private const string SWEEPER_STRING =
     "DELETE FROM Object WHERE parent IS NULL";
 
+    private const string GET_CHILD_ID_STRING =
+    "SELECT upnp_id FROM OBJECT WHERE parent = ?";
+
     private void open_db (string name) {
         var dirname = Path.build_filename (Environment.get_user_cache_dir (),
                                            Environment.get_prgname ());
@@ -639,6 +642,28 @@ public class Rygel.MediaDB : Object {
         item.color_depth = statement.column_int (15);
     }
 
+    public ArrayList<string> get_child_ids (string object_id) {
+        ArrayList<string> children = new ArrayList<string> (str_equal);
+        Statement statement;
+
+        var rc = db.prepare_v2 (GET_CHILD_ID_STRING,
+                                -1,
+                                out statement,
+                                null);
+        if (rc == Sqlite.OK) {
+            statement.bind_text (1, object_id);
+            while ((rc = statement.step ()) == Sqlite.ROW) {
+                children.add (statement.column_text (0));
+            }
+        } else {
+            warning ("Failed to get children for obj %s: %s",
+                     object_id,
+                     db.errmsg ());
+        }
+
+        return children;
+    }
+
     public int get_child_count (string object_id) {
         Statement statement;
         int count = 0;