Small. Fast. Reliable.
Choose any three.

SQLite C 接口

保存临时文件的目录名
Name Of The Folder Holding Temporary Files

SQLITE_EXTERN char *sqlite3_temp_directory;

如果这个全局变量指向一个内容为路径名的字符串,那么SQLite使用内置VFS创建的所有临时文件都会放在这个目录中。如果这个变量是一个NULL指针,那么SQLite会搜索适合的临时文件目录。
If this global variable is made to point to a string which is the name of a folder (a.k.a. directory), then all temporary files created by SQLite when using a built-in VFS will be placed in that directory. If this variable is a NULL pointer, then SQLite performs a search for an appropriate temporary file directory.

在多线程访问的时候修改或读取这个变量是不安全的。如果一个数据库连接在多个不同的线程中使用时修改或读取这个变量也是不安全的。这个变量应当在程序初始化的时候、执行其它SQLite接口之前设置一次。并且在这之后不再修改这个变量。
It is not safe to read or modify this variable in more than one thread at a time. It is not safe to read or modify this variable if a database connection is being used at the same time in a separate thread. It is intended that this variable be set once as part of process initialization and before any SQLite interface routines have been called and that this variable remain unchanged thereafter.

temp_store_directory pragma可以修改这个变量,并使之指向一块从sqlite3_malloc获取的内存。另外temp_store_directory pragma会假设这变量指定的字符串一定是存储在从sqlite3_malloc获取的内存中,并且会使用sqlite3_free来释放内存。因此,如果直接修改这个变量,那么要么设置为NULL,要么指向从sqlite3_malloc中分配的内存。否则,使用temp_store_directory pragma可能会失效。
The temp_store_directory pragma may modify this variable and cause it to point to memory obtained from sqlite3_malloc. Furthermore, the temp_store_directory pragma always assumes that any string that this variable points to is held in memory obtained from sqlite3_malloc and the pragma may attempt to free that memory using sqlite3_free. Hence, if this variable is modified directly, either it should be made NULL or made to point to memory obtained from sqlite3_malloc or else the use of the temp_store_directory pragma should be avoided.

Windows用户注意:必须在sqlite3_opensqlite3_open_v2调用之前设置临时目录。否则,许多需要使用临时文件的特性都会失败。这里有一个在Windows下如何使用C++来设置的示例:
Note to Windows Runtime users: The temporary directory must be set prior to calling sqlite3_open or sqlite3_open_v2. Otherwise, various features that require the use of temporary files may fail. Here is an example of how to do this using C++ with the Windows Runtime:

LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
      TemporaryFolder->Path->Data();
char zPathBuf[MAX_PATH + 1];
memset(zPathBuf, 0, sizeof(zPathBuf));
WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
      NULL, NULL);
sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);

另行参见ObjectsConstantsFunctions的列表。
See also lists of Objects, Constants, and Functions.