How to open SQLite connection in WAL mode

The line below is what I was looking for, many thanks to Turbot whose answer includes it:

new SQLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;")

how about a factory approach to specify in the SQLiteConnection connetion string ?

for e.g

public static class Connection
{
    public abstract SQLiteConnection NewConnection(String file);
}

public class NormalConnection : Connection 
{
  public override SQLiteConnection NewConnection(String file)
  {
     return new SQLiteConnection("Data Source=" + file);
  }
}

public class WALConnection : Connection 
{
  public override SQLiteConnection NewConnection(String file)
  {
    return new SQLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;"
  }
}

The code is not tested, but I hope you can get the idea, so when you use it you can do like that.

   SQLiteConnection conWal = new WALConnection(file);
    conWAL.Open();

    SQLiteConnection conNormal = new NormalConnection(file);
    conNormal.Open();

Here is my less-than-perfect solution:

SQLiteConnection connection = new SQLiteConnection("Data Source=" + file);
connection.Open();
using (var command = new SQLiteCommand(sqliteConnection))
{
    command.CommandText = "PRAGMA journal_mode=WAL";
    command.ExecuteNonQuery();
}
// (Perform my query)

If you know something less verbose, I would be happy to hear about it!

Tags:

C#

Sqlite

Wal