[tracker/wip/carlosg/tracker-3.0-api-breaks: 91/95] libtracker-sparql: Be lenient in generic tracker_sparql_cursor_get_*() methods



commit 7efa617d7ad353c6e5364157214255daa98431c8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Feb 5 11:53:55 2020 +0100

    libtracker-sparql: Be lenient in generic tracker_sparql_cursor_get_*() methods
    
    The default implementation for get_integer/double/boolean cursor methods
    only transformed the underlying string if the column type matches.
    
    However the direct connection (and SQLite underneath) are more lenient with
    that, doing implicit casts even though the type does not imply numbers.
    Doing the same in the default methods results in other cursors (eg. DBus)
    behaving the same.

 src/libtracker-sparql/tracker-cursor.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-cursor.c b/src/libtracker-sparql/tracker-cursor.c
index 65438840b..7ef716a7c 100644
--- a/src/libtracker-sparql/tracker-cursor.c
+++ b/src/libtracker-sparql/tracker-cursor.c
@@ -59,42 +59,30 @@ static gint64
 tracker_sparql_cursor_real_get_integer (TrackerSparqlCursor *cursor,
                                         gint                 column)
 {
-       if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_INTEGER) {
-               const gchar *text;
+       const gchar *text;
 
-               text = tracker_sparql_cursor_get_string (cursor, column, NULL);
-               return g_ascii_strtoll (text, NULL, 10);
-       }
-
-       return 0;
+       text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+       return g_ascii_strtoll (text, NULL, 10);
 }
 
 static gdouble
 tracker_sparql_cursor_real_get_double (TrackerSparqlCursor *cursor,
                                        gint                 column)
 {
-       if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_DOUBLE) {
-               const gchar *text;
-
-               text = tracker_sparql_cursor_get_string (cursor, column, NULL);
-               return g_ascii_strtod (text, NULL);
-       }
+       const gchar *text;
 
-       return 0.0;
+       text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+       return g_ascii_strtod (text, NULL);
 }
 
 static gboolean
 tracker_sparql_cursor_real_get_boolean (TrackerSparqlCursor *cursor,
                                         gint                 column)
 {
-       if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_BOOLEAN) {
-               const gchar *text;
-
-               text = tracker_sparql_cursor_get_string (cursor, column, NULL);
-               return g_ascii_strcasecmp (text, "true") == 0;
-       }
+       const gchar *text;
 
-       return FALSE;
+       text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+       return g_ascii_strcasecmp (text, "true") == 0;
 }
 
 static gboolean


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