[tracker/sql-error-checks] libtracker-[db|data]: Improve error checking on SQL calls.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sql-error-checks] libtracker-[db|data]: Improve error checking on SQL calls.
- Date: Wed, 19 May 2010 10:27:40 +0000 (UTC)
commit 1bd168f60e4d9a6dfc90bfb3b0dd18cf68d0f556
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 19 11:46:26 2010 +0200
libtracker-[db|data]: Improve error checking on SQL calls.
A new GError parameter was added to tracker_db_interface_create_statement(), all
callers have been updated to handle errors where it made most sense. Also,
a bunch of calls to execute_query(), execute(), start_cursor() and iter_next()
have been changed to also check for errors.
src/libtracker-data/tracker-data-manager.c | 231 +++++++++++++-----
src/libtracker-data/tracker-data-query.c | 50 +++-
src/libtracker-data/tracker-data-update.c | 292 ++++++++++++++++-------
src/libtracker-db/libtracker-db.vapi | 5 +-
src/libtracker-db/tracker-db-interface-sqlite.c | 16 +-
src/libtracker-db/tracker-db-interface.c | 3 +-
src/libtracker-db/tracker-db-interface.h | 6 +-
src/libtracker-db/tracker-db-manager.c | 28 ++-
8 files changed, 452 insertions(+), 179 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c82deeb..7dfe84e 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1093,11 +1093,19 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
{
TrackerDBStatement *stmt;
TrackerDBCursor *cursor;
+ GError *error = NULL;
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:subClassOf\") "
"FROM \"rdfs:Class_rdfs:subClassOf\" "
"WHERE ID = (SELECT ID FROM Resource WHERE Uri = ?)");
+
+ if (!stmt) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
tracker_db_statement_bind_text (stmt, 0, tracker_class_get_uri (class));
cursor = tracker_db_statement_start_cursor (stmt, NULL);
g_object_unref (stmt);
@@ -1122,11 +1130,19 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
{
TrackerDBStatement *stmt;
TrackerDBCursor *cursor;
+ GError *error = NULL;
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:subPropertyOf\") "
"FROM \"rdf:Property_rdfs:subPropertyOf\" "
"WHERE ID = (SELECT ID FROM Resource WHERE Uri = ?)");
+
+ if (!stmt) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
tracker_db_statement_bind_text (stmt, 0, tracker_property_get_uri (property));
cursor = tracker_db_statement_start_cursor (stmt, NULL);
g_object_unref (stmt);
@@ -1149,18 +1165,22 @@ static void
db_get_static_data (TrackerDBInterface *iface)
{
TrackerDBStatement *stmt;
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBResultSet *result_set;
+ GError *error = NULL;
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Ontology\".ID), "
"\"nao:lastModified\" "
"FROM \"tracker:Ontology\"");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
TrackerOntology *ontology;
const gchar *uri;
time_t last_mod;
@@ -1179,17 +1199,26 @@ db_get_static_data (TrackerDBInterface *iface)
}
g_object_unref (cursor);
+ cursor = NULL;
}
- stmt = tracker_db_interface_create_statement (iface,
+ if (error) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ }
+
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Namespace\".ID), "
"\"tracker:prefix\" "
"FROM \"tracker:Namespace\"");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
TrackerNamespace *namespace;
const gchar *uri, *prefix;
@@ -1208,18 +1237,27 @@ db_get_static_data (TrackerDBInterface *iface)
}
g_object_unref (cursor);
+ cursor = NULL;
+ }
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
}
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT \"rdfs:Class\".ID, "
"(SELECT Uri FROM Resource WHERE ID = \"rdfs:Class\".ID), "
"\"tracker:notify\" "
"FROM \"rdfs:Class\" ORDER BY ID");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
TrackerClass *class;
const gchar *uri;
gint id;
@@ -1256,21 +1294,33 @@ db_get_static_data (TrackerDBInterface *iface)
/* xsd classes do not derive from rdfs:Resource and do not use separate tables */
if (!g_str_has_prefix (tracker_class_get_name (class), "xsd:")) {
/* update statistics */
- stmt = tracker_db_interface_create_statement (iface, "SELECT COUNT(1) FROM \"%s\"", tracker_class_get_name (class));
- result_set = tracker_db_statement_execute (stmt, NULL);
- tracker_db_result_set_get (result_set, 0, &count, -1);
- tracker_class_set_count (class, count);
- g_object_unref (result_set);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &error, "SELECT COUNT(1) FROM \"%s\"", tracker_class_get_name (class));
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ } else {
+ result_set = tracker_db_statement_execute (stmt, NULL);
+ tracker_db_result_set_get (result_set, 0, &count, -1);
+ tracker_class_set_count (class, count);
+ g_object_unref (result_set);
+ g_object_unref (stmt);
+ }
}
g_object_unref (class);
}
g_object_unref (cursor);
+ cursor = NULL;
+ }
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
}
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT \"rdf:Property\".ID, (SELECT Uri FROM Resource WHERE ID = \"rdf:Property\".ID), "
"(SELECT Uri FROM Resource WHERE ID = \"rdfs:domain\"), "
"(SELECT Uri FROM Resource WHERE ID = \"rdfs:range\"), "
@@ -1284,11 +1334,14 @@ db_get_static_data (TrackerDBInterface *iface)
"(SELECT 1 FROM \"rdfs:Resource_rdf:type\" WHERE ID = \"rdf:Property\".ID AND "
"\"rdf:type\" = (SELECT ID FROM Resource WHERE Uri = '" NRL_INVERSE_FUNCTIONAL_PROPERTY "')) "
"FROM \"rdf:Property\" ORDER BY ID");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
GValue value = { 0 };
TrackerProperty *property;
const gchar *uri, *domain_uri, *range_uri;
@@ -1411,6 +1464,12 @@ db_get_static_data (TrackerDBInterface *iface)
}
g_object_unref (cursor);
+ cursor = NULL;
+ }
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
}
@@ -1423,11 +1482,17 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
TrackerDBStatement *stmt;
GError *error = NULL;
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"INSERT "
"INTO Resource "
"(ID, Uri) "
"VALUES (?, ?)");
+ if (error) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
tracker_db_statement_bind_int (stmt, 0, id);
tracker_db_statement_bind_text (stmt, 1, uri);
tracker_db_statement_execute (stmt, &error);
@@ -2003,26 +2068,35 @@ get_ontologies (gboolean test_schema,
static gint
get_new_service_id (TrackerDBInterface *iface)
{
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBStatement *stmt;
gint max_service_id = 0;
+ GError *error = NULL;
/* Don't intermix this thing with tracker_data_update_get_new_service_id,
* if you use this, know what you are doing! */
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT MAX(ID) AS A FROM Resource");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- tracker_db_cursor_iter_next (cursor, NULL);
+ tracker_db_cursor_iter_next (cursor, &error);
max_service_id = tracker_db_cursor_get_int (cursor, 0);
g_object_unref (cursor);
}
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
return ++max_service_id;
}
@@ -2209,6 +2283,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
guint p;
GPtrArray *seen_classes;
GPtrArray *seen_properties;
+ GError *error = NULL;
seen_classes = g_ptr_array_new ();
seen_properties = g_ptr_array_new ();
@@ -2247,30 +2322,41 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
* for all the ontology files in ontologies_dir whether the last-modified
* has changed since we dealt with the file last time. */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT Resource.Uri, \"rdfs:Resource\".\"nao:lastModified\" FROM \"tracker:Ontology\""
"INNER JOIN Resource ON Resource.ID = \"tracker:Ontology\".ID "
"INNER JOIN \"rdfs:Resource\" ON \"tracker:Ontology\".ID = \"rdfs:Resource\".ID");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ } else {
+ cursor = NULL;
+ }
ontos_table = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
NULL);
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
- const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0);
- /* It's stored as an int in the db anyway. This is caused by
- * string_to_gvalue in tracker-data-update.c */
- gint value = tracker_db_cursor_get_int (cursor, 1);
+ if (cursor) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
+ const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0);
+ /* It's stored as an int in the db anyway. This is caused by
+ * string_to_gvalue in tracker-data-update.c */
+ gint value = tracker_db_cursor_get_int (cursor, 1);
- g_hash_table_insert (ontos_table, g_strdup (onto_uri),
- GINT_TO_POINTER (value));
+ g_hash_table_insert (ontos_table, g_strdup (onto_uri),
+ GINT_TO_POINTER (value));
+ }
+
+ g_object_unref (cursor);
}
- g_object_unref (cursor);
+ if (error) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ }
for (l = ontos; l; l = l->next) {
TrackerOntology *ontology;
@@ -2333,17 +2419,24 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (update_nao) {
/* Update the nao:lastModified in the database */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
"WHERE \"rdfs:Resource\".ID = "
"(SELECT Resource.ID FROM Resource INNER JOIN \"rdfs:Resource\" "
"ON \"rdfs:Resource\".ID = Resource.ID WHERE "
"Resource.Uri = ?)");
- tracker_db_statement_bind_int (stmt, 0, last_mod);
- tracker_db_statement_bind_text (stmt, 1, ontology_uri);
- tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, last_mod);
+ tracker_db_statement_bind_text (stmt, 1, ontology_uri);
+ tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
+
+ if (error) {
+ g_critical ("%s", error->message);
+ g_clear_error (&error);
+ }
}
g_object_unref (ontology);
@@ -2405,18 +2498,22 @@ tracker_data_manager_get_db_option_int64 (const gchar *option)
{
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
- TrackerDBResultSet *result_set;
+ TrackerDBResultSet *result_set = NULL;
gchar *str;
gint value = 0;
+ GError *error = NULL;
g_return_val_if_fail (option != NULL, 0);
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface, "SELECT OptionValue FROM Options WHERE OptionKey = ?");
- tracker_db_statement_bind_text (stmt, 0, option);
- result_set = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &error, "SELECT OptionValue FROM Options WHERE OptionKey = ?");
+
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, option);
+ result_set = tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
if (result_set) {
tracker_db_result_set_get (result_set, 0, &str, -1);
@@ -2429,6 +2526,12 @@ tracker_data_manager_get_db_option_int64 (const gchar *option)
g_object_unref (result_set);
}
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
return value;
}
@@ -2439,20 +2542,30 @@ tracker_data_manager_set_db_option_int64 (const gchar *option,
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
gchar *str;
+ GError *error = NULL;
g_return_if_fail (option != NULL);
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface, "REPLACE INTO Options (OptionKey, OptionValue) VALUES (?,?)");
- tracker_db_statement_bind_text (stmt, 0, option);
+ stmt = tracker_db_interface_create_statement (iface, &error, "REPLACE INTO Options (OptionKey, OptionValue) VALUES (?,?)");
- str = g_strdup_printf ("%"G_GINT64_FORMAT, value);
- tracker_db_statement_bind_text (stmt, 1, str);
- g_free (str);
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, option);
- tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ str = g_strdup_printf ("%"G_GINT64_FORMAT, value);
+ tracker_db_statement_bind_text (stmt, 1, str);
+ g_free (str);
+
+ tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
}
gboolean
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 3d8eba5..fccb7a7 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -40,21 +40,24 @@
GPtrArray*
tracker_data_query_rdf_type (gint id)
{
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
GPtrArray *ret = NULL;
+ GError *error = NULL;
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") "
"FROM \"rdfs:Resource_rdf:type\" "
"WHERE ID = ?");
- tracker_db_statement_bind_int (stmt, 0, id);
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, id);
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
@@ -63,7 +66,7 @@ tracker_data_query_rdf_type (gint id)
* function is called fairly often) */
ret = g_ptr_array_sized_new (20);
- while (tracker_db_cursor_iter_next (cursor, NULL)) {
+ while (tracker_db_cursor_iter_next (cursor, &error)) {
const gchar *class_uri;
TrackerClass *cl;
@@ -78,33 +81,54 @@ tracker_data_query_rdf_type (gint id)
g_object_unref (cursor);
}
+ if (G_UNLIKELY (error)) {
+ g_critical ("Could not query RDF type: %s\n", error->message);
+ g_error_free (error);
+
+ if (ret) {
+ g_ptr_array_free (ret, FALSE);
+ ret = NULL;
+ }
+ }
+
return ret;
}
gint
tracker_data_query_resource_id (const gchar *uri)
{
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
+ GError *error = NULL;
gint id = 0;
g_return_val_if_fail (uri != NULL, 0);
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT ID FROM Resource WHERE Uri = ?");
- tracker_db_statement_bind_text (stmt, 0, uri);
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, uri);
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- tracker_db_cursor_iter_next (cursor, NULL);
- id = tracker_db_cursor_get_int (cursor, 0);
+ if (tracker_db_cursor_iter_next (cursor, &error)) {
+ id = tracker_db_cursor_get_int (cursor, 0);
+ }
+
g_object_unref (cursor);
}
+ if (G_UNLIKELY (error)) {
+ g_critical ("Could not query resource ID: %s\n", error->message);
+ g_error_free (error);
+ }
+
return id;
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 3cdc383..5694696 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -330,9 +330,10 @@ GQuark tracker_data_error_quark (void) {
static gint
tracker_data_update_get_new_service_id (void)
{
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
+ GError *error = NULL;
if (G_LIKELY (max_service_id != 0)) {
return ++max_service_id;
@@ -340,17 +341,27 @@ tracker_data_update_get_new_service_id (void)
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT MAX(ID) AS A FROM Resource");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- tracker_db_cursor_iter_next (cursor, NULL);
- max_service_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_service_id);
+ if (tracker_db_cursor_iter_next (cursor, &error)) {
+ max_service_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_service_id);
+ }
+
g_object_unref (cursor);
}
+ if (G_UNLIKELY (error)) {
+ g_warning ("Could not get new resource ID: %s\n", error->message);
+ g_error_free (error);
+ }
+
return ++max_service_id;
}
@@ -364,9 +375,10 @@ tracker_data_update_shutdown (void)
static gint
tracker_data_update_get_next_modseq (void)
{
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBInterface *temp_iface;
TrackerDBStatement *stmt;
+ GError *error = NULL;
if (G_LIKELY (max_modseq != 0)) {
return ++max_modseq;
@@ -374,17 +386,27 @@ tracker_data_update_get_next_modseq (void)
temp_iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (temp_iface,
+ stmt = tracker_db_interface_create_statement (temp_iface, &error,
"SELECT MAX(\"tracker:modified\") AS A FROM \"rdfs:Resource\"");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, &error);
+ g_object_unref (stmt);
+ }
if (cursor) {
- tracker_db_cursor_iter_next (cursor, NULL);
- max_modseq = MAX (tracker_db_cursor_get_int (cursor, 0), max_modseq);
+ if (tracker_db_cursor_iter_next (cursor, &error)) {
+ max_modseq = MAX (tracker_db_cursor_get_int (cursor, 0), max_modseq);
+ }
+
g_object_unref (cursor);
}
+ if (G_UNLIKELY (error)) {
+ g_warning ("Could not get new resource ID: %s\n", error->message);
+ g_error_free (error);
+ }
+
return ++max_modseq;
}
@@ -523,7 +545,7 @@ ensure_resource_id (const gchar *uri,
{
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
-
+ GError *error = NULL;
gint id;
id = query_resource_id (uri);
@@ -536,11 +558,19 @@ ensure_resource_id (const gchar *uri,
iface = tracker_db_manager_get_db_interface ();
id = tracker_data_update_get_new_service_id ();
- stmt = tracker_db_interface_create_statement (iface, "INSERT INTO Resource (ID, Uri) VALUES (?, ?)");
- tracker_db_statement_bind_int (stmt, 0, id);
- tracker_db_statement_bind_text (stmt, 1, uri);
- tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &error, "INSERT INTO Resource (ID, Uri) VALUES (?, ?)");
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, id);
+ tracker_db_statement_bind_text (stmt, 1, uri);
+ tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
+
+ if (error) {
+ g_critical ("Could not ensure resource existence: %s", error->message);
+ g_error_free (error);
+ }
if (!in_journal_replay) {
tracker_db_journal_append_resource (id, uri);
@@ -626,12 +656,12 @@ tracker_data_resource_buffer_flush (GError **error)
if (table->delete_value) {
/* delete rows for multiple value properties */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
"DELETE FROM \"%s\" WHERE ID = ? AND \"%s\" = ?",
table_name,
property->name);
} else if (property->date_time) {
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
"INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:localDate\", \"%s:localTime\", \"%s:graph\") VALUES (?, ?, ?, ?, ?)",
table_name,
property->name,
@@ -639,13 +669,18 @@ tracker_data_resource_buffer_flush (GError **error)
property->name,
property->name);
} else {
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
"INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:graph\") VALUES (?, ?, ?)",
table_name,
property->name,
property->name);
}
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
+
param = 0;
tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
@@ -668,11 +703,14 @@ tracker_data_resource_buffer_flush (GError **error)
} else {
if (table->delete_row) {
/* remove entry from rdf:type table */
- stmt = tracker_db_interface_create_statement (iface, "DELETE FROM \"rdfs:Resource_rdf:type\" WHERE ID = ? AND \"rdf:type\" = ?");
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- tracker_db_statement_bind_int (stmt, 1, ensure_resource_id (tracker_class_get_uri (table->class), NULL));
- tracker_db_statement_execute (stmt, &actual_error);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error, "DELETE FROM \"rdfs:Resource_rdf:type\" WHERE ID = ? AND \"rdf:type\" = ?");
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ tracker_db_statement_bind_int (stmt, 1, ensure_resource_id (tracker_class_get_uri (table->class), NULL));
+ tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
if (actual_error) {
g_propagate_error (error, actual_error);
@@ -684,10 +722,13 @@ tracker_data_resource_buffer_flush (GError **error)
}
/* remove row from class table */
- stmt = tracker_db_interface_create_statement (iface, "DELETE FROM \"%s\" WHERE ID = ?", table_name);
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- tracker_db_statement_execute (stmt, &actual_error);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error, "DELETE FROM \"%s\" WHERE ID = ?", table_name);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
if (actual_error) {
g_propagate_error (error, actual_error);
@@ -700,23 +741,29 @@ tracker_data_resource_buffer_flush (GError **error)
if (table->insert) {
if (strcmp (table_name, "rdfs:Resource") == 0) {
/* ensure we have a row for the subject id */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
"INSERT OR IGNORE INTO \"%s\" (ID, \"tracker:added\", \"tracker:modified\", Available) VALUES (?, ?, ?, 1)",
table_name);
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- g_warn_if_fail (resource_time != 0);
- tracker_db_statement_bind_int64 (stmt, 1, (gint64) resource_time);
- tracker_db_statement_bind_int (stmt, 3, tracker_data_update_get_next_modseq ());
- tracker_db_statement_execute (stmt, &actual_error);
- g_object_unref (stmt);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ g_warn_if_fail (resource_time != 0);
+ tracker_db_statement_bind_int64 (stmt, 1, (gint64) resource_time);
+ tracker_db_statement_bind_int (stmt, 3, tracker_data_update_get_next_modseq ());
+ tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
} else {
/* ensure we have a row for the subject id */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
"INSERT OR IGNORE INTO \"%s\" (ID) VALUES (?)",
table_name);
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- tracker_db_statement_execute (stmt, &actual_error);
- g_object_unref (stmt);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
}
if (actual_error) {
@@ -749,7 +796,13 @@ tracker_data_resource_buffer_flush (GError **error)
g_string_append (sql, " WHERE ID = ?");
- stmt = tracker_db_interface_create_statement (iface, "%s", sql->str);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error, "%s", sql->str);
+ g_string_free (sql, TRUE);
+
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
param = 0;
for (i = 0; i < table->properties->len; i++) {
@@ -777,8 +830,6 @@ tracker_data_resource_buffer_flush (GError **error)
tracker_db_statement_execute (stmt, &actual_error);
g_object_unref (stmt);
- g_string_free (sql, TRUE);
-
if (actual_error) {
g_propagate_error (error, actual_error);
return;
@@ -1111,18 +1162,28 @@ get_property_values (TrackerProperty *property)
if (!resource_buffer->create) {
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
- TrackerDBResultSet *result_set;
+ TrackerDBResultSet *result_set = NULL;
const gchar *table_name;
const gchar *field_name;
+ GError *error = NULL;
table_name = tracker_property_get_table_name (property);
field_name = tracker_property_get_name (property);
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface, "SELECT \"%s\" FROM \"%s\" WHERE ID = ?", field_name, table_name);
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- result_set = tracker_db_statement_execute (stmt, NULL);
+ stmt = tracker_db_interface_create_statement (iface, &error, "SELECT \"%s\" FROM \"%s\" WHERE ID = ?", field_name, table_name);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ result_set = tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
+
+ if (error) {
+ g_warning ("Could not get property values: %s\n", error->message);
+ g_error_free (error);
+ }
/* We use a result_set instead of a cursor here because it's
* possible that otherwise the cursor would remain open during
@@ -1153,7 +1214,6 @@ get_property_values (TrackerProperty *property)
}
g_object_unref (result_set);
}
- g_object_unref (stmt);
}
return old_values;
@@ -1410,11 +1470,12 @@ cache_delete_resource_type (TrackerClass *class,
{
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
- TrackerDBResultSet *result_set;
+ TrackerDBResultSet *result_set = NULL;
TrackerProperty **properties, *prop;
gboolean found;
gint i;
guint p, n_props;
+ GError *error = NULL;
iface = tracker_db_manager_get_db_interface ();
@@ -1432,14 +1493,22 @@ cache_delete_resource_type (TrackerClass *class,
/* retrieve all subclasses we need to remove from the subject
* before we can remove the class specified as object of the statement */
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdfs:Class_rdfs:subClassOf\".ID) "
"FROM \"rdfs:Resource_rdf:type\" INNER JOIN \"rdfs:Class_rdfs:subClassOf\" ON (\"rdf:type\" = \"rdfs:Class_rdfs:subClassOf\".ID) "
"WHERE \"rdfs:Resource_rdf:type\".ID = ? AND \"rdfs:subClassOf\" = (SELECT ID FROM Resource WHERE Uri = ?)");
- tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
- tracker_db_statement_bind_text (stmt, 1, tracker_class_get_uri (class));
- result_set = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
+ tracker_db_statement_bind_text (stmt, 1, tracker_class_get_uri (class));
+ result_set = tracker_db_statement_execute (stmt, &error);
+ g_object_unref (stmt);
+ }
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
if (result_set) {
do {
@@ -2043,7 +2112,7 @@ tracker_data_delete_resource_description (const gchar *graph,
{
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
- TrackerDBResultSet *result_set, *single_result, *multi_result;
+ TrackerDBResultSet *result_set = NULL, *single_result, *multi_result = NULL;
TrackerClass *class;
gchar *urn;
GString *sql;
@@ -2052,6 +2121,7 @@ tracker_data_delete_resource_description (const gchar *graph,
gboolean first, bail_out = FALSE;
gint resource_id;
guint p, n_props;
+ GError *actual_error = NULL;
/* We use result_sets instead of cursors here because it's possible
* that otherwise the query of the outer cursor would be reused by the
@@ -2061,10 +2131,19 @@ tracker_data_delete_resource_description (const gchar *graph,
/* DROP GRAPH <url> - url here is nie:url */
- stmt = tracker_db_interface_create_statement (iface, "SELECT ID, (SELECT Uri FROM Resource WHERE ID = \"nie:DataObject\".ID) FROM \"nie:DataObject\" WHERE \"nie:DataObject\".\"nie:url\" = ?");
- tracker_db_statement_bind_text (stmt, 0, url);
- result_set = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
+ "SELECT ID, (SELECT Uri FROM Resource WHERE ID = \"nie:DataObject\".ID) FROM \"nie:DataObject\" WHERE \"nie:DataObject\".\"nie:url\" = ?");
+
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, url);
+ result_set = tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
+
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
if (result_set) {
tracker_db_result_set_get (result_set, 0, &resource_id, -1);
@@ -2078,10 +2157,19 @@ tracker_data_delete_resource_description (const gchar *graph,
properties = tracker_ontologies_get_properties (&n_props);
- stmt = tracker_db_interface_create_statement (iface, "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
- tracker_db_statement_bind_int (stmt, 0, resource_id);
- result_set = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error,
+ "SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_id);
+ result_set = tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
+
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
if (result_set) {
do {
@@ -2126,10 +2214,19 @@ tracker_data_delete_resource_description (const gchar *graph,
single_result = NULL;
if (!first) {
g_string_append_printf (sql, " FROM \"%s\" WHERE ID = ?", tracker_class_get_name (class));
- stmt = tracker_db_interface_create_statement (iface, "%s", sql->str);
- tracker_db_statement_bind_int (stmt, 0, resource_id);
- single_result = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error, "%s", sql->str);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_id);
+ single_result = tracker_db_statement_execute (stmt, &actual_error);
+ g_object_unref (stmt);
+ }
+
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ bail_out = TRUE;
+ break;
+ }
}
g_string_free (sql, TRUE);
@@ -2153,7 +2250,6 @@ tracker_data_delete_resource_description (const gchar *graph,
if (!tracker_property_get_multiple_values (property)) {
gchar *value;
- GError *new_error = NULL;
/* single value property, value in single_result_set */
@@ -2163,10 +2259,11 @@ tracker_data_delete_resource_description (const gchar *graph,
tracker_data_delete_statement (graph, urn,
tracker_property_get_uri (property),
value,
- &new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
+ &actual_error);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
bail_out = TRUE;
+ break;
}
g_free (value);
}
@@ -2182,27 +2279,35 @@ tracker_data_delete_resource_description (const gchar *graph,
" FROM \"%s\" WHERE ID = ?",
tracker_property_get_table_name (property));
- stmt = tracker_db_interface_create_statement (iface, "%s", sql->str);
- tracker_db_statement_bind_int (stmt, 0, resource_id);
- multi_result = tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (iface, &actual_error, "%s", sql->str);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, resource_id);
+ multi_result = tracker_db_statement_execute (stmt, NULL);
+ g_object_unref (stmt);
+ }
+
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ bail_out = TRUE;
+ break;
+ }
if (multi_result) {
do {
gchar *value;
- GError *new_error = NULL;
tracker_db_result_set_get (multi_result, 0, &value, -1);
tracker_data_delete_statement (graph, urn,
tracker_property_get_uri (property),
value,
- &new_error);
+ &actual_error);
g_free (value);
- if (new_error) {
- g_propagate_error (error, new_error);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
bail_out = TRUE;
break;
}
@@ -2420,6 +2525,7 @@ ontology_transaction_end (GList *ontology_queue,
gint last_mod = 0;
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
+ GError *error = NULL;
iface = tracker_db_manager_get_db_interface ();
@@ -2427,16 +2533,21 @@ ontology_transaction_end (GList *ontology_queue,
* db. See tracker-data-manager.c for more info. */
last_mod = (gint) tracker_ontology_get_last_modified (ontology);
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &error,
"UPDATE \"rdfs:Resource\" SET \"nao:lastModified\"= ? "
"WHERE \"rdfs:Resource\".ID = "
"(SELECT Resource.ID FROM Resource INNER JOIN \"rdfs:Resource\" "
"ON \"rdfs:Resource\".ID = Resource.ID WHERE "
"Resource.Uri = ?)");
- tracker_db_statement_bind_int (stmt, 0, last_mod);
- tracker_db_statement_bind_text (stmt, 1, ontology_uri);
- tracker_db_statement_execute (stmt, NULL);
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, last_mod);
+ tracker_db_statement_bind_text (stmt, 1, ontology_uri);
+ tracker_db_statement_execute (stmt, NULL);
+ } else {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
}
}
@@ -2532,15 +2643,18 @@ tracker_data_replay_journal (GHashTable *classes,
iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (iface,
+ stmt = tracker_db_interface_create_statement (iface, &new_error,
"INSERT "
"INTO Resource "
"(ID, Uri) "
"VALUES (?, ?)");
- tracker_db_statement_bind_int (stmt, 0, id);
- tracker_db_statement_bind_text (stmt, 1, uri);
- tracker_db_statement_execute (stmt, &new_error);
- g_object_unref (stmt);
+
+ if (stmt) {
+ tracker_db_statement_bind_int (stmt, 0, id);
+ tracker_db_statement_bind_text (stmt, 1, uri);
+ tracker_db_statement_execute (stmt, &new_error);
+ g_object_unref (stmt);
+ }
if (new_error) {
g_warning ("Journal replay error: '%s'", new_error->message);
diff --git a/src/libtracker-db/libtracker-db.vapi b/src/libtracker-db/libtracker-db.vapi
index f320ab6..170ed99 100644
--- a/src/libtracker-db/libtracker-db.vapi
+++ b/src/libtracker-db/libtracker-db.vapi
@@ -30,13 +30,14 @@ namespace Tracker {
[CCode (cprefix = "TRACKER_DB_", cheader_filename = "libtracker-db/tracker-db-interface.h")]
public errordomain DBInterfaceError {
QUERY_ERROR,
- CORRUPT
+ CORRUPT,
+ INTERRUPTED
}
[CCode (cheader_filename = "libtracker-db/tracker-db-interface.h")]
public interface DBInterface : GLib.Object {
[PrintfFormat]
- public abstract DBStatement create_statement (string query, ...);
+ public abstract DBStatement create_statement (...) throws DBInterfaceError;
}
[CCode (cheader_filename = "libtracker-db/tracker-db-manager.h")]
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index c290d16..9ebece6 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -756,8 +756,9 @@ add_row (TrackerDBResultSet *result_set,
static TrackerDBStatement *
-tracker_db_interface_sqlite_create_statement (TrackerDBInterface *db_interface,
- const gchar *query)
+tracker_db_interface_sqlite_create_statement (TrackerDBInterface *db_interface,
+ GError **error,
+ const gchar *query)
{
TrackerDBInterfaceSqlitePrivate *priv;
TrackerDBStatementSqlite *stmt;
@@ -768,11 +769,18 @@ tracker_db_interface_sqlite_create_statement (TrackerDBInterface *db_interface,
if (!stmt) {
sqlite3_stmt *sqlite_stmt;
+ int retval;
g_debug ("Preparing query: '%s'", query);
- if (sqlite3_prepare_v2 (priv->db, query, -1, &sqlite_stmt, NULL) != SQLITE_OK) {
- g_critical ("Unable to prepare query '%s': %s", query, sqlite3_errmsg (priv->db));
+ retval = sqlite3_prepare_v2 (priv->db, query, -1, &sqlite_stmt, NULL);
+
+ if (retval != SQLITE_OK) {
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_QUERY_ERROR,
+ "%s",
+ sqlite3_errmsg (priv->db));
return NULL;
}
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index 84cec0a..98bc6c2 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -235,6 +235,7 @@ ensure_result_set_state (TrackerDBResultSet *result_set)
TrackerDBStatement *
tracker_db_interface_create_statement (TrackerDBInterface *interface,
+ GError **error,
const gchar *query,
...)
{
@@ -254,7 +255,7 @@ tracker_db_interface_create_statement (TrackerDBInterface *interface,
va_end (args);
iface = TRACKER_DB_INTERFACE_GET_IFACE (interface);
- stmt = iface->create_statement (interface, str);
+ stmt = iface->create_statement (interface, error, str);
g_free (str);
return stmt;
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 2f0e161..585130a 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -72,6 +72,7 @@ struct TrackerDBInterfaceIface {
GTypeInterface iface;
TrackerDBStatement * (* create_statement) (TrackerDBInterface *interface,
+ GError **error,
const gchar *query);
TrackerDBResultSet * (* execute_query) (TrackerDBInterface *interface,
GError **error,
@@ -139,8 +140,9 @@ GType tracker_db_result_set_get_type (void);
/* Functions to create queries/procedures */
TrackerDBStatement *tracker_db_interface_create_statement (TrackerDBInterface *interface,
- const gchar *query,
- ...) G_GNUC_PRINTF (2, 3);
+ GError **error,
+ const gchar *query,
+ ...) G_GNUC_PRINTF (3, 4);
TrackerDBResultSet *tracker_db_interface_execute_vquery (TrackerDBInterface *interface,
GError **error,
const gchar *query,
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 66efc03..3ebbe33 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -555,7 +555,12 @@ tracker_db_manager_ensure_locale (void)
common = dbs[TRACKER_DB_METADATA].iface;
- stmt = tracker_db_interface_create_statement (common, "SELECT OptionValue FROM Options WHERE OptionKey = 'CollationLocale'");
+ stmt = tracker_db_interface_create_statement (common, NULL, "SELECT OptionValue FROM Options WHERE OptionKey = 'CollationLocale'");
+
+ if (!stmt) {
+ return;
+ }
+
result_set = tracker_db_statement_execute (stmt, NULL);
g_object_unref (stmt);
@@ -568,10 +573,13 @@ tracker_db_manager_ensure_locale (void)
/* Locales differ, update collate keys */
g_message ("Updating DB locale dependent data to: %s\n", current_locale);
- stmt = tracker_db_interface_create_statement (common, "UPDATE Options SET OptionValue = ? WHERE OptionKey = 'CollationLocale'");
- tracker_db_statement_bind_text (stmt, 0, current_locale);
- tracker_db_statement_execute (stmt, NULL);
- g_object_unref (stmt);
+ stmt = tracker_db_interface_create_statement (common, NULL, "UPDATE Options SET OptionValue = ? WHERE OptionKey = 'CollationLocale'");
+
+ if (stmt) {
+ tracker_db_statement_bind_text (stmt, 0, current_locale);
+ tracker_db_statement_execute (stmt, NULL);
+ g_object_unref (stmt);
+ }
}
g_free (stored_locale);
@@ -835,7 +843,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
g_message ("Didn't shut down cleanly last time, doing integrity checks");
for (i = 1; i < G_N_ELEMENTS (dbs) && !must_recreate; i++) {
- TrackerDBCursor *cursor;
+ TrackerDBCursor *cursor = NULL;
TrackerDBStatement *stmt;
struct stat st;
@@ -856,11 +864,13 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
loaded = TRUE;
- stmt = tracker_db_interface_create_statement (dbs[i].iface,
+ stmt = tracker_db_interface_create_statement (dbs[i].iface, NULL,
"PRAGMA integrity_check(1)");
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+ if (stmt) {
+ cursor = tracker_db_statement_start_cursor (stmt, NULL);
+ g_object_unref (stmt);
+ }
if (cursor) {
if (tracker_db_cursor_iter_next (cursor, NULL)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]