[rygel] media-export: Handle null SearchExpression



commit 73c0196db2c47374423f3d46c6e8baafcf4feeb9
Author: Jens Georg <mail jensge org>
Date:   Wed Aug 4 19:45:38 2010 +0300

    media-export: Handle null SearchExpression
    
    Let the database to the dirty work

 .../rygel-media-export-db-container.vala           |    7 ---
 .../rygel-media-export-media-cache.vala            |   52 +++++++++----------
 2 files changed, 25 insertions(+), 34 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index 54bd5a9..142cd0d 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -70,13 +70,6 @@ public class Rygel.MediaExport.DBContainer : MediaContainer {
                                                 out uint          total_matches,
                                                 Cancellable?      cancellable)
                                                 throws GLib.Error {
-        if (expression == null) {
-            return yield base.search (expression,
-                                      offset,
-                                      max_count,
-                                      out total_matches,
-                                      cancellable);
-        }
         MediaObjects children = null;
 
         var max_objects = max_count;
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 89944fc..c281a2f 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -177,8 +177,7 @@ public class Rygel.MediaExport.MediaCache : Object {
     "FROM Object o " +
         "JOIN Closure c ON o.upnp_id = c.descendant AND c.ancestor = ? " +
         "LEFT OUTER JOIN meta_data m " +
-            "ON o.upnp_id = m.object_fk " +
-    "WHERE %s " +
+            "ON o.upnp_id = m.object_fk %s" +
         "ORDER BY o.parent ASC, " +
                  "o.type_fk ASC, " +
                  "m.class ASC, " +
@@ -191,9 +190,7 @@ public class Rygel.MediaExport.MediaCache : Object {
     "SELECT COUNT(o.type_fk) FROM Object o " +
         "JOIN Closure c ON o.upnp_id = c.descendant AND c.ancestor = ? " +
         "JOIN meta_data m " +
-            "ON o.upnp_id = m.object_fk " +
-    "WHERE %s ";
-
+            "ON o.upnp_id = m.object_fk %s";
 
     private const string CHILDREN_COUNT_STRING =
     "SELECT COUNT(upnp_id) FROM Object WHERE Object.parent = ?";
@@ -365,15 +362,13 @@ public class Rygel.MediaExport.MediaCache : Object {
                                         out uint          total_matches)
                                         throws Error {
         var args = new GLib.ValueArray (0);
-        var filter = this.search_expression_to_sql (expression, args);
+        var filter = this.translate_search_expression (expression, args);
 
-        if (filter == null) {
-            return new MediaObjects ();
+        if (expression != null) {
+            debug ("Original search: %s", expression.to_string ());
+            debug ("Parsed search expression: %s", filter);
         }
 
-        debug ("Original search: %s", expression.to_string ());
-        debug ("Parsed search expression: %s", filter);
-
         for (int i = 0; i < args.n_values; i++) {
             debug ("Arg %d: %s", i, args.get_nth (i).get_string ());
         }
@@ -399,15 +394,13 @@ public class Rygel.MediaExport.MediaCache : Object {
                                         uint              max_count)
                                         throws Error {
         var args = new GLib.ValueArray (0);
-        var filter = this.search_expression_to_sql (expression, args);
+        var filter = this.translate_search_expression (expression, args);
 
-        if (filter == null) {
-            return 0;
+        if (expression != null) {
+            debug (_("Original search: %s"), expression.to_string ());
+            debug (_("Parsed search expression: %s"), filter);
         }
 
-        debug (_("Original search: %s"), expression.to_string ());
-        debug (_("Parsed search expression: %s"), filter);
-
         for (int i = 0; i < args.n_values; i++) {
             debug ("Arg %d: %s", i, args.get_nth (i).get_string ());
         }
@@ -726,18 +719,28 @@ public class Rygel.MediaExport.MediaCache : Object {
         return children;
     }
 
+    private string translate_search_expression (SearchExpression? expression,
+                                                ValueArray        args)
+                                                throws Error {
+        if (expression == null) {
+            return "";
+        }
+
+        return " WHERE " + this.search_expression_to_sql (expression, args);
+    }
+
     private string? search_expression_to_sql (SearchExpression? expression,
                                              GLib.ValueArray   args)
                                              throws Error {
         if (expression == null) {
-            return null;
+            return "";
         }
 
         if (expression is LogicalExpression) {
-            return logical_expression_to_sql (expression as LogicalExpression,
-                                              args);
+            return this.logical_expression_to_sql (expression as LogicalExpression,
+                                                   args);
         } else {
-            return relational_expression_to_sql (
+            return this.relational_expression_to_sql (
                                         expression as RelationalExpression,
                                         args);
         }
@@ -895,12 +898,7 @@ public class Rygel.MediaExport.MediaCache : Object {
                                         long              max_count)
                                         throws Error {
         var args = new ValueArray (0);
-        var filter = this.search_expression_to_sql (expression, args);
-        if (filter != null) {
-            filter = " WHERE %s ".printf (filter);
-        } else {
-            filter = "";
-        }
+        var filter = this.translate_search_expression (expression, args);
 
         debug ("Parsed filter: %s", filter);
 



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