[tracker/sparql-update] libtracker-data: Add syntax support for REPLACE, () is not impl. yet
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sparql-update] libtracker-data: Add syntax support for REPLACE, () is not impl. yet
- Date: Tue, 8 Mar 2011 16:42:47 +0000 (UTC)
commit 97c555b23eb4556aa66c8cb4e6366ca0ae4af5d5
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Mar 8 17:42:09 2011 +0100
libtracker-data: Add syntax support for REPLACE, () is not impl. yet
src/libtracker-data/libtracker-data.vapi | 1 +
src/libtracker-data/tracker-sparql-query.vala | 20 +++++++++++++++++++-
src/libtracker-data/tracker-sparql-scanner.vala | 13 ++++++++++++-
3 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 5d92807..ab2e4db 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -171,6 +171,7 @@ namespace Tracker {
public void load_turtle_file (GLib.File file) throws Sparql.Error;
public void notify_transaction (bool start_timer);
public void delete_statement (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
+ public void update_statement (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
public void insert_statement (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
public void insert_statement_with_uri (string? graph, string subject, string predicate, string object) throws Sparql.Error;
public void insert_statement_with_string (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 6295edd..f101dd8 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -212,6 +212,7 @@ public class Tracker.Sparql.Query : Object {
internal Context context;
bool delete_statements;
+ bool update_statements;
int bnodeid = 0;
// base UUID used for blank nodes
@@ -448,6 +449,7 @@ public class Tracker.Sparql.Query : Object {
case SparqlTokenType.WITH:
case SparqlTokenType.INSERT:
case SparqlTokenType.DELETE:
+ case SparqlTokenType.REPLACE:
if (blank) {
ublank_nodes.open ((VariantType) "aa{ss}");
execute_insert_or_delete (ublank_nodes);
@@ -588,9 +590,11 @@ public class Tracker.Sparql.Query : Object {
}
bool delete_statements;
+ bool update_statements;
if (accept (SparqlTokenType.INSERT)) {
delete_statements = false;
+ update_statements = false;
// SILENT => ignore (non-syntax) errors
silent = accept (SparqlTokenType.SILENT);
@@ -598,9 +602,19 @@ public class Tracker.Sparql.Query : Object {
if (current_graph == null && accept (SparqlTokenType.INTO)) {
parse_from_or_into_param ();
}
+ } else if (accept (SparqlTokenType.REPLACE)) {
+ delete_statements = false;
+ update_statements = true;
+
+ /* REPLACE is currently not part of any SPARQL spec */
+
+ if (current_graph == null && accept (SparqlTokenType.INTO)) {
+ parse_from_or_into_param ();
+ }
} else {
expect (SparqlTokenType.DELETE);
delete_statements = true;
+ update_statements = false;
blank = false;
// SILENT => ignore (non-syntax) errors
@@ -670,6 +684,7 @@ public class Tracker.Sparql.Query : Object {
var cursor = exec_sql_cursor (sql.str, null, null, false);
this.delete_statements = delete_statements;
+ this.update_statements = update_statements;
// iterate over all solutions
while (cursor.next ()) {
@@ -908,7 +923,10 @@ public class Tracker.Sparql.Query : Object {
return;
}
try {
- if (delete_statements) {
+ if (update_statements) {
+ // update triple in database
+ Data.update_statement (current_graph, current_subject, current_predicate, object);
+ } else if (delete_statements) {
// delete triple from database
Data.delete_statement (current_graph, current_subject, current_predicate, object);
} else {
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index e9f6615..7fde09e 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -291,7 +291,16 @@ public class Tracker.SparqlScanner : Object {
switch (begin[0]) {
case 'R':
case 'r':
- if (matches (begin, "REDUCED")) return SparqlTokenType.REDUCED;
+ switch (begin[2]) {
+ case 'D':
+ case 'd':
+ if (matches (begin, "REDUCED")) return SparqlTokenType.REDUCED;
+ break;
+ case 'P':
+ case 'p':
+ if (matches (begin, "REPLACE")) return SparqlTokenType.REPLACE;
+ break;
+ }
break;
case 'I':
case 'i':
@@ -905,6 +914,7 @@ public enum Tracker.SparqlTokenType {
PREFIX,
REDUCED,
REGEX,
+ REPLACE,
SAMETERM,
SELECT,
SEMICOLON,
@@ -997,6 +1007,7 @@ public enum Tracker.SparqlTokenType {
case PREFIX: return "`PREFIX'";
case REDUCED: return "`REDUCED'";
case REGEX: return "`REGEX'";
+ case REPLACE: return "`REPLACE'";
case SAMETERM: return "`SAMETERM'";
case SELECT: return "`SELECT'";
case SEMICOLON: return "`;'";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]