c# - 如何在 Xamarin iOS SQLite 中添加 SQLiteOpenFlags.FullMutex 标志

标签 c# multithreading sqlite xamarin xamarin.ios

我正尝试在我的项目中跨多个线程使用 SQLite 数据库 using a method discussed在 Xamarin 论坛中。他们在其中创建了以下静态类:

public static class Data {
    static readonly string Path = System.IO.Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "database.db");
    static SQLite.SQLiteConnection connection;
    public static SQLite.SQLiteConnection Connection
    {
        get {
            if (connection == null) {
                connection = new SQLiteConnection (Path,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex , true);
            }
            return connection;
        }
    }
}

我正在尝试实现此功能,但我当前使用的连接方法具有不同的方法签名。我认为这是因为我正在使用 PCL。我目前连接使用:

SQLiteConnection db = new SQLiteConnection (new SQLitePlatformIOS (), AppController._dbPath, false, null);

如何添加 SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.创建 | SQLiteOpenFlags.FullMutex 所以我可以像这样使用连接:

new SQLiteConnection (Path,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex , true)

我已经厌倦了以下但它失败了,因为它不匹配所需的方法签名

_connection = new SQLiteConnection (new SQLitePlatformIOS (),Path,false,null,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex);

最佳答案

我还在我的 PCL 项目中使用 SQLite,我有以下方法,这正是您要查找的方法。

public SQLiteConnection(ISQLitePlatform sqlitePlatform
                        , string databasePath
                        , SQLiteOpenFlags openFlags
                        , bool storeDateTimeAsTicks = true
                        , IBlobSerializer serializer = null
                        , IDictionary<string, TableMapping> tableMappings = null
                        , IDictionary<Type, string> extraTypeMappings = null
                        , IContractResolver resolver = null);

我使用的PCL SQLite版本是3.0.5,你可以找到Nuget here . 如果有兴趣,您可以获得 Async 版本 here .

关于c# - 如何在 Xamarin iOS SQLite 中添加 SQLiteOpenFlags.FullMutex 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068288/

相关文章:

c# - ASP.NET 构建 - Bin 文件夹与代码隐藏文件

Java n 线程更新值

java - 多线程场景下的 volatile+synchronized 组合

c++ - 如何解决C++中未释放的锁问题

r - 使用带有引号的值的 RSQLite 加载数据

c# - 如何在 UWP ListView 中拥有多个数据模板 (x :bind)

c# - 如何在 Raspbian 操作系统启动时启动 Mono 程序?

c# - 替换为 Html.BeginForm()

java - Android - 检查数据库中是否存在行

android - 用于具有潜在多个用户的 Android 应用程序的 SQLite 数据库