[grilo-plugins/wip/carlosg/tracker3: 24/48] tracker3: Port test_media_from_uri() to the statement cache




commit e8b6b97b4864002324a33592571e624f208a4a60
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 22 16:32:01 2020 +0200

    tracker3: Port test_media_from_uri() to the statement cache
    
    This is essentially a GRL_TRACKER_QUERY_MEDIA_FROM_URI with no
    additional keys or filters.

 src/tracker3/grl-tracker-source-api.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index 44bbb970..7934c425 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -129,15 +129,6 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
   "DELETE { <%s> %s } WHERE { <%s> a nfo:Media . %s } " \
   "INSERT { <%s> a nfo:Media ; %s . }"
 
-#define TRACKER_TEST_MEDIA_FROM_URI_REQUEST             \
-  "SELECT ?urn "                                        \
-  "WHERE "                                              \
-  "{ "                                                  \
-  "?urn nie:url \"%s\" ; "                              \
-  "tracker:available true ; "                           \
-  "a nfo:Media . "                                      \
-  "}"
-
 /**/
 
 /**/
@@ -1262,20 +1253,24 @@ gboolean
 grl_tracker_source_test_media_from_uri (GrlSource *source,
                                         const gchar *uri)
 {
-  GrlTrackerSourcePriv *priv  = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
   GError               *error = NULL;
   TrackerSparqlCursor  *cursor;
+  TrackerSparqlStatement *statement;
   gboolean              empty;
-  gchar                *sparql_final;
 
-  sparql_final = g_strdup_printf (TRACKER_TEST_MEDIA_FROM_URI_REQUEST,
-                                  uri);
+  statement = grl_tracker_source_create_statement (GRL_TRACKER_SOURCE (source),
+                                                   GRL_TRACKER_QUERY_MEDIA_FROM_URI,
+                                                   NULL, NULL, NULL,
+                                                   &error);
+  if (!statement) {
+    g_critical ("Error creating statement: %s", error->message);
+    g_error_free (error);
+    return FALSE;
+  }
 
-  cursor = tracker_sparql_connection_query (grl_tracker_connection,
-                                            sparql_final,
-                                            NULL,
-                                            &error);
-  g_free (sparql_final);
+  tracker_sparql_statement_bind_string (statement, "uri", uri);
+  cursor = tracker_sparql_statement_execute (statement, NULL, &error);
+  g_object_unref (statement);
 
   if (error) {
     GRL_WARNING ("Error when executig sparql query: %s",


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