[tracker/wip/carlosg/update-perf: 61/65] core: Return a boolean on tracker_db_statement_execute()




commit 162e0a085cb314373f892cde16d56b33c62a62de
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Aug 20 16:40:38 2022 +0200

    core: Return a boolean on tracker_db_statement_execute()
    
    Instead of having to pass a GError and looking for that to check for
    errors.

 .../core/tracker-db-interface-sqlite.c             | 56 +++++++++++-----------
 src/libtracker-sparql/core/tracker-db-interface.h  |  2 +-
 2 files changed, 28 insertions(+), 30 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index ce8447b4d..2c98f153e 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -2866,32 +2866,26 @@ execute_stmt (TrackerDBInterface  *interface,
                        return FALSE;
                }
 
-               if (!error) {
-                       g_warning ("Could not perform SQLite operation, error:%d->'%s'",
-                                  sqlite3_errcode (interface->db),
-                                  sqlite3_errmsg (interface->db));
+               if (result == SQLITE_INTERRUPT) {
+                       g_set_error (error,
+                                    TRACKER_DB_INTERFACE_ERROR,
+                                    TRACKER_DB_INTERRUPTED,
+                                    "Interrupted");
+               } else if (result == SQLITE_CONSTRAINT) {
+                       g_set_error (error,
+                                    TRACKER_DB_INTERFACE_ERROR,
+                                    TRACKER_DB_CONSTRAINT,
+                                    "Constraint would be broken: %s",
+                                    sqlite3_errmsg (interface->db));
                } else {
-                       if (result == SQLITE_INTERRUPT) {
-                               g_set_error (error,
-                                            TRACKER_DB_INTERFACE_ERROR,
-                                            TRACKER_DB_INTERRUPTED,
-                                            "Interrupted");
-                       } else if (result == SQLITE_CONSTRAINT) {
-                               g_set_error (error,
-                                            TRACKER_DB_INTERFACE_ERROR,
-                                            TRACKER_DB_CONSTRAINT,
-                                            "Constraint would be broken: %s",
-                                            sqlite3_errmsg (interface->db));
-                       } else {
-                               g_set_error (error,
-                                            TRACKER_DB_INTERFACE_ERROR,
-                                            errno != ENOSPC ? TRACKER_DB_QUERY_ERROR : TRACKER_DB_NO_SPACE,
-                                            "%s%s%s%s",
-                                            sqlite3_errmsg (interface->db),
-                                            errno != 0 ? " (strerror of errno (not necessarily related): " : 
"",
-                                            errno != 0 ? g_strerror (errno) : "",
-                                            errno != 0 ? ")" : "");
-                       }
+                       g_set_error (error,
+                                    TRACKER_DB_INTERFACE_ERROR,
+                                    errno != ENOSPC ? TRACKER_DB_QUERY_ERROR : TRACKER_DB_NO_SPACE,
+                                    "%s%s%s%s",
+                                    sqlite3_errmsg (interface->db),
+                                    errno != 0 ? " (strerror of errno (not necessarily related): " : "",
+                                    errno != 0 ? g_strerror (errno) : "",
+                                    errno != 0 ? ")" : "");
                }
        }
 
@@ -3640,15 +3634,19 @@ tracker_db_cursor_get_string (TrackerDBCursor *cursor,
        return result;
 }
 
-void
+gboolean
 tracker_db_statement_execute (TrackerDBStatement  *stmt,
                               GError             **error)
 {
-       g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
-       g_return_if_fail (!stmt->stmt_is_used);
+       gboolean retval;
+
+       g_return_val_if_fail (TRACKER_IS_DB_STATEMENT (stmt), FALSE);
+       g_return_val_if_fail (!stmt->stmt_is_used, FALSE);
 
-       execute_stmt (stmt->db_interface, stmt->stmt, NULL, error);
+       retval = execute_stmt (stmt->db_interface, stmt->stmt, NULL, error);
        tracker_db_statement_sqlite_release (stmt);
+
+       return retval;
 }
 
 GArray *
diff --git a/src/libtracker-sparql/core/tracker-db-interface.h 
b/src/libtracker-sparql/core/tracker-db-interface.h
index 4a040b898..db8381264 100644
--- a/src/libtracker-sparql/core/tracker-db-interface.h
+++ b/src/libtracker-sparql/core/tracker-db-interface.h
@@ -144,7 +144,7 @@ void                    tracker_db_statement_bind_bytes              (TrackerDBS
 void                    tracker_db_statement_bind_value              (TrackerDBStatement         *stmt,
                                                                       int                         index,
                                                                      const GValue               *value);
-void                    tracker_db_statement_execute                 (TrackerDBStatement         *stmt,
+gboolean                tracker_db_statement_execute                 (TrackerDBStatement         *stmt,
                                                                       GError                    **error);
 TrackerDBCursor *       tracker_db_statement_start_cursor            (TrackerDBStatement         *stmt,
                                                                       GError                    **error);


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