[evolution-ews] Implement get/set has_partial_content, sync_data, custom key/value pairs, partially_cached_uids.



commit ef5ee682725939e3cac5ef967f4698c4a2325826
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Tue May 10 19:08:43 2011 +0530

    Implement get/set has_partial_content, sync_data, custom key/value pairs,
    partially_cached_uids.

 src/addressbook/e-book-backend-sqlitedb.c |  184 ++++++++++++++++++++++++++++-
 1 files changed, 182 insertions(+), 2 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-sqlitedb.c b/src/addressbook/e-book-backend-sqlitedb.c
index a5437f5..19faed3 100644
--- a/src/addressbook/e-book-backend-sqlitedb.c
+++ b/src/addressbook/e-book-backend-sqlitedb.c
@@ -254,8 +254,8 @@ create_folders_table	(EBookBackendSqliteDB *ebsdb,
 	
 	
 	/* Create a child table to store key/value pairs for a folder */
-	stmt = "CREATE TABLE IF NOT EXISTS keys	\
-		( key TEXT, value TEXT,\
+	stmt = "CREATE TABLE IF NOT EXISTS keys				\
+		( key TEXT PRIMARY KEY, value TEXT,			\
 		  folder_id TEXT REFERENCES folders)";
 	book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, &err);
 
@@ -1020,3 +1020,183 @@ e_book_backend_sqlitedb_set_is_populated	(EBookBackendSqliteDB *ebsdb,
 
 	return ret;
 }
+
+gboolean	
+e_book_backend_sqlitedb_get_has_partial_content	(EBookBackendSqliteDB *ebsdb,
+						 const gchar *folderid,
+						 GError **error)
+{
+	gchar *stmt;
+	gboolean ret = FALSE;
+	
+	READER_LOCK (ebsdb);
+
+	stmt = sqlite3_mprintf ("SELECT partial_content FROM folders WHERE folder_id = %Q", folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, get_bool_cb , &ret, error);
+	sqlite3_free (stmt);
+
+	READER_UNLOCK (ebsdb);
+
+	return ret;
+}
+
+gboolean	
+e_book_backend_sqlitedb_set_has_partial_content	(EBookBackendSqliteDB *ebsdb,
+						 const gchar *folderid,
+						 gboolean partial_content,
+						 GError **error)
+{
+	gchar *stmt = NULL;
+	GError *err = NULL;
+	gboolean ret = TRUE;
+	
+	WRITER_LOCK (ebsdb);
+	book_backend_sqlitedb_start_transaction (ebsdb, &err);
+	
+	stmt = sqlite3_mprintf ("INSERT or REPLACE INTO folders (folder_id, 		\
+				folder_name, sync_data, is_populated,			\
+				partial_content) SELECT %Q, folder_name, sync_data,	\
+	     			is_populated, %d) WHERE folder_id = %Q)", folderid,
+				partial_content, folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, &err);
+
+	book_backend_sqlitedb_end_transaction (ebsdb, &err);
+	WRITER_UNLOCK (ebsdb);
+	if (err)
+		ret = FALSE;
+
+	return ret;
+}
+
+static int
+get_string_cb (gpointer ref, gint col, gchar **cols, gchar **name)
+{
+	gchar **ret = ref;
+
+	*ret = g_strdup (cols [0]);
+
+	return 0;
+}
+
+gchar *		
+e_book_backend_sqlitedb_get_sync_data	(EBookBackendSqliteDB *ebsdb,
+					 const gchar *folderid,
+					 GError **error)
+{
+	gchar *stmt, *ret = NULL;
+	
+	READER_LOCK (ebsdb);
+
+	stmt = sqlite3_mprintf ("SELECT sync_data FROM folders WHERE folder_id = %Q", folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, get_string_cb , &ret, error);
+	sqlite3_free (stmt);
+
+	READER_UNLOCK (ebsdb);
+
+	return ret;
+}
+
+gboolean	
+e_book_backend_sqlitedb_set_sync_data	(EBookBackendSqliteDB *ebsdb,
+					 const gchar *folderid,
+					 const gchar *sync_data,
+					 GError **error)
+{
+	gchar *stmt = NULL;
+	GError *err = NULL;
+	gboolean ret = TRUE;
+	
+	WRITER_LOCK (ebsdb);
+	book_backend_sqlitedb_start_transaction (ebsdb, &err);
+	
+	stmt = sqlite3_mprintf ("INSERT or REPLACE INTO folders (folder_id, 		\
+				folder_name, sync_data, is_populated,			\
+				partial_content) SELECT %Q, folder_name, %Q,		\
+	     			is_populated, partial_content) WHERE folder_id = %Q)", folderid,
+				sync_data, folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, &err);
+
+	book_backend_sqlitedb_end_transaction (ebsdb, &err);
+	WRITER_UNLOCK (ebsdb);
+	if (err)
+		ret = FALSE;
+
+	return ret;
+}
+
+gchar *		
+e_book_backend_sqlitedb_get_key_value	(EBookBackendSqliteDB *ebsdb,
+					 const gchar *folderid,
+					 const gchar *key,
+					 GError **error)
+{
+	gchar *stmt, *ret = NULL;
+	
+	READER_LOCK (ebsdb);
+
+	stmt = sqlite3_mprintf ("SELECT value FROM folders WHERE folder_id = %Q AND key = %Q", 
+							folderid, key);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, get_string_cb , &ret, error);
+	sqlite3_free (stmt);
+
+	READER_UNLOCK (ebsdb);
+
+	return ret;
+}
+
+gboolean	
+e_book_backend_sqlitedb_set_key_value	(EBookBackendSqliteDB *ebsdb,
+					 const gchar *folderid,
+					 const gchar *key,
+					 const gchar *value,
+					 GError **error)
+{
+	gchar *stmt = NULL;
+	GError *err = NULL;
+	gboolean ret = TRUE;
+	
+	WRITER_LOCK (ebsdb);
+	book_backend_sqlitedb_start_transaction (ebsdb, &err);
+	
+	stmt = sqlite3_mprintf ("INSERT or REPLACE INTO keys (key, value, folder_id)	\
+	     			values (%Q %Q %Q)", key, value, folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, &err);
+
+	book_backend_sqlitedb_end_transaction (ebsdb, &err);
+	WRITER_UNLOCK (ebsdb);
+	if (err)
+		ret = FALSE;
+
+	return ret;
+}
+
+static gint
+addto_slist_cb (gpointer ref, gint col, gchar **cols, gchar **name)
+{
+	GSList **uids = ref;
+
+	if (cols [0])
+		*uids = g_slist_prepend (*uids, cols [0]);
+
+	return 0;
+}
+
+GSList *	
+e_book_backend_sqlitedb_get_partially_cached_ids	(EBookBackendSqliteDB *ebsdb,
+							 const gchar *folderid,
+							 GError **error)
+{
+	gchar *stmt;
+	GSList *uids = NULL;
+	
+	READER_LOCK (ebsdb);
+
+	stmt = sqlite3_mprintf ("SELECT uid FROM %Q WHERE partial_content = 1", 
+							folderid);
+	book_backend_sql_exec (ebsdb->priv->db, stmt, addto_slist_cb, &uids, error);
+	sqlite3_free (stmt);
+
+	READER_UNLOCK (ebsdb);
+
+	return uids;
+}



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