[geary/wip/contact-cleanup-713932: 2/2] Database upgrade to fix existing contacts
- From: Charles Lindsay <clindsay src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/contact-cleanup-713932: 2/2] Database upgrade to fix existing contacts
- Date: Fri, 21 Feb 2014 19:57:59 +0000 (UTC)
commit a3ece76c4f156aa3073128b99293999ad968d025
Author: Charles Lindsay <chaz yorba org>
Date: Fri Feb 21 11:44:47 2014 -0800
Database upgrade to fix existing contacts
sql/CMakeLists.txt | 1 +
sql/version-019.sql | 5 +++++
src/engine/imap-db/imap-db-database.vala | 29 +++++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index c206d2c..84ad3e4 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -18,3 +18,4 @@ install(FILES version-015.sql DESTINATION ${SQL_DEST})
install(FILES version-016.sql DESTINATION ${SQL_DEST})
install(FILES version-017.sql DESTINATION ${SQL_DEST})
install(FILES version-018.sql DESTINATION ${SQL_DEST})
+install(FILES version-019.sql DESTINATION ${SQL_DEST})
diff --git a/sql/version-019.sql b/sql/version-019.sql
new file mode 100644
index 0000000..6ea8732
--- /dev/null
+++ b/sql/version-019.sql
@@ -0,0 +1,5 @@
+--
+-- Dummy database upgrade to validate contact email addresses. See
+-- src/engine/imap-db/imap-db-database.vala in post_upgrade() for the code
+-- that runs the upgrade.
+--
diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala
index f9ce635..a594356 100644
--- a/src/engine/imap-db/imap-db-database.vala
+++ b/src/engine/imap-db/imap-db-database.vala
@@ -97,6 +97,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
case 18:
post_upgrade_populate_internal_date_time_t();
break;
+
+ case 19:
+ post_upgrade_validate_contacts();
+ break;
}
}
@@ -370,6 +374,31 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
}
}
+ // Version 19.
+ private void post_upgrade_validate_contacts() {
+ try {
+ exec_transaction(Db.TransactionType.RW, (cx) => {
+ Db.Result result = cx.query("SELECT id, email FROM ContactTable");
+ while (!result.finished) {
+ string email = result.string_at(1);
+ if (!RFC822.MailboxAddress.is_valid_address(email)) {
+ int64 id = result.rowid_at(0);
+
+ Db.Statement stmt = cx.prepare("DELETE FROM ContactTable WHERE id = ?");
+ stmt.bind_rowid(0, id);
+ stmt.exec();
+ }
+
+ result.next();
+ }
+
+ return Db.TransactionOutcome.COMMIT;
+ });
+ } catch (Error err) {
+ debug("Error populating autocompletion table during upgrade to database schema 5");
+ }
+ }
+
private void on_prepare_database_connection(Db.Connection cx) throws Error {
cx.set_busy_timeout_msec(Db.Connection.RECOMMENDED_BUSY_TIMEOUT_MSEC);
cx.set_foreign_keys(true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]