[tracker/wip/garnacho/sparql1.1: 11/23] libtracker-data: Add SparqlStrBefore/After sqlite functions
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/garnacho/sparql1.1: 11/23] libtracker-data: Add SparqlStrBefore/After sqlite functions
- Date: Thu, 20 Aug 2015 08:53:36 +0000 (UTC)
commit 1d20e38f4cfde75d4ee9d966d4226b40e30cdce2
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jul 28 23:16:13 2015 +0200
libtracker-data: Add SparqlStrBefore/After sqlite functions
These will be used in STRBEFORE/STRAFTER, as per sparql 1.1
src/libtracker-data/tracker-db-interface-sqlite.c | 85 +++++++++++++++++++++
1 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 01fc19d..5e6cada 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -901,6 +901,84 @@ function_sparql_encode_for_uri (sqlite3_context *context,
sqlite3_result_text (context, encoded, -1, g_free);
}
+static void
+function_sparql_string_before (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ const gchar *str, *substr, *loc;
+ gchar *encoded;
+ gint len;
+
+ if (argc != 2) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ if (sqlite3_value_type (argv[0]) != SQLITE_TEXT ||
+ sqlite3_value_type (argv[1]) != SQLITE_TEXT) {
+ sqlite3_result_error (context, "Invalid argument types", -1);
+ return;
+ }
+
+ str = sqlite3_value_text (argv[0]);
+ substr = sqlite3_value_text (argv[1]);
+ len = strlen (substr);
+
+ if (len == 0) {
+ sqlite3_result_text (context, "", -1, NULL);
+ return;
+ }
+
+ loc = strstr (str, substr);
+
+ if (!loc) {
+ sqlite3_result_text (context, "", -1, NULL);
+ return;
+ }
+
+ sqlite3_result_text (context, g_strndup (str, loc - str), -1, g_free);
+}
+
+static void
+function_sparql_string_after (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ const gchar *str, *substr, *loc;
+ gchar *encoded;
+ gint len;
+
+ if (argc != 2) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ if (sqlite3_value_type (argv[0]) != SQLITE_TEXT ||
+ sqlite3_value_type (argv[1]) != SQLITE_TEXT) {
+ sqlite3_result_error (context, "Invalid argument types", -1);
+ return;
+ }
+
+ str = sqlite3_value_text (argv[0]);
+ substr = sqlite3_value_text (argv[1]);
+ len = strlen (substr);
+
+ if (len == 0) {
+ sqlite3_result_text (context, g_strdup (str), -1, g_free);
+ return;
+ }
+
+ loc = strstr (str, substr);
+
+ if (!loc) {
+ sqlite3_result_text (context, "", -1, NULL);
+ return;
+ }
+
+ sqlite3_result_text (context, g_strdup (loc + len), -1, g_free);
+}
+
static inline int
stmt_step (sqlite3_stmt *stmt)
{
@@ -1028,6 +1106,13 @@ open_database (TrackerDBInterface *db_interface,
db_interface, &function_sparql_encode_for_uri,
NULL, NULL);
+ sqlite3_create_function (db_interface->db, "SparqlStringBefore", 2, SQLITE_ANY,
+ db_interface, &function_sparql_string_before,
+ NULL, NULL);
+ sqlite3_create_function (db_interface->db, "SparqlStringAfter", 2, SQLITE_ANY,
+ db_interface, &function_sparql_string_after,
+ NULL, NULL);
+
sqlite3_extended_result_codes (db_interface->db, 0);
sqlite3_busy_timeout (db_interface->db, 100000);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]