原因:sqlite3_open第一个参数路径中有中文字符,而它只支持UTF-8编码,所以使数据库打开失败
解决:我在网上找的转码,先把路径转码。
CString MbcsToUtf8(const char *file)
{
CString str;
WCHAR *pwchar=0;
CHAR *pchar=0;
int len=0;
int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
len=MultiByteToWideChar(codepage, 0, file, -1, NULL,0);
pwchar=new WCHAR[len];
if(pwchar!=0)
{
len = MultiByteToWideChar(codepage, 0, file, -1, pwchar, len);
if( len!=0 )
{
len = WideCharToMultiByte(CP_UTF8, 0, pwchar, -1, 0, 0, 0, 0);
pchar=new CHAR[len];
if(pchar!=0)
{
len = WideCharToMultiByte(CP_UTF8, 0, pwchar, -1, pchar, len,0, 0);
if(len!=0)
{
str=pchar;
}
delete pchar;
}
delete pwchar;
}
}
return str;
}
本文介绍了一个关于SQLite数据库的问题:当使用包含中文字符的路径时,由于SQLite仅支持UTF-8编码,导致无法正常打开数据库。文章提供了一个解决方案,通过将路径从Windows默认编码转换为UTF-8来解决这一问题。

1519

被折叠的 条评论
为什么被折叠?



