[evolution-ews] EBookBackendSqliteDB: Check if folder exists before creating it



commit 62068041cd9eca04ff430d0cb1a97016eef8306d
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Mon Jun 6 12:36:02 2011 +0530

    EBookBackendSqliteDB: Check if folder exists before creating it

 src/addressbook/e-book-backend-sqlitedb.c |   33 +++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-sqlitedb.c b/src/addressbook/e-book-backend-sqlitedb.c
index 9cd53eb..ca356f1 100644
--- a/src/addressbook/e-book-backend-sqlitedb.c
+++ b/src/addressbook/e-book-backend-sqlitedb.c
@@ -280,6 +280,36 @@ create_folders_table	(EBookBackendSqliteDB *ebsdb,
 	return;
 }
 
+
+static gint
+folder_found_cb (gpointer ref, gint col, gchar **cols, gchar **name)
+{
+	gboolean *found = ref;
+
+	*found = TRUE;
+
+	return 0;
+}
+
+static gboolean
+folder_exists	(EBookBackendSqliteDB *ebsdb,
+		 const gchar *folderid,
+		 GError **error)
+{
+	gchar *stmt;
+	gboolean found = FALSE;
+
+	READER_LOCK (ebsdb);
+
+	stmt = sqlite3_mprintf ("SELECT folder_id FROM folders WHERE folder_id = %Q", folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, folder_found_cb , &found, error);
+	sqlite3_free (stmt);
+
+	READER_UNLOCK (ebsdb);
+
+	return found;
+}
+
 static void
 add_folder_into_db	(EBookBackendSqliteDB *ebsdb,
 			 const gchar *folderid,
@@ -289,6 +319,9 @@ add_folder_into_db	(EBookBackendSqliteDB *ebsdb,
 	gchar *stmt;
 	GError *err = NULL;
 
+	if (folder_exists (ebsdb, folderid, error))
+		return;
+
 	WRITER_LOCK (ebsdb);
 	book_backend_sqlitedb_start_transaction (ebsdb, &err);
 



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