evolution-data-server r8838 - branches/camel-db-summary/camel



Author: psankar
Date: Fri May 23 11:44:21 2008
New Revision: 8838
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8838&view=rev

Log:
trying to store foldersummary in db.
moved few structures form cfs.h to camel-db.h
etc.


Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-db.h
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/camel-folder-summary.h
   branches/camel-db-summary/camel/camel-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	Fri May 23 11:44:21 2008
@@ -141,6 +141,51 @@
 	return ret;
 }
 
+int
+camel_db_create_folders_table (CamelDB *cdb)
+{
+	char *query = "CREATE TABLE IF NOT EXISTS folders ( \
+			foldername TEXT PRIMARY KEY, \
+			version REAL, \
+			flags INTEGER, \
+			nextuid INTEGER, \
+			time NUMERIC, \
+			saved_count INTEGER, \
+			unread_count INTEGER, \
+			deleted_count INTEGER, \
+			junk_count INTEGER, \
+			bdata TEXT, \
+			)";
+
+	return ((camel_db_command (cdb, query)) == TRUE);
+}
+
+int
+camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex)
+{
+
+	char *query;
+
+	query = g_strdup_printf ("UPDATE folders SET \
+					version = %d, \
+					flags = %d, \
+					nextuid = %d, \
+					time = 14/6/83, \
+					saved_count = %d, \
+					unread_count = %d, \
+					deleted_count = %d, \
+					junk_count = %d, \
+					bdata = %s, \
+					WHERE foldername = %s",
+					record->version, record->flags, record->nextuid, 
+					record->saved_count, record->unread_count, 
+					record->deleted_count, record->junk_count,
+					"PROVIDER SPECIFIC DATA", record->folder_name );
+
+	camel_db_command (cdb, query);
+	g_free (query);
+}
+
 gboolean
 camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid)
 {

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	Fri May 23 11:44:21 2008
@@ -13,6 +13,81 @@
 	GMutex *lock;
 };
 
+
+/* The extensive DB format, supporting basic searching and sorting
+  uid, - Message UID
+  flags, - Camel Message info flags
+  unread/read, - boolean read/unread status
+  deleted, - boolean deleted status
+  replied, - boolean replied status
+  imp, - boolean important status
+  junk, - boolean junk status
+  size, - size of the mail
+  attachment, boolean attachment status
+  dsent, - sent date
+  dreceived, - received date
+  subject, - subject of the mail
+  from, - sender
+  to, - recipient
+  cc, - CC members
+  mlist, - message list headers
+  follow-up-flag, - followup flag / also can be queried to see for followup or not
+  completed-on-set, - completed date, can be used to see if completed
+  due-by,  - to see the due by date
+  Location - This can be derived from the database location/name. No need to store.
+  label, - labels of mails
+  userflags, composite string of user flags
+  usertags, composite string of user tags
+  cinfo, content info string - composite string
+  bdata, provider specific data
+  part, part/references/thread id
+*/
+
+typedef struct _CamelMIRecord {
+	char *uid;
+	guint32 flags;
+	gboolean read;
+	gboolean deleted;
+	gboolean replied;
+	gboolean important;
+	gboolean junk;
+	gboolean attachment;
+	guint32 size;
+	time_t dsent;
+	time_t dreceived;
+	char *subject;
+	char *from;
+	char *to;
+	char *cc;
+	char *mlist;
+	char *followup_flag;
+	char *followup_completed_on;
+	char *followup_due_by;
+	char *part;
+	char *labels;
+	char *userflags;
+	char *usertags;
+	char *cinfo;
+	char *bdata;
+} CamelMIRecord;
+
+typedef struct _CamelFIRecord {
+	char *folder_name;
+	guint32 version;
+	guint32 flags;
+	guint32 nextuid;
+	time_t time;
+	guint32 saved_count;
+	/* Are these three really required? Can we just query it*/
+	guint32 unread_count;
+	guint32 deleted_count;
+	guint32 junk_count;
+	char *bdata;
+} CamelFIRecord;
+
+
+
+
 typedef struct _CamelDB CamelDB;
 typedef int (*CamelDBSelectCB) (void *data, int ncol, char **colvalues, char **colnames);
 
@@ -21,6 +96,7 @@
 void camel_db_close (CamelDB *cdb);
 gboolean camel_db_command (CamelDB *cdb, const char *stmt);
 int camel_db_select (CamelDB *cdb, const char* stmt, CamelDBSelectCB callback, gpointer data);
+int camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex);
 
 guint32 camel_db_count (CamelDB *cdb, const char *stmt);
 

Modified: branches/camel-db-summary/camel/camel-folder-summary.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.c	Fri May 23 11:44:21 2008
@@ -637,6 +637,26 @@
 }
 
 
+int
+camel_folder_summary_save_db (CamelFolderSummary *s, CamelException *ex)
+{
+	CamelDB *cdb = s->folder->parent_store->cdb;
+	CamelFIRecord *record;
+	int ret;
+
+	record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s));
+	if (!record) {
+		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create folder summary"));
+		return -1;
+	}
+
+	ret = camel_db_write_folder_info_record (cdb, record, ex);
+
+	g_free (record);
+	
+	return ret;
+}
+
 /**
  * camel_folder_summary_save:
  * @summary: a #CamelFolderSummary object
@@ -1524,11 +1544,11 @@
 	s->flags = record->flags;
 	s->nextuid = record->nextuid;
 	s->time = record->time;
-	s->saved_count = record->savedcount;
+	s->saved_count = record->saved_count;
 
-	s->unread_count = record->unread;
-	s->deleted_count = record->deleted;
-	s->junk_count = record->junk;
+	s->unread_count = record->unread_count;
+	s->deleted_count = record->deleted_count;
+	s->junk_count = record->junk_count;
 
 	return 0;	
 }
@@ -1591,7 +1611,7 @@
 	
 	io(printf("Savining header to db\n"));
 	
-	record->folder = table_name;
+	record->folder_name = table_name;
 	
 	/* we always write out the current version */
 	record->version = CAMEL_FOLDER_SUMMARY_VERSION;
@@ -1599,10 +1619,10 @@
 	record->nextuid = s->nextuid;
 	record->time = s->time;
 
-	DB_COUNT(record->savedcount, "uid", "");
-	DB_COUNT(record->unread, "read", " where read=0");
-	DB_COUNT(record->deleted, "deleted", " where deleted=1");
-	DB_COUNT(record->junk, "junk", "where junk=1");
+	DB_COUNT(record->saved_count, "uid", "");
+	DB_COUNT(record->unread_count, "read", " where read=0");
+	DB_COUNT(record->deleted_count, "deleted", " where deleted=1");
+	DB_COUNT(record->junk_count, "junk", "where junk=1");
 	
 	return record;	
 }

Modified: branches/camel-db-summary/camel/camel-folder-summary.h
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.h	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.h	Fri May 23 11:44:21 2008
@@ -27,6 +27,7 @@
 #include <camel/camel-mime-parser.h>
 #include <camel/camel-object.h>
 #include <camel/camel-index.h>
+#include <camel/camel-db.h>
 
 #define CAMEL_FOLDER_SUMMARY_TYPE         camel_folder_summary_get_type ()
 #define CAMEL_FOLDER_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_folder_summary_get_type (), CamelFolderSummary)
@@ -193,77 +194,6 @@
 };
 */
 
-/* The extensive DB format, supporting basic searching and sorting
-  uid, - Message UID
-  flags, - Camel Message info flags
-  unread/read, - boolean read/unread status
-  deleted, - boolean deleted status
-  replied, - boolean replied status
-  imp, - boolean important status
-  junk, - boolean junk status
-  size, - size of the mail
-  attachment, boolean attachment status
-  dsent, - sent date
-  dreceived, - received date
-  subject, - subject of the mail
-  from, - sender
-  to, - recipient
-  cc, - CC members
-  mlist, - message list headers
-  follow-up-flag, - followup flag / also can be queried to see for followup or not
-  completed-on-set, - completed date, can be used to see if completed
-  due-by,  - to see the due by date
-  Location - This can be derived from the database location/name. No need to store.
-  label, - labels of mails
-  userflags, composite string of user flags
-  usertags, composite string of user tags
-  cinfo, content info string - composite string
-  bdata, provider specific data
-  part, part/references/thread id
-*/
-
-typedef struct _CamelMIRecord {
-	char *uid;
-	guint32 flags;
-	gboolean read;
-	gboolean deleted;
-	gboolean replied;
-	gboolean important;
-	gboolean junk;
-	gboolean attachment;
-	guint32 size;
-	time_t dsent;
-	time_t dreceived;
-	char *subject;
-	char *from;
-	char *to;
-	char *cc;
-	char *mlist;
-	char *followup_flag;
-	char *followup_completedon;
-	char *followup_dueby;
-	char *part;
-	char *labels;
-	char *userflags;
-	char *usertags;
-	char *cinfo;
-	char *bdata;
-} CamelMIRecord;
-
-typedef struct _CamelFIRecord {
-	char *folder;
-	guint32 version;
-	guint32 flags;
-	guint32 nextuid;
-	time_t time;
-	guint32 savedcount;
-	/* Are these three really required? Can we just query it*/
-	guint32 unread;
-	guint32 deleted;
-	guint32 junk;
-	char *bdata;
-} CamelFIRecord;
-
 typedef enum _CamelFolderSummaryFlags {
 	CAMEL_SUMMARY_DIRTY = 1<<0
 } CamelFolderSummaryFlags;

Modified: branches/camel-db-summary/camel/camel-store.c
==============================================================================
--- branches/camel-db-summary/camel/camel-store.c	(original)
+++ branches/camel-db-summary/camel/camel-store.c	Fri May 23 11:44:21 2008
@@ -216,6 +216,12 @@
 	store->cdb = camel_db_open (store_db_path, ex);
 	g_free (store_path);
 	g_free (store_db_path);
+	if (camel_exception_is_set (ex))
+		return;
+
+	camel_db_create_folders_table (store->cdb, ex);
+	if (camel_exception_is_set (ex))
+		return;
 
 	if (camel_url_get_param(url, "filter"))
 		store->flags |= CAMEL_STORE_FILTER_INBOX;



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