[tracker/tracker-0.8] TrackerDBInterfaceSqlite: Add functions to deal with URIs hierarchy.
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.8] TrackerDBInterfaceSqlite: Add functions to deal with URIs hierarchy.
- Date: Thu, 29 Apr 2010 13:52:00 +0000 (UTC)
commit 319f39972234b87c1a5417c49fbbbfec285ff21b
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Apr 21 15:37:30 2010 +0200
TrackerDBInterfaceSqlite: Add functions to deal with URIs hierarchy.
SparqlUriIsParent and SparqlUriIsDescendant have been added, taking 2 URIs and
returning true if the second is a direct/indirect child of the former.
src/libtracker-db/tracker-db-interface-sqlite.c | 103 +++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 878d1f2..c70628f 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -222,6 +222,101 @@ function_sparql_string_from_filename (sqlite3_context *context,
}
static void
+function_sparql_uri_is_parent (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ const gchar *uri, *parent, *remaining;
+ gboolean match = FALSE;
+ guint parent_len;
+
+ if (argc != 2) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ parent = sqlite3_value_text (argv[0]);
+ uri = sqlite3_value_text (argv[1]);
+
+ if (!parent || !uri) {
+ sqlite3_result_error (context, "Invalid arguments", -1);
+ return;
+ }
+
+ parent_len = strlen (parent);
+
+ /* Remove trailing '/', will
+ * be checked later on uri.
+ */
+ while (parent[parent_len - 1] == '/') {
+ parent_len--;
+ }
+
+ if (strncmp (uri, parent, parent_len) == 0 && uri[parent_len] == '/') {
+ while (uri[parent_len] == '/') {
+ parent_len++;
+ }
+
+ remaining = &uri[parent_len];
+
+ if (strchr (remaining, '/') == NULL) {
+ /* Remaining doesn't have uri
+ * separator, it's a direct child.
+ */
+ match = TRUE;
+ }
+ }
+
+ sqlite3_result_int (context, match);
+}
+
+static void
+function_sparql_uri_is_descendant (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ const gchar *uri, *parent, *remaining;
+ gboolean match = FALSE;
+ guint parent_len;
+
+ if (argc != 2) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ parent = sqlite3_value_text (argv[0]);
+ uri = sqlite3_value_text (argv[1]);
+
+ if (!parent || !uri) {
+ sqlite3_result_error (context, "Invalid arguments", -1);
+ return;
+ }
+
+ parent_len = strlen (parent);
+
+ /* Remove trailing '/', will
+ * be checked later on uri.
+ */
+ while (parent[parent_len - 1] == '/') {
+ parent_len--;
+ }
+
+ if (strncmp (uri, parent, parent_len) == 0 && uri[parent_len] == '/') {
+ while (uri[parent_len] == '/') {
+ parent_len++;
+ }
+
+ remaining = &uri[parent_len];
+
+ if (remaining && *remaining) {
+ match = TRUE;
+ }
+ }
+
+ sqlite3_result_int (context, match);
+}
+
+static void
function_sparql_cartesian_distance (sqlite3_context *context,
int argc,
sqlite3_value *argv[])
@@ -399,6 +494,14 @@ open_database (TrackerDBInterfaceSqlitePrivate *priv)
priv, &function_sparql_string_join,
NULL, NULL);
+ sqlite3_create_function (priv->db, "SparqlUriIsParent", 2, SQLITE_ANY,
+ priv, &function_sparql_uri_is_parent,
+ NULL, NULL);
+
+ sqlite3_create_function (priv->db, "SparqlUriIsDescendant", 2, SQLITE_ANY,
+ priv, &function_sparql_uri_is_descendant,
+ NULL, NULL);
+
sqlite3_extended_result_codes (priv->db, 0);
sqlite3_busy_timeout (priv->db, 100000);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]