C# では、WAL モードでSQLite 接続を開く方法は?
通常モードで開く方法は次のとおりです。
SQLiteConnection connection = new SQLiteConnection("Data Source=" + file);
connection.Open();
// (Perform my query)
C# では、WAL モードでSQLite 接続を開く方法は?
通常モードで開く方法は次のとおりです。
SQLiteConnection connection = new SQLiteConnection("Data Source=" + file);
connection.Open();
// (Perform my query)
SQLiteConnection 接続文字列で指定するファクトリ アプローチはどうですか?
例えば
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;"
}
}
コードはテストされていませんが、アイデアが得られることを願っています。使用すると、そのようにすることができます。
SQLiteConnection conWal = new WALConnection(file);
conWAL.Open();
SQLiteConnection conNormal = new NormalConnection(file);
conNormal.Open();
以下の行は、私が探していたものです。Turbot の回答に感謝します。
new SQLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;")
WALモードの永続性
「他のジャーナリング モードとは異なり、PRAGMA journal_mode=WAL は永続的です。プロセスが WAL モードを設定し、データベースを閉じて再度開くと、データベースは WAL モードに戻ります。」
http://www.sqlite.org/wal.html
私が正しく理解している場合、これは、データベースの WAL モードを一度設定すればよいことを意味し、すべての接続で設定する必要はありません。
SQLite のコマンド ライン シェルで実行できます: http://www.sqlite.org/sqlite.html
これが私の完璧ではない解決策です:
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)
あまり詳しくないことを知っていれば、それについて聞いてうれしいです!