C# sqlite3\u win32\u set\u directory/sqlite3.SetDirectory的用途是什么?
您好,我已经安装了sqlite net nuget包,它附带了两个cs文件:sqlite.cs和SQLiteAsync.csC# sqlite3\u win32\u set\u directory/sqlite3.SetDirectory的用途是什么?,c#,sqlite,windows-runtime,sqlite-net,C#,Sqlite,Windows Runtime,Sqlite Net,您好,我已经安装了sqlite net nuget包,它附带了两个cs文件:sqlite.cs和SQLiteAsync.cs SQLite.cs包含一个名为SQLite3的类,该类包含以下方法: [DllImport("sqlite3", EntryPoint = "sqlite3_win32_set_directory", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] public static
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.
*/
从
SQLiteConnection
构造函数显示的特定调用为SQLite设置临时目录。这是SQLite用于临时/工作存储的目录
我相信由于应用程序沙盒,SQLite无法写入默认的临时目录;这就是您引用的代码使用应用程序的临时目录的原因
如果未设置目录,则副作用是在执行update语句时出现错误
请参阅此处的更多信息:
- 烟囱溢流柱-