加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite中文路径支持

发布时间:2020-12-12 20:03:45 所属栏目:百科 来源:网络整理
导读:在工程中加sqlite3源代码,调用第一个函数sqlite3_open,发现其不支持中文路径。 经过检索发现该函数要求输入的文件名为utf8编码。 //再sqlite3.c中 winFullPathname、sqlite3_win32_mbcs_to_utf8、mbcsToUnicode、unicodeToUtf8与此事相关。 //参考以上4个函
在工程中加sqlite3源代码,调用第一个函数sqlite3_open,发现其不支持中文路径。
经过检索发现该函数要求输入的文件名为utf8编码。
//再sqlite3.c中 winFullPathname、sqlite3_win32_mbcs_to_utf8、mbcsToUnicode、unicodeToUtf8与此事相关。
//参考以上4个函数,做的一个编码转换函数
CString CMyApp::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,file,-1,NULL,0);
pwchar=new WCHAR[len];
if(pwchar!=0)
{
len = MultiByteToWideChar(codepage,pwchar,len);
if( len!=0 )
{
len = WideCharToMultiByte(CP_UTF8,0);
pchar=new CHAR[len];
if(pchar!=0)
{
len = WideCharToMultiByte(CP_UTF8,pchar,len,0);
if(len!=0)
{
str=pchar;
}
delete pchar;
}
delete pwchar;
}
}
return str;
}

//在调用 sqlite_open 前将文件路径,通过MbcsToUtf8函数将编码转换到utf8即可支持中文路径。


转自:http://rectnote.blog.sohu.com/222224142.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读