[tracker/wip/carlosg/sparql-parser-ng: 22/56] libtracker-data: Expose TrackerSparql API for updates
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql-parser-ng: 22/56] libtracker-data: Expose TrackerSparql API for updates
- Date: Tue, 13 Nov 2018 10:21:43 +0000 (UTC)
commit 1c3a6f2dca2b3eb30822fbc34f2e171260bf590b
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Aug 6 19:28:00 2018 +0200
libtracker-data: Expose TrackerSparql API for updates
src/libtracker-data/tracker-sparql.c | 54 ++++++++++++++++++++++++++++++++++++
src/libtracker-data/tracker-sparql.h | 6 ++++
2 files changed, 60 insertions(+)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 6def40023..793ddaaa4 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -97,6 +97,8 @@ struct _TrackerSparql
GPtrArray *var_names;
GArray *var_types;
+ GVariantBuilder *blank_nodes;
+
struct {
TrackerContext *context;
TrackerContext *select_context;
@@ -143,6 +145,9 @@ tracker_sparql_finalize (GObject *object)
g_ptr_array_unref (sparql->var_names);
g_array_unref (sparql->var_types);
+ if (sparql->blank_nodes)
+ g_variant_builder_unref (sparql->blank_nodes);
+
G_OBJECT_CLASS (tracker_sparql_parent_class)->finalize (object);
}
@@ -5884,3 +5889,52 @@ tracker_sparql_execute_cursor (TrackerSparql *sparql,
return TRACKER_SPARQL_CURSOR (cursor);
}
+
+TrackerSparql *
+tracker_sparql_new_update (TrackerDataManager *manager,
+ const gchar *query)
+{
+ TrackerNodeTree *tree;
+ TrackerSparql *sparql;
+
+ g_return_val_if_fail (TRACKER_IS_DATA_MANAGER (manager), NULL);
+ g_return_val_if_fail (query != NULL, NULL);
+
+ sparql = g_object_new (TRACKER_TYPE_SPARQL, NULL);
+ sparql->data_manager = g_object_ref (manager);
+ sparql->sparql = query;
+
+ tree = tracker_sparql_parse_update (sparql->sparql, -1, NULL,
+ &sparql->parser_error);
+ if (tree) {
+ sparql->tree = tree;
+ sparql->sql = tracker_string_builder_new ();
+
+ sparql->current_state.node = tracker_node_tree_get_root (sparql->tree);
+ sparql->current_state.sql = sparql->sql;
+ }
+
+ return sparql;
+}
+
+GVariant *
+tracker_sparql_execute_update (TrackerSparql *sparql,
+ gboolean blank,
+ GError **error)
+{
+ GVariant *result = NULL;
+ GVariantBuilder *blank_nodes = NULL;
+
+ if (sparql->parser_error) {
+ g_propagate_error (error, sparql->parser_error);
+ return NULL;
+ }
+
+ if (blank)
+ sparql->blank_nodes = g_variant_builder_new ((GVariantType *) "aaa{ss}");
+
+ if (!_call_rule_func (sparql, NAMED_RULE_Update, error))
+ return NULL;
+
+ return sparql->blank_nodes ? g_variant_builder_end (sparql->blank_nodes) : NULL;
+}
diff --git a/src/libtracker-data/tracker-sparql.h b/src/libtracker-data/tracker-sparql.h
index 74a52d660..bf0b3b137 100644
--- a/src/libtracker-data/tracker-sparql.h
+++ b/src/libtracker-data/tracker-sparql.h
@@ -38,4 +38,10 @@ TrackerSparql * tracker_sparql_new (TrackerDataManager *manager,
TrackerSparqlCursor * tracker_sparql_execute_cursor (TrackerSparql *sparql,
GError **error);
+TrackerSparql * tracker_sparql_new_update (TrackerDataManager *manager,
+ const gchar *query);
+GVariant * tracker_sparql_execute_update (TrackerSparql *sparql,
+ gboolean blank,
+ GError **error);
+
#endif /* __TRACKER_SPARQL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]