[tracker/wip/carlosg/test-error-fixes: 1/5] libtracker-data: Make get_db_interface() return a GError
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/test-error-fixes: 1/5] libtracker-data: Make get_db_interface() return a GError
- Date: Tue, 13 Jul 2021 12:06:00 +0000 (UTC)
commit 69ee74526bd1e16c7c5e5dc0ddf7f10efaf5ec2a
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jul 13 12:15:40 2021 +0200
libtracker-data: Make get_db_interface() return a GError
This is a failable operation, so add a GError parameter and propagate
errors happening inside instead of warning in place.
src/libtracker-data/tracker-data-manager.c | 5 +++--
src/libtracker-data/tracker-data-manager.h | 3 ++-
src/libtracker-data/tracker-db-manager.c | 6 +++---
src/libtracker-data/tracker-db-manager.h | 3 ++-
src/libtracker-data/tracker-sparql.c | 6 +++++-
src/tracker/tracker-sql.c | 8 +++++---
6 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 24be7b4ee..5edde0c4f 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -4557,9 +4557,10 @@ tracker_data_manager_get_db_manager (TrackerDataManager *manager)
}
TrackerDBInterface *
-tracker_data_manager_get_db_interface (TrackerDataManager *manager)
+tracker_data_manager_get_db_interface (TrackerDataManager *manager,
+ GError **error)
{
- return tracker_db_manager_get_db_interface (manager->db_manager);
+ return tracker_db_manager_get_db_interface (manager->db_manager, error);
}
TrackerDBInterface *
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 388b72f08..47f8c07f9 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -72,7 +72,8 @@ GFile * tracker_data_manager_get_cache_location (TrackerDataManage
TrackerOntologies * tracker_data_manager_get_ontologies (TrackerDataManager *manager);
TrackerDBManager * tracker_data_manager_get_db_manager (TrackerDataManager *manager);
-TrackerDBInterface * tracker_data_manager_get_db_interface (TrackerDataManager *manager);
+TrackerDBInterface * tracker_data_manager_get_db_interface (TrackerDataManager *manager,
+ GError **error);
TrackerDBInterface * tracker_data_manager_get_writable_db_interface (TrackerDataManager *manager);
TrackerData * tracker_data_manager_get_data (TrackerDataManager *manager);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 5485ce623..8485af62e 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -817,7 +817,8 @@ tracker_db_manager_create_db_interface (TrackerDBManager *db_manager,
* returns: (callee-owns): a database connection
**/
TrackerDBInterface *
-tracker_db_manager_get_db_interface (TrackerDBManager *db_manager)
+tracker_db_manager_get_db_interface (TrackerDBManager *db_manager,
+ GError **error)
{
GError *internal_error = NULL;
TrackerDBInterface *interface = NULL;
@@ -863,8 +864,7 @@ tracker_db_manager_get_db_interface (TrackerDBManager *db_manager)
g_signal_emit (db_manager, signals[SETUP_INTERFACE], 0, interface);
} else {
if (g_async_queue_length_unlocked (db_manager->interfaces) == 0) {
- g_critical ("Error opening database: %s", internal_error->message);
- g_error_free (internal_error);
+ g_propagate_prefixed_error (error, internal_error, "Error opening database:
");
g_async_queue_unlock (db_manager->interfaces);
return NULL;
} else {
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 66b2b6b5f..b8fd04aa4 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -63,7 +63,8 @@ TrackerDBManager *tracker_db_manager_new (TrackerDBManagerF
GObject *iface_data,
gpointer vtab_data,
GError **error);
-TrackerDBInterface *tracker_db_manager_get_db_interface (TrackerDBManager *db_manager);
+TrackerDBInterface *tracker_db_manager_get_db_interface (TrackerDBManager *db_manager,
+ GError **error);
TrackerDBInterface *tracker_db_manager_get_writable_db_interface (TrackerDBManager *db_manager);
gboolean tracker_db_manager_has_enough_space (TrackerDBManager *db_manager);
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 7b11fa44e..3d8c76b89 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -9740,7 +9740,11 @@ tracker_sparql_execute_cursor (TrackerSparql *sparql,
goto error;
}
- iface = tracker_data_manager_get_db_interface (sparql->data_manager);
+ iface = tracker_data_manager_get_db_interface (sparql->data_manager,
+ error);
+ if (!iface)
+ goto error;
+
stmt = prepare_query (sparql, iface,
TRACKER_SELECT_CONTEXT (sparql->context)->literal_bindings,
parameters,
diff --git a/src/tracker/tracker-sql.c b/src/tracker/tracker-sql.c
index 6803813d0..6204dfe4f 100644
--- a/src/tracker/tracker-sql.c
+++ b/src/tracker/tracker-sql.c
@@ -96,7 +96,7 @@ static int
sql_by_query (void)
{
TrackerDBInterface *iface;
- TrackerDBStatement *stmt;
+ TrackerDBStatement *stmt = NULL;
TrackerDBCursor *cursor = NULL;
GError *error = NULL;
gint n_rows = 0;
@@ -122,9 +122,11 @@ sql_by_query (void)
g_print ("--------------------------------------------------\n");
g_print ("\n\n");
- iface = tracker_data_manager_get_db_interface (data_manager);
+ iface = tracker_data_manager_get_db_interface (data_manager, &error);
- stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, &error,
query);
+ if (iface) {
+ stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
&error, query);
+ }
if (stmt) {
cursor = tracker_db_statement_start_cursor (stmt, &error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]