经过大量搜索后,我无法找到如何将 SQLite.NET 页面大小从默认值 4096 更改。我有一个带有 SQLite.NET Async PCL Nuget 的 Xamarin Forms PCL 应用程序(和 Twincoders Extensions,但这不相关) .
在平台项目中,SQLiteConnectionString 似乎没有设置 Pagesize 的工具。
我的 iOS 代码如下所示:
private static SQLiteConnectionString connectionString = new SQLiteConnectionString(Path.Combine(DatabaseFilePath, DatabaseFilename), false);
private static SQLiteAsyncConnection asyncConnection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(new SQLitePlatformIOS(), connectionString));
public SQLiteAsyncConnection GetAsyncConnection()
{
return asyncConnection;
}
帮助表示赞赏!如果没有办法做到这一点,也很高兴知道这一点。
******** 编辑: ********
@Paul 建议使用 PRAGMA page_size,我相信这是正确的想法。然而 SQLite.Net 会忽略更改 page_size 的请求,即使尚未创建表且日志模式为默认值。至少在 iOS 中。除非我的代码是错误的:
在 Xamarin Forms PCL 中,我有:
public interface ISQLite
{
SQLiteAsyncConnection GetAsyncConnection ();
}
在我的 iOS 项目中,我有:
private static string DatabaseFilename = "MyDatabase.db3";
private static string DatabaseFilePath
{
get
{
return (NSFileManager.DefaultManager.GetUrls
(NSSearchPathDirectory.LibraryDirectory,
NSSearchPathDomain.User) [0]).ToString();
}
}
private static readonly SQLiteConnectionString connectionString =
new SQLiteConnectionString(Path.Combine(DatabaseFilePath, DatabaseFilename), false);
private static readonly SQLiteAsyncConnection asyncConnection =
new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(new SQLitePlatformIOS(), connectionString));
public SQLiteAsyncConnection GetAsyncConnection()
{
var syncTask = new Task (() =>
{
//asyncConnection.ExecuteAsync("PRAGMA journal_mode=DELETE");
asyncConnection.ExecuteAsync ("PRAGMA page_size=1024"); // Has no effect on page size
});
syncTask.RunSynchronously();
return asyncConnection;
}
这会正确执行,但不会更改页面大小。
欢迎所有想法!
********进一步编辑:********
添加 VACUUM 也没有效果:
asyncConnection.ExecuteAsync ("PRAGMA page_size=1024; vacuum");