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

3
我正在尝试在我的项目中跨多个线程使用SQLite数据库使用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.Create | 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);
1个回答

1

我在我的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,你可以在这里找到Nugethere。 如果感兴趣,你可以在这里获取Async版本here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接