sqlite3_win32_set_directory / SQLite3.SetDirectory的目的是什么?

时间:2013-11-07 19:09:08

标签: c# sqlite windows-runtime sqlite-net

嗨,我已经安装了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.
*/

1 个答案:

答案 0 :(得分:3)

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

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

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

在此处查看更多信息:

相关问题