evolution-data-server r8840 - in branches/camel-db-summary/camel: . providers/local
- From: psankar svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8840 - in branches/camel-db-summary/camel: . providers/local
- Date: Fri, 23 May 2008 17:36:47 +0000 (UTC)
Author: psankar
Date: Fri May 23 17:36:47 2008
New Revision: 8840
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8840&view=rev
Log:
Completed camel_folder_summary_save_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/camel-store.c
branches/camel-db-summary/camel/providers/local/camel-local-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 Fri May 23 17:36:47 2008
@@ -1,22 +1,32 @@
/* Srinivasa Ragavan - <sragavan novell com> - GPL v2 or later */
-#include <glib.h>
#include "camel-db.h"
-#define d(x)
-static gboolean
-cdb_sql_exec (sqlite3 *db, const char* stmt) {
+#include <config.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#define d(x) x
+
+static int
+cdb_sql_exec (sqlite3 *db, const char* stmt, CamelException *ex)
+{
char *errmsg;
int ret;
ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
d(g_warning ("Error in statement: %s [%s].\n", stmt, errmsg));
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(errmsg));
sqlite3_free (errmsg);
+ return -1;
}
-
- return ret == SQLITE_OK;
+ return 0;
}
CamelDB *
@@ -32,9 +42,9 @@
if (!db) {
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Insufficient memory"));
} else {
- char *error;
+ const char *error;
error = sqlite3_errmsg (db);
- d(printf("Can't open database %s: %s\n", path, error));
+ d(g_print("Can't open database %s: %s\n", path, error));
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(error));
sqlite3_close(db);
}
@@ -44,6 +54,7 @@
cdb = g_new (CamelDB, 1);
cdb->db = db;
cdb->lock = g_mutex_new ();
+ d(g_print ("\n\aDatabase succesfully opened \n\a"));
return cdb;
}
@@ -54,19 +65,20 @@
sqlite3_close (cdb->db);
g_mutex_free (cdb->lock);
g_free (cdb);
+ d(g_print ("\n\aDatabase succesfully closed \n\a"));
}
}
gboolean
-camel_db_command (CamelDB *cdb, const char *stmt)
+camel_db_command (CamelDB *cdb, const char *stmt, CamelException *ex)
{
gboolean ret;
if (!cdb)
return TRUE;
g_mutex_lock (cdb->lock);
- d(printf("Executing: %s\n", stmt));
- ret = cdb_sql_exec (cdb->db, stmt);
+ d(g_print("Executing: %s\n", stmt));
+ ret = cdb_sql_exec (cdb->db, stmt, ex);
g_mutex_unlock (cdb->lock);
return ret;
}
@@ -102,7 +114,7 @@
sqlite3_free (errmsg);
}
g_mutex_unlock (cdb->lock);
- d(printf("count of '%s' is %d\n", stmt, count));
+ d(g_print("count of '%s' is %d\n", stmt, count));
return count;
}
@@ -111,7 +123,7 @@
camel_db_select (CamelDB *cdb, const char* stmt, CamelDBSelectCB callback, gpointer data)
{
char *errmsg;
- int nrecs = 0;
+ //int nrecs = 0;
int ret;
if (!cdb)
@@ -130,69 +142,62 @@
gboolean
-camel_db_delete_folder (CamelDB *cdb, char *folder)
+camel_db_delete_folder (CamelDB *cdb, char *folder, CamelException *ex)
{
- char *tab = g_strdup_printf ("delete from folders where folder='%s'", folder);
+ char *tab = g_strdup_printf ("delete from folders where folder_name ='%s'", folder);
gboolean ret;
- ret = camel_db_command (cdb, tab);
+ ret = camel_db_command (cdb, tab, ex);
g_free (tab);
return ret;
}
int
-camel_db_create_folders_table (CamelDB *cdb)
+camel_db_create_folders_table (CamelDB *cdb, CamelException *ex)
{
- 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, \
- )";
+ char *query = "CREATE TABLE IF NOT EXISTS folders ( folder_name 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);
+ return ((camel_db_command (cdb, query, ex)));
}
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 );
+ 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);
+
+ 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
+ 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);
+#endif
+
+ g_free (upd_query);
+ g_free (del_query);
+ g_free (ins_query);
- camel_db_command (cdb, query);
- g_free (query);
+ return 0;
}
gboolean
-camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid)
+camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid, CamelException *ex)
{
char *tab = g_strdup_printf ("delete from %s where uid='%s'", folder, uid);
gboolean ret;
- ret = camel_db_command (cdb, tab);
+ ret = camel_db_command (cdb, tab, ex);
g_free (tab);
return ret;
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 17:36:47 2008
@@ -94,11 +94,12 @@
CamelDB * camel_db_open (const char *path, CamelException *ex);
void camel_db_close (CamelDB *cdb);
-gboolean camel_db_command (CamelDB *cdb, const char *stmt);
+gboolean camel_db_command (CamelDB *cdb, const char *stmt, 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);
int camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *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 Fri May 23 17:36:47 2008
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <glib.h>
+#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <libedataserver/e-memory.h>
@@ -66,7 +67,7 @@
/* this should probably be conditional on it existing */
#define USE_BSEARCH
-#define d(x)
+#define d(x) x
#define io(x) /* io debug */
#define w(x)
@@ -638,12 +639,14 @@
int
-camel_folder_summary_save_db (CamelFolderSummary *s, CamelException *ex)
+camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
{
CamelDB *cdb = s->folder->parent_store->cdb;
CamelFIRecord *record;
int ret;
+ d(printf ("\n\acamel_folder_summary_save_to_db called \n\a"));
+
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"));
@@ -1606,7 +1609,8 @@
summary_header_to_db (CamelFolderSummary *s)
{
CamelFIRecord * record = g_new0 (struct _CamelFIRecord, 1);
- char *table_name = safe_table (camel_file_util_safe_filename (s->folder->full_name));
+ //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"));
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 17:36:47 2008
@@ -312,6 +312,9 @@
int camel_folder_summary_load(CamelFolderSummary *summary);
int camel_folder_summary_save(CamelFolderSummary *summary);
+/* load/save the full summary from/to the db */
+int camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex);
+
/* only load the header */
int camel_folder_summary_header_load(CamelFolderSummary *summary);
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 17:36:47 2008
@@ -42,7 +42,7 @@
#include "camel-store.h"
#include "camel-vtrash-folder.h"
-#define d(x)
+#define d(x) x
#define w(x)
static CamelServiceClass *parent_class = NULL;
@@ -153,6 +153,7 @@
{
CamelStore *store = CAMEL_STORE (object);
+ d(printf ("\n\acamel_store_finalize called \n\a"));
if (store->folders)
camel_object_bag_destroy(store->folders);
@@ -219,7 +220,11 @@
if (camel_exception_is_set (ex))
return;
- camel_db_create_folders_table (store->cdb, ex);
+ if (camel_db_create_folders_table (store->cdb, ex))
+ printf ("something went wrong terribly\n");
+ else
+ printf ("folders table succesfully created \n");
+
if (camel_exception_is_set (ex))
return;
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 Fri May 23 17:36:47 2008
@@ -403,13 +403,9 @@
{
int ret = 0;
- ret = camel_folder_summary_save((CamelFolderSummary *)cls);
+ ret = camel_folder_summary_save_to_db ((CamelFolderSummary *)cls, ex);
if (ret == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Could not save summary: %s: %s"),
- cls->folder_path, g_strerror (errno));
-
- g_warning ("Could not save summary for %s: %s", cls->folder_path, strerror (errno));
+ g_warning ("Could not save summary for local providers");
}
if (cls->index && camel_index_sync(cls->index) == -1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]