我正在创建一个使用多个SQLite数据库的跨平台应用程序(Android,iOS,WP8)。我在所有平台上安装了MvvmCross.HotTuna.Plugin.Sqlite,但它不适用于WP8。我得到了这个例外:
"Could not open database file: C:\\Data\\Users\\DefApps\\AppData\\{284E2D10-051E-48D8-B895 E8126CCE3192}\\Local\\database.sqlite (CannotOpen)".
我正在打开这样的数据库:
dataService.Initialize(Path.Combine(ApplicationData.Current.LocalFolder.Path, filename));
然后我尝试使用新的Sqlite插件(MvvmCross - 社区SQLite-Net插件),它几乎在每个查询中都给出了奇怪的错误:
Message: "not an error"
StackTrace: " at Community.SQLite.SQLite3.Prepare2(sqlite3 db, String query)\r\n at Community.SQLite.SQLiteCommand.Prepare()\r\n at Community.SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__0`1.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Community.SQLite.SQLiteCommand.ExecuteQuery[T]()\r\n at Community.SQLite.SQLiteConnection.Query[T](String query, Object[] args)\r\n at
任何建议我如何才能使其发挥作用?
修改
我发现“不是错误”背后的原因是我的多线程。我使用Task.Run并等待创建后台线程(在iOS和Android上运行良好,但在WP8上失败)。我从我的代码中删除了它(使用#if WINDOWS_PHONE指令),所以现在它同步工作。但是社区SQLite插件无法将我的SQLite日期类型映射到DateTime。它总是给我相同的DateTime:{0001.01.01。 0点00分00秒}。
顺便说一下我如何使用原生SQLite?你能告诉我一个样品吗?我需要在我的WP8项目中添加新的SQLite库,并实现IDataService,ISQLiteConnectionFactory,并将它们注册到:
Setup.InitializeLastChance()
{
Mvx.LazyConstructAndRegisterSingleton<IDataService, MyOwnDataService>();
Mvx.LazyConstructAndRegisterSingleton<ISQLiteConnectionFactory , MyOwnConnectionFactory>();
}