如何添加SQLiteOpenFlags.Xamarin iOS SQLite中的FullMutex标志
本文关键字:SQLite iOS 中的 FullMutex 标志 Xamarin SQLiteOpenFlags 何添加 添加 | 更新日期: 2023-09-27 18:17:06
我试图在我的项目中使用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);
我也在我的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。如果有兴趣,你可以在这里获得Async
版本。