[tracker/wip/carlosg/anonymous-nodes: 30/46] libtracker-data: Use TrackerProperty for predicate in tracker_data_*_statement()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/anonymous-nodes: 30/46] libtracker-data: Use TrackerProperty for predicate in tracker_data_*_statement()
- Date: Sun, 12 Dec 2021 14:15:41 +0000 (UTC)
commit 10fb35577fd0b8bf321d995e848eb522a67e2b9b
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Sep 21 18:26:06 2021 +0200
libtracker-data: Use TrackerProperty for predicate in tracker_data_*_statement()
These strings may only be URIs identifying properties set in the ontology.
Make it the caller's business to find the corresponding TrackerProperty.
src/libtracker-data/tracker-data-manager.c | 45 +++-
src/libtracker-data/tracker-data-update.c | 325 +++++++++++++----------------
src/libtracker-data/tracker-data-update.h | 6 +-
src/libtracker-data/tracker-sparql.c | 27 ++-
4 files changed, 213 insertions(+), 190 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 6a74e1fb1..a5617a7e3 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -508,6 +508,8 @@ update_property_value (TrackerDataManager *manager,
TrackerProperty *property,
GError **error_in)
{
+ TrackerOntologies *ontologies;
+ TrackerProperty *pred;
GError *error = NULL;
gboolean needed = TRUE;
gboolean is_new = FALSE;
@@ -528,6 +530,16 @@ update_property_value (TrackerDataManager *manager,
column_no = tracker_property_get_definition_column_no (property);
}
+ ontologies = tracker_data_manager_get_ontologies (manager);
+ pred = tracker_ontologies_get_property_by_uri (ontologies, predicate);
+ if (!pred) {
+ g_set_error (error_in, TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology",
+ predicate);
+ return FALSE;
+ }
+
if (!is_new) {
gchar *query = NULL;
TrackerDBCursor *cursor;
@@ -564,7 +576,7 @@ update_property_value (TrackerDataManager *manager,
if (!unsup_onto_err) {
bytes = g_bytes_new (str, strlen (str) + 1);
- tracker_data_delete_statement (manager->data_update, NULL, subject,
predicate, bytes, &error);
+ tracker_data_delete_statement (manager->data_update, NULL, subject,
pred, bytes, &error);
g_bytes_unref (bytes);
if (!error)
@@ -591,7 +603,7 @@ update_property_value (TrackerDataManager *manager,
if (!error && needed && object) {
bytes = g_bytes_new (object, strlen (object) + 1);
tracker_data_insert_statement (manager->data_update, NULL, subject,
- predicate, bytes,
+ pred, bytes,
&error);
g_bytes_unref (bytes);
@@ -1441,7 +1453,8 @@ check_for_deleted_domain_index (TrackerDataManager *manager,
TrackerClass *class,
GError **error)
{
- TrackerProperty **last_domain_indexes;
+ TrackerProperty **last_domain_indexes, *property;
+ TrackerOntologies *ontologies;
GSList *hfound = NULL, *deleted = NULL;
last_domain_indexes = tracker_class_get_last_domain_indexes (class);
@@ -1450,6 +1463,11 @@ check_for_deleted_domain_index (TrackerDataManager *manager,
return;
}
+ ontologies = tracker_data_manager_get_ontologies (manager);
+ property = tracker_ontologies_get_property_by_uri (ontologies,
+ TRACKER_PREFIX_NRL "domainIndex");
+ g_assert (property);
+
while (*last_domain_indexes) {
TrackerProperty *last_domain_index = *last_domain_indexes;
gboolean found = FALSE;
@@ -1518,7 +1536,7 @@ check_for_deleted_domain_index (TrackerDataManager *manager,
bytes = g_bytes_new (uri, strlen (uri) + 1);
tracker_data_delete_statement (manager->data_update, NULL,
tracker_class_get_uri (class),
- TRACKER_PREFIX_NRL "domainIndex",
+ property,
bytes,
error);
g_bytes_unref (bytes);
@@ -1642,8 +1660,10 @@ check_for_deleted_super_properties (TrackerDataManager *manager,
GError **error)
{
TrackerProperty **last_super_properties;
+ TrackerOntologies *ontologies;
GList *to_remove = NULL;
+ ontologies = tracker_data_manager_get_ontologies (manager);
last_super_properties = tracker_property_get_last_super_properties (property);
if (!last_super_properties) {
@@ -1684,12 +1704,21 @@ check_for_deleted_super_properties (TrackerDataManager *manager,
const gchar *subject = tracker_property_get_uri (property);
GBytes *bytes;
+ property = tracker_ontologies_get_property_by_uri (ontologies,
+ TRACKER_PREFIX_RDFS
"subPropertyOf");
+ if (!property) {
+ g_set_error (error, TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology",
+ TRACKER_PREFIX_RDFS "subPropertyOf");
+ return;
+ }
+
tracker_property_del_super_property (property, prop_to_remove);
bytes = g_bytes_new (object, strlen (object) + 1);
tracker_data_delete_statement (manager->data_update, NULL, subject,
- TRACKER_PREFIX_RDFS "subPropertyOf",
- bytes, &n_error);
+ property, bytes, &n_error);
g_bytes_unref (bytes);
if (!n_error) {
@@ -2230,11 +2259,11 @@ tracker_data_ontology_process_statement (TrackerDataManager *manager,
if (tracker_property_get_is_new (property) ||
tracker_property_get_multiple_values (property)) {
tracker_data_insert_statement (manager->data_update, NULL,
- subject, predicate, bytes,
+ subject, property, bytes,
error);
} else {
tracker_data_update_statement (manager->data_update, NULL,
- subject, predicate, bytes,
+ subject, property, bytes,
error);
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 5b2587cd6..a448f8ce7 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -164,18 +164,18 @@ static gboolean update_resource_single (TrackerData *data,
GHashTable *bnodes,
GError **error);
-void tracker_data_insert_statement_with_uri (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error);
-void tracker_data_insert_statement_with_string (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error);
+void tracker_data_insert_statement_with_uri (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error);
+void tracker_data_insert_statement_with_string (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error);
void
@@ -2367,12 +2367,12 @@ resource_buffer_switch (TrackerData *data,
}
void
-tracker_data_delete_statement (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error)
+tracker_data_delete_statement (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error)
{
TrackerClass *class;
gint subject_id = 0;
@@ -2399,7 +2399,8 @@ tracker_data_delete_statement (TrackerData *data,
object_str = g_bytes_get_data (object, NULL);
- if (object && g_strcmp0 (predicate, TRACKER_PREFIX_RDF "type") == 0) {
+ if (object &&
+ predicate == tracker_ontologies_get_rdf_type (ontologies)) {
class = tracker_ontologies_get_class_by_uri (ontologies, object_str);
if (class != NULL) {
data->has_persistent = TRUE;
@@ -2410,19 +2411,11 @@ tracker_data_delete_statement (TrackerData *data,
"Class '%s' not found in the ontology", object_str);
}
} else {
- gint pred_id = 0;
- TrackerProperty *field;
+ gint pred_id;
- field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- if (field != NULL) {
- pred_id = tracker_property_get_id (field);
- data->has_persistent = TRUE;
- change = delete_metadata_decomposed (data, field, object, error);
- } else {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
- "Property '%s' not found in the ontology", predicate);
- return;
- }
+ pred_id = tracker_property_get_id (predicate);
+ data->has_persistent = TRUE;
+ change = delete_metadata_decomposed (data, predicate, object, error);
if (change) {
tracker_data_dispatch_delete_statement_callbacks (data,
@@ -2551,46 +2544,43 @@ tracker_data_delete_all (TrackerData *data,
}
static gboolean
-delete_single_valued (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- gboolean super_is_single_valued,
- GError **error)
-{
- TrackerProperty *field, **super_properties;
- TrackerOntologies *ontologies;
+delete_single_valued (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ gboolean super_is_single_valued,
+ GError **error)
+{
+ TrackerProperty **super_properties;
gboolean multiple_values;
- ontologies = tracker_data_manager_get_ontologies (data->manager);
- field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- super_properties = tracker_property_get_super_properties (field);
- multiple_values = tracker_property_get_multiple_values (field);
+ super_properties = tracker_property_get_super_properties (predicate);
+ multiple_values = tracker_property_get_multiple_values (predicate);
if (super_is_single_valued && multiple_values) {
cache_delete_all_values (data,
- tracker_property_get_table_name (field),
- tracker_property_get_name (field));
- if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- if (!tracker_data_resource_unref_all (data, field, error))
+ tracker_property_get_table_name (predicate),
+ tracker_property_get_name (predicate));
+ if (tracker_property_get_data_type (predicate) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ if (!tracker_data_resource_unref_all (data, predicate, error))
return FALSE;
}
} else if (!multiple_values) {
GError *inner_error = NULL;
GArray *old_values;
- old_values = get_old_property_values (data, field, &inner_error);
+ old_values = get_old_property_values (data, predicate, &inner_error);
if (old_values && old_values->len == 1) {
GValue *value;
value = &g_array_index (old_values, GValue, 0);
cache_delete_value (data,
- tracker_property_get_table_name (field),
- tracker_property_get_name (field),
+ tracker_property_get_table_name (predicate),
+ tracker_property_get_name (predicate),
value,
FALSE);
- if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE)
+ if (tracker_property_get_data_type (predicate) == TRACKER_PROPERTY_TYPE_RESOURCE)
tracker_data_resource_unref (data, g_value_get_int64 (value),
multiple_values);
} else {
/* no need to error out if statement does not exist for any reason */
@@ -2600,7 +2590,7 @@ delete_single_valued (TrackerData *data,
while (*super_properties) {
if (!delete_single_valued (data, graph, subject,
- tracker_property_get_uri (*super_properties),
+ *super_properties,
super_is_single_valued,
error))
return FALSE;
@@ -2612,47 +2602,35 @@ delete_single_valued (TrackerData *data,
}
void
-tracker_data_insert_statement (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error)
+tracker_data_insert_statement (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error)
{
- TrackerProperty *property;
- TrackerOntologies *ontologies;
-
g_return_if_fail (subject != NULL);
g_return_if_fail (predicate != NULL);
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies (data->manager);
-
- property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- if (property != NULL) {
- if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- tracker_data_insert_statement_with_uri (data, graph, subject, predicate, object,
error);
- } else {
- tracker_data_insert_statement_with_string (data, graph, subject, predicate, object,
error);
- }
+ if (tracker_property_get_data_type (predicate) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ tracker_data_insert_statement_with_uri (data, graph, subject, predicate, object, error);
} else {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
- "Property '%s' not found in the ontology", predicate);
+ tracker_data_insert_statement_with_string (data, graph, subject, predicate, object, error);
}
}
void
-tracker_data_insert_statement_with_uri (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error)
+tracker_data_insert_statement_with_uri (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error)
{
GError *actual_error = NULL;
TrackerClass *class;
- TrackerProperty *property;
gint prop_id = 0;
gboolean change = FALSE;
TrackerOntologies *ontologies;
@@ -2663,21 +2641,11 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies (data->manager);
+ g_assert (tracker_property_get_data_type (predicate) ==
+ TRACKER_PROPERTY_TYPE_RESOURCE);
- property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- if (property == NULL) {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
- "Property '%s' not found in the ontology", predicate);
- return;
- } else {
- if (tracker_property_get_data_type (property) != TRACKER_PROPERTY_TYPE_RESOURCE) {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_TYPE,
- "Property '%s' does not accept URIs", predicate);
- return;
- }
- prop_id = tracker_property_get_id (property);
- }
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
+ prop_id = tracker_property_get_id (predicate);
data->has_persistent = TRUE;
@@ -2686,7 +2654,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
object_str = g_bytes_get_data (object, NULL);
- if (property == tracker_ontologies_get_rdf_type (ontologies)) {
+ if (predicate == tracker_ontologies_get_rdf_type (ontologies)) {
/* handle rdf:type statements specially to
cope with inference and insert blank rows */
class = tracker_ontologies_get_class_by_uri (ontologies, object_str);
@@ -2700,7 +2668,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
}
} else {
/* add value to metadata database */
- change = cache_insert_metadata_decomposed (data, property, object, &actual_error);
+ change = cache_insert_metadata_decomposed (data, predicate, object, &actual_error);
if (actual_error) {
g_propagate_error (error, actual_error);
@@ -2716,47 +2684,33 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
}
void
-tracker_data_insert_statement_with_string (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error)
+tracker_data_insert_statement_with_string (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error)
{
GError *actual_error = NULL;
- TrackerProperty *property;
gboolean change;
gint pred_id = 0;
- TrackerOntologies *ontologies;
g_return_if_fail (subject != NULL);
g_return_if_fail (predicate != NULL);
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies (data->manager);
-
- property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- if (property == NULL) {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
- "Property '%s' not found in the ontology", predicate);
- return;
- } else {
- if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_TYPE,
- "Property '%s' only accepts URIs", predicate);
- return;
- }
- pred_id = tracker_property_get_id (property);
- }
+ g_assert (tracker_property_get_data_type (predicate) !=
+ TRACKER_PROPERTY_TYPE_RESOURCE);
+ pred_id = tracker_property_get_id (predicate);
data->has_persistent = TRUE;
if (!resource_buffer_switch (data, graph, subject, error))
return;
/* add value to metadata database */
- change = cache_insert_metadata_decomposed (data, property, object, &actual_error);
+ change = cache_insert_metadata_decomposed (data, predicate, object, &actual_error);
if (actual_error) {
g_propagate_error (error, actual_error);
@@ -2771,14 +2725,13 @@ tracker_data_insert_statement_with_string (TrackerData *data,
}
void
-tracker_data_update_statement (TrackerData *data,
- const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- GBytes *object,
- GError **error)
+tracker_data_update_statement (TrackerData *data,
+ const gchar *graph,
+ const gchar *subject,
+ TrackerProperty *predicate,
+ GBytes *object,
+ GError **error)
{
- TrackerProperty *property;
TrackerOntologies *ontologies;
GError *new_error = NULL;
@@ -2787,64 +2740,59 @@ tracker_data_update_statement (TrackerData *data,
g_return_if_fail (data->in_transaction);
ontologies = tracker_data_manager_get_ontologies (data->manager);
- property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
- if (property != NULL) {
- if (object == NULL) {
- if (property == tracker_ontologies_get_rdf_type (ontologies)) {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
- "Using 'null' with '%s' is not supported", predicate);
- return;
- }
-
- /* Flush upfront to make a null,x,null,y,z work: When x is set then
- * if a null comes, we need to be flushed */
+ if (object == NULL) {
+ if (predicate == tracker_ontologies_get_rdf_type (ontologies)) {
+ g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
+ "Using 'null' with '%s' is not supported",
+ tracker_property_get_uri (predicate));
+ return;
+ }
- tracker_data_update_buffer_flush (data, &new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return;
- }
+ /* Flush upfront to make a null,x,null,y,z work: When x is set then
+ * if a null comes, we need to be flushed */
- if (!resource_buffer_switch (data, graph, subject, error))
- return;
-
- cache_delete_all_values (data,
- tracker_property_get_table_name (property),
- tracker_property_get_name (property));
- if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- if (!tracker_data_resource_unref_all (data, property, error))
- return;
- }
- } else {
- if (!resource_buffer_switch (data, graph, subject, error))
- return;
+ tracker_data_update_buffer_flush (data, &new_error);
+ if (new_error) {
+ g_propagate_error (error, new_error);
+ return;
+ }
- if (!delete_single_valued (data, graph, subject, predicate,
- !tracker_property_get_multiple_values (property),
- error))
- return;
+ if (!resource_buffer_switch (data, graph, subject, error))
+ return;
- tracker_data_update_buffer_flush (data, &new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
+ cache_delete_all_values (data,
+ tracker_property_get_table_name (predicate),
+ tracker_property_get_name (predicate));
+ if (tracker_property_get_data_type (predicate) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ if (!tracker_data_resource_unref_all (data, predicate, error))
return;
- }
-
- if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- tracker_data_insert_statement_with_uri (data, graph, subject, predicate,
object, error);
- } else {
- tracker_data_insert_statement_with_string (data, graph, subject, predicate,
object, error);
- }
}
+ } else {
+ if (!resource_buffer_switch (data, graph, subject, error))
+ return;
+
+ if (!delete_single_valued (data, graph, subject, predicate,
+ !tracker_property_get_multiple_values (predicate),
+ error))
+ return;
tracker_data_update_buffer_flush (data, &new_error);
if (new_error) {
g_propagate_error (error, new_error);
+ return;
+ }
+
+ if (tracker_property_get_data_type (predicate) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ tracker_data_insert_statement_with_uri (data, graph, subject, predicate, object,
error);
+ } else {
+ tracker_data_insert_statement_with_string (data, graph, subject, predicate, object,
error);
}
- } else {
- g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
- "Property '%s' not found in the ontology", predicate);
+ }
+
+ tracker_data_update_buffer_flush (data, &new_error);
+ if (new_error) {
+ g_propagate_error (error, new_error);
}
}
@@ -3044,8 +2992,9 @@ tracker_data_load_turtle_file (TrackerData *data,
GError **error)
{
TrackerTurtleReader *reader = NULL;
+ TrackerOntologies *ontologies;
GError *inner_error = NULL;
- const gchar *subject, *predicate, *object_str, *langtag;
+ const gchar *subject, *predicate_str, *object_str, *langtag;
gboolean object_is_uri;
goffset last_parsed_line_no, last_parsed_column_no;
gchar *ontology_uri;
@@ -3054,19 +3003,31 @@ tracker_data_load_turtle_file (TrackerData *data,
if (!reader)
return;
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
+
while (tracker_turtle_reader_next (reader,
&subject,
- &predicate,
+ &predicate_str,
&object_str,
&langtag,
&object_is_uri,
&last_parsed_line_no,
&last_parsed_column_no,
&inner_error)) {
+ TrackerProperty *predicate;
GBytes *object;
object = tracker_sparql_make_langstring (object_str, langtag);
+ predicate = tracker_ontologies_get_property_by_uri (ontologies, predicate_str);
+ if (predicate == NULL) {
+ g_set_error (&inner_error, TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology",
+ predicate_str);
+ goto failed;
+ }
+
if (object_is_uri) {
tracker_data_insert_statement_with_uri (data, graph,
subject, predicate, object,
@@ -3195,6 +3156,8 @@ update_resource_property (TrackerData *data,
GHashTable *bnodes,
GError **error)
{
+ TrackerOntologies *ontologies;
+ TrackerProperty *predicate;
GList *values, *v;
gchar *property_uri;
GError *inner_error = NULL;
@@ -3205,6 +3168,16 @@ update_resource_property (TrackerData *data,
NULL, NULL,
&property_uri);
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
+ predicate = tracker_ontologies_get_property_by_uri (ontologies, property_uri);
+ if (predicate == NULL) {
+ g_set_error (error, TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology",
+ property_uri);
+ return FALSE;
+ }
+
for (v = values; v && !inner_error; v = v->next) {
GBytes *bytes = NULL;
@@ -3229,7 +3202,7 @@ update_resource_property (TrackerData *data,
tracker_data_insert_statement (data,
graph_uri,
subject,
- property_uri,
+ predicate,
bytes,
&inner_error);
g_bytes_unref (bytes);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 31283dbea..8cea7ef01 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -60,19 +60,19 @@ GQuark tracker_data_error_quark (void);
void tracker_data_delete_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
- const gchar *predicate,
+ TrackerProperty *predicate,
GBytes *object,
GError **error);
void tracker_data_insert_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
- const gchar *predicate,
+ TrackerProperty *predicate,
GBytes *object,
GError **error);
void tracker_data_update_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
- const gchar *predicate,
+ TrackerProperty *predicate,
GBytes *object,
GError **error);
void tracker_data_begin_transaction (TrackerData *data,
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 94bfb3380..cdc3b1674 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2079,6 +2079,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
GError **error)
{
GError *inner_error = NULL;
+ TrackerProperty *predicate = NULL;
if ((tracker_token_is_empty (&sparql->current_state->graph) &&
sparql->policy.filter_unnamed_graph) ||
@@ -2089,6 +2090,26 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_token_get_idstring (&sparql->current_state->graph));
}
+ if (sparql->current_state->type == TRACKER_SPARQL_TYPE_INSERT ||
+ sparql->current_state->type == TRACKER_SPARQL_TYPE_DELETE ||
+ sparql->current_state->type == TRACKER_SPARQL_TYPE_UPDATE) {
+ TrackerOntologies *ontologies;
+ const gchar *property;
+
+ ontologies = tracker_data_manager_get_ontologies (sparql->data_manager);
+ property = tracker_token_get_idstring (&sparql->current_state->predicate);
+ predicate = tracker_ontologies_get_property_by_uri (ontologies,
+ property);
+
+ if (predicate == NULL) {
+ g_set_error (error, TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology",
+ property);
+ return FALSE;
+ }
+ }
+
switch (sparql->current_state->type) {
case TRACKER_SPARQL_TYPE_SELECT:
_add_quad (sparql,
@@ -2110,7 +2131,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_data_insert_statement (tracker_data_manager_get_data (sparql->data_manager),
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
- tracker_token_get_idstring (&sparql->current_state->predicate),
+ predicate,
tracker_token_get_literal (&sparql->current_state->object),
&inner_error);
break;
@@ -2118,7 +2139,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_data_delete_statement (tracker_data_manager_get_data (sparql->data_manager),
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
- tracker_token_get_idstring (&sparql->current_state->predicate),
+ predicate,
tracker_token_get_literal (&sparql->current_state->object),
&inner_error);
break;
@@ -2126,7 +2147,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_data_update_statement (tracker_data_manager_get_data (sparql->data_manager),
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
- tracker_token_get_idstring (&sparql->current_state->predicate),
+ predicate,
tracker_token_get_literal (&sparql->current_state->object),
&inner_error);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]