15

C# では、WAL モードでSQLite 接続を開く方法は?

通常モードで開く方法は次のとおりです。

SQLiteConnection connection = new SQLiteConnection("Data Source=" + file);
connection.Open();
// (Perform my query)
4

4 に答える 4

13

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();
于 2013-04-08T02:31:35.227 に答える
9

以下の行は、私が探していたものです。Turbot の回答に感謝します。

new SQLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;")
于 2013-04-08T03:48:44.713 に答える
4

WALモードの永続性

「他のジャーナリング モードとは異なり、PRAGMA journal_mode=WAL は永続的です。プロセスが WAL モードを設定し、データベースを閉じて再度開くと、データベースは WAL モードに戻ります。」

http://www.sqlite.org/wal.html

私が正しく理解している場合、これは、データベースの WAL モードを一度設定すればよいことを意味し、すべての接続で設定する必要はありません。

SQLite のコマンド ライン シェルで実行できます: http://www.sqlite.org/sqlite.html

于 2013-06-15T11:47:19.883 に答える
3

これが私の完璧ではない解決策です:

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)

あまり詳しくないことを知っていれば、それについて聞いてうれしいです!

于 2013-04-08T02:02:54.093 に答える