[tracker/insert-silent: 2/2] SPARQL: Support experimental INSERT SILENT and DELETE SILENT



commit d6f8b38ed0cdb596c77d93917046f1f0bf142f91
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jun 7 12:17:25 2010 +0200

    SPARQL: Support experimental INSERT SILENT and DELETE SILENT
    
    When the SILENT keyword is used, non-syntax errors will be ignored.

 src/libtracker-data/tracker-sparql-query.vala   |   31 ++++++++++++++++++----
 src/libtracker-data/tracker-sparql-scanner.vala |   13 +++++++++-
 2 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 0a9867b..9efb479 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -210,6 +210,9 @@ public class Tracker.Sparql.Query : Object {
 	string current_predicate;
 	bool current_predicate_is_var;
 
+	// SILENT => ignore (non-syntax) errors
+	bool silent;
+
 	HashTable<string,string> prefix_map;
 
 	// All SPARQL literals
@@ -603,6 +606,9 @@ public class Tracker.Sparql.Query : Object {
 		if (accept (SparqlTokenType.INSERT)) {
 			delete_statements = false;
 
+			// SILENT => ignore (non-syntax) errors
+			silent = accept (SparqlTokenType.SILENT);
+
 			if (current_graph == null && accept (SparqlTokenType.INTO)) {
 				parse_from_or_into_param ();
 			}
@@ -611,6 +617,9 @@ public class Tracker.Sparql.Query : Object {
 			delete_statements = true;
 			blank = false;
 
+			// SILENT => ignore (non-syntax) errors
+			silent = accept (SparqlTokenType.SILENT);
+
 			if (current_graph == null && accept (SparqlTokenType.FROM)) {
 				parse_from_or_into_param ();
 			}
@@ -924,12 +933,22 @@ public class Tracker.Sparql.Query : Object {
 
 	void parse_construct_object (HashTable<string,string> var_value_map) throws SparqlError, DataError, DateError {
 		string object = parse_construct_var_or_term (var_value_map);
-		if (delete_statements) {
-			// delete triple from database
-			Data.delete_statement (current_graph, current_subject, current_predicate, object);
-		} else {
-			// insert triple into database
-			Data.insert_statement (current_graph, current_subject, current_predicate, object);
+		try {
+			if (delete_statements) {
+				// delete triple from database
+				Data.delete_statement (current_graph, current_subject, current_predicate, object);
+			} else {
+				// insert triple into database
+				Data.insert_statement (current_graph, current_subject, current_predicate, object);
+			}
+		} catch (DataError e) {
+			if (!silent) {
+				throw e;
+			}
+		} catch (DateError e) {
+			if (!silent) {
+				throw e;
+			}
 		}
 	}
 
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index 9956660..a42c60e 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -254,7 +254,16 @@ public class Tracker.SparqlScanner : Object {
 				break;
 			case 'S':
 			case 's':
-				if (matches (begin, "SELECT")) return SparqlTokenType.SELECT;
+				switch (begin[1]) {
+				case 'E':
+				case 'e':
+					if (matches (begin, "SELECT")) return SparqlTokenType.SELECT;
+					break;
+				case 'I':
+				case 'i':
+					if (matches (begin, "SILENT")) return SparqlTokenType.SILENT;
+					break;
+				}
 				break;
 			}
 			break;
@@ -857,6 +866,7 @@ public enum Tracker.SparqlTokenType {
 	SAMETERM,
 	SELECT,
 	SEMICOLON,
+	SILENT,
 	STAR,
 	STR,
 	STRING_LITERAL1,
@@ -944,6 +954,7 @@ public enum Tracker.SparqlTokenType {
 		case SAMETERM: return "`SAMETERM'";
 		case SELECT: return "`SELECT'";
 		case SEMICOLON: return "`;'";
+		case SILENT: return "`SILENT'";
 		case STAR: return "`*'";
 		case STR: return "`STR'";
 		case STRING_LITERAL1: return "string literal";



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