evolution-data-server r8863 - in branches/camel-db-summary/camel: . providers/local



Author: psankar
Date: Tue May 27 13:16:12 2008
New Revision: 8863
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8863&view=rev

Log:
Added TRANSACTION support to camel-db and added
db closure commands to local store finalize block.



Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-db.h
   branches/camel-db-summary/camel/providers/local/camel-local-store.c

Modified: branches/camel-db-summary/camel/camel-db.c
==============================================================================
--- branches/camel-db-summary/camel/camel-db.c	(original)
+++ branches/camel-db-summary/camel/camel-db.c	Tue May 27 13:16:12 2008
@@ -21,7 +21,7 @@
   	ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
 
   	if (ret != SQLITE_OK) {
-    		d(g_warning ("Error in statement: %s [%s].\n", stmt, errmsg));
+    		d(g_print ("Error in SQL EXEC statement: %s [%s].\n", stmt, errmsg));
 		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(errmsg));
 		sqlite3_free (errmsg);
 		return -1;
@@ -69,10 +69,11 @@
 	}
 }
 
-gboolean
+/* Should this be really exposed ? */
+int
 camel_db_command (CamelDB *cdb, const char *stmt, CamelException *ex)
 {
-	gboolean ret;
+	int ret;
 	
 	if (!cdb)
 		return TRUE;
@@ -83,6 +84,41 @@
 	return ret;
 }
 
+
+int 
+camel_db_transaction_command (CamelDB *cdb, GSList *qry_list, CamelException *ex)
+{
+	int ret;
+	const char *query;
+
+	if (!cdb)
+		return -1;
+
+	g_mutex_lock (cdb->lock);
+
+	ret = cdb_sql_exec (cdb->db, "BEGIN", ex);
+	if (ret)
+		goto end;
+
+	d(g_print ("\nBEGIN Transaction\n"));
+
+	while (qry_list) {
+		query = qry_list->data;
+		d(g_print ("\nInside Transaction: [%s] \n", query));
+		ret = cdb_sql_exec (cdb->db, query, ex);
+		if (ret)
+			goto end;
+		qry_list = g_slist_next (qry_list);
+	}
+
+	ret = cdb_sql_exec (cdb->db, "COMMIT", ex);
+
+end:
+	g_mutex_unlock (cdb->lock);
+	d(g_print ("\nTransaction Result: [%d] \n", ret));
+	return ret;
+}
+
 /* We enforce it to be count and not COUNT just to speed up */
 static int 
 count_cb (void *data, int argc, char **argv, char **azColName)
@@ -142,11 +178,11 @@
 }
 
 
-gboolean
+int
 camel_db_delete_folder (CamelDB *cdb, char *folder, CamelException *ex)
 {
 	char *tab = g_strdup_printf ("delete from folders where folder_name ='%s'", folder);
-	gboolean ret;
+	int ret;
 
 	ret = camel_db_command (cdb, tab, ex);
 	g_free (tab);
@@ -166,11 +202,13 @@
 camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex)
 {
 
+	int ret;
+
 	char *upd_query;
 	char *del_query;
 	char *ins_query;
 
-	ins_query = g_strdup_printf ("INSERT INTO folders VALUES ( \"%s\", %d, %d, %d, 143, %d, %d, %d, %d, \"%s\" ) ", record->folder_name, record->version, record->flags , record->nextuid , record->saved_count , record->unread_count , record->deleted_count , record->junk_count , record->bdata); 
+	ins_query = g_strdup_printf ("INSERT INTO folders VALUES ( \"%s\", %d, %d, %d, 143, %d, %d, %d, %d, \"%s\" ) ", record->folder_name, record->version, record->flags , record->nextuid , record->saved_count , record->unread_count , record->deleted_count , record->junk_count , "PROVIDER SPECIFIC DATA"); 
 
 	del_query = g_strdup_printf ("DELETE FROM folders WHERE folder_name = \"%s\"", record->folder_name);
 
@@ -179,17 +217,24 @@
 #if 0
 	camel_db_command (cdb, upd_query, ex);
 #else
-	camel_db_command (cdb, "BEGIN", ex);
-	camel_db_command (cdb, del_query, ex);
-	camel_db_command (cdb, ins_query, ex);
-	camel_db_command (cdb, "COMMIT", ex);
+
+	GSList *qry_list = NULL;
+
+	qry_list = g_slist_prepend (qry_list, ins_query);
+	qry_list = g_slist_prepend (qry_list, del_query);
+
+	qry_list = g_slist_reverse (qry_list);
+	
+	ret = camel_db_transaction_command (cdb, qry_list, ex);
+
+	g_slist_free (qry_list);
 #endif
 
 	g_free (upd_query);
 	g_free (del_query);
 	g_free (ins_query);
 
-	return 0;
+	return ret;
 }
 
 static int 

Modified: branches/camel-db-summary/camel/camel-db.h
==============================================================================
--- branches/camel-db-summary/camel/camel-db.h	(original)
+++ branches/camel-db-summary/camel/camel-db.h	Tue May 27 13:16:12 2008
@@ -94,7 +94,9 @@
 
 CamelDB * camel_db_open (const char *path, CamelException *ex);
 void camel_db_close (CamelDB *cdb);
-gboolean camel_db_command (CamelDB *cdb, const char *stmt, CamelException *ex);
+int camel_db_command (CamelDB *cdb, const char *stmt, CamelException *ex);
+int camel_db_transaction_command (CamelDB *cdb, GSList *qry_list, CamelException *ex);
+
 gboolean camel_db_delete_folder (CamelDB *cdb, char *folder, CamelException *ex);
 gboolean camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid, CamelException *ex);
 int camel_db_create_folders_table (CamelDB *cdb, CamelException *ex);

Modified: branches/camel-db-summary/camel/providers/local/camel-local-store.c
==============================================================================
--- branches/camel-db-summary/camel/providers/local/camel-local-store.c	(original)
+++ branches/camel-db-summary/camel/providers/local/camel-local-store.c	Tue May 27 13:16:12 2008
@@ -100,6 +100,18 @@
 {
 	if (local_store->toplevel_dir)
 		g_free (local_store->toplevel_dir);
+
+	CamelStore *store;
+
+	store = ((CamelStore *)local_store); 
+	d(printf ("\n\aLocal Store Finalize \n\a"));
+
+	if (store && store->cdb) {
+	d(printf ("\n\aClosing Store DB for hte local provider \n\a"));
+		camel_db_close (store->cdb);
+		store->cdb = NULL;
+	}
+
 }
 
 CamelType



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