[tracker/sparql11] SPARQL: Support WITH <uri> syntax specified in SPARQL 1.1 Update draft



commit a7c7e2cb2519a24b9076797f600cee06dd14eadd
Author: Jürg Billeter <j bitron ch>
Date:   Mon Mar 8 13:23:16 2010 +0100

    SPARQL: Support WITH <uri> syntax specified in SPARQL 1.1 Update draft
    
    The old DELETE FROM / INSERT INTO syntax remains supported to not break
    any clients.

 src/libtracker-data/tracker-sparql-query.vala   |   41 ++++++++++++----------
 src/libtracker-data/tracker-sparql-scanner.vala |   15 +++++++-
 2 files changed, 35 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 2a9e696..d6111c7 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -533,15 +533,14 @@ public class Tracker.SparqlQuery : Object {
 
 		while (current () != SparqlTokenType.EOF) {
 			switch (current ()) {
+			case SparqlTokenType.WITH:
 			case SparqlTokenType.INSERT:
-				PtrArray* ptr = execute_insert (blank);
+			case SparqlTokenType.DELETE:
+				PtrArray* ptr = execute_insert_or_delete (blank);
 				if (blank) {
 					blank_nodes.add (ptr);
 				}
 				break;
-			case SparqlTokenType.DELETE:
-				execute_delete ();
-				break;
 			case SparqlTokenType.DROP:
 				execute_drop_graph ();
 				break;
@@ -971,28 +970,32 @@ public class Tracker.SparqlQuery : Object {
 		}
 	}
 
-	PtrArray? execute_insert (bool blank) throws DBInterfaceError, DataError, SparqlError, DateError {
-		expect (SparqlTokenType.INSERT);
-		if (accept (SparqlTokenType.INTO)) {
+	PtrArray? execute_insert_or_delete (bool blank) throws DBInterfaceError, DataError, SparqlError, DateError {
+		// INSERT or DELETE
+
+		if (accept (SparqlTokenType.WITH)) {
 			parse_from_or_into_param ();
 		} else {
 			current_graph = null;
 		}
-		return execute_insert_or_delete (false, blank);
-	}
 
-	void execute_delete () throws DBInterfaceError, DataError, SparqlError, DateError {
-		expect (SparqlTokenType.DELETE);
-		if (accept (SparqlTokenType.FROM)) {
-			parse_from_or_into_param ();
+		bool delete_statements;
+
+		if (accept (SparqlTokenType.INSERT)) {
+			delete_statements = false;
+
+			if (current_graph == null && accept (SparqlTokenType.INTO)) {
+				parse_from_or_into_param ();
+			}
 		} else {
-			current_graph = null;
-		}
-		execute_insert_or_delete (true, false);
-	}
+			expect (SparqlTokenType.DELETE);
+			delete_statements = true;
+			blank = false;
 
-	PtrArray? execute_insert_or_delete (bool delete_statements, bool blank) throws DBInterfaceError, DataError, SparqlError, DateError {
-		// INSERT or DELETE
+			if (current_graph == null && accept (SparqlTokenType.FROM)) {
+				parse_from_or_into_param ();
+			}
+		}
 
 		var pattern_sql = new StringBuilder ();
 		begin_query ();
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index 4fceb4f..e90abb6 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -195,7 +195,16 @@ public class Tracker.SparqlScanner : Object {
 				break;
 			case 'W':
 			case 'w':
-				if (matches (begin, "WHERE")) return SparqlTokenType.WHERE;
+				switch (begin[1]) {
+				case 'H':
+				case 'h':
+					if (matches (begin, "WHERE")) return SparqlTokenType.WHERE;
+					break;
+				case 'I':
+				case 'i':
+					if (matches (begin, "WITH")) return SparqlTokenType.WITH;
+					break;
+				}
 				break;
 			case 'F':
 			case 'f':
@@ -864,7 +873,8 @@ public enum Tracker.SparqlTokenType {
 	TRUE,
 	UNION,
 	VAR,
-	WHERE;
+	WHERE,
+	WITH;
 
 	public weak string to_string () {
 		switch (this) {
@@ -951,6 +961,7 @@ public enum Tracker.SparqlTokenType {
 		case UNION: return "`UNION'";
 		case VAR: return "variable";
 		case WHERE: return "`WHERE'";
+		case WITH: return "`WITH'";
 		default: return "unknown token";
 		}
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]