[tracker/wip/carlosg/sparql1.1: 71/113] libtracker-data: Use separate SQLITE function for blank nodes
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql1.1: 71/113] libtracker-data: Use separate SQLITE function for blank nodes
- Date: Sun, 21 Jul 2019 14:35:11 +0000 (UTC)
commit 5b6f7ba07ea6149538c730e0ee392d7ac77cf19c
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jul 7 20:06:00 2019 +0200
libtracker-data: Use separate SQLITE function for blank nodes
And use a different uri scheme on those, as we want to be able to
differentiate them later on.
src/libtracker-data/tracker-db-interface-sqlite.c | 41 +++++++++++++++++------
1 file changed, 30 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 97c1fdf80..073823508 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1732,20 +1732,14 @@ stmt_step (sqlite3_stmt *stmt)
}
static void
-function_sparql_uuid (sqlite3_context *context,
- int argc,
- sqlite3_value *argv[])
+generate_uuid (sqlite3_context *context,
+ const gchar *uri_prefix)
{
gchar *uuid = NULL;
sqlite3_stmt *stmt;
sqlite3 *db;
gint result;
- if (argc > 1) {
- sqlite3_result_error (context, "Invalid argument count", -1);
- return;
- }
-
db = sqlite3_context_db_handle (context);
result = sqlite3_prepare_v2 (db, "SELECT ID FROM Resource WHERE Uri=?",
@@ -1757,7 +1751,7 @@ function_sparql_uuid (sqlite3_context *context,
do {
g_clear_pointer (&uuid, g_free);
- uuid = tracker_generate_uuid ("urn:uuid");
+ uuid = tracker_generate_uuid (uri_prefix);
sqlite3_reset (stmt);
sqlite3_bind_text (stmt, 1, uuid, -1, SQLITE_TRANSIENT);
@@ -1769,10 +1763,35 @@ function_sparql_uuid (sqlite3_context *context,
if (result != SQLITE_DONE) {
sqlite3_result_error (context, sqlite3_errstr (result), -1);
g_free (uuid);
+ } else {
+ sqlite3_result_text (context, uuid, -1, g_free);
+ }
+}
+
+static void
+function_sparql_uuid (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ if (argc > 0) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ generate_uuid (context, "urn:uuid");
+}
+
+static void
+function_sparql_bnode (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ if (argc > 1) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
return;
}
- sqlite3_result_text (context, uuid, -1, g_free);
+ generate_uuid (context, "urn:bnode");
}
static int
@@ -1860,7 +1879,7 @@ initialize_functions (TrackerDBInterface *db_interface)
function_sparql_data_type },
/* UUID */
{ "SparqlUUID", 0, SQLITE_ANY, function_sparql_uuid },
- { "SparqlBNODE", -1, SQLITE_ANY | SQLITE_DETERMINISTIC, function_sparql_uuid },
+ { "SparqlBNODE", -1, SQLITE_ANY | SQLITE_DETERMINISTIC, function_sparql_bnode },
};
for (i = 0; i < G_N_ELEMENTS (functions); i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]