[tracker/wip/carlosg/inverse-functional-property-on-updates: 2/2] libtracker-sparql/core: Use boolean getter for ASK query




commit e55ae2133de063f87417216d09507e1cdcbd991e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 28 16:50:57 2022 +0200

    libtracker-sparql/core: Use boolean getter for ASK query
    
    During ontology updates, we ask our own database about changes in
    certain properties for our incompatible change checks. Specifically
    for nrl:InverseFunctionalProperty checks, we are using an ASK query
    to check for properties being such prior to the ontology updates.
    
    However, we are using the internal get_int() cursor getter, whereas
    the result of an ASK query is either a boolean, or "true"/"false"
    strings, since it's internally provided as the latter, get_int()
    falls short and always returns 0.
    
    Deal with this as a boolean using the high-level TrackerSparqlCursor
    API instead. This fixes the misdetection of changes about
    nrl:InverseFunctionalProperty properties during ontology updates,
    when possibly none was done.
    
    While at it, shuffle a bit the code to propagate errors, and free
    the cursor on all situations.

 src/libtracker-sparql/core/tracker-data-manager.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-manager.c 
b/src/libtracker-sparql/core/tracker-data-manager.c
index 33decd3e2..192bcf4a2 100644
--- a/src/libtracker-sparql/core/tracker-data-manager.c
+++ b/src/libtracker-sparql/core/tracker-data-manager.c
@@ -742,20 +742,20 @@ ensure_inverse_functional_property (TrackerDataManager  *manager,
        gchar *query;
 
        query = g_strdup_printf ("ASK { <%s> a nrl:InverseFunctionalProperty }", property_uri);
-       cursor = tracker_data_query_sparql_cursor (manager, query, NULL);
+       cursor = tracker_data_query_sparql_cursor (manager, query, error);
        g_free (query);
 
-       if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL)) {
-               if (!tracker_db_cursor_get_int (cursor, 0)) {
+       if (cursor && tracker_db_cursor_iter_next (cursor, NULL, error)) {
+               if (!tracker_sparql_cursor_get_boolean (cursor, 0)) {
                        handle_unsupported_ontology_change (manager,
                                                            NULL, -1, -1,
                                                            property_uri,
                                                            "nrl:InverseFunctionalProperty", "-", "-",
                                                            error);
                }
-
-               g_object_unref (cursor);
        }
+
+       g_clear_object (&cursor);
 }
 
 static void


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