diff options
author | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-10-03 16:25:15 +0200 |
---|---|---|
committer | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-10-03 18:29:53 +0200 |
commit | 2e686fba88016d0265bf3fa1252f21b01bb0408a (patch) | |
tree | ef4f66dd5962dd1263aa135ddf15c62540eefe0a | |
parent | 5c69b30cfc0ab134fbe87b7299c91627620aacd6 (diff) | |
download | epiphany-2e686fba88016d0265bf3fa1252f21b01bb0408a.tar.gz |
sqlite-connection: Add function to enable foreign keys
This removes the duplicate code in EphyHistoryService and EphyGSBStorage.
-rw-r--r-- | lib/ephy-sqlite-connection.c | 14 | ||||
-rw-r--r-- | lib/ephy-sqlite-connection.h | 1 | ||||
-rw-r--r-- | lib/history/ephy-history-service.c | 21 | ||||
-rw-r--r-- | lib/safe-browsing/ephy-gsb-storage.c | 7 |
4 files changed, 18 insertions, 25 deletions
diff --git a/lib/ephy-sqlite-connection.c b/lib/ephy-sqlite-connection.c index 3d349210d..8f91e6b2b 100644 --- a/lib/ephy-sqlite-connection.c +++ b/lib/ephy-sqlite-connection.c @@ -191,6 +191,20 @@ ephy_sqlite_connection_get_last_insert_id (EphySQLiteConnection *self) return sqlite3_last_insert_rowid (self->database); } +void +ephy_sqlite_connection_enable_foreign_keys (EphySQLiteConnection *self) +{ + GError *error = NULL; + + g_assert (EPHY_IS_SQLITE_CONNECTION (self)); + + ephy_sqlite_connection_execute (self, "PRAGMA foreign_keys=ON", &error); + if (error) { + g_warning ("Failed to enable foreign keys pragma: %s", error->message); + g_error_free (error); + } +} + gboolean ephy_sqlite_connection_begin_transaction (EphySQLiteConnection *self, GError **error) { diff --git a/lib/ephy-sqlite-connection.h b/lib/ephy-sqlite-connection.h index 2c19b6546..b332c270d 100644 --- a/lib/ephy-sqlite-connection.h +++ b/lib/ephy-sqlite-connection.h @@ -46,6 +46,7 @@ void ephy_sqlite_connection_get_error (EphySQLi gboolean ephy_sqlite_connection_execute (EphySQLiteConnection *self, const char *sql, GError **error); EphySQLiteStatement * ephy_sqlite_connection_create_statement (EphySQLiteConnection *self, const char *sql, GError **error); gint64 ephy_sqlite_connection_get_last_insert_id (EphySQLiteConnection *self); +void ephy_sqlite_connection_enable_foreign_keys (EphySQLiteConnection *self); gboolean ephy_sqlite_connection_begin_transaction (EphySQLiteConnection *self, GError **error); gboolean ephy_sqlite_connection_commit_transaction (EphySQLiteConnection *self, GError **error); diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c index be43f266f..448c4ebef 100644 --- a/lib/history/ephy-history-service.c +++ b/lib/history/ephy-history-service.c @@ -391,23 +391,6 @@ ephy_history_service_commit_transaction (EphyHistoryService *self) } } -static void -ephy_history_service_enable_foreign_keys (EphyHistoryService *self) -{ - GError *error = NULL; - - if (self->history_database == NULL) - return; - - ephy_sqlite_connection_execute (self->history_database, - "PRAGMA foreign_keys = ON", &error); - - if (error) { - g_warning ("Could not enable foreign keys pragma: %s", error->message); - g_error_free (error); - } -} - static gboolean ephy_history_service_open_database_connections (EphyHistoryService *self) { @@ -434,10 +417,10 @@ ephy_history_service_open_database_connections (EphyHistoryService *self) } g_error_free (error); return FALSE; + } else { + ephy_sqlite_connection_enable_foreign_keys (self->history_database); } - ephy_history_service_enable_foreign_keys (self); - return self->read_only || (ephy_history_service_initialize_hosts_table (self) && ephy_history_service_initialize_urls_table (self) && diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c index bff3b4f5a..18950ee64 100644 --- a/lib/safe-browsing/ephy-gsb-storage.c +++ b/lib/safe-browsing/ephy-gsb-storage.c @@ -314,12 +314,7 @@ ephy_gsb_storage_open_db (EphyGSBStorage *self) return FALSE; } - /* Enable foreign keys. */ - ephy_sqlite_connection_execute (self->db, "PRAGMA foreign_keys=ON", &error); - if (error) { - g_warning ("Failed to enable foreign keys pragma: %s", error->message); - g_clear_pointer (&error, (GDestroyNotify)g_error_free); - } + ephy_sqlite_connection_enable_foreign_keys (self->db); ephy_sqlite_connection_execute (self->db, "PRAGMA synchronous=OFF", &error); if (error) { |