summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2019-08-26 15:58:48 +0300
committerSam Thursfield <sam@afuera.me.uk>2019-08-26 15:58:48 +0300
commit3c23ffa5eac724830aa4f3f70eba2e97fe13c3fa (patch)
tree056b24391869499d3a6440748300553ceb98f7db
parentbdfe556478b5d09a6e5024a413cd1a52e721cc0a (diff)
downloadtracker-sam/tracker-resource-avoid-invalid-sparql.tar.gz
libtracker-sparql: Warn when serializing a resource with 0 propertiessam/tracker-resource-avoid-invalid-sparql
We can't describe an RDF resource without knowing at least one property about it. If we have 0 properties, it is due to a programmer error or a bug. We now warn in this case, where previously we would just generate invalid SPARQL and trigger an error further down the line.
-rw-r--r--src/libtracker-sparql/tracker-resource.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 9c9fd53aa..9c504272c 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -1440,6 +1440,14 @@ generate_sparql_insert_pattern (TrackerResource *resource,
const GValue *value;
gboolean had_property = FALSE;
+ /* If the resource has no properties, this function would generate invalid
+ * SPARQL. */
+ if (g_hash_table_size(priv->properties) == 0) {
+ g_warning("Resource with identifier %s has no properties. Unable to "
+ " serialize to SPARQL.", priv->identifier);
+ return;
+ }
+
/* First, emit any sub-resources. */
g_hash_table_foreach (priv->properties, generate_sparql_relation_inserts_foreach, data);