我正尝试在我的项目中跨多个线程使用 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/