I’m currently using SQLite3 v3.7.14 download through the Extensions and Updates manager in Visual Studio 2012. When I compile for Win32 it works but when I compile and run on ARM it does not. It crashes whenever I try to set the sqlite3_temp_directory. I feel like I am following the documentation here (http://www.sqlite.org/c3ref/temp_directory.html).
void init()
{
// Set the temporary directory for sqlite prior to opening the database
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); // CRASHES HERE ON WINRT
auto localDataPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
std::wstring path(localDataPath->Data());
path += L"\\database.sql";
sqlite3_open16(path.c_str(), &m_DB);
}
I wonder if I have missed something? I am not sure how to debug this one nor can I find any good examples of using SQLite3 on WinRT or use sqlite3_temp_directory correctly.
Update:
It turns out the above code works as expected if I include the raw sqlite3.h/.c files bypassing the official precompiled .lib/.dll files.
The SQLite3 team has informed me that there is indeed a problem. The problem itself is either in the SQLite3 codebase or with the Microsoft MSVC compiler and they are actively working towards a solution.
It turns out the problem is only occurring when optimizations are enabled, the main culprit being the /Og switch. You can temporarily disable build optimizations to resolve this issue.