]> source.dussan.org Git - rspamd.git/commitdiff
Enable foreign keys in sqlite3.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 28 Sep 2015 09:40:43 +0000 (10:40 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 28 Sep 2015 09:40:43 +0000 (10:40 +0100)
src/libserver/fuzzy_backend.c
src/libutil/sqlite_utils.c

index ce6bd6a5acb74efa2f4b99afe56f7d3046dbd4f5..016ee2b5afc8f64d9db375b6323e06b63d28e1d5 100644 (file)
@@ -408,7 +408,8 @@ rspamd_fuzzy_backend_open (const gchar *path, GError **err)
        gint fd;
        struct rspamd_fuzzy_backend *backend;
        static const char sqlite_wal[] = "PRAGMA journal_mode=\"wal\";",
-                       fallback_journal[] = "PRAGMA journal_mode=\"off\";";
+                       fallback_journal[] = "PRAGMA journal_mode=\"off\";",
+                       foreign_keys[] = "PRAGMA foreign_keys=\"ON\";";
        int rc;
 
        if (path == NULL) {
@@ -466,6 +467,11 @@ rspamd_fuzzy_backend_open (const gchar *path, GError **err)
                sqlite3_exec (backend->db, fallback_journal, NULL, NULL, NULL);
        }
 
+       if ((rc = sqlite3_exec (backend->db, foreign_keys, NULL, NULL, NULL)) !=
+                       SQLITE_OK) {
+               msg_warn_fuzzy_backend ("foreign keys are not supported", rc);
+       }
+
        /* Cleanup database */
        rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_VACUUM, backend, NULL);
 
index 0dea2edc298ded8e9b73fc1be5e9c266c3643a15..d677a0dc24eaa88eda4d40d3677effc5d64567f3 100644 (file)
@@ -249,7 +249,8 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
        gchar lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir;
        static const char sqlite_wal[] = "PRAGMA journal_mode=\"wal\";",
                        exclusive_lock_sql[] = "PRAGMA locking_mode=\"exclusive\";",
-                       fsync_sql[] = "PRAGMA synchronous=1;";
+                       fsync_sql[] = "PRAGMA synchronous=1;",
+                       foreign_keys[] = "PRAGMA foreign_keys=\"ON\";";
        gboolean create = FALSE, has_lock = FALSE;
 
        flags = SQLITE_OPEN_READWRITE;
@@ -377,6 +378,12 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
                                sqlite3_errmsg (sqlite));
        }
 
+       if ((rc = sqlite3_exec (sqlite, foreign_keys, NULL, NULL, NULL)) !=
+                       SQLITE_OK) {
+               msg_warn_pool ("cannot enable foreign keys: %s",
+                               sqlite3_errmsg (sqlite));
+       }
+
        if (has_lock) {
                msg_debug_pool ("removing lock from %s", lock_path);
                rspamd_file_unlock (lock_fd, FALSE);