[tracker/async-queries-cursor-review: 3/6] libtracker-db, libtracker-data, tracker-store: Support for interrupting queries
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/async-queries-cursor-review: 3/6] libtracker-db, libtracker-data, tracker-store: Support for interrupting queries
- Date: Wed, 21 Apr 2010 15:26:37 +0000 (UTC)
commit 9f040797878d7e83f7a3565f224bce5f3cb40bb1
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Apr 20 10:55:31 2010 +0200
libtracker-db, libtracker-data, tracker-store: Support for interrupting queries
src/libtracker-data/tracker-data-manager.c | 17 +++++++--------
src/libtracker-data/tracker-data-query.c | 4 +-
src/libtracker-data/tracker-data-update.c | 4 +-
src/libtracker-db/tracker-db-interface-sqlite.c | 14 +++++++++--
src/libtracker-db/tracker-db-interface.c | 5 ++-
src/libtracker-db/tracker-db-interface.h | 26 ++++++++++++----------
src/libtracker-db/tracker-db-manager.c | 2 +-
src/tracker-store/tracker-resources.c | 19 +++++++++++++---
8 files changed, 56 insertions(+), 35 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 25a4b1b..574e299 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1103,7 +1103,7 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
g_object_unref (stmt);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
TrackerClass *super_class;
const gchar *super_class_uri;
@@ -1132,7 +1132,7 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
g_object_unref (stmt);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
TrackerProperty *super_property;
const gchar *super_property_uri;
@@ -1160,7 +1160,7 @@ db_get_static_data (TrackerDBInterface *iface)
g_object_unref (stmt);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
TrackerOntology *ontology;
const gchar *uri;
time_t last_mod;
@@ -1189,7 +1189,7 @@ db_get_static_data (TrackerDBInterface *iface)
g_object_unref (stmt);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
TrackerNamespace *namespace;
const gchar *uri, *prefix;
@@ -1219,7 +1219,7 @@ db_get_static_data (TrackerDBInterface *iface)
g_object_unref (stmt);
if (cursor) {
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
TrackerClass *class;
const gchar *uri;
gint id;
@@ -1288,8 +1288,7 @@ db_get_static_data (TrackerDBInterface *iface)
g_object_unref (stmt);
if (cursor) {
-
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
GValue value = { 0 };
TrackerProperty *property;
const gchar *uri, *domain_uri, *range_uri;
@@ -2022,7 +2021,7 @@ get_new_service_id (TrackerDBInterface *iface)
g_object_unref (stmt);
if (cursor) {
- tracker_db_cursor_iter_next (cursor);
+ tracker_db_cursor_iter_next (cursor, NULL);
max_service_id = tracker_db_cursor_get_int (cursor, 0);
g_object_unref (cursor);
}
@@ -2264,7 +2263,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_free,
NULL);
- while (tracker_db_cursor_iter_next (cursor)) {
+ 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 */
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index ebf98c8..3d8eba5 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -63,7 +63,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)) {
+ while (tracker_db_cursor_iter_next (cursor, NULL)) {
const gchar *class_uri;
TrackerClass *cl;
@@ -100,7 +100,7 @@ tracker_data_query_resource_id (const gchar *uri)
g_object_unref (stmt);
if (cursor) {
- tracker_db_cursor_iter_next (cursor);
+ tracker_db_cursor_iter_next (cursor, NULL);
id = tracker_db_cursor_get_int (cursor, 0);
g_object_unref (cursor);
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index dd057e3..3cdc383 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -346,7 +346,7 @@ tracker_data_update_get_new_service_id (void)
g_object_unref (stmt);
if (cursor) {
- tracker_db_cursor_iter_next (cursor);
+ tracker_db_cursor_iter_next (cursor, NULL);
max_service_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_service_id);
g_object_unref (cursor);
}
@@ -380,7 +380,7 @@ tracker_data_update_get_next_modseq (void)
g_object_unref (stmt);
if (cursor) {
- tracker_db_cursor_iter_next (cursor);
+ tracker_db_cursor_iter_next (cursor, NULL);
max_modseq = MAX (tracker_db_cursor_get_int (cursor, 0), max_modseq);
g_object_unref (cursor);
}
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 56710dc..63a3527 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -1044,15 +1044,23 @@ tracker_db_cursor_sqlite_rewind (TrackerDBCursor *cursor)
}
static gboolean
-tracker_db_cursor_sqlite_iter_next (TrackerDBCursor *cursor)
+tracker_db_cursor_sqlite_iter_next (TrackerDBCursor *cursor,
+ GError **error)
{
TrackerDBCursorSqlitePrivate *priv;
priv = TRACKER_DB_CURSOR_SQLITE_GET_PRIVATE (cursor);
if (!priv->finished) {
- guint result;
+ guint result = SQLITE_BUSY;
- result = sqlite3_step (priv->stmt);
+ while (result == SQLITE_BUSY || result == SQLITE_IOERR_BLOCKED) {
+ result = sqlite3_step (priv->stmt);
+ }
+
+ if (result == SQLITE_INTERRUPT) {
+ g_set_error (error, TRACKER_DB_INTERFACE_ERROR, TRACKER_DB_INTERRUPTED,
+ "Interrupted");
+ }
priv->finished = (result != SQLITE_ROW);
}
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index 727391a..84cec0a 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -476,14 +476,15 @@ tracker_db_cursor_rewind (TrackerDBCursor *cursor)
}
gboolean
-tracker_db_cursor_iter_next (TrackerDBCursor *cursor)
+tracker_db_cursor_iter_next (TrackerDBCursor *cursor,
+ GError **error)
{
/* Removed for performance
g_return_val_if_fail (TRACKER_IS_DB_CURSOR (cursor), FALSE); */
g_return_val_if_fail (cursor != NULL, FALSE);
- return TRACKER_DB_CURSOR_GET_IFACE (cursor)->iter_next (cursor);
+ return TRACKER_DB_CURSOR_GET_IFACE (cursor)->iter_next (cursor, error);
}
guint
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 5c2586d..2f0e161 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -54,7 +54,8 @@ G_BEGIN_DECLS
typedef enum {
TRACKER_DB_QUERY_ERROR,
- TRACKER_DB_CORRUPT
+ TRACKER_DB_CORRUPT,
+ TRACKER_DB_INTERRUPTED
} TrackerDBInterfaceError;
typedef struct TrackerDBInterface TrackerDBInterface;
@@ -75,7 +76,7 @@ struct TrackerDBInterfaceIface {
TrackerDBResultSet * (* execute_query) (TrackerDBInterface *interface,
GError **error,
const gchar *query);
- gboolean (* interrupt) (TrackerDBInterface *interface);
+ gboolean (* interrupt) (TrackerDBInterface *interface);
};
struct TrackerDBStatementIface {
@@ -114,7 +115,8 @@ struct TrackerDBCursorIface {
GTypeInterface iface;
void (*rewind) (TrackerDBCursor *cursor);
- gboolean (*iter_next) (TrackerDBCursor *cursor);
+ gboolean (*iter_next) (TrackerDBCursor *cursor,
+ GError **error);
guint (*get_n_columns) (TrackerDBCursor *cursor);
void (*get_value) (TrackerDBCursor *cursor,
guint column,
@@ -139,19 +141,18 @@ GType tracker_db_result_set_get_type (void);
TrackerDBStatement *tracker_db_interface_create_statement (TrackerDBInterface *interface,
const gchar *query,
...) G_GNUC_PRINTF (2, 3);
-TrackerDBResultSet *tracker_db_interface_execute_vquery (TrackerDBInterface *interface,
- GError **error,
- const gchar *query,
- va_list args);
+TrackerDBResultSet *tracker_db_interface_execute_vquery (TrackerDBInterface *interface,
+ GError **error,
+ const gchar *query,
+ va_list args);
TrackerDBResultSet *tracker_db_interface_execute_query (TrackerDBInterface *interface,
- GError **error,
- const gchar *query,
+ GError **error,
+ const gchar *query,
...) G_GNUC_PRINTF (3, 4);
gboolean tracker_db_interface_interrupt (TrackerDBInterface *interface);
-
gboolean tracker_db_interface_start_transaction (TrackerDBInterface *interface);
-gboolean tracker_db_interface_end_db_transaction (TrackerDBInterface *interface);
+gboolean tracker_db_interface_end_db_transaction(TrackerDBInterface *interface);
void tracker_db_statement_bind_double (TrackerDBStatement *stmt,
int index,
double value);
@@ -191,7 +192,8 @@ guint tracker_db_result_set_get_n_rows (TrackerDBResultSet
/* Functions to deal with a cursor */
void tracker_db_cursor_rewind (TrackerDBCursor *cursor);
-gboolean tracker_db_cursor_iter_next (TrackerDBCursor *cursor);
+gboolean tracker_db_cursor_iter_next (TrackerDBCursor *cursor,
+ GError **error);
guint tracker_db_cursor_get_n_columns (TrackerDBCursor *cursor);
void tracker_db_cursor_get_value (TrackerDBCursor *cursor,
guint column,
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 22def9c..bc8eb01 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -846,7 +846,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
g_object_unref (stmt);
if (cursor) {
- if (tracker_db_cursor_iter_next (cursor)) {
+ if (tracker_db_cursor_iter_next (cursor, NULL)) {
if (g_strcmp0 (tracker_db_cursor_get_string (cursor, 0), "ok") != 0) {
must_recreate = TRUE;
}
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index c568c27..14170e1 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -178,6 +178,7 @@ tracker_resources_load (TrackerResources *object,
g_object_unref (file);
}
+
static void
query_callback (TrackerDBCursor *cursor, GError *error, gpointer user_data)
{
@@ -185,6 +186,7 @@ query_callback (TrackerDBCursor *cursor, GError *error, gpointer user_data)
DBusMessage *reply;
DBusMessageIter iter, rows_iter;
guint cols;
+ GError *loop_error = NULL;
if (error) {
tracker_dbus_request_failed (info->request_id,
@@ -207,10 +209,14 @@ query_callback (TrackerDBCursor *cursor, GError *error, gpointer user_data)
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
"as", &rows_iter);
- while (tracker_db_cursor_iter_next (cursor)) {
+ while (tracker_db_cursor_iter_next (cursor, &loop_error)) {
DBusMessageIter cols_iter;
guint i;
+ if (error != NULL) {
+ break;
+ }
+
dbus_message_iter_open_container (&rows_iter, DBUS_TYPE_ARRAY,
"s", &cols_iter);
@@ -223,9 +229,14 @@ query_callback (TrackerDBCursor *cursor, GError *error, gpointer user_data)
dbus_message_iter_close_container (&rows_iter, &cols_iter);
}
- dbus_message_iter_close_container (&iter, &rows_iter);
-
- dbus_g_method_send_reply (info->context, reply);
+ if (loop_error == NULL) {
+ dbus_message_iter_close_container (&iter, &rows_iter);
+ dbus_g_method_send_reply (info->context, reply);
+ } else {
+ dbus_message_unref (reply);
+ dbus_g_method_return_error (info->context, loop_error);
+ g_error_free (loop_error);
+ }
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]