Skip to content

Commit f88773d

Browse files
authored
Do not force journal mode unless specified (#341)
Let SQLite use the default journal mode if none is given. This is important because the database may be in WAL mode already (which is persistent) and forcing it to DELETE mode unexpectedly changes the database out of WAL mode (also in a persistent way). Closes #340.
1 parent f415367 commit f88773d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/exqlite/connection.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ defmodule Exqlite.Connection do
464464
end
465465

466466
defp set_journal_mode(db, options) do
467-
maybe_set_pragma(db, "journal_mode", Pragma.journal_mode(options))
467+
set_pragma_if_present(db, "journal_mode", Keyword.get(options, :journal_mode))
468468
end
469469

470470
defp set_temp_store(db, options) do

test/exqlite/connection_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ defmodule Exqlite.ConnectionTest do
171171
assert {:error, "attempt to write a readonly database"} ==
172172
Sqlite3.execute(ro_state.db, insert_value_query)
173173
end
174+
175+
test "preserves WAL mode across connections" do
176+
path = Temp.path!()
177+
178+
{:ok, state1} = Connection.connect(database: path, journal_mode: :wal)
179+
assert {:ok, "wal"} = get_pragma(state1.db, :journal_mode)
180+
181+
{:ok, state2} = Connection.connect(database: path)
182+
assert {:ok, "wal"} = get_pragma(state2.db, :journal_mode)
183+
184+
File.rm(path)
185+
end
174186
end
175187

176188
defp get_pragma(db, pragma_name) do

0 commit comments

Comments
 (0)