Sqlite3 is used in the Utf-8 code, so when the database is created if the path is plain English letters and numbers, so many ansii and utf-8 encoding is the same, this time the Sqlite3_open function call completely no problem. However, if it is in Chinese, asnsii directly into the Utf-8 will be wrong, the path cannot be found, thus creating or opening the database failed. The workaround is as follows:
// The sdk can be directly converted from UNICODE to utf-8, not directly from ansii to utf-8
// So Ansii is converted to Utf-8, it needs to be converted to UNICODE first and then to utf-8
void UnicodeToUtf8 (char ** dest, const WCHAR * src)
{
// ASSERT (dest! = NULL || src! = NULL);
int len = -1;
len = WideCharToMultiByte (CP_UTF8, 0, src, -1, 0, 0, 0, 0) +1;
* dest = new char [len + 1];
:: WideCharToMultiByte (CP_UTF8, 0, src, -1, * dest, len, 0, 0);
}
void AnsiToUtf8 (char ** dest, const char * src)
{
// ASSERT (dest! = NULL || src! = NULL);
WCHAR * pwszStr = NULL;
C2W (& pwszStr, src);
UnicodeToUtf8 (dest, pwszStr);
SAFE_ARRYDELETE (pwszStr);
}
// Create \ Open database
// szCreateTable = "c: \\ program files \\ yoyo \\ test.db"
char * pszCreateSql = NULL;
// Failed to create or open without this sentence
AnsiToUtf8 (& pszCreateSql, szCreateTable);
///////////
if (sqlite3_open (/ * szCreateTable * / pszCreateSql, ppdb)! = SQLITE_OK)
{
// Failed to open or create database
sqlite3_close (* ppdb);
* ppdb = null;
return DB_FAILED;
}
else {}