diary r86 - in trunk: . src



Author: pwithnall
Date: Sun Oct 12 18:48:05 2008
New Revision: 86
URL: http://svn.gnome.org/viewvc/diary?rev=86&view=rev

Log:
2008-10-12  Philip Withnall  <philip tecnocode co uk>

	* src/main.c (storage_manager_disconnected_cb), (diary_quit),
	(main):
	* src/main.h:
	* src/storage-manager.c (almanah_storage_manager_class_init),
	(create_tables), (cipher_operation_free), (database_idle_cb),
	(decrypt_database), (encrypt_database),
	(almanah_storage_manager_connect),
	(almanah_storage_manager_disconnect),
	(almanah_storage_manager_query),
	(almanah_storage_manager_query_async),
	(almanah_storage_manager_get_statistics),
	(almanah_storage_manager_entry_exists),
	(almanah_storage_manager_get_entry),
	(almanah_storage_manager_set_entry),
	(almanah_storage_manager_search_entries),
	(almanah_storage_manager_get_month_marked_days),
	(almanah_storage_manager_get_entry_links),
	(almanah_storage_manager_add_entry_link),
	(almanah_storage_manager_remove_entry_link):
	* src/storage-manager.h: Cleaned up AlmanahStorageManager, 
removing
	all GUI code from it, and replacing it with signals and GErrors.
	Also improved recovery from database corruption, with better 
logic in
	place for handling missing or empty plaintext/encrypted database
	files.



Modified:
   trunk/ChangeLog
   trunk/src/main.c
   trunk/src/main.h
   trunk/src/storage-manager.c
   trunk/src/storage-manager.h

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Sun Oct 12 18:48:05 2008
@@ -29,22 +29,8 @@
 #include "storage-manager.h"
 #include "interface.h"
 
-void
-diary_quit (void)
-{
-	diary->quitting = TRUE;
-	almanah_storage_manager_disconnect (diary->storage_manager);
-
-	gtk_widget_destroy (diary->add_link_dialog);
-	gtk_widget_destroy (diary->search_dialog);
-	gtk_widget_destroy (diary->main_window);
-
-	/* Quitting is actually done in the idle handler for disconnection
-	 * which calls diary_quit_real. */
-}
-
-void
-diary_quit_real (void)
+static void
+storage_manager_disconnected_cb (AlmanahStorageManager *self, gpointer user_data)
 {
 	g_object_unref (diary->storage_manager);
 #ifdef ENABLE_ENCRYPTION
@@ -58,6 +44,29 @@
 	exit (0);
 }
 
+void
+diary_quit (void)
+{
+	GError *error = NULL;
+
+	g_signal_connect (diary->storage_manager, "disconnected", storage_manager_disconnected_cb, NULL);
+	if (almanah_storage_manager_disconnect (diary->storage_manager, &error) == FALSE) {
+		diary_interface_error (error->message, diary->main_window);
+	}
+
+	gtk_widget_destroy (diary->add_link_dialog);
+	gtk_widget_destroy (diary->search_dialog);
+	gtk_widget_destroy (diary->main_window);
+
+	/* Quitting is actually done in storage_manager_disconnected_cb, which is called once
+	 * the storage manager has encrypted the DB and disconnected from it.
+	 * Unless, that is, disconnection failed. */
+	if (error != NULL) {
+		g_error_free (error);
+		storage_manager_disconnected_cb (diary->storage_manager, NULL);
+	}
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -106,7 +115,6 @@
 	/* Setup */
 	diary = g_new (Diary, 1);
 	diary->debug = debug;
-	diary->quitting = FALSE;
 
 #ifdef ENABLE_ENCRYPTION
 	/* Open GConf */
@@ -122,7 +130,10 @@
 	diary->storage_manager = almanah_storage_manager_new (db_filename);
 	g_free (db_filename);
 
-	almanah_storage_manager_connect (diary->storage_manager);
+	if (almanah_storage_manager_connect (diary->storage_manager, &error) == FALSE) {
+		diary_interface_error (error->message, NULL);
+		diary_quit ();
+	}
 
 	/* Create and show the interface */
 	diary_create_interface ();

Modified: trunk/src/main.h
==============================================================================
--- trunk/src/main.h	(original)
+++ trunk/src/main.h	Sun Oct 12 18:48:05 2008
@@ -44,13 +44,11 @@
 	GdkAtom native_serialisation_atom;
 
 	gboolean debug;
-	gboolean quitting;
 } Diary;
 
 Diary *diary;
 
 void diary_quit (void);
