[tracker/wip/carlosg/anonymous-nodes: 9/24] libtracker-data: Pass GValue as object instead of GBytes
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/anonymous-nodes: 9/24] libtracker-data: Pass GValue as object instead of GBytes
- Date: Fri, 8 Oct 2021 09:40:54 +0000 (UTC)
commit 764dea8d111c9be28cc55208cdfbdf5b3247f60c
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Sep 22 23:19:51 2021 +0200
libtracker-data: Pass GValue as object instead of GBytes
Between the first things we do with those GBytes are converting them
to a GValue, it becomes a bit awkward that in some places we are
converting GValues to GBytes just to interface with this API.
Make it all GValues, and make it the callers responsibility to
convert from the entry format to GValues that can be consumed here.
As a side effect, the tracker-data-update.c machinery no longer
deals with resources as strings, but plain ROWIDs. It is also
the caller responsibility to obtain a URN first, if required.
src/libtracker-data/tracker-data-manager.c | 83 +++++---
src/libtracker-data/tracker-data-query.c | 73 +++++++
src/libtracker-data/tracker-data-query.h | 7 +
src/libtracker-data/tracker-data-update.c | 309 +++++++----------------------
src/libtracker-data/tracker-data-update.h | 6 +-
src/libtracker-data/tracker-sparql.c | 59 +++++-
6 files changed, 261 insertions(+), 276 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 3f2e635bb..2eeb144c1 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -506,7 +506,6 @@ update_property_value (TrackerDataManager *manager,
GError *error = NULL;
gboolean needed = TRUE;
gboolean is_new = FALSE;
- GBytes *bytes;
const gchar *ontology_path = NULL;
goffset line_no = -1;
goffset column_no = -1;
@@ -568,9 +567,16 @@ 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,
pred, bytes, &error);
- g_bytes_unref (bytes);
+ GValue value = G_VALUE_INIT;
+
+ tracker_data_query_string_to_value (manager,
+ str, NULL,
+ tracker_property_get_data_type
(pred),
+ &value, &error);
+
+ if (!error)
+ tracker_data_delete_statement (manager->data_update, NULL,
subject, pred, &value, &error);
+ g_value_unset (&value);
if (!error)
tracker_data_update_buffer_flush (manager->data_update,
&error);
@@ -594,11 +600,18 @@ 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,
- pred, bytes,
- &error);
- g_bytes_unref (bytes);
+ GValue value = G_VALUE_INIT;
+
+ tracker_data_query_string_to_value (manager,
+ object, NULL,
+ tracker_property_get_data_type (pred),
+ &value, &error);
+
+ if (!error)
+ tracker_data_insert_statement (manager->data_update, NULL, subject,
+ pred, &value,
+ &error);
+ g_value_unset (&value);
if (!error)
tracker_data_update_buffer_flush (manager->data_update, &error);
@@ -1523,7 +1536,7 @@ check_for_deleted_domain_index (TrackerDataManager *manager,
for (l = deleted; l != NULL; l = l->next) {
TrackerProperty *prop = l->data;
const gchar *uri;
- GBytes *bytes;
+ GValue value = G_VALUE_INIT;
TRACKER_NOTE (ONTOLOGY_CHANGES,
g_message ("Ontology change: deleting nrl:domainIndex: %s",
@@ -1532,13 +1545,19 @@ check_for_deleted_domain_index (TrackerDataManager *manager,
tracker_class_del_domain_index (class, prop);
uri = tracker_property_get_uri (prop);
- bytes = g_bytes_new (uri, strlen (uri) + 1);
- tracker_data_delete_statement (manager->data_update, NULL,
- tracker_class_get_uri (class),
- property,
- bytes,
- error);
- g_bytes_unref (bytes);
+
+ if (tracker_data_query_string_to_value (manager,
+ uri, NULL,
+ tracker_property_get_data_type (property),
+ &value, error)) {
+ tracker_data_delete_statement (manager->data_update, NULL,
+ tracker_class_get_uri (class),
+ property,
+ &value,
+ error);
+ }
+
+ g_value_unset (&value);
if (!(*error))
tracker_data_update_buffer_flush (manager->data_update, error);
@@ -1701,7 +1720,7 @@ check_for_deleted_super_properties (TrackerDataManager *manager,
TrackerProperty *prop_to_remove = copy->data;
const gchar *object = tracker_property_get_uri (prop_to_remove);
const gchar *subject = tracker_property_get_uri (property);
- GBytes *bytes;
+ GValue value = G_VALUE_INIT;
property = tracker_ontologies_get_property_by_uri (ontologies,
TRACKER_PREFIX_RDFS
"subPropertyOf");
@@ -1715,10 +1734,15 @@ check_for_deleted_super_properties (TrackerDataManager *manager,
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,
- property, bytes, &n_error);
- g_bytes_unref (bytes);
+ tracker_data_query_string_to_value (manager,
+ object, NULL,
+ tracker_property_get_data_type (property),
+ &value, &n_error);
+
+ if (!n_error)
+ tracker_data_delete_statement (manager->data_update, NULL, subject,
+ property, &value, &n_error);
+ g_value_unset (&value);
if (!n_error) {
tracker_data_update_buffer_flush (manager->data_update, &n_error);
@@ -2169,7 +2193,7 @@ tracker_data_ontology_process_statement (TrackerDataManager *manager,
GError **error)
{
TrackerProperty *property;
- GBytes *bytes;
+ GValue value = G_VALUE_INIT;
if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
if (g_strcmp0 (object, RDFS_CLASS) == 0) {
@@ -2244,7 +2268,6 @@ tracker_data_ontology_process_statement (TrackerDataManager *manager,
}
}
- bytes = g_bytes_new (object, strlen (object) + 1);
property = tracker_ontologies_get_property_by_uri (manager->ontologies, predicate);
if (!property) {
@@ -2255,19 +2278,25 @@ tracker_data_ontology_process_statement (TrackerDataManager *manager,
goto out;
}
+ if (!tracker_data_query_string_to_value (manager,
+ object, NULL,
+ tracker_property_get_data_type (property),
+ &value, error))
+ goto out;
+
if (tracker_property_get_is_new (property) ||
tracker_property_get_multiple_values (property)) {
tracker_data_insert_statement (manager->data_update, NULL,
- subject, property, bytes,
+ subject, property, &value,
error);
} else {
tracker_data_update_statement (manager->data_update, NULL,
- subject, property, bytes,
+ subject, property, &value,
error);
}
out:
- g_bytes_unref (bytes);
+ g_value_unset (&value);
}
static void
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index de7ea1f67..ea3d56a0c 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -187,3 +187,76 @@ tracker_data_query_sparql_cursor (TrackerDataManager *manager,
return TRACKER_DB_CURSOR (cursor);
}
+gboolean
+tracker_data_query_string_to_value (TrackerDataManager *manager,
+ const gchar *value,
+ const gchar *langtag,
+ TrackerPropertyType type,
+ GValue *gvalue,
+ GError **error)
+{
+ TrackerData *data;
+ gint object_id;
+ gchar *datetime_str;
+ GDateTime *datetime;
+
+ switch (type) {
+ case TRACKER_PROPERTY_TYPE_STRING:
+ g_value_init (gvalue, G_TYPE_STRING);
+ g_value_set_string (gvalue, value);
+ break;
+ case TRACKER_PROPERTY_TYPE_LANGSTRING:
+ g_value_init (gvalue, G_TYPE_BYTES);
+ g_value_take_boxed (gvalue, tracker_sparql_make_langstring (value, langtag));
+ break;
+ case TRACKER_PROPERTY_TYPE_INTEGER:
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, atoll (value));
+ break;
+ case TRACKER_PROPERTY_TYPE_BOOLEAN:
+ /* use G_TYPE_INT64 to be compatible with value stored in DB
+ (important for value_equal function) */
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, g_ascii_strncasecmp (value, "true", 4) == 0);
+ break;
+ case TRACKER_PROPERTY_TYPE_DOUBLE:
+ g_value_init (gvalue, G_TYPE_DOUBLE);
+ g_value_set_double (gvalue, g_ascii_strtod (value, NULL));
+ break;
+ case TRACKER_PROPERTY_TYPE_DATE:
+ g_value_init (gvalue, G_TYPE_INT64);
+ datetime_str = g_strdup_printf ("%sT00:00:00Z", value);
+ datetime = tracker_date_new_from_iso8601 (datetime_str, error);
+ g_free (datetime_str);
+
+ if (!datetime)
+ return FALSE;
+
+ g_value_set_int64 (gvalue, g_date_time_to_unix (datetime));
+ g_date_time_unref (datetime);
+ break;
+ case TRACKER_PROPERTY_TYPE_DATETIME:
+ g_value_init (gvalue, G_TYPE_DATE_TIME);
+ datetime = tracker_date_new_from_iso8601 (value, error);
+
+ if (!datetime)
+ return FALSE;
+
+ g_value_take_boxed (gvalue, datetime);
+ break;
+ case TRACKER_PROPERTY_TYPE_RESOURCE:
+ data = tracker_data_manager_get_data (manager);
+ object_id = tracker_data_update_ensure_resource (data, value, error);
+ if (object_id == 0)
+ return FALSE;
+
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, object_id);
+ break;
+ case TRACKER_PROPERTY_TYPE_UNKNOWN:
+ g_warn_if_reached ();
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index cec8caa3e..a5b17ae13 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -50,6 +50,13 @@ GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *mana
gint id,
GError **error);
+gboolean tracker_data_query_string_to_value (TrackerDataManager *manager,
+ const gchar *value,
+ const gchar *langtag,
+ TrackerPropertyType type,
+ GValue *gvalue,
+ GError **error);
+
G_END_DECLS
#endif /* __LIBTRACKER_DATA_QUERY_H__ */
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index df05593f9..1f2aa3520 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -144,14 +144,14 @@ G_DEFINE_TYPE (TrackerData, tracker_data, G_TYPE_OBJECT)
static void cache_insert_value (TrackerData *data,
const gchar *table_name,
const gchar *field_name,
- GValue *value,
+ const GValue *value,
gboolean multiple_values);
static GArray *get_old_property_values (TrackerData *data,
TrackerProperty *property,
GError **error);
static gboolean delete_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- GBytes *object,
+ const GValue *object,
GError **error);
static gboolean resource_buffer_switch (TrackerData *data,
const gchar *graph,
@@ -168,13 +168,13 @@ void tracker_data_insert_statement_with_uri (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error);
void tracker_data_insert_statement_with_string (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error);
@@ -591,11 +591,11 @@ cache_insert_row (TrackerData *data,
}
static void
-cache_insert_value (TrackerData *data,
- const gchar *table_name,
- const gchar *field_name,
- GValue *value,
- gboolean multiple_values)
+cache_insert_value (TrackerData *data,
+ const gchar *table_name,
+ const gchar *field_name,
+ const GValue *value,
+ gboolean multiple_values)
{
TrackerDataUpdateBufferTable *table;
TrackerDataUpdateBufferProperty property = { 0 };
@@ -639,11 +639,11 @@ cache_delete_all_values (TrackerData *data,
}
static void
-cache_delete_value (TrackerData *data,
- const gchar *table_name,
- const gchar *field_name,
- GValue *value,
- gboolean multiple_values)
+cache_delete_value (TrackerData *data,
+ const gchar *table_name,
+ const gchar *field_name,
+ const GValue *value,
+ gboolean multiple_values)
{
TrackerDataUpdateBufferTable *table;
TrackerDataUpdateBufferProperty property = { 0 };
@@ -1378,8 +1378,8 @@ cache_create_service_decomposed (TrackerData *data,
}
static gboolean
-value_equal (GValue *value1,
- GValue *value2)
+value_equal (const GValue *value1,
+ const GValue *value2)
{
GType type = G_VALUE_TYPE (value1);
@@ -1408,8 +1408,8 @@ value_equal (GValue *value1,
}
static gboolean
-value_set_add_value (GArray *value_set,
- GValue *value)
+value_set_add_value (GArray *value_set,
+ const GValue *value)
{
GValue gvalue_copy = { 0 };
guint i;
@@ -1434,8 +1434,8 @@ value_set_add_value (GArray *value_set,
}
static gboolean
-value_set_remove_value (GArray *value_set,
- GValue *value)
+value_set_remove_value (GArray *value_set,
+ const GValue *value)
{
guint i;
@@ -1659,72 +1659,6 @@ get_old_property_values (TrackerData *data,
return old_values;
}
-static void
-bytes_to_gvalue (GBytes *bytes,
- TrackerPropertyType type,
- GValue *gvalue,
- TrackerData *data,
- GError **error)
-{
- gint object_id;
- gchar *datetime_str;
- GDateTime *datetime;
- const gchar *value;
-
- value = g_bytes_get_data (bytes, NULL);
-
- switch (type) {
- case TRACKER_PROPERTY_TYPE_STRING:
- g_value_init (gvalue, G_TYPE_STRING);
- g_value_set_string (gvalue, value);
- break;
- case TRACKER_PROPERTY_TYPE_LANGSTRING:
- g_value_init (gvalue, G_TYPE_BYTES);
- g_value_set_boxed (gvalue, bytes);
- break;
- case TRACKER_PROPERTY_TYPE_INTEGER:
- g_value_init (gvalue, G_TYPE_INT64);
- g_value_set_int64 (gvalue, atoll (value));
- break;
- case TRACKER_PROPERTY_TYPE_BOOLEAN:
- /* use G_TYPE_INT64 to be compatible with value stored in DB
- (important for value_equal function) */
- g_value_init (gvalue, G_TYPE_INT64);
- g_value_set_int64 (gvalue, g_ascii_strncasecmp (value, "true", 4) == 0);
- break;
- case TRACKER_PROPERTY_TYPE_DOUBLE:
- g_value_init (gvalue, G_TYPE_DOUBLE);
- g_value_set_double (gvalue, g_ascii_strtod (value, NULL));
- break;
- case TRACKER_PROPERTY_TYPE_DATE:
- g_value_init (gvalue, G_TYPE_INT64);
- datetime_str = g_strdup_printf ("%sT00:00:00Z", value);
- datetime = tracker_date_new_from_iso8601 (datetime_str, error);
- g_free (datetime_str);
-
- if (datetime) {
- g_value_set_int64 (gvalue, g_date_time_to_unix (datetime));
- g_date_time_unref (datetime);
- }
- break;
- case TRACKER_PROPERTY_TYPE_DATETIME:
- g_value_init (gvalue, G_TYPE_DATE_TIME);
- datetime = tracker_date_new_from_iso8601 (value, error);
-
- if (datetime)
- g_value_take_boxed (gvalue, datetime);
- break;
- case TRACKER_PROPERTY_TYPE_RESOURCE:
- object_id = tracker_data_update_ensure_resource (data, value, error);
- g_value_init (gvalue, G_TYPE_INT64);
- g_value_set_int64 (gvalue, object_id);
- break;
- case TRACKER_PROPERTY_TYPE_UNKNOWN:
- g_warn_if_reached ();
- break;
- }
-}
-
static const gchar *
get_bnode_for_resource (GHashTable *bnodes,
TrackerData *data,
@@ -1750,99 +1684,6 @@ get_bnode_for_resource (GHashTable *bnodes,
return bnode;
}
-static gboolean
-bytes_from_gvalue (GValue *gvalue,
- GBytes **bytes,
- TrackerData *data,
- GHashTable *bnodes,
- GError **error)
-{
- gchar *str;
-
- if (G_VALUE_HOLDS_BOOLEAN (gvalue)) {
- if (g_value_get_boolean (gvalue)) {
- *bytes = g_bytes_new_static ("true", strlen ("true") + 1);
- } else {
- *bytes = g_bytes_new_static ("false", strlen ("false") + 1);
- }
- } else if (G_VALUE_HOLDS_INT (gvalue)) {
- str = g_strdup_printf ("%d", g_value_get_int (gvalue));
- *bytes = g_bytes_new_take (str, strlen (str) + 1);
- } else if (G_VALUE_HOLDS_INT64 (gvalue)) {
- str = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (gvalue));
- *bytes = g_bytes_new_take (str, strlen (str) + 1);
- } else if (G_VALUE_HOLDS_DOUBLE (gvalue)) {
- gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
- g_ascii_dtostr (buffer, G_ASCII_DTOSTR_BUF_SIZE,
- g_value_get_double (gvalue));
- *bytes = g_bytes_new (buffer, strlen (buffer) + 1);
- } else if (g_strcmp0 (G_VALUE_TYPE_NAME (gvalue), "TrackerUri") == 0) {
- /* FIXME: We can't access TrackerUri GType here */
- const gchar *uri;
- gchar *expanded;
-
- uri = g_value_get_string (gvalue);
-
- if (g_str_has_prefix (uri, "_:")) {
- gchar *bnode;
-
- bnode = g_hash_table_lookup (bnodes, uri);
-
- if (!bnode) {
- TrackerDBInterface *iface;
-
- iface = tracker_data_manager_get_writable_db_interface (data->manager);
- bnode = tracker_data_update_ensure_new_bnode (data, iface, error);
- if (!bnode)
- return FALSE;
-
- g_hash_table_insert (bnodes, g_strdup (uri), bnode);
- }
-
- *bytes = g_bytes_new (bnode, strlen (bnode) + 1);
- } else {
- tracker_data_manager_expand_prefix (data->manager,
- g_value_get_string (gvalue),
- NULL, NULL,
- &expanded);
- *bytes = g_bytes_new_take (expanded, strlen (expanded) + 1);
- }
- } else if (G_VALUE_HOLDS_STRING (gvalue)) {
- const gchar *ptr;
- ptr = g_value_get_string (gvalue);
- *bytes = g_bytes_new (ptr, strlen (ptr) + 1);
- } else if (G_VALUE_HOLDS (gvalue, TRACKER_TYPE_RESOURCE)) {
- TrackerResource *res;
- const gchar *object;
-
- res = g_value_get_object (gvalue);
- object = tracker_resource_get_identifier (res);
-
- if (!object || g_str_has_prefix (object, "_:")) {
- object = get_bnode_for_resource (bnodes, data, res, error);
- if (!object)
- return FALSE;
- }
-
- *bytes = g_bytes_new (object, strlen (object) + 1);
- } else if (G_VALUE_HOLDS (gvalue, G_TYPE_DATE_TIME)) {
- GDateTime *datetime;
-
- datetime = g_value_get_boxed (gvalue);
- str = tracker_date_format_iso8601 (datetime);
- *bytes = g_bytes_new_take (str, strlen (str) + 1);
- } else {
- g_set_error (error,
- TRACKER_SPARQL_ERROR,
- TRACKER_SPARQL_ERROR_UNSUPPORTED,
- "Conversion to bytes unavailable for type %s",
- G_VALUE_TYPE_NAME (gvalue));
- return FALSE;
- }
-
- return TRUE;
-}
-
static gboolean
resource_in_domain_index_class (TrackerData *data,
TrackerClass *domain_index_class)
@@ -1859,7 +1700,7 @@ resource_in_domain_index_class (TrackerData *data,
static void
process_domain_indexes (TrackerData *data,
TrackerProperty *property,
- GValue *gvalue,
+ const GValue *gvalue,
const gchar *field_name)
{
TrackerClass **domain_index_classes;
@@ -1880,7 +1721,7 @@ process_domain_indexes (TrackerData *data,
static gboolean
cache_insert_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- GBytes *object,
+ const GValue *object,
GError **error)
{
gboolean multiple_values;
@@ -1890,7 +1731,6 @@ cache_insert_metadata_decomposed (TrackerData *data,
GArray *old_values;
GError *new_error = NULL;
gboolean change = FALSE;
- GValue value = G_VALUE_INIT;
/* read existing property values */
old_values = get_old_property_values (data, property, &new_error);
@@ -1931,17 +1771,10 @@ cache_insert_metadata_decomposed (TrackerData *data,
super_properties++;
}
- bytes_to_gvalue (object, tracker_property_get_data_type (property),
- &value, data, &new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return FALSE;
- }
-
table_name = tracker_property_get_table_name (property);
field_name = tracker_property_get_name (property);
- if (!value_set_add_value (old_values, &value)) {
+ if (!value_set_add_value (old_values, object)) {
/* value already inserted */
} else if (!multiple_values && old_values->len > 1) {
/* trying to add second value to single valued property */
@@ -1980,28 +1813,26 @@ cache_insert_metadata_decomposed (TrackerData *data,
g_value_unset (&new_value);
} else {
cache_insert_value (data, table_name, field_name,
- &value,
+ object,
multiple_values);
if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE)
- tracker_data_resource_ref (data, g_value_get_int64 (&value), multiple_values);
+ tracker_data_resource_ref (data, g_value_get_int64 (object), multiple_values);
if (!multiple_values) {
- process_domain_indexes (data, property, &value, field_name);
+ process_domain_indexes (data, property, object, field_name);
}
change = TRUE;
}
- g_value_unset (&value);
-
return change;
}
static gboolean
delete_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- GBytes *object,
+ const GValue *object,
GError **error)
{
gboolean multiple_values;
@@ -2011,14 +1842,6 @@ delete_metadata_decomposed (TrackerData *data,
GArray *old_values;
GError *new_error = NULL;
gboolean change = FALSE;
- GValue value = G_VALUE_INIT;
-
- bytes_to_gvalue (object, tracker_property_get_data_type (property),
- &value, data, &new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return FALSE;
- }
multiple_values = tracker_property_get_multiple_values (property);
table_name = tracker_property_get_table_name (property);
@@ -2028,18 +1851,17 @@ delete_metadata_decomposed (TrackerData *data,
old_values = get_old_property_values (data, property, &new_error);
if (new_error) {
/* no need to error out if statement does not exist for any reason */
- g_value_unset (&value);
g_clear_error (&new_error);
return FALSE;
}
- if (!value_set_remove_value (old_values, &value)) {
+ if (!value_set_remove_value (old_values, object)) {
/* value not found */
} else {
cache_delete_value (data, table_name, field_name,
- &value, multiple_values);
+ object, multiple_values);
if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE)
- tracker_data_resource_unref (data, g_value_get_int64 (&value), multiple_values);
+ tracker_data_resource_unref (data, g_value_get_int64 (object), multiple_values);
if (!multiple_values) {
TrackerClass **domain_index_classes;
@@ -2051,7 +1873,7 @@ delete_metadata_decomposed (TrackerData *data,
cache_delete_value (data,
tracker_class_get_name (*domain_index_classes),
field_name,
- &value, multiple_values);
+ object, multiple_values);
}
domain_index_classes++;
}
@@ -2060,8 +1882,6 @@ delete_metadata_decomposed (TrackerData *data,
change = TRUE;
}
- g_value_unset (&value);
-
/* also delete super property values */
super_properties = tracker_property_get_super_properties (property);
while (*super_properties) {
@@ -2371,14 +2191,13 @@ tracker_data_delete_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error)
{
TrackerClass *class;
gint subject_id = 0;
gboolean change = FALSE;
TrackerOntologies *ontologies;
- const gchar *object_str;
g_return_if_fail (subject != NULL);
g_return_if_fail (predicate != NULL);
@@ -2397,10 +2216,11 @@ tracker_data_delete_statement (TrackerData *data,
ontologies = tracker_data_manager_get_ontologies (data->manager);
- object_str = g_bytes_get_data (object, NULL);
+ if (predicate == tracker_ontologies_get_rdf_type (ontologies)) {
+ const gchar *object_str = NULL;
+ gint64 object_id = g_value_get_int64 (object);
- if (object &&
- predicate == tracker_ontologies_get_rdf_type (ontologies)) {
+ object_str = tracker_ontologies_get_uri_by_id (ontologies, object_id);
class = tracker_ontologies_get_class_by_uri (ontologies, object_str);
if (class != NULL) {
data->has_persistent = TRUE;
@@ -2606,7 +2426,7 @@ tracker_data_insert_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error)
{
g_return_if_fail (subject != NULL);
@@ -2626,7 +2446,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error)
{
GError *actual_error = NULL;
@@ -2634,7 +2454,6 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
gint prop_id = 0;
gboolean change = FALSE;
TrackerOntologies *ontologies;
- const gchar *object_str;
g_return_if_fail (subject != NULL);
g_return_if_fail (predicate != NULL);
@@ -2652,9 +2471,21 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
if (!resource_buffer_switch (data, graph, subject, error))
return;
- object_str = g_bytes_get_data (object, NULL);
-
if (predicate == tracker_ontologies_get_rdf_type (ontologies)) {
+ gchar *object_str = NULL;
+
+ if (G_VALUE_HOLDS_INT64 (object)) {
+ gint64 object_id;
+
+ object_id = g_value_get_int64 (object);
+ object_str = g_strdup (tracker_ontologies_get_uri_by_id (ontologies, object_id));
+ } else {
+ tracker_data_manager_expand_prefix (data->manager,
+ g_value_get_string (object),
+ NULL, NULL,
+ &object_str);
+ }
+
/* handle rdf:type statements specially to
cope with inference and insert blank rows */
class = tracker_ontologies_get_class_by_uri (ontologies, object_str);
@@ -2688,7 +2519,7 @@ tracker_data_insert_statement_with_string (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error)
{
GError *actual_error = NULL;
@@ -2729,7 +2560,7 @@ tracker_data_update_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error)
{
TrackerOntologies *ontologies;
@@ -2741,7 +2572,7 @@ tracker_data_update_statement (TrackerData *data,
ontologies = tracker_data_manager_get_ontologies (data->manager);
- if (object == NULL) {
+ if (object == NULL || !G_VALUE_TYPE (object)) {
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",
@@ -3015,9 +2846,7 @@ tracker_data_load_turtle_file (TrackerData *data,
&last_parsed_column_no,
&inner_error)) {
TrackerProperty *predicate;
- GBytes *object;
-
- object = tracker_sparql_make_langstring (object_str, langtag);
+ GValue object = G_VALUE_INIT;
predicate = tracker_ontologies_get_property_by_uri (ontologies, predicate_str);
if (predicate == NULL) {
@@ -3028,17 +2857,25 @@ tracker_data_load_turtle_file (TrackerData *data,
goto failed;
}
+ if (!tracker_data_query_string_to_value (data->manager,
+ object_str,
+ langtag,
+ tracker_property_get_data_type (predicate),
+ &object,
+ &inner_error))
+ goto failed;
+
if (object_is_uri) {
tracker_data_insert_statement_with_uri (data, graph,
- subject, predicate, object,
+ subject, predicate, &object,
&inner_error);
} else {
tracker_data_insert_statement_with_string (data, graph,
- subject, predicate, object,
+ subject, predicate, &object,
&inner_error);
}
- g_bytes_unref (object);
+ g_value_unset (&object);
if (inner_error)
goto failed;
@@ -3183,8 +3020,6 @@ update_resource_property (TrackerData *data,
}
for (v = values; v && !inner_error; v = v->next) {
- GBytes *bytes = NULL;
-
if (G_VALUE_HOLDS (v->data, TRACKER_TYPE_RESOURCE)) {
update_resource_single (data,
graph_uri,
@@ -3196,20 +3031,12 @@ update_resource_property (TrackerData *data,
break;
}
- if (!bytes_from_gvalue (v->data,
- &bytes,
- data,
- bnodes,
- &inner_error))
- break;
-
tracker_data_insert_statement (data,
graph_uri,
subject,
predicate,
- bytes,
+ v->data,
&inner_error);
- g_bytes_unref (bytes);
}
g_list_free (values);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 8cea7ef01..fa21417d5 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -61,19 +61,19 @@ void tracker_data_delete_statement (TrackerData *
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error);
void tracker_data_insert_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error);
void tracker_data_update_statement (TrackerData *data,
const gchar *graph,
const gchar *subject,
TrackerProperty *predicate,
- GBytes *object,
+ const GValue *object,
GError **error);
void tracker_data_begin_transaction (TrackerData *data,
GError **error);
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 62488b68a..d3e2b0bb5 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2034,12 +2034,44 @@ _construct_clause (TrackerSparql *sparql,
return TRUE;
}
+static void
+value_init_from_token (TrackerSparql *sparql,
+ GValue *value,
+ TrackerProperty *property,
+ TrackerToken *token,
+ GError **error)
+{
+ GBytes *literal;
+
+ literal = tracker_token_get_literal (token);
+
+ if (literal) {
+ const gchar *str, *langstring = NULL;
+ gsize size;
+ int len;
+
+ str = g_bytes_get_data (literal, &size);
+ len = strlen (str);
+
+ if (((gsize) len + 1) < size)
+ langstring = &str[len + 1];
+
+ tracker_data_query_string_to_value (sparql->data_manager,
+ str,
+ langstring,
+ tracker_property_get_data_type (property),
+ value,
+ error);
+ }
+}
+
static gboolean
tracker_sparql_apply_quad (TrackerSparql *sparql,
GError **error)
{
GError *inner_error = NULL;
TrackerProperty *predicate = NULL;
+ GValue object = G_VALUE_INIT;
if ((tracker_token_is_empty (&sparql->current_state->graph) &&
sparql->policy.filter_unnamed_graph) ||
@@ -2068,6 +2100,15 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
property);
return FALSE;
}
+
+ value_init_from_token (sparql, &object, predicate,
+ &sparql->current_state->object,
+ &inner_error);
+
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
}
switch (sparql->current_state->type) {
@@ -2092,7 +2133,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
predicate,
- tracker_token_get_literal (&sparql->current_state->object),
+ &object,
&inner_error);
break;
case TRACKER_SPARQL_TYPE_DELETE:
@@ -2100,7 +2141,7 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
predicate,
- tracker_token_get_literal (&sparql->current_state->object),
+ &object,
&inner_error);
break;
case TRACKER_SPARQL_TYPE_UPDATE:
@@ -2108,13 +2149,15 @@ tracker_sparql_apply_quad (TrackerSparql *sparql,
tracker_token_get_idstring (&sparql->current_state->graph),
tracker_token_get_idstring (&sparql->current_state->subject),
predicate,
- tracker_token_get_literal (&sparql->current_state->object),
+ &object,
&inner_error);
break;
default:
g_assert_not_reached ();
}
+ g_value_unset (&object);
+
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -9051,9 +9094,15 @@ translate_RDFLiteral (TrackerSparql *sparql,
if (is_parameter) {
binding = tracker_parameter_binding_new (str, NULL);
} else {
+ const gchar *lang = NULL;
GBytes *bytes;
- bytes = tracker_sparql_make_langstring (str, langtag);
+ if (langtag) {
+ g_assert (langtag[0] == '@');
+ lang = &langtag[1];
+ }
+
+ bytes = tracker_sparql_make_langstring (str, lang);
binding = tracker_literal_binding_new (bytes, NULL);
g_bytes_unref (bytes);
}
@@ -9908,7 +9957,7 @@ tracker_sparql_make_langstring (const gchar *str,
if (langtag) {
g_string_append_c (langstr, '\0');
- g_string_append_printf (langstr, "%s", &langtag[1]);
+ g_string_append_printf (langstr, "%s", langtag);
}
bytes = g_bytes_new_take (langstr->str,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]