[tracker/wip/carlosg/serialize-api: 35/53] libtracker-data: Add internal API to tell whether a query may be serialized to RDF
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/serialize-api: 35/53] libtracker-data: Add internal API to tell whether a query may be serialized to RDF
- Date: Mon, 13 Dec 2021 01:10:25 +0000 (UTC)
commit b94519e7f085c0401936f67d34b5336d617d39fd
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Nov 21 00:01:22 2021 +0100
libtracker-data: Add internal API to tell whether a query may be serialized to RDF
These are basically DESCRIBE and CONSTRUCT queries, which are guaranteed
to return data in a format that is fully serializable.
src/libtracker-data/tracker-sparql.c | 37 ++++++++++++++++++++++++++++++++++++
src/libtracker-data/tracker-sparql.h | 2 ++
2 files changed, 39 insertions(+)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 756ca07bf..aa732580c 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -10084,3 +10084,40 @@ tracker_sparql_make_langstring (const gchar *str,
return bytes;
}
+
+gboolean
+tracker_sparql_is_serializable (TrackerSparql *sparql)
+{
+ TrackerParserNode *node;
+
+ /* Updates are the other way around */
+ if (sparql->query_type == TRACKER_SPARQL_QUERY_UPDATE)
+ return FALSE;
+
+ if (!sparql->tree)
+ return FALSE;
+
+ node = tracker_node_tree_get_root (sparql->tree);
+
+ for (node = tracker_sparql_parser_tree_find_first (node, FALSE);
+ node;
+ node = tracker_sparql_parser_tree_find_next (node, FALSE)) {
+ const TrackerGrammarRule *rule;
+
+ rule = tracker_parser_node_get_rule (node);
+
+ /* Only DESCRIBE and CONSTRUCT queries apply, since these
+ * are guaranteed to return full RDF data.
+ */
+ if (tracker_grammar_rule_is_a (rule, RULE_TYPE_RULE, NAMED_RULE_DescribeQuery) ||
+ tracker_grammar_rule_is_a (rule, RULE_TYPE_RULE, NAMED_RULE_ConstructQuery))
+ return TRUE;
+
+ /* Early out in other query types */
+ if (tracker_grammar_rule_is_a (rule, RULE_TYPE_RULE, NAMED_RULE_SelectQuery) ||
+ tracker_grammar_rule_is_a (rule, RULE_TYPE_RULE, NAMED_RULE_AskQuery))
+ break;
+ }
+
+ return FALSE;
+}
diff --git a/src/libtracker-data/tracker-sparql.h b/src/libtracker-data/tracker-sparql.h
index 74297bd0a..29c881cc9 100644
--- a/src/libtracker-data/tracker-sparql.h
+++ b/src/libtracker-data/tracker-sparql.h
@@ -35,6 +35,8 @@ G_DECLARE_FINAL_TYPE (TrackerSparql, tracker_sparql,
TrackerSparql * tracker_sparql_new (TrackerDataManager *manager,
const gchar *sparql);
+gboolean tracker_sparql_is_serializable (TrackerSparql *sparql);
+
TrackerSparqlCursor * tracker_sparql_execute_cursor (TrackerSparql *sparql,
GHashTable *parameters,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]