evolution-data-server r8893 - in branches/camel-db-summary/camel: . providers/groupwise providers/imap providers/local
- From: psankar svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8893 - in branches/camel-db-summary/camel: . providers/groupwise providers/imap providers/local
- Date: Mon, 2 Jun 2008 10:17:41 +0000 (UTC)
Author: psankar
Date: Mon Jun 2 10:17:41 2008
New Revision: 8893
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8893&view=rev
Log:
Add exception handling support to summary_header_to_db
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/providers/groupwise/camel-groupwise-summary.c
branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c
branches/camel-db-summary/camel/providers/local/camel-local-summary.c
branches/camel-db-summary/camel/providers/local/camel-mbox-summary.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 Mon Jun 2 10:17:41 2008
@@ -10,7 +10,7 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
-#define d(x) x
+#define d(x)
static int
cdb_sql_exec (sqlite3 *db, const char* stmt, CamelException *ex)
@@ -116,7 +116,7 @@
int ret;
d(g_print ("\nABORT TRANSACTION \n"));
- ret = cdb_sql_exec (cdb->db, "ABORT TRANSACTION;", ex);
+ ret = cdb_sql_exec (cdb->db, "ABORT ", ex);
g_mutex_unlock (cdb->lock);
return ret;
@@ -182,22 +182,89 @@
return 0;
}
-guint32
-camel_db_count (CamelDB *cdb, const char *stmt)
+static int
+camel_db_count_message_info (CamelDB *cdb, const char *query, guint32 *count, CamelException *ex)
{
- int count=0;
+ int ret;
char *errmsg;
+
+ ret = sqlite3_exec (cdb->db, query, count_cb, count, &errmsg);
+ if (ret != SQLITE_OK) {
+ d(g_print ("Error in SQL SELECT statement: %s [%s]\n", query, errmsg));
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(errmsg));
+ sqlite3_free (errmsg);
+ }
+ return ret;
+}
+
+int
+camel_db_count_junk_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
int ret;
if (!cdb)
return 0;
- 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);
- }
- d(g_print("count of '%s' is %d\n", stmt, count));
- return count;
+
+ char *query;
+ query = sqlite3_mprintf ("SELECT COUNT (junk) FROM %Q WHERE junk = 1", table_name);
+
+ ret = camel_db_count_message_info (cdb, query, count, ex);
+ sqlite3_free (query);
+
+ return ret;
+}
+
+int
+camel_db_count_unread_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+ int ret;
+
+ if (!cdb)
+ return 0;
+
+ char *query ;
+ query = sqlite3_mprintf ("SELECT COUNT (read) FROM %Q WHERE read = 0", table_name);
+
+ ret = camel_db_count_message_info (cdb, query, count, ex);
+ sqlite3_free (query);
+
+ return ret;
+}
+
+
+int
+camel_db_count_deleted_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+ int ret;
+
+ if (!cdb)
+ return 0;
+
+ char *query ;
+ query = sqlite3_mprintf ("SELECT COUNT (deleted) FROM %Q WHERE deleted = 1", table_name);
+
+ ret = camel_db_count_message_info (cdb, query, count, ex);
+ sqlite3_free (query);
+
+ return ret;
+}
+
+
+int
+camel_db_count_total_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+ int ret;
+
+ if (!cdb)
+ return 0;
+
+ char *query ;
+ query = sqlite3_mprintf ("SELECT COUNT (uid) FROM %Q", table_name);
+
+ ret = camel_db_count_message_info (cdb, query, count, ex);
+ sqlite3_free (query);
+
+ return ret;
}
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 Mon Jun 2 10:17:41 2008
@@ -115,6 +115,11 @@
int camel_db_write_message_info_record (CamelDB *cdb, const char *folder_name, CamelMIRecord *record, CamelException *ex);
int camel_db_read_message_info_records (CamelDB *cdb, char *folder_name, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex);
-guint32 camel_db_count (CamelDB *cdb, const char *stmt);
+
+int camel_db_count_junk_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);
+int camel_db_count_unread_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);
+int camel_db_count_deleted_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);
+int camel_db_count_total_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);
+
#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 Mon Jun 2 10:17:41 2008
@@ -881,9 +881,8 @@
camel_db_begin_transaction (cdb, ex);
g_timer_start (trans_timer);
- record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s));
+ record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s, ex));
if (!record) {
- camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create folder summary"));
return -1;
}
@@ -1857,34 +1856,35 @@
return 0;
}
-#define DB_COUNT(lhs,var,cond) str = g_strdup_printf ("select count(%s) from %s%s", var, table_name, cond); \
- lhs = camel_db_count (s->folder->parent_store->cdb, str); \
- g_free (str);
-
-
static CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s)
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
{
- CamelFIRecord * record = g_new0 (struct _CamelFIRecord, 1);
+ CamelFIRecord * record = g_new0 (CamelFIRecord, 1);
+ CamelDB *db;
+
+ db = s->folder->parent_store->cdb;
//char *table_name = safe_table (camel_file_util_safe_filename (s->folder->full_name));
char *table_name = s->folder->full_name;
- char *str;
-
+
io(printf("Savining header to db\n"));
-
+
record->folder_name = table_name;
-
+
/* we always write out the current version */
record->version = CAMEL_FOLDER_SUMMARY_VERSION;
record->flags = s->flags;
record->nextuid = s->nextuid;
record->time = s->time;
- 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");
-
+ if (!camel_db_count_total_message_info (db, table_name, &(record->saved_count), ex))
+ return NULL;
+ if (!camel_db_count_junk_message_info (db, table_name, &(record->junk_count), ex))
+ return NULL;
+ if (!camel_db_count_deleted_message_info (db, table_name, &(record->deleted_count), ex))
+ return NULL;
+ if (!camel_db_count_unread_message_info (db, table_name, &(record->unread_count), ex))
+ return NULL;
+
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 Mon Jun 2 10:17:41 2008
@@ -242,7 +242,7 @@
/* Load/Save folder summary from DB*/
int (*summary_header_from_db)(CamelFolderSummary *, CamelFIRecord *);
- CamelFIRecord * (*summary_header_to_db)(CamelFolderSummary *);
+ CamelFIRecord * (*summary_header_to_db)(CamelFolderSummary *, CamelException *ex);
CamelMessageInfo * (*message_info_from_db) (CamelFolderSummary *, struct _CamelMIRecord*);
CamelMIRecord * (*message_info_to_db) (CamelFolderSummary *, CamelMessageInfo *);
CamelMessageContentInfo * (*content_info_from_db) (CamelFolderSummary *, CamelMIRecord *);
Modified: branches/camel-db-summary/camel/providers/groupwise/camel-groupwise-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/groupwise/camel-groupwise-summary.c (original)
+++ branches/camel-db-summary/camel/providers/groupwise/camel-groupwise-summary.c Mon Jun 2 10:17:41 2008
@@ -54,7 +54,7 @@
static gboolean gw_info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set);
static int summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir);
-static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s);
+static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, CamelException *ex);
static CamelMIRecord * message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info);
static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
static int content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelMIRecord *mir);
@@ -222,7 +222,7 @@
static CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s)
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
{
CamelFIRecord *fir;
GString *str = g_string_new (NULL);
Modified: branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c (original)
+++ branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c Mon Jun 2 10:17:41 2008
@@ -53,7 +53,7 @@
CamelMessageContentInfo *info);
static int summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir);
-static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s);
+static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, CamelException *ex);
static CamelMIRecord * message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info);
static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
static int content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelMIRecord *mir);
@@ -228,13 +228,13 @@
}
static CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s)
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
{
CamelImapSummary *ims = CAMEL_IMAP_SUMMARY(s);
struct _CamelFIRecord *fir;
GString *str = g_string_new (NULL);
- fir = camel_imap_summary_parent->summary_header_to_db (s);
+ fir = camel_imap_summary_parent->summary_header_to_db (s, ex);
if (!fir)
return NULL;
Modified: branches/camel-db-summary/camel/providers/local/camel-local-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/local/camel-local-summary.c (original)
+++ branches/camel-db-summary/camel/providers/local/camel-local-summary.c Mon Jun 2 10:17:41 2008
@@ -48,7 +48,7 @@
#define EXTRACT_FIRST_DIGIT(val) val=strtoul (part, &part, 10);
-static CamelFIRecord * summary_header_to_db (CamelFolderSummary *);
+static CamelFIRecord * summary_header_to_db (CamelFolderSummary *, CamelException *ex);
static int summary_header_from_db (CamelFolderSummary *, CamelFIRecord *);
static int summary_header_load (CamelFolderSummary *, FILE *);
@@ -156,9 +156,6 @@
int
camel_local_summary_load(CamelLocalSummary *cls, int forceindex, CamelException *ex)
{
- struct stat st;
- CamelFolderSummary *s = (CamelFolderSummary *)cls;
-
d(printf("Loading summary ...\n"));
if (forceindex
@@ -634,12 +631,13 @@
}
static struct _CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s)
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
{
struct _CamelFIRecord *fir;
- fir = ((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_to_db (s);
- fir->bdata = g_strdup_printf ("%lu", CAMEL_LOCAL_SUMMARY_VERSION);
+ fir = ((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_to_db (s, ex);
+ if (fir)
+ fir->bdata = g_strdup_printf ("%lu", CAMEL_LOCAL_SUMMARY_VERSION);
return fir;
}
Modified: branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c (original)
+++ branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c Mon Jun 2 10:17:41 2008
@@ -52,7 +52,7 @@
#define EXTRACT_DIGIT(val) part++; val=strtoul (part, &part, 10);
#define EXTRACT_FIRST_DIGIT(val) val=strtoul (part, &part, 10);
-static CamelFIRecord * summary_header_to_db (CamelFolderSummary *);
+static CamelFIRecord * summary_header_to_db (CamelFolderSummary *, CamelException *ex);
static int summary_header_from_db (CamelFolderSummary *, CamelFIRecord *);
static CamelMessageInfo * message_info_from_db(CamelFolderSummary *s, CamelMIRecord *record);
static CamelMIRecord * message_info_to_db(CamelFolderSummary *s, CamelMessageInfo *info);
@@ -291,16 +291,18 @@
}
static CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s)
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
{
CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s);
struct _CamelFIRecord *fir;
char *tmp;
- fir = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_to_db(s);
- tmp = fir->bdata;
- fir->bdata = g_strdup_printf ("%s %lu %lu", tmp ? tmp : "", CAMEL_MBOX_SUMMARY_VERSION, mbs->folder_size);
- g_free (tmp);
+ fir = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_to_db (s, ex);
+ if (fir) {
+ tmp = fir->bdata;
+ fir->bdata = g_strdup_printf ("%s %d %d", tmp ? tmp : "", CAMEL_MBOX_SUMMARY_VERSION, mbs->folder_size);
+ g_free (tmp);
+ }
return fir;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]