[tracker/wip/carlosg/property-paths: 4/6] libtracker-data: Implement PathMod
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/property-paths: 4/6] libtracker-data: Implement PathMod
- Date: Wed, 26 Dec 2018 12:24:20 +0000 (UTC)
commit 862b1617269f5466c658b9a01366f0a399e44a14
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Dec 24 18:35:18 2018 +0100
libtracker-data: Implement PathMod
All three modifiers in PathMod are implemented now:
- ?(zero or one): { ?u nfo:belongsToContainer? ?c } returns direct
children of ?c, plus ?c itself.
- *(zero or more): { ?u nfo:belongsToContainer* ?c } returns all children
of ?c recursively, including ?c itself.
- +(one or more): { ?u nfo:belongsToContainer+ ?c } returns all children
of ?c recursively.
src/libtracker-data/tracker-sparql.c | 60 +++++++++++++++++++++++++++++++++++-
1 file changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index a1befd7f5..d2e9477c4 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -570,6 +570,46 @@ _prepend_path_element (TrackerSparql *sparql,
path_elem->data.composite.child1->name,
path_elem->data.composite.child2->name);
break;
+ case TRACKER_PATH_OPERATOR_ZEROORMORE:
+ _append_string_printf (sparql,
+ "\"%s\" (ID, value, graph) AS "
+ "(SELECT ID, ID, graph "
+ "FROM \"%s\" "
+ "UNION "
+ "SELECT a.ID, b.value, b.graph "
+ "FROM \"%s\" AS a, \"%s\" AS b "
+ "WHERE b.ID = a.value) ",
+ path_elem->name,
+ path_elem->data.composite.child1->name,
+ path_elem->data.composite.child1->name,
+ path_elem->name);
+ break;
+ case TRACKER_PATH_OPERATOR_ONEORMORE:
+ _append_string_printf (sparql,
+ "\"%s\" (ID, value, graph) AS "
+ "(SELECT ID, value, graph "
+ "FROM \"%s\" "
+ "UNION "
+ "SELECT a.ID, b.value, b.graph "
+ "FROM \"%s\" AS a, \"%s\" AS b "
+ "WHERE b.ID = a.value) ",
+ path_elem->name,
+ path_elem->data.composite.child1->name,
+ path_elem->data.composite.child1->name,
+ path_elem->name);
+ break;
+ case TRACKER_PATH_OPERATOR_ZEROORONE:
+ _append_string_printf (sparql,
+ "\"%s\" (ID, value, graph) AS "
+ "(SELECT ID, ID, graph "
+ "FROM \"%s\" "
+ "UNION ALL "
+ "SELECT ID, value, graph "
+ "FROM \"%s\") ",
+ path_elem->name,
+ path_elem->data.composite.child1->name,
+ path_elem->data.composite.child1->name);
+ break;
default:
g_assert_not_reached ();
break;
@@ -4270,9 +4310,27 @@ static gboolean
translate_PathMod (TrackerSparql *sparql,
GError **error)
{
+ TrackerPathElement *path_elem;
+ TrackerPathOperator op;
+
/* PathMod ::= '?' | '*' | '+'
*/
- _unimplemented ("Path modifiers");
+ if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_PATH_STAR)) {
+ op = TRACKER_PATH_OPERATOR_ZEROORMORE;
+ } else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_PATH_PLUS)) {
+ op = TRACKER_PATH_OPERATOR_ONEORMORE;
+ } else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_PATH_OPTIONAL)) {
+ op = TRACKER_PATH_OPERATOR_ZEROORONE;
+ } else {
+ return TRUE;
+ }
+
+ path_elem = tracker_path_element_operator_new (op, sparql->current_state.path, NULL);
+ tracker_select_context_add_path_element (TRACKER_SELECT_CONTEXT (sparql->context),
+ path_elem);
+ _prepend_path_element (sparql, path_elem);
+ sparql->current_state.path = path_elem;
+ return TRUE;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]