首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Name Of The Folder Holding Temporary Files

代码语言:javascript
复制
SQLITE_EXTERN char *sqlite3_temp_directory;

如果这个全局变量指向一个文件夹(也称为目录)名称的字符串,那么 SQLite 在使用内置 VFS 时创建的所有临时文件都将被放置在该目录中。如果这个变量是一个 NULL 指针,那么 SQLite 会执行一个适当的临时文件目录的搜索。

应用程序强烈建议不要使用这个全局变量。需要在 Windows 运行时(WinRT)上设置临时文件夹。但对于所有其他平台,强烈建议应用程序既不读取也不写入此变量。这个全局变量是存在遗留应用程序的向后兼容性的遗留物,应该在新项目中避免。

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 编译指示可以修改这个变量并使其指向从 sqlite3_malloc 获得的内存。而且,temp_store_directory 编译指示总是假设该变量指向的任何字符串都保存在从 sqlite3_malloc 获取的内存中,并且该编译指示可能会尝试使用 sqlite3_free 释放该内存。因此,如果直接修改此变量,则应将其设置为 NULL 或指向从 sqlite3_malloc 获取的内存,否则应避免使用 temp_store_directory 编译指示。除了 temp_store_directory 编译指示的请求外,SQLite 不释放 sqlite3_temp_directory 指向的内存。如果应用程序想要释放内存,则它必须自行执行,在所有数据库连接对象都被销毁后,请注意这样做。

Windows 运行时用户注意:必须在调用 sqlite3_open 或 sqlite3_open_v2 之前设置临时目录。否则,需要使用临时文件的各种功能可能会失败。下面是一个如何使用 C ++ 和 Windows 运行时来执行此操作的示例:

代码语言:javascript
复制
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);

扫码关注腾讯云开发者

领取腾讯云代金券