-void diary_quit_real (void);
 
 G_END_DECLS
 

Modified: trunk/src/storage-manager.c
==============================================================================
--- trunk/src/storage-manager.c	(original)
+++ trunk/src/storage-manager.c	Sun Oct 12 18:48:05 2008
@@ -30,8 +30,6 @@
 #endif /* ENABLE_ENCRYPTION */
 
 #include "main.h"
-/* TODO: Remove dependency on interface.h --- use GErrors better */
-#include "interface.h"
 #include "entry.h"
 #include "link.h"
 #include "storage-manager.h"
@@ -53,6 +51,14 @@
 	PROP_FILENAME = 1
 };
 
+enum {
+	SIGNAL_DISCONNECTED,
+	LAST_SIGNAL
+};
+
+static guint storage_manager_signals[LAST_SIGNAL] = { 0, };
+
+
 G_DEFINE_TYPE (AlmanahStorageManager, almanah_storage_manager, G_TYPE_OBJECT)
 #define ALMANAH_STORAGE_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ALMANAH_TYPE_STORAGE_MANAGER, AlmanahStorageManagerPrivate))
 
@@ -78,6 +84,13 @@
 					"Database filename", "The path and filename for the unencrypted SQLite database.",
 					NULL,
 					G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+	storage_manager_signals[SIGNAL_DISCONNECTED] = g_signal_new ("disconnected",
+				G_TYPE_FROM_CLASS (klass),
+				G_SIGNAL_RUN_LAST,
+				0, NULL, NULL,
+				g_cclosure_marshal_VOID__OBJECT,
+				G_TYPE_NONE, 1, ALMANAH_TYPE_STORAGE_MANAGER);
 }
 
 static void
@@ -162,11 +175,12 @@
 
 	i = 0;
 	while (queries[i] != NULL)
-		almanah_storage_manager_query_async (self, queries[i++], NULL, NULL);
+		almanah_storage_manager_query_async (self, queries[i++], NULL, NULL, NULL);
 }
 
 #ifdef ENABLE_ENCRYPTION
 typedef struct {
+	AlmanahStorageManager *storage_manager;
 	GIOChannel *cipher_io_channel;
 	GIOChannel *plain_io_channel;
 	gpgme_data_t gpgme_cipher;
@@ -268,6 +282,8 @@
 
 	gpgme_signers_clear (operation->context);
 	gpgme_release (operation->context);
+
+	g_object_unref (operation->storage_manager);
 	g_free (operation);
 }
 
@@ -277,12 +293,13 @@
 	gpgme_error_t gpgme_error;
 
 	if (!(gpgme_wait (operation->context, &gpgme_error, FALSE) == NULL && gpgme_error == 0)) {
+		/* A slight assumption that we're disconnecting at this point (we're technically
+		 * only encrypting), but a valid one. */
+		g_signal_emit (operation->storage_manager, storage_manager_signals[SIGNAL_DISCONNECTED], 0, operation->storage_manager);
+
 		/* Finished! */
 		cipher_operation_free (operation);
 
-		if (diary->quitting == TRUE)
-			diary_quit_real ();
-
 		return FALSE;
 	}
 
@@ -297,6 +314,7 @@
 	gpgme_error_t gpgme_error;
 
 	operation = g_new0 (CipherOperation, 1);
