diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2022-03-04 23:42:40 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2022-03-04 23:56:16 +0100 |
commit | 6303cd484162b7750131d69587e5d39614d44270 (patch) | |
tree | 6283ed5f113c84f6b88394954d2faae32e505adb | |
parent | 3573dd0c24aacf71f10d17a81a7d1520b3b0c570 (diff) | |
download | tracker-6303cd484162b7750131d69587e5d39614d44270.tar.gz |
libtracker-data: Pass correct variable name for non-direct types
Property types like dates or resources use wrapper functions to print
the user visible values, so the SQL query ends up as:
SELECT SparqlFormatTime("v_date") ...
And results in those variables having the unintended name (e.g.
`SparqlFormatTime("v_date")` instead of `date`. Ensure these (and
any other variable, just redundantly) get an AS alias so we get
the right variable name propagated. E.g.:
SELECT SparqlFormatTime("v_date") AS "date" ...
It is worth noting that in other places, the internal variable
name (e.g. `v_date`) is passed to the upper layers, and the v_
prefix is removed in TrackerDBCursor code. This cannot be done
here esp. for date types, since SQL places GROUP/ORDER BY at a
different level than SPARQL, so these manage to pick up the
user-visible strings instead of the more accurate timestamps.
This is not intended, so produce the final variable name in
place so the SQL does not get confused about that variable to
use.
Fixes: https://gitlab.gnome.org/GNOME/tracker/-/issues/352
-rw-r--r-- | src/libtracker-data/tracker-sparql.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c index d02686360..fa52cc85e 100644 --- a/src/libtracker-data/tracker-sparql.c +++ b/src/libtracker-data/tracker-sparql.c @@ -2968,7 +2968,9 @@ translate_SelectClause (TrackerSparql *sparql, return FALSE; } } else { - if (!found) { + if (sparql->current_state->select_context == sparql->context) { + _append_string_printf (sparql, "AS \"%s\" ", var->name); + } else if (!found) { _append_string_printf (sparql, "AS %s ", tracker_variable_get_sql_expression (var)); } |