[tracker/wip/carlosg/sparql-parser-ng: 25/50] libtracker-data: Add back support for DELETE{}/INSERT{} with no WHERE clause



commit 64c5784bf93ed41d33d926c9df71f5da04172268
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Sep 2 12:13:23 2018 +0200

    libtracker-data: Add back support for DELETE{}/INSERT{} with no WHERE clause
    
    This is a Tracker extension to SPARQL.

 src/libtracker-data/tracker-sparql-grammar.h |  8 +++++++-
 src/libtracker-data/tracker-sparql.c         | 18 +++++++++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-grammar.h b/src/libtracker-data/tracker-sparql-grammar.h
index 8e305b1fc..3dcffff4c 100644
--- a/src/libtracker-data/tracker-sparql-grammar.h
+++ b/src/libtracker-data/tracker-sparql-grammar.h
@@ -1245,6 +1245,10 @@ static const TrackerGrammarRule helper_DeleteClause_opt_1[] = { L(SILENT), NIL }
 static const TrackerGrammarRule rule_DeleteClause[] = { L(DELETE), OPT(helper_DeleteClause_opt_1), 
R(QuadPattern), NIL };
 
 /* Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' 
GroupGraphPattern
+ *
+ * TRACKER EXTENSION:
+ * Last part of the clause is:
+ * ('WHERE' GroupGraphPattern)?
  */
 static const TrackerGrammarRule helper_Modify_seq_1[] = { L(WITH), R(iri), NIL };
 static const TrackerGrammarRule helper_Modify_opt_1[] = { S(helper_Modify_seq_1), NIL };
@@ -1252,7 +1256,9 @@ static const TrackerGrammarRule helper_Modify_opt_2[] = { R(InsertClause), NIL }
 static const TrackerGrammarRule helper_Modify_seq_2[] = { R(DeleteClause), OPT(helper_Modify_opt_2), NIL };
 static const TrackerGrammarRule helper_Modify_or[] = { S(helper_Modify_seq_2), R(InsertClause), NIL };
 static const TrackerGrammarRule helper_Modify_gte0[] = { R(UsingClause), NIL };
-static const TrackerGrammarRule rule_Modify[] = { OPT(helper_Modify_opt_1), OR(helper_Modify_or), 
GTE0(helper_Modify_gte0), L(WHERE), R(GroupGraphPattern), NIL };
+static const TrackerGrammarRule helper_Modify_seq_3[] = { L(WHERE), R(GroupGraphPattern), NIL };
+static const TrackerGrammarRule helper_Modify_opt_3[] = { S(helper_Modify_seq_3), NIL };
+static const TrackerGrammarRule rule_Modify[] = { OPT(helper_Modify_opt_1), OR(helper_Modify_or), 
GTE0(helper_Modify_gte0), OPT(helper_Modify_opt_3), NIL };
 
 /* DeleteWhere ::= 'DELETE WHERE' QuadPattern
  */
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 20538e030..3e3dc5b48 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2706,6 +2706,10 @@ translate_Modify (TrackerSparql  *sparql,
        gboolean retval = TRUE;
 
        /* Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' 
GroupGraphPattern
+        *
+        * TRACKER EXTENSION:
+        * Last part of the clause is:
+        * ('WHERE' GroupGraphPattern)?
         */
        if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_WITH)) {
                _call_rule (sparql, NAMED_RULE_iri, error);
@@ -2725,11 +2729,15 @@ translate_Modify (TrackerSparql  *sparql,
                _call_rule (sparql, NAMED_RULE_UsingClause, error);
        }
 
-       _expect (sparql, RULE_TYPE_LITERAL, LITERAL_WHERE);
-       where = _skip_rule (sparql, NAMED_RULE_GroupGraphPattern);
-       solution = get_solution_for_pattern (sparql, where, error);
-       if (!solution)
-               return FALSE;
+       if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_WHERE)) {
+               where = _skip_rule (sparql, NAMED_RULE_GroupGraphPattern);
+               solution = get_solution_for_pattern (sparql, where, error);
+               if (!solution)
+                       return FALSE;
+       } else {
+               solution = tracker_solution_new (1);
+               tracker_solution_add_value (solution, "");
+       }
 
        if (delete) {
                retval = iterate_solution (sparql, solution, delete, error);


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