+	operation->storage_manager = g_object_ref (self);
 
 	/* Set up */
 	if (prepare_gpgme (self, FALSE, operation, &preparation_error) != TRUE ||
@@ -331,6 +349,7 @@
 	gpgme_key_t gpgme_keys[2] = { NULL, };
 
 	operation = g_new0 (CipherOperation, 1);
+	operation->storage_manager = g_object_ref (self);
 
 	/* Set up */
 	if (prepare_gpgme (self, TRUE, operation, &preparation_error) != TRUE) {
@@ -412,34 +431,38 @@
 }
 #endif /* ENABLE_ENCRYPTION */
 
-void
-almanah_storage_manager_connect (AlmanahStorageManager *self)
+gboolean
+almanah_storage_manager_connect (AlmanahStorageManager *self, GError **error)
 {
 #ifdef ENABLE_ENCRYPTION
+	struct stat encrypted_db_stat, plaintext_db_stat;
+
+	g_stat (self->priv->filename, &encrypted_db_stat);
+
 	/* If we're decrypting, don't bother if the cipher file doesn't exist
-	 * (i.e. the database hasn't yet been created). */
-	if (g_file_test (self->priv->filename, G_FILE_TEST_IS_REGULAR) == TRUE) {
-		GError *error = NULL;
-
-		/* If both files exist, throw an error. We can't be sure which is the corrupt one,
-		 * and attempting to go any further may jeopardise the good one. */
-		if (g_file_test (self->priv->plain_filename, G_FILE_TEST_IS_REGULAR) == TRUE) {
-			gchar *error_message = g_strdup_printf (_("Both an encrypted and plaintext version of the database exist as \"%s\" and \"%s\", and one is likely corrupt. Please delete the corrupt one (i.e. one which is 0KiB in size) before continuing. If neither file is 0KiB, the problem will most likely have been caused by Almanah being unable to encrypt the database, so you should move the first file."),
-							self->priv->filename, 
-							self->priv->plain_filename);
-			diary_interface_error (error_message, diary->main_window);
-			g_free (error_message);
-			diary_quit ();
-		}
+	 * (i.e. the database hasn't yet been created), or is empty (i.e. corrupt). */
+	if (g_file_test (self->priv->filename, G_FILE_TEST_IS_REGULAR) == TRUE && encrypted_db_stat.st_size > 0) {
+		GError *child_error = NULL;
+
+		g_stat (self->priv->plain_filename, &plaintext_db_stat);
+
+		/* Only decrypt the database if the plaintext database doesn't exist or is empty. If the plaintext
+		 * database exists and is non-empty, don't decrypt --- just use that database. */
+		if (g_file_test (self->priv->plain_filename, G_FILE_TEST_IS_REGULAR) != TRUE || plaintext_db_stat.st_size == 0) {
+			/* Decrypt the database, or display an error if that fails (but not if it
+			 * fails due to a missing encrypted DB file --- just fall through and
+			 * try to open the plain DB file in that case). */
+			if (decrypt_database (self, &child_error) != TRUE) {
+				if (child_error->code != G_FILE_ERROR_NOENT) {
+					g_propagate_error (error, child_error);
+					return FALSE;
+				}
 
-		/* Decrypt the database, or display an error if that fails (but not if it
-		 * fails due to a missing encrypted DB file --- just fall through and
-		 * try to open the plain DB file in that case). */
-		if (decrypt_database (self, &error) != TRUE && error->code != G_FILE_ERROR_NOENT) {
-			diary_interface_error (error->message, diary->main_window);
-			g_error_free (error);
-			diary_quit ();
+				g_error_free (child_error);
+			}
 		}
+
+		
 	}
 
 	self->priv->decrypted = TRUE;
@@ -449,74 +472,74 @@
 
 	/* Open the plain database */
 	if (sqlite3_open (self->priv->plain_filename, &(self->priv->connection)) != SQLITE_OK) {
-		gchar *error_message = g_strdup_printf (_("Could not open database \"%s\". SQLite provided the following error message: %s"),
-							self->priv->filename, 
-							sqlite3_errmsg (self->priv->connection));
-		diary_interface_error (error_message, diary->main_window);
-		g_free (error_message);
-		diary_quit ();
+		g_set_error (error, ALMANAH_STORAGE_MANAGER_ERROR, ALMANAH_STORAGE_MANAGER_ERROR_OPENING_FILE,
+			     _("Could not open database \"%s\". SQLite provided the following error message: %s"),
+			     self->priv->filename, 
+			     sqlite3_errmsg (self->priv->connection));
+		return FALSE;
 	}
 
 	/* Can't hurt to create the tables now */
 	create_tables (self);
+
+	return TRUE;
 }
 
-void
-almanah_storage_manager_disconnect (AlmanahStorageManager *self)
+gboolean
+almanah_storage_manager_disconnect (AlmanahStorageManager *self, GError **error)
 {
 #ifdef ENABLE_ENCRYPTION
 	gchar *encryption_key;
-	GError *error = NULL;
+	GError *child_error = NULL;
 #endif /* ENABLE_ENCRYPTION */
 
 	/* Close the DB connection */
 	sqlite3_close (self->priv->connection);
 
 	if (self->priv->decrypted == FALSE) {
-		if (diary->quitting == TRUE)
-			diary_quit_real ();
-		return;
+		g_signal_emit (self, storage_manager_signals[SIGNAL_DISCONNECTED], 0, self);
+		return TRUE;
 	}
 
 #ifdef ENABLE_ENCRYPTION
 	encryption_key = get_encryption_key ();
 	if (encryption_key == NULL) {
 		g_message (_("Error getting encryption key: GConf key \"%s\" invalid or empty. Your almanah will not be encrypted; please install Seahorse and set up a default key, or ignore this message."), ENCRYPTION_KEY_GCONF_PATH);
-		if (diary->quitting == TRUE)
-			diary_quit_real ();
-		return;
+		g_signal_emit (self, storage_manager_signals[SIGNAL_DISCONNECTED], 0, self);
+		return TRUE;
 	}
 
 	/* Encrypt the plain DB file */
-	if (encrypt_database (self, encryption_key, &error) != TRUE) {
-		if (error->code == ALMANAH_STORAGE_MANAGER_ERROR_GETTING_KEY) {
-			/* Log an error about being unable to get the key
-			 * then continue without encrypting. */
-			g_warning ("%s", error->message);
-		} else {
-			/* Display an error */
-			diary_interface_error (error->message, diary->main_window);
+	if (encrypt_database (self, encryption_key, &child_error) != TRUE) {
+		if (child_error->code != ALMANAH_STORAGE_MANAGER_ERROR_GETTING_KEY) {
+			/* Propagate the error */
+			g_propagate_error (error, child_error);
+			return FALSE;
 		}
 
-		g_error_free (error);
+		/* Log an error about being unable to get the key
+		 * then continue without encrypting. */
+		g_warning ("%s", child_error->message);
+		g_error_free (child_error);
 
-		if (diary->quitting == TRUE)
-			diary_quit_real ();
+		g_signal_emit (self, storage_manager_signals[SIGNAL_DISCONNECTED], 0, self);
 	}
 
 	g_free (encryption_key);
 #endif /* ENABLE_ENCRYPTION */
+
+	return TRUE;
 }
 
 AlmanahQueryResults *
-almanah_storage_manager_query (AlmanahStorageManager *self, const gchar *query, ...)
+almanah_storage_manager_query (AlmanahStorageManager *self, const gchar *query, GError **error, ...)
 {
 	AlmanahStorageManagerPrivate *priv = self->priv;
-	gchar *error_message, *new_query;
+	gchar *new_query;
 	va_list params;
 	AlmanahQueryResults *results;
 
-	va_start (params, query);
+	va_start (params, error);
 	new_query = sqlite3_vmprintf (query, params);
 	va_end (params);
 
@@ -525,11 +548,12 @@
 	if (diary->debug)
 		g_debug ("Database query: %s", new_query);
 	if (sqlite3_get_table (priv->connection, new_query, &(results->data), &(results->rows), &(results->columns), NULL) != SQLITE_OK) {
-		error_message = g_strdup_printf (_("Could not run query \"%s\". SQLite provided the following error message: %s"), new_query, sqlite3_errmsg (priv->connection));
-		diary_interface_error (error_message, diary->main_window);
-		g_free (error_message);
+		g_set_error (error, ALMANAH_STORAGE_MANAGER_ERROR, ALMANAH_STORAGE_MANAGER_ERROR_RUNNING_QUERY,
+			     _("Could not run query \"%s\". SQLite provided the following error message: %s"),
+			     new_query,
+			     sqlite3_errmsg (priv->connection));
 		sqlite3_free (new_query);
-		diary_quit ();
+		return NULL;
 	}
 
 	sqlite3_free (new_query);
@@ -545,24 +569,25 @@
 }
 
 gboolean
-almanah_storage_manager_query_async (AlmanahStorageManager *self, const gchar *query, const AlmanahQueryCallback callback, gpointer user_data, ...)
+almanah_storage_manager_query_async (AlmanahStorageManager *self, const gchar *query, const AlmanahQueryCallback callback, gpointer user_data, GError **error, ...)
 {
 	AlmanahStorageManagerPrivate *priv = self->priv;
-	gchar *error_message, *new_query;
+	gchar *new_query;
 	va_list params;
 
-	va_start (params, user_data);
+	va_start (params, error);
 	new_query = sqlite3_vmprintf (query, params);
 	va_end (params);
 
 	if (diary->debug)
 		g_debug ("Database query: %s", new_query);
 	if (sqlite3_exec (priv->connection, new_query, callback, user_data, NULL) != SQLITE_OK) {
-		error_message = g_strdup_printf (_("Could not run query \"%s\". SQLite provided the following error message: %s"), new_query, sqlite3_errmsg (priv->connection));
-		diary_interface_error (error_message, diary->main_window);
-		g_free (error_message);
+		g_set_error (error, ALMANAH_STORAGE_MANAGER_ERROR, ALMANAH_STORAGE_MANAGER_ERROR_RUNNING_QUERY,
+			     _("Could not run query \"%s\". SQLite provided the following error message: %s"),
+			     new_query,
+			     sqlite3_errmsg (priv->connection));
 		sqlite3_free (new_query);
-		diary_quit ();
+		return FALSE;
 	}
 
 	sqlite3_free (new_query);
@@ -575,13 +600,15 @@
 {
 	AlmanahQueryResults *results;
 
-	/* Get the number of entries and the number of letters */
-	results = almanah_storage_manager_query (self, "SELECT COUNT (year), SUM (LENGTH (content)) FROM entries");
-	if (results->rows != 1) {
-		*entry_count = 0;
-		*character_count = 0;
-		*link_count = 0;
+	*entry_count = 0;
+	*character_count = 0;
+	*link_count = 0;
 
+	/* Get the number of entries and the number of letters */
+	results = almanah_storage_manager_query (self, "SELECT COUNT (year), SUM (LENGTH (content)) FROM entries", NULL);
+	if (results == NULL) {
+		return FALSE;
+	} else if (results->rows != 1) {
 		almanah_storage_manager_free_results (results);
 		return FALSE;
 	} else {
@@ -597,8 +624,10 @@
 	almanah_storage_manager_free_results (results);
 
 	/* Get the number of links */
-	results = almanah_storage_manager_query (self, "SELECT COUNT (year) FROM entry_links");
-	if (results->rows != 1) {
+	results = almanah_storage_manager_query (self, "SELECT COUNT (year) FROM entry_links", NULL);
+	if (results == NULL) {
+		return FALSE;
+	} else if (results->rows != 1) {
 		*link_count = 0;
 
 		almanah_storage_manager_free_results (results);
@@ -617,11 +646,13 @@
 	AlmanahQueryResults *results;
 	gboolean exists = FALSE;
 
-	results = almanah_storage_manager_query (self, "SELECT day FROM entries WHERE year = %u AND month = %u AND day = %u LIMIT 1",
-					       g_date_get_year (date),
-					       g_date_get_month (date),
-					       g_date_get_day (date));
+	results = almanah_storage_manager_query (self, "SELECT day FROM entries WHERE year = %u AND month = %u AND day = %u LIMIT 1", NULL,
+						 g_date_get_year (date),
+						 g_date_get_month (date),
+						 g_date_get_day (date));
 
+	if (results == NULL)
+		return FALSE;
 	if (results->rows == 1)
 		exists = TRUE;
 
@@ -646,11 +677,13 @@
 	AlmanahQueryResults *results;
 	AlmanahEntry *entry;
 
-	results = almanah_storage_manager_query (self, "SELECT content FROM entries WHERE year = %u AND month = %u AND day = %u",
+	results = almanah_storage_manager_query (self, "SELECT content FROM entries WHERE year = %u AND month = %u AND day = %u", NULL,
 						 g_date_get_year (date),
 						 g_date_get_month (date),
 						 g_date_get_day (date));
 
+	if (results == NULL)
+		return NULL;
 	if (results->rows != 1) {
 		/* Invalid number of rows returned. */
 		almanah_storage_manager_free_results (results);
@@ -685,11 +718,11 @@
 
 	if (almanah_entry_is_empty (entry) == TRUE) {
 		/* Delete the entry */
-		almanah_storage_manager_query_async (self, "DELETE FROM entries WHERE year = %u AND month = %u AND day = %u", NULL, NULL,
+		almanah_storage_manager_query_async (self, "DELETE FROM entries WHERE year = %u AND month = %u AND day = %u", NULL, NULL, NULL,
 						     g_date_get_year (&date),
 						     g_date_get_month (&date),
 						     g_date_get_day (&date));
-		almanah_storage_manager_query_async (self, "DELETE FROM entry_links WHERE year = %u AND month = %u AND day = %u", NULL, NULL,
+		almanah_storage_manager_query_async (self, "DELETE FROM entry_links WHERE year = %u AND month = %u AND day = %u", NULL, NULL, NULL,
 						     g_date_get_year (&date),
 						     g_date_get_month (&date),
 						     g_date_get_day (&date));
@@ -699,7 +732,7 @@
 		/* Update the entry */
 		gchar *content = almanah_entry_get_content (entry);
 
-		almanah_storage_manager_query_async (self, "REPLACE INTO entries (year, month, day, content) VALUES (%u, %u, %u, '%q')", NULL, NULL,
+		almanah_storage_manager_query_async (self, "REPLACE INTO entries (year, month, day, content) VALUES (%u, %u, %u, '%q')", NULL, NULL, NULL,
 						     g_date_get_year (&date),
 						     g_date_get_month (&date),
 						     g_date_get_day (&date),
@@ -730,12 +763,16 @@
 	AlmanahQueryResults *results;
 	guint i;
 
-	results = almanah_storage_manager_query (self, "SELECT day, month, year FROM entries WHERE content LIKE '%%%q%%'", search_string);
+	results = almanah_storage_manager_query (self, "SELECT day, month, year FROM entries WHERE content LIKE '%%%q%%'", NULL,
+						 search_string);
+
+	*matches = NULL;
+	if (results == NULL)
+		return 0;
 
 	/* No results? */
 	if (results->rows < 1) {
 		almanah_storage_manager_free_results (results);
-		*matches = NULL;
 		return 0;
 	}
 
@@ -762,7 +799,12 @@
 	guint i;
 	gboolean *days = g_slice_alloc0 (sizeof (gboolean) * 32);
 
-	results = almanah_storage_manager_query (self, "SELECT day FROM entries WHERE year = %u AND month = %u", year, month);
+	results = almanah_storage_manager_query (self, "SELECT day FROM entries WHERE year = %u AND month = %u", NULL,
+						 year,
+						 month);
+
+	if (results == NULL)
+		return days;
 
 	for (i = 1; i <= results->rows; i++)
 		days[atoi (results->data[i])] = TRUE;
@@ -780,13 +822,15 @@
 	AlmanahLink **links;
 	guint i;
 
-	results = almanah_storage_manager_query (self, "SELECT link_type, link_value, link_value2 FROM entry_links WHERE year = %u AND month = %u AND day = %u",
+	results = almanah_storage_manager_query (self, "SELECT link_type, link_value, link_value2 FROM entry_links WHERE year = %u AND month = %u AND day = %u", NULL,
 						 g_date_get_year (date),
 						 g_date_get_month (date),
 						 g_date_get_day (date));
 
-	if (results->rows == 0) {
-		almanah_storage_manager_free_results (results);
+	if (results == NULL || results->rows == 0) {
+		if (results != NULL)
+			almanah_storage_manager_free_results (results);
+
 		/* Return empty array */
 		links = (AlmanahLink**) g_new (AlmanahLink*, 1);
 		links[0] = NULL;
@@ -818,14 +862,14 @@
 	value2 = almanah_link_get_value2 (link);
 
 	if (value2 == NULL) {
-		return_value = almanah_storage_manager_query_async (self, "REPLACE INTO entry_links (year, month, day, link_type, link_value) VALUES (%u, %u, %u, '%q', '%q')", NULL, NULL,
+		return_value = almanah_storage_manager_query_async (self, "REPLACE INTO entry_links (year, month, day, link_type, link_value) VALUES (%u, %u, %u, '%q', '%q')", NULL, NULL, NULL,
 								    g_date_get_year (date),
 								    g_date_get_month (date),
 								    g_date_get_day (date),
 								    type_id,
 								    value);
 	} else {
-		return_value = almanah_storage_manager_query_async (self, "REPLACE INTO entry_links (year, month, day, link_type, link_value, link_value2) VALUES (%u, %u, %u, '%q', '%q', '%q')", NULL, NULL,
+		return_value = almanah_storage_manager_query_async (self, "REPLACE INTO entry_links (year, month, day, link_type, link_value, link_value2) VALUES (%u, %u, %u, '%q', '%q', '%q')", NULL, NULL, NULL,
 								    g_date_get_year (date),
 								    g_date_get_month (date),
 								    g_date_get_day (date),
@@ -843,7 +887,7 @@
 gboolean
 almanah_storage_manager_remove_entry_link (AlmanahStorageManager *self, GDate *date, const gchar *link_type_id)
 {
-	return almanah_storage_manager_query_async (self, "DELETE FROM entry_links WHERE year = %u AND month = %u AND day = %u AND link_type = '%q'", NULL, NULL,
+	return almanah_storage_manager_query_async (self, "DELETE FROM entry_links WHERE year = %u AND month = %u AND day = %u AND link_type = '%q'", NULL, NULL, NULL,
 						    g_date_get_year (date),
 						    g_date_get_month (date),
 						    g_date_get_day (date),

Modified: trunk/src/storage-manager.h
==============================================================================
--- trunk/src/storage-manager.h	(original)
+++ trunk/src/storage-manager.h	Sun Oct 12 18:48:05 2008
@@ -53,7 +53,8 @@
 	ALMANAH_STORAGE_MANAGER_ERROR_CREATING_CONTEXT,
 	ALMANAH_STORAGE_MANAGER_ERROR_DECRYPTING,
 	ALMANAH_STORAGE_MANAGER_ERROR_ENCRYPTING,
-	ALMANAH_STORAGE_MANAGER_ERROR_GETTING_KEY
+	ALMANAH_STORAGE_MANAGER_ERROR_GETTING_KEY,
+	ALMANAH_STORAGE_MANAGER_ERROR_RUNNING_QUERY
 } AlmanahStorageManagerError;
 
 typedef gint (*AlmanahQueryCallback) (gpointer user_data, gint columns, gchar **data, gchar **column_names);
@@ -68,12 +69,12 @@
 GQuark almanah_storage_manager_error_quark (void);
 AlmanahStorageManager *almanah_storage_manager_new (const gchar *filename);
 
-void almanah_storage_manager_connect (AlmanahStorageManager *self);
-void almanah_storage_manager_disconnect (AlmanahStorageManager *self);
+gboolean almanah_storage_manager_connect (AlmanahStorageManager *self, GError **error);
+gboolean almanah_storage_manager_disconnect (AlmanahStorageManager *self, GError **error);
 
-AlmanahQueryResults *almanah_storage_manager_query (AlmanahStorageManager *self, const gchar *query, ...);
+AlmanahQueryResults *almanah_storage_manager_query (AlmanahStorageManager *self, const gchar *query, GError **error, ...);
 void almanah_storage_manager_free_results (AlmanahQueryResults *results);
-gboolean almanah_storage_manager_query_async (AlmanahStorageManager *self, const gchar *query, const AlmanahQueryCallback callback, gpointer user_data, ...);
+gboolean almanah_storage_manager_query_async (AlmanahStorageManager *self, const gchar *query, const AlmanahQueryCallback callback, gpointer user_data, GError **error, ...);
 
 gboolean almanah_storage_manager_get_statistics (AlmanahStorageManager *self, guint *entry_count, guint *link_count, guint *character_count);
 



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