[evolution-data-server/openismus-work-master] EBookBackendSqliteDB: Added e_book_backend_new_contact[s]() APIs
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master] EBookBackendSqliteDB: Added e_book_backend_new_contact[s]() APIs
- Date: Mon, 21 Jan 2013 04:19:44 +0000 (UTC)
commit 29cdaede22fefa3dd83b488adae1f50570d0e00e
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Fri Jan 18 15:50:04 2013 +0900
EBookBackendSqliteDB: Added e_book_backend_new_contact[s]() APIs
The new API allows control on whether or not to overwrite existing contacts
with the same UID.
Deprecated the older e_book_backend_add_contact[s]() apis which include
the unused 'partial_contact' parameter and have no control on whether
or not to overwrite existing contacts.
Additionally this patch exposes the E_BOOK_SDB_ERROR domain and a couple
of error codes to distinguish if an error occurred because of a constraint
or other errors (UID conflicts at contact addition time are constraint
errors).
Conflicts:
addressbook/libedata-book/e-book-backend-sqlitedb.c
addressbook/libedata-book/e-book-backend-sqlitedb.h
.../libedata-book/e-book-backend-sqlitedb.c | 118 ++++++++++++++------
.../libedata-book/e-book-backend-sqlitedb.h | 43 +++++++-
2 files changed, 125 insertions(+), 36 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 20cf529..857b2a9 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -79,8 +79,6 @@ struct _EBookBackendSqliteDBPrivate {
G_DEFINE_TYPE (EBookBackendSqliteDB, e_book_backend_sqlitedb, G_TYPE_OBJECT)
-#define E_BOOK_SDB_ERROR \
- (e_book_backend_sqlitedb_error_quark ())
static GHashTable *db_connections = NULL;
static GMutex dbcon_lock;
@@ -153,7 +151,7 @@ typedef struct {
GSList *list;
} StoreVCardData;
-static GQuark
+GQuark
e_book_backend_sqlitedb_error_quark (void)
{
static GQuark quark = 0;
@@ -1371,15 +1369,16 @@ e_book_backend_sqlitedb_unlock_updates (EBookBackendSqliteDB *ebsdb,
static gchar *
insert_stmt_from_contact (EBookBackendSqliteDB *ebsdb,
EContact *contact,
- gboolean partial_content,
const gchar *folderid,
- gboolean store_vcard)
+ gboolean store_vcard,
+ gboolean replace_existing)
{
GString *string;
gchar *str, *vcard_str;
gint i;
- str = sqlite3_mprintf ("INSERT or REPLACE INTO %Q VALUES (", folderid);
+ str = sqlite3_mprintf ("INSERT or %s INTO %Q VALUES (",
+ replace_existing ? "REPLACE" : "FAIL", folderid);
string = g_string_new (str);
sqlite3_free (str);
@@ -1444,10 +1443,10 @@ insert_stmt_from_contact (EBookBackendSqliteDB *ebsdb,
static gboolean
insert_contact (EBookBackendSqliteDB *ebsdb,
- EContact *contact,
- gboolean partial_content,
- const gchar *folderid,
- GError **error)
+ EContact *contact,
+ const gchar *folderid,
+ gboolean replace_existing,
+ GError **error)
{
EBookBackendSqliteDBPrivate *priv;
gboolean success;
@@ -1456,7 +1455,7 @@ insert_contact (EBookBackendSqliteDB *ebsdb,
priv = ebsdb->priv;
/* Update main summary table */
- stmt = insert_stmt_from_contact (ebsdb, contact, partial_content, folderid, priv->store_vcard);
+ stmt = insert_stmt_from_contact (ebsdb, contact, folderid, priv->store_vcard, replace_existing);
success = book_backend_sql_exec (priv->db, stmt, NULL, NULL, error);
g_free (stmt);
@@ -1519,26 +1518,25 @@ insert_contact (EBookBackendSqliteDB *ebsdb,
}
/**
- * e_book_backend_sqlitedb_add_contact
- * @ebsdb:
+ * e_book_backend_sqlitedb_new_contact
+ * @ebsdb: An #EBookBackendSqliteDB
* @folderid: folder id
* @contact: EContact to be added
- * @partial_content: contact does not contain full information. Used when
- * the backend cache's partial information for auto-completion.
- * @error:
+ * @replace_existing: Whether this contact should replace another contact with the same UID.
+ * @error: A location to store any error that may have occurred.
*
- * This is a convenience wrapper for e_book_backend_sqlitedb_add_contacts,
- * which is the preferred means to add multiple contacts when possible.
+ * This is a convenience wrapper for e_book_backend_sqlitedb_new_contacts,
+ * which is the preferred means to add or modify multiple contacts when possible.
*
* Returns: TRUE on success.
*
- * Since: 3.2
+ * Since: 3.8
**/
gboolean
-e_book_backend_sqlitedb_add_contact (EBookBackendSqliteDB *ebsdb,
+e_book_backend_sqlitedb_new_contact (EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
EContact *contact,
- gboolean partial_content,
+ gboolean replace_existing,
GError **error)
{
GSList l;
@@ -1550,30 +1548,32 @@ e_book_backend_sqlitedb_add_contact (EBookBackendSqliteDB *ebsdb,
l.data = contact;
l.next = NULL;
- return e_book_backend_sqlitedb_add_contacts (
+ return e_book_backend_sqlitedb_new_contacts (
ebsdb, folderid, &l,
- partial_content, error);
+ replace_existing, error);
}
/**
- * e_book_backend_sqlitedb_add_contacts
- * @ebsdb:
+ * e_book_backend_sqlitedb_new_contacts
+ * @ebsdb: An #EBookBackendSqliteDB
* @folderid: folder id
* @contacts: list of EContacts
- * @partial_content: contact does not contain full information. Used when
- * the backend cache's partial information for auto-completion.
- * @error:
+ * @replace_existing: Whether this contact should replace another contact with the same UID.
+ * @error: A location to store any error that may have occurred.
*
+ * Adds or replaces contacts in @ebsdb. If @replace_existing is specified then existing
+ * contacts with the same UID will be replaced, otherwise adding an existing contact
+ * will return an error.
*
* Returns: TRUE on success.
*
- * Since: 3.2
+ * Since: 3.8
**/
gboolean
-e_book_backend_sqlitedb_add_contacts (EBookBackendSqliteDB *ebsdb,
+e_book_backend_sqlitedb_new_contacts (EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
GSList *contacts,
- gboolean partial_content,
+ gboolean replace_existing,
GError **error)
{
GSList *l;
@@ -1588,7 +1588,7 @@ e_book_backend_sqlitedb_add_contacts (EBookBackendSqliteDB *ebsdb,
for (l = contacts; success && l != NULL; l = g_slist_next (l)) {
EContact *contact = (EContact *) l->data;
- success = insert_contact (ebsdb, contact, partial_content, folderid, error);
+ success = insert_contact (ebsdb, contact, folderid, replace_existing, error);
}
if (success)
@@ -1601,6 +1601,60 @@ e_book_backend_sqlitedb_add_contacts (EBookBackendSqliteDB *ebsdb,
}
/**
+ * e_book_backend_sqlitedb_add_contact
+ * @ebsdb:
+ * @folderid: folder id
+ * @contact: EContact to be added
+ * @partial_content: contact does not contain full information. Used when
+ * the backend cache's partial information for auto-completion.
+ * @error:
+ *
+ * This is a convenience wrapper for e_book_backend_sqlitedb_add_contacts,
+ * which is the preferred means to add multiple contacts when possible.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.2
+ *
+ * Deprecated: 3.8: Use e_book_backend_sqlitedb_new_contact() instead.
+ **/
+gboolean
+e_book_backend_sqlitedb_add_contact (EBookBackendSqliteDB *ebsdb,
+ const gchar *folderid,
+ EContact *contact,
+ gboolean partial_content,
+ GError **error)
+{
+ return e_book_backend_sqlitedb_new_contact (ebsdb, folderid, contact, TRUE, error);
+}
+
+/**
+ * e_book_backend_sqlitedb_add_contacts
+ * @ebsdb:
+ * @folderid: folder id
+ * @contacts: list of EContacts
+ * @partial_content: contact does not contain full information. Used when
+ * the backend cache's partial information for auto-completion.
+ * @error:
+ *
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.2
+ *
+ * Deprecated: 3.8: Use e_book_backend_sqlitedb_new_contacts() instead.
+ **/
+gboolean
+e_book_backend_sqlitedb_add_contacts (EBookBackendSqliteDB *ebsdb,
+ const gchar *folderid,
+ GSList *contacts,
+ gboolean partial_content,
+ GError **error)
+{
+ return e_book_backend_sqlitedb_new_contacts (ebsdb, folderid, contacts, TRUE, error);
+}
+
+/**
* e_book_backend_sqlitedb_remove_contact:
*
* FIXME: Document me.
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.h b/addressbook/libedata-book/e-book-backend-sqlitedb.h
index f7153a4..8d6de5e 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.h
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.h
@@ -47,6 +47,15 @@
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_BOOK_BACKEND_SQLITEDB, EBookBackendSqliteDBClass))
+/**
+ * E_BOOK_SDB_ERROR:
+ *
+ * Error domain for #EBookBackendSqliteDB operations.
+ *
+ * Since: 3.8
+ **/
+#define E_BOOK_SDB_ERROR (e_book_backend_sqlitedb_error_quark ())
+
G_BEGIN_DECLS
typedef struct _EBookBackendSqliteDB EBookBackendSqliteDB;
@@ -54,6 +63,18 @@ typedef struct _EBookBackendSqliteDBClass EBookBackendSqliteDBClass;
typedef struct _EBookBackendSqliteDBPrivate EBookBackendSqliteDBPrivate;
/**
+ * EBookSDBError:
+ * @E_BOOK_SDB_ERROR_CONSTRAINT: The error occurred due to an explicit constraint
+ * @E_BOOK_SDB_ERROR_OTHER: Another error occurred
+ *
+ * Defines the types of possible errors reported by the #EBookBackendSqliteDB
+ */
+typedef enum {
+ E_BOOK_SDB_ERROR_CONSTRAINT,
+ E_BOOK_SDB_ERROR_OTHER
+} EBookSDBError;
+
+/**
* EBookBackendSqliteDB:
*
* Contains only private data that should be read and manipulated using the
@@ -85,6 +106,8 @@ typedef struct {
GType e_book_backend_sqlitedb_get_type
(void) G_GNUC_CONST;
+GQuark e_book_backend_sqlitedb_error_quark
+ (void);
EBookBackendSqliteDB *
e_book_backend_sqlitedb_new (const gchar *path,
const gchar *emailid,
@@ -108,17 +131,17 @@ gboolean e_book_backend_sqlitedb_unlock_updates
(EBookBackendSqliteDB *ebsdb,
gboolean do_commit,
GError **error);
-gboolean e_book_backend_sqlitedb_add_contact
+gboolean e_book_backend_sqlitedb_new_contact
(EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
EContact *contact,
- gboolean partial_content,
+ gboolean replace_existing,
GError **error);
-gboolean e_book_backend_sqlitedb_add_contacts
+gboolean e_book_backend_sqlitedb_new_contacts
(EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
GSList *contacts,
- gboolean partial_content,
+ gboolean replace_existing,
GError **error);
gboolean e_book_backend_sqlitedb_remove_contact
(EBookBackendSqliteDB *ebsdb,
@@ -251,6 +274,18 @@ gboolean e_book_backend_sqlitedb_is_summary_query
(const gchar *query);
gboolean e_book_backend_sqlitedb_is_summary_fields
(GHashTable *fields_of_interest);
+gboolean e_book_backend_sqlitedb_add_contact
+ (EBookBackendSqliteDB *ebsdb,
+ const gchar *folderid,
+ EContact *contact,
+ gboolean partial_content,
+ GError **error);
+gboolean e_book_backend_sqlitedb_add_contacts
+ (EBookBackendSqliteDB *ebsdb,
+ const gchar *folderid,
+ GSList *contacts,
+ gboolean partial_content,
+ GError **error);
#endif
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]