[tracker/wip/carlosg/sparql1.1: 20/80] libtracker-data: Implement the LOAD command



commit 27262e3b0171b8897f421c2e9496b127248b1fd7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 31 17:57:31 2019 +0200

    libtracker-data: Implement the LOAD command
    
    This command instructs the store to load a file containing RDF triples
    into the specified graph (or the default graph if none). Add support
    for it.

 src/libtracker-data/tracker-sparql.c           | 38 +++++++++++++++++++++++++-
 src/libtracker-data/tracker-turtle-reader.vala |  2 +-
 2 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 6163dc28d..6f6ff67f0 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2394,7 +2394,43 @@ static gboolean
 translate_Load (TrackerSparql  *sparql,
                 GError        **error)
 {
-       _unimplemented ("LOAD");
+       TrackerToken resource;
+       gboolean silent = FALSE;
+       GError *inner_error = NULL;
+       const gchar *graph = NULL;
+       GFile *file;
+
+       _expect (sparql, RULE_TYPE_LITERAL, LITERAL_LOAD);
+
+       if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SILENT))
+               silent = TRUE;
+
+       _call_rule (sparql, NAMED_RULE_iri, error);
+       _init_token (&resource, sparql->current_state.prev_node, sparql);
+
+       if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_INTO)) {
+               _call_rule (sparql, NAMED_RULE_GraphRefAll, error);
+
+               if (!tracker_token_is_empty (&sparql->current_state.graph))
+                       graph = tracker_token_get_idstring (&sparql->current_state.graph);
+       }
+
+       file = g_file_new_for_uri (tracker_token_get_idstring (&resource));
+       tracker_token_unset (&resource);
+
+       tracker_data_load_turtle_file (tracker_data_manager_get_data (sparql->data_manager),
+                                      file, graph, &inner_error);
+
+       if (inner_error) {
+               g_clear_object (&file);
+
+               if (!silent) {
+                       g_propagate_error (error, inner_error);
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
 }
 
 static gboolean
diff --git a/src/libtracker-data/tracker-turtle-reader.vala b/src/libtracker-data/tracker-turtle-reader.vala
index 43006ca46..198467418 100644
--- a/src/libtracker-data/tracker-turtle-reader.vala
+++ b/src/libtracker-data/tracker-turtle-reader.vala
@@ -381,7 +381,7 @@ public class Tracker.TurtleReader : Object {
                }
        }
 
-       public static void load (File file, Data.Update data, string graph) throws Error, FileError, 
Sparql.Error, DateError, DBInterfaceError {
+       public static void load (File file, Data.Update data, string? graph) throws Error, FileError, 
Sparql.Error, DateError, DBInterfaceError {
                try {
                        data.begin_transaction ();
 


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