diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-20 23:11:24 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-20 23:11:24 +0100 |
commit | 6c62e78180c5dd39e7f3ef02eefc2751c3963926 (patch) | |
tree | 9e0e27143c7f1757c7bdc6551640b452a133e2a6 /src | |
parent | 1aa3dd206e89e935e61eadaf6ea650903d3d3131 (diff) | |
download | rspamd-6c62e78180c5dd39e7f3ef02eefc2751c3963926.tar.gz rspamd-6c62e78180c5dd39e7f3ef02eefc2751c3963926.zip |
Check user_version upon start.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index c85d774d8..5a791b6aa 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -287,9 +287,11 @@ rspamd_sqlite3_opendb (const gchar *path, const ucl_object_t *opts, { struct rspamd_stat_sqlite3_db *bk; sqlite3 *sqlite; + sqlite3_stmt *stmt; gint rc, flags; static const char sqlite_wal[] = "PRAGMA journal_mode=WAL;", - fallback_journal[] = "PRAGMA journal_mode=OFF;"; + fallback_journal[] = "PRAGMA journal_mode=OFF;", + user_version[] = "PRAGMA user_version;"; flags = SQLITE_OPEN_READWRITE; @@ -306,6 +308,23 @@ rspamd_sqlite3_opendb (const gchar *path, const ucl_object_t *opts, return NULL; } + if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) { + msg_warn ("WAL mode is not supported, locking issues might occur"); + sqlite3_exec (sqlite, fallback_journal, NULL, NULL, NULL); + } + + /* Check user_version */ + g_assert (sqlite3_prepare_v2 (sqlite, user_version, -1, &stmt, NULL) + == SQLITE_OK); + g_assert (sqlite3_step (stmt) == SQLITE_ROW); + + if (sqlite3_column_int (stmt, 0) != atoi (SQLITE3_SCHEMA_VERSION)) { + msg_warn ("bad sqlite database: %s, try to recreate it", path); + create = TRUE; + } + + sqlite3_finalize (stmt); + if (create) { if (sqlite3_exec (sqlite, create_tables_sql, NULL, NULL, NULL) != SQLITE_OK) { g_set_error (err, rspamd_sqlite3_quark (), @@ -317,11 +336,6 @@ rspamd_sqlite3_opendb (const gchar *path, const ucl_object_t *opts, } } - if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) { - msg_warn ("WAL mode is not supported, locking issues might occur"); - sqlite3_exec (sqlite, fallback_journal, NULL, NULL, NULL); - } - bk = g_slice_alloc0 (sizeof (*bk)); bk->sqlite = sqlite; bk->prstmt = g_slice_alloc0 (sizeof (prepared_stmts)); |