sqlite3问题2:中文路径的支持
2012-02-09 19:18
337 查看
在工程中加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, 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;
}
经过检索发现该函数要求输入的文件名为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, 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;
}
相关文章推荐
- 浅析GDAL库C#版本支持中文路径问题(续)
- SQLite 对中文路径的支持(用到了StringToWideChar和Utf8Encode在D7的System单元中自带)
- 如何解决python不支持中文路径的问题?
- MySQL 5.1的中文支持的一个改进,从MySQL 4.1开始不支持中文路径,文件名的问题解决了
- svn不支持中文路径问题的解决
- svn不支持中文路径问题的解决
- vs2005环境,fstream不支持中文路径的问题
- java连接sqlite3,解决sqlite中文路径问题
- ImageMaigck不支持中文路径的问题
- c++中sqlite中文路径创建数据库失败的问题
- Mint Linux自定义快捷键不支持中文路径的问题的解决
- 解决Sqlite中的中文路径问题
- 谈谈c#中的字符编码转化 (sqlite 中文路径的问题)
- SQLite 对中文路径的支持
- tomcat不支持中文路径和文件名问题的解决
- Sqlite中文路径问题
- 关于CppSqlite中数据库文件中文路径识别问题的解决法
- 解决sqlite3_open函数无法打开中文路径问题
- sqlite中文路径问题
- sqlite数据库支持中文路径问题