[tracker: 1/21] add current line and column numbers parameters to tracker_turtle_reader_next()




commit 756120221e9897823f79be220031b530254657ce
Author: Abanoub Ghadban <abanoub gdb gmail com>
Date:   Mon Jul 19 13:46:21 2021 +0200

    add current line and column numbers parameters to tracker_turtle_reader_next()
    
    The added paramerers hold the last parsed line and column numbers.
    These numbers can be used later to display detailed error messages that specifies the location of the 
parsing error.

 src/libtracker-data/tracker-data-manager.c  | 19 +++++++++++--------
 src/libtracker-data/tracker-data-update.c   |  6 ++++--
 src/libtracker-data/tracker-turtle-reader.c | 13 ++++++++++++-
 src/libtracker-data/tracker-turtle-reader.h |  2 ++
 4 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 89deafc42..427eb66eb 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1794,7 +1794,8 @@ load_ontology_file (TrackerDataManager  *manager,
 
        while (tracker_turtle_reader_next (reader,
                                           &subject, &predicate, &object,
-                                          NULL, NULL, &ttl_error)) {
+                                          NULL, NULL, NULL,
+                                          NULL, &ttl_error)) {
                GError *ontology_error = NULL;
 
                tracker_data_ontology_load_statement (manager, ontology_uri,
@@ -1844,7 +1845,8 @@ get_ontology_from_file (TrackerDataManager *manager,
 
        while (tracker_turtle_reader_next (reader,
                                           &subject, &predicate, &object,
-                                          NULL, NULL, &internal_error)) {
+                                          NULL, NULL, NULL,
+                                          NULL, &internal_error)) {
                if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
                        if (g_strcmp0 (object, TRACKER_PREFIX_NRL "Ontology") == 0) {
                                TrackerOntology *ontology;
@@ -2037,7 +2039,8 @@ import_ontology_file (TrackerDataManager *manager,
 
        while (tracker_turtle_reader_next (reader,
                                           &subject, &predicate, &object,
-                                          NULL, NULL, &error)) {
+                                          NULL, NULL, NULL,
+                                          NULL, &error)) {
                tracker_data_ontology_process_statement (manager,
                                                         subject, predicate, object,
                                                         in_update);
@@ -4023,8 +4026,8 @@ tracker_data_manager_initable_init (GInitable     *initable,
                 * has changed since we dealt with the file last time. */
 
                stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, 
&n_error,
-                       "SELECT Resource.Uri, \"nrl:Ontology\".\"nrl:lastModified\" FROM \"nrl:Ontology\" "
-                       "INNER JOIN Resource ON Resource.ID = \"nrl:Ontology\".ID ");
+                                                             "SELECT Resource.Uri, 
\"nrl:Ontology\".\"nrl:lastModified\" FROM \"nrl:Ontology\" "
+                                                             "INNER JOIN Resource ON Resource.ID = 
\"nrl:Ontology\".ID ");
 
                if (stmt) {
                        cursor = tracker_db_statement_start_cursor (stmt, &n_error);
@@ -4141,7 +4144,7 @@ tracker_data_manager_initable_init (GInitable     *initable,
                                                if (ontos) {
                                                        g_list_free_full (ontos, g_object_unref);
                                                }
-                                               
+
                                                goto rollback_db_changes;
                                        }
 
@@ -4181,7 +4184,7 @@ tracker_data_manager_initable_init (GInitable     *initable,
                                        if (ontos) {
                                                g_list_free_full (ontos, g_object_unref);
                                        }
-                                       
+
                                        goto rollback_db_changes;
                                }
 
@@ -4288,7 +4291,7 @@ tracker_data_manager_initable_init (GInitable     *initable,
                                if (ontos) {
                                        g_list_free_full (ontos, g_object_unref);
                                }
-                               
+
                                goto rollback_db_changes;
                        }
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 437859af3..04804cecb 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -3131,6 +3131,8 @@ tracker_data_load_turtle_file (TrackerData  *data,
                                           &object_str,
                                           &langtag,
                                           &object_is_uri,
+                                          NULL,
+                                          NULL,
                                           &inner_error)) {
                GBytes *object;
 
@@ -3139,11 +3141,11 @@ tracker_data_load_turtle_file (TrackerData  *data,
                if (object_is_uri) {
                        tracker_data_insert_statement_with_uri (data, graph,
                                                                subject, predicate, object,
-                                                               &inner_error);
+                                                               &inner_error);
                } else {
                        tracker_data_insert_statement_with_string (data, graph,
                                                                   subject, predicate, object,
-                                                                  &inner_error);
+                                                                  &inner_error);
                }
 
                g_bytes_unref (object);
diff --git a/src/libtracker-data/tracker-turtle-reader.c b/src/libtracker-data/tracker-turtle-reader.c
index 44fbb2936..184d9b43c 100644
--- a/src/libtracker-data/tracker-turtle-reader.c
+++ b/src/libtracker-data/tracker-turtle-reader.c
@@ -735,15 +735,26 @@ tracker_turtle_reader_next (TrackerTurtleReader  *reader,
                             const gchar         **object,
                             const gchar         **object_lang,
                             gboolean             *object_is_uri,
+                            goffset              *last_parsed_line_no,
+                            goffset              *last_parsed_column_no,
                             GError              **error)
 {
+       gboolean ret;
+
        g_return_val_if_fail (TRACKER_IS_TURTLE_READER (reader), FALSE);
        g_return_val_if_fail (subject, FALSE);
        g_return_val_if_fail (predicate, FALSE);
        g_return_val_if_fail (object, FALSE);
        g_return_val_if_fail (!error || !*error, FALSE);
 
-       if (!tracker_turtle_reader_iterate_next (reader, error))
+       ret = tracker_turtle_reader_iterate_next (reader, error);
+
+       if (last_parsed_line_no)
+               *last_parsed_line_no = reader->line_no;
+       if (last_parsed_column_no)
+               *last_parsed_column_no = reader->column_no;
+
+       if (!ret)
                return FALSE;
 
        *subject = reader->subject;
diff --git a/src/libtracker-data/tracker-turtle-reader.h b/src/libtracker-data/tracker-turtle-reader.h
index 8663f3cec..310cca8e2 100644
--- a/src/libtracker-data/tracker-turtle-reader.h
+++ b/src/libtracker-data/tracker-turtle-reader.h
@@ -40,6 +40,8 @@ gboolean tracker_turtle_reader_next (TrackerTurtleReader  *reader,
                                      const gchar         **object,
                                      const gchar         **object_lang,
                                      gboolean             *object_is_uri,
+                                     goffset              *last_parsed_line_no,
+                                     goffset              *last_parsed_column_no,
                                      GError              **error);
 
 GHashTable *tracker_turtle_reader_get_prefixes (TrackerTurtleReader *reader);


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