[tracker/wip/halfline/photos-album-fix] libtracker-data: Allow text based row id inputs to SparqlPrintIRI()




commit 80a4d2089e44f45ac72c4033c64625bc8ff42708
Author: Ray Strode <rstrode redhat com>
Date:   Fri May 6 09:54:10 2022 -0400

    libtracker-data: Allow text based row id inputs to SparqlPrintIRI()
    
    Since commit 6cf3168302350f3fd3ef7f8bf79022950563300e tracker sometimes
    returns an unqualified row id to applications that are asking for
    a fully qualfied blank node urn.
    
    This is because sometimes it generates urn with a text type instead of
    an IRI type.
    
    The result is that gnome-photos fails to match up album collections internally
    between different queries, because sometimes tracker returns the fully
    qualified urn and sometimes it returns the bare row id.
    
    This commit address the problem by making `SparqlPrintIRI()` more
    lenient in its inputs. It already properly parses a text input and it already
    properly parses a numeric input, but now it also parses  number stored as a text
    input.
    
    Closes https://gitlab.gnome.org/GNOME/tracker/-/issues/363

 .../core/tracker-db-interface-sqlite.c                  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index 49f6764f4..7b19d9e57 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -1905,13 +1905,28 @@ function_sparql_print_iri (sqlite3_context *context,
                            sqlite3_value   *argv[])
 {
        const gchar *fn = "PrintIRI helper";
+       sqlite3_value *row_id_value = NULL;
+       gboolean row_id_passed_in = FALSE;
 
        if (argc > 1) {
                result_context_function_error (context, fn, "Invalid argument count");
                return;
        }
 
-       if (sqlite3_value_type (argv[0]) == SQLITE_INTEGER) {
+       /* See if the input argument parses as an unqualified row id.
+        * Note we duplicate the input argument when performing the
+        * check because sqlite3_value_numeric_type modifies the value
+        * type of its argument, and that would be undesirable if e.g.
+        * the argument was a valid number but not a valid row id
+        * (e.g., a floating point number or negative number).
+        */
+       row_id_value = sqlite3_value_dup (argv[0]);
+       if (sqlite3_value_numeric_type (row_id_value) == SQLITE_INTEGER) {
+               row_id_passed_in = sqlite3_value_int64 (row_id_value) >= 0;
+       }
+       g_clear_pointer (&row_id_value, sqlite3_value_free);
+
+       if (row_id_passed_in) {
                sqlite3_stmt *stmt;
                gboolean store_auxdata = FALSE;
                sqlite3 *db;


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