sqlite3_open打开数据库失败 返回值14问题
2012-12-19 16:20
597 查看
原因: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;
}
解决:我在网上找的转码,先把路径转码。
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打开路径含中文的数据库文件失败的问题
- SQLiteOpenHelper在query得到Cursor返回值异常问题探究
- xcode打开sqlite3数据库的遇到的问题以及数据库操作方法
- SQLiteOpenHelper 打开自定义路径下的db数据库文件
- 3516cv300的ttyAMA1打开失败的问题吗? open tty /dev/ttyAMA1 failed
- sqlite 数据库打开失败
- 项目报错:打开文件过多,数据库连接失败等资源问题
- SQLiteOpenHelper(创建或打开数据库)
- android数据库操作 sqlite returned: error code = 14, msg = cannot open file at source line 25502
- 关于sql server 无法打开登录所请求的数据库“XXX”,登录失败。问题解决
- c++中sqlite中文路径创建数据库失败的问题
- android: SQLiteOpenHelper,会将数据库放在当前应用程序的某个文件下(14)
- Typecho SQLite与MySQL的数据库切换及解决MySQL连接打开缓慢问题
- arm开发板 libusb_open打开失败问题
- 不用SQLiteOpenHelper来打开和创建数据库
- sqlite3数据库连接失败的问题
- FFmpeg avformat_open_input函数打开acc,h264失败的错误问题
- 解决sqlite3_open函数无法打开中文路径问题
- SQLiteOpenHelper数据库打开连接帮助类使用说明
- window.open 打开的子窗口 闪一下即自动关闭问题