[evolution-data-server/openismus-work] EBookBackendSqliteDB: Avoid summary introspection on initial creation.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] EBookBackendSqliteDB: Avoid summary introspection on initial creation.
- Date: Tue, 16 Apr 2013 08:25:59 +0000 (UTC)
commit e75fd515a4e416bed590a40953937b0661ecccc5
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Tue Apr 16 17:18:53 2013 +0900
EBookBackendSqliteDB: Avoid summary introspection on initial creation.
The summary introspection does not introspect whether regular prefix
indexes are created, which is acceptable since it does not effect queries.
However since we introspect before creating the indexes, we lose the
configured index information which is needed to initially create those
indexes.
This patch simply checks if the table exists when initially creating
the summary and avoids the introspection if the table is being created
for the first time.
.../libedata-book/e-book-backend-sqlitedb.c | 50 +++++++++++++++++++++-
1 file changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 3625037..1cf9069 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -747,6 +747,47 @@ collect_columns_cb (gpointer ref,
return 0;
}
+static gint
+get_count_cb (gpointer ref,
+ gint n_cols,
+ gchar **cols,
+ gchar **name)
+{
+ gint64 count = 0;
+ gint *ret = ref;
+ gint i;
+
+ for (i = 0; i < n_cols; i++) {
+ if (g_strcmp0 (name[i], "count(*)") == 0) {
+ count = g_ascii_strtoll (cols[i], NULL, 10);
+ }
+ }
+
+ *ret = count;
+
+ return 0;
+}
+
+static gboolean
+check_folderid_exists (EBookBackendSqliteDB *ebsdb,
+ const gchar *folderid,
+ gboolean *exists,
+ GError **error)
+{
+ gboolean success;
+ gint count = 0;
+ gchar *stmt;
+
+ stmt = sqlite3_mprintf ("SELECT count(*) FROM sqlite_master WHERE type='table' AND name=%Q;",
folderid);
+
+ success = book_backend_sql_exec (ebsdb->priv->db, stmt, get_count_cb, &count, error);
+ sqlite3_free (stmt);
+
+ *exists = (count > 0);
+
+ return success;
+}
+
static gboolean
introspect_summary (EBookBackendSqliteDB *ebsdb,
const gchar *folderid,
@@ -896,8 +937,12 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
gboolean success;
gchar *stmt, *tmp;
GString *string;
+ gboolean already_exists = FALSE;
+
+ success = check_folderid_exists (ebsdb, folderid, &already_exists, error);
+ if (!success)
+ return FALSE;
- /* Construct the create statement from the summary fields table */
string = g_string_new (
"CREATE TABLE IF NOT EXISTS %Q ( uid TEXT PRIMARY KEY, ");
@@ -980,7 +1025,8 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
g_free (tmp);
}
- if (success)
+ /* Dont introspect the summary if the table did not yet exist */
+ if (success && already_exists)
success = introspect_summary (ebsdb, folderid, error);
/* Create indexes on the summary fields configured for indexing */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]