4

嗨,我已经安装了 sqlite-net nuget 包,它带有 2 个 cs 文件:SQLite.cs 和 SQLiteAsync.cs。

SQLite.cs包含一个名为的类SQLite3,其中包含方法:

[DllImport("sqlite3", EntryPoint = "sqlite3_win32_set_directory", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int SetDirectory(uint directoryType, string directoryPath);

我看到SQLiteConnection构造函数有以下代码:

#if NETFX_CORE
         SQLite3.SetDirectory(/*temp directory type*/2, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
#endif

但是为什么?!这是做什么的,为什么每次创建新的 SQLiteConnection 时都需要设置它?似乎我AccessViolationExceptions对这条线有些零星。

更新

我找到了此方法的文档,但仍然不了解 TempDirectory 的用途。那里写的是什么?

/*
** This function sets the data directory or the temporary directory based on
** the provided arguments.  The type argument must be 1 in order to set the
** data directory or 2 in order to set the temporary directory.  The zValue
** argument is the name of the directory to use.  The return value will be
** SQLITE_OK if successful.
*/
4

1 回答 1

3

您从构造函数中显示的特定调用SQLiteConnection设置了 SQLite 的临时目录。这是 SQLite 用于临时/工作存储的目录。

我相信由于应用沙盒,SQLite 无法写入默认临时目录;这就是您引用的代码使用应用程序的临时目录的原因。

如果未设置目录,则副作用是执行更新语句时会出错。

在这里查看更多:

于 2013-11-07T23:46:26.060 回答