evolution-data-server r8866 - branches/camel-db-summary/camel
- From: psankar svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8866 - branches/camel-db-summary/camel
- Date: Wed, 28 May 2008 11:27:14 +0000 (UTC)
Author: psankar
Date: Wed May 28 11:27:14 2008
New Revision: 8866
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8866&view=rev
Log:
Added transaction support, add-to transaction, abort transaction also
done.
save message-infos to db almost done.
miscellaneous warnings fix.
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
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 Wed May 28 11:27:14 2008
@@ -54,6 +54,7 @@
cdb = g_new (CamelDB, 1);
cdb->db = db;
cdb->lock = g_mutex_new ();
+ cdb->read_lock = g_mutex_new ();
d(g_print ("\nDatabase succesfully opened \n"));
return cdb;
}
@@ -64,6 +65,7 @@
if (cdb) {
sqlite3_close (cdb->db);
g_mutex_free (cdb->lock);
+ g_mutex_free (cdb->read_lock);
g_free (cdb);
d(g_print ("\nDatabase succesfully closed \n"));
}
@@ -86,6 +88,54 @@
int
+camel_db_begin_transaction (CamelDB *cdb, CamelException *ex)
+{
+ if (!cdb)
+ return -1;
+
+ d(g_print ("\n\aBEGIN TRANSACTION \n\a"));
+ g_mutex_lock (cdb->lock);
+ return (cdb_sql_exec (cdb->db, "BEGIN", ex));
+}
+
+int
+camel_db_end_transaction (CamelDB *cdb, CamelException *ex)
+{
+ int ret;
+ if (!cdb)
+ return -1;
+
+ d(g_print ("\nCOMMIT TRANSACTION \n"));
+ ret = cdb_sql_exec (cdb->db, "COMMIT", ex);
+ g_mutex_unlock (cdb->lock);
+
+ return ret;
+}
+
+int
+camel_db_abort_transaction (CamelDB *cdb, CamelException *ex)
+{
+ int ret;
+
+ d(g_print ("\nABORT TRANSACTION \n"));
+ ret = cdb_sql_exec (cdb->db, "ABORT TRANSACTION", ex);
+ g_mutex_unlock (cdb->lock);
+
+ return ret;
+}
+
+int
+camel_db_add_to_transaction (CamelDB *cdb, const char *stmt, CamelException *ex)
+{
+ if (!cdb)
+ return -1;
+
+ d(g_print("Adding the following query to transaction: %s\n", stmt));
+
+ return (cdb_sql_exec (cdb->db, stmt, ex));
+}
+
+int
camel_db_transaction_command (CamelDB *cdb, GSList *qry_list, CamelException *ex)
{
int ret;
@@ -143,13 +193,13 @@
if (!cdb)
return 0;
- g_mutex_lock (cdb->lock);
+ g_mutex_lock (cdb->read_lock);
ret = sqlite3_exec(cdb->db, stmt, count_cb, &count, &errmsg);
if(ret != SQLITE_OK) {
d(g_warning ("Error in select statement %s [%s].\n", stmt, errmsg));
sqlite3_free (errmsg);
}
- g_mutex_unlock (cdb->lock);
+ g_mutex_unlock (cdb->read_lock);
d(g_print("count of '%s' is %d\n", stmt, count));
return count;
}
@@ -164,7 +214,7 @@
if (!cdb)
return TRUE;
- g_mutex_lock (cdb->lock);
+ g_mutex_lock (cdb->read_lock);
ret = sqlite3_exec(cdb->db, stmt, callback, data, &errmsg);
if(ret != SQLITE_OK) {
@@ -172,7 +222,7 @@
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, errmsg);
sqlite3_free (errmsg);
}
- g_mutex_unlock (cdb->lock);
+ g_mutex_unlock (cdb->read_lock);
return ret;
}
@@ -198,13 +248,52 @@
return ((camel_db_command (cdb, query, ex)));
}
+
int
-camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex)
+camel_db_write_message_info_record (CamelDB *cdb, const char *folder_name, CamelMIRecord *record, CamelException *ex)
{
int ret;
+ if (!cdb)
+ return -1;
+
+ char *table_creation_query;
+
+ table_creation_query = g_strdup_printf ("CREATE TABLE IF NOT EXISTS %s ( uid TEXT PRIMARY KEY , flags INTEGER , read INTEGER , deleted INTEGER , replied INTEGER , important INTEGER , junk INTEGER , attachment INTEGER , size INTEGER , dsent NUMERIC , dreceived NUMERIC , subject TEXT , mail_from TEXT , mail_to TEXT , cc TEXT , mlist TEXT , followup_flag TEXT , followup_completed_on TEXT , followup_due_by TEXT , part TEXT , labels TEXT , usertags TEXT , cinfo TEXT , bdata TEXT )", folder_name);
+
+ char *del_query;
+ char *ins_query;
+
+ ins_query = g_strdup_printf ("INSERT INTO \"%s\" VALUES (\"%s\", %d, %d, %d, %d, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" )", folder_name, record->uid, record->flags, record->read, record->deleted, record->replied, record->important, record->junk, record->attachment, record->size, ctime (&(record->dsent)), ctime (&(record->dreceived)), record->subject, record->from, record->to, record->cc, record->mlist, record->followup_flag, record->followup_completed_on, record->followup_due_by, record->part, record->labels, record->usertags, record->cinfo, record->bdata);
+
+ del_query = g_strdup_printf ("DELETE FROM %s WHERE uid = \"%s\"", folder_name, record->uid);
+
+#if 0
char *upd_query;
+
+ upd_query = g_strdup_printf ("IMPLEMENT AND THEN TRY");
+ camel_db_command (cdb, upd_query, ex);
+ g_free (upd_query);
+#else
+
+ ret = camel_db_add_to_transaction (cdb, table_creation_query, ex);
+ ret = camel_db_add_to_transaction (cdb, del_query, ex);
+ ret = camel_db_add_to_transaction (cdb, ins_query, ex);
+
+#endif
+
+ g_free (del_query);
+ g_free (ins_query);
+
+ return ret;
+}
+
+int
+camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex)
+{
+ int ret;
+
char *del_query;
char *ins_query;
@@ -212,25 +301,20 @@
del_query = g_strdup_printf ("DELETE FROM folders WHERE folder_name = \"%s\"", record->folder_name);
- upd_query = g_strdup_printf ("UPDATE folders SET version = %d, flags = %d, nextuid = %d, time = 143, saved_count = %d, unread_count = %d, deleted_count = %d, junk_count = %d, bdata = %s, WHERE folder_name = \"%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 );
#if 0
+ char *upd_query;
+
+ upd_query = g_strdup_printf ("UPDATE folders SET version = %d, flags = %d, nextuid = %d, time = 143, saved_count = %d, unread_count = %d, deleted_count = %d, junk_count = %d, bdata = %s, WHERE folder_name = \"%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, upd_query, ex);
+ g_free (upd_query);
#else
- GSList *qry_list = NULL;
-
- qry_list = g_slist_prepend (qry_list, ins_query);
- qry_list = g_slist_prepend (qry_list, del_query);
+ ret = camel_db_add_to_transaction (cdb, del_query, ex);
+ ret = camel_db_add_to_transaction (cdb, ins_query, ex);
- 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);
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 Wed May 28 11:27:14 2008
@@ -11,6 +11,7 @@
struct _CamelDB {
sqlite3 *db;
GMutex *lock;
+ GMutex *read_lock;
};
@@ -93,14 +94,24 @@
CamelDB * camel_db_open (const char *path, CamelException *ex);
void camel_db_close (CamelDB *cdb);
int camel_db_command (CamelDB *cdb, const char *stmt, CamelException *ex);
+
int camel_db_transaction_command (CamelDB *cdb, GSList *qry_list, CamelException *ex);
+int camel_db_begin_transaction (CamelDB *cdb, CamelException *ex);
+int camel_db_add_to_transaction (CamelDB *cdb, const char *query, CamelException *ex);
+int camel_db_end_transaction (CamelDB *cdb, CamelException *ex);
+int camel_db_abort_transaction (CamelDB *cdb, 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);
int camel_db_select (CamelDB *cdb, const char* stmt, CamelDBSelectCB callback, gpointer data, CamelException *ex);
+
int camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex);
int camel_db_read_folder_info_record (CamelDB *cdb, char *folder_name, CamelFIRecord **record, CamelException *ex);
+
+int camel_db_write_message_info_record (CamelDB *cdb, const char *folder_name, CamelMIRecord *record, CamelException *ex);
guint32 camel_db_count (CamelDB *cdb, const char *stmt);
#endif
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 Wed May 28 11:27:14 2008
@@ -104,6 +104,7 @@
static CamelMessageInfo * message_info_new_from_message(CamelFolderSummary *s, CamelMimeMessage *msg);
static CamelMessageInfo * message_info_load(CamelFolderSummary *, FILE *);
static int message_info_save(CamelFolderSummary *, FILE *, CamelMessageInfo *);
+static int save_message_infos_to_db (CamelFolderSummary *s, CamelException *ex);
static int meta_message_info_save(CamelFolderSummary *s, FILE *out_meta, FILE *out, CamelMessageInfo *info);
static void message_info_free(CamelFolderSummary *, CamelMessageInfo *);
@@ -123,6 +124,8 @@
static void camel_folder_summary_init (CamelFolderSummary *obj);
static void camel_folder_summary_finalize (CamelObject *obj);
+static CamelMIRecord * message_info_to_db (CamelMessageInfo *info);
+
static CamelObjectClass *camel_folder_summary_parent;
static void
@@ -678,6 +681,27 @@
return 0;
}
+static int
+save_message_infos_to_db (CamelFolderSummary *s, CamelException *ex)
+{
+ CamelMIRecord *mir;
+ CamelDB *cdb = s->folder->parent_store->cdb;
+ CamelMessageInfo *mi;
+
+ int i, count;
+ char *folder_name;
+
+ /* Push MessageInfo-es */
+ folder_name = s->folder->full_name;
+ count = s->messages->len;
+ for (i = 0; i < count; ++i) {
+ mi = s->messages->pdata [i];
+ mir = message_info_to_db (mi);
+ if (camel_db_write_message_info_record (cdb, folder_name, mir, ex) != 0)
+ return -1;
+ }
+ return 0;
+}
int
camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
@@ -687,6 +711,7 @@
int ret;
d(printf ("\ncamel_folder_summary_save_to_db called \n"));
+ camel_db_begin_transaction (cdb, ex);
record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s));
if (!record) {
@@ -695,9 +720,20 @@
}
ret = camel_db_write_folder_info_record (cdb, record, ex);
-
g_free (record);
-
+ if (ret != 0) {
+ camel_db_abort_transaction (cdb, ex);
+ return -1;
+ }
+
+ ret = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->save_message_infos_to_db (s, ex));
+ if (ret != 0) {
+ camel_db_abort_transaction (cdb, ex);
+ return -1;
+ }
+
+ camel_db_end_transaction (cdb, ex);
+
return ret;
}
@@ -2140,7 +2176,7 @@
static CamelMIRecord *
-message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
+message_info_to_db (CamelMessageInfo *info)
{
CamelMIRecord *record = g_new0(CamelMIRecord, 1);
CamelMessageInfoBase *mi = (CamelMessageInfoBase *) info;
@@ -2176,11 +2212,11 @@
tmp = g_string_new (NULL);
if (mi->references) {
- g_string_append_printf (tmp, "%lu %lu %lu", mi->message_id.id.part.hi, mi->message_id.id.part.lo, mi->references->size);
+ g_string_append_printf (tmp, "%lu %lu %lu", (long unsigned) mi->message_id.id.part.hi, (long unsigned) mi->message_id.id.part.lo, (long unsigned) mi->references->size);
for (i=0;i<mi->references->size;i++)
- g_string_append_printf (tmp, " %lu %lu", mi->references->references[i].id.part.hi, mi->references->references[i].id.part.lo);
+ g_string_append_printf (tmp, " %lu %lu", (long unsigned) mi->references->references[i].id.part.hi, (long unsigned) mi->references->references[i].id.part.lo);
} else {
- g_string_append_printf (tmp, "%lu %lu %lu", mi->message_id.id.part.hi, mi->message_id.id.part.lo, 0);
+ g_string_append_printf (tmp, "%lu %lu %lu", (long unsigned) mi->message_id.id.part.hi, (long unsigned) mi->message_id.id.part.lo, (long unsigned) 0);
}
record->part = tmp->str;
g_string_free (tmp, FALSE);
@@ -2201,19 +2237,20 @@
tmp = g_string_new (NULL);
count = camel_tag_list_size(&mi->user_tags);
- g_string_append_printf (tmp, "%lu", count);
+ g_string_append_printf (tmp, "%lu", (long unsigned) count);
tag = mi->user_tags;
while (tag) {
/* FIXME: Should we handle empty tags? Can it be empty? If it potential crasher ahead*/
- g_string_append_printf (tmp, " %lu-%s %lu-%s", strlen(tag->name), tag->name, strlen(tag->value), tag->value);
+ g_string_append_printf (tmp, " %lu-%s %lu-%s", (long unsigned) strlen(tag->name), tag->name, (long unsigned) strlen(tag->value), tag->value);
tag = tag->next;
}
record->usertags = tmp->str;
g_string_free (tmp, FALSE);
- record->usertags;
-}
+ //record->usertags;
+ return record;
+}
static int
message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *info)
@@ -3568,6 +3605,7 @@
klass->message_info_new_from_message = message_info_new_from_message;
klass->message_info_load = message_info_load;
klass->message_info_save = message_info_save;
+ klass->save_message_infos_to_db = save_message_infos_to_db;
klass->meta_message_info_save = meta_message_info_save;
klass->message_info_free = message_info_free;
klass->message_info_clone = message_info_clone;
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 Wed May 28 11:27:14 2008
@@ -244,9 +244,11 @@
int (*summary_header_from_db)(CamelFolderSummary *, CamelFIRecord *);
CamelFIRecord * (*summary_header_to_db)(CamelFolderSummary *);
CamelMessageInfo * (*message_info_from_db) (CamelFolderSummary *, struct _CamelMIRecord*);
- CamelMIRecord * (*message_info_to_db) (CamelFolderSummary *, CamelMessageInfo *);
+ CamelMIRecord * (*message_info_to_db) (CamelMessageInfo *);
CamelMessageContentInfo * (*content_info_from_db) (CamelFolderSummary *, CamelMIRecord *);
int (*content_info_to_db) (CamelFolderSummary *, CamelMessageContentInfo *, CamelMIRecord *);
+ int (*save_message_infos_to_db) (CamelFolderSummary *s, CamelException *ex);
+
/* create/save/load an individual message info */
CamelMessageInfo * (*message_info_new_from_header)(CamelFolderSummary *, struct _camel_header_raw *);
@@ -256,6 +258,8 @@
int (*message_info_save)(CamelFolderSummary *, FILE *, CamelMessageInfo *);
int (*meta_message_info_save)(CamelFolderSummary *, FILE *, FILE *, CamelMessageInfo *);
+
+
void (*message_info_free)(CamelFolderSummary *, CamelMessageInfo *);
CamelMessageInfo * (*message_info_clone)(CamelFolderSummary *, const CamelMessageInfo *);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]