如何在WAL模式下打开SQLite连接 [英] How to open SQLite connection in WAL mode

查看:93
本文介绍了如何在WAL模式下打开SQLite连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,如何在WAL模式下打开SQLite连接 ?

In C#, how to open an SQLite connection in WAL mode?

这是我在正常模式下打开的方式:

Here is how I open in normal mode:

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

推荐答案

如何在SQLiteConnection连接字符串中指定工厂方法?

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

例如

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();

这篇关于如何在WAL模式下打开SQLite连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