SQLite 对中文路径的支持(用到了StringToWideChar和Utf8Encode在D7的System单元中自带)
2016-10-03 23:32
1146 查看
最近用SQLITE作为数据库,发现,如果直接传递带中文路径或文件名的数据库,会导致无法打开数据库的情况.
看了一下SQLITE的源码,才发现,原来SQLITE中是用UTF8编码进行文件打开操作的.
所以,在传递文件名的时候,需要先进行编码.在DELPHI中,用以下的函数就可以.
function TranslateDBFile(Str: string): string;
var
tmp: UTF8String;
l: Integer;
l_WideString: PWideChar;
l_Length: Integer;
begin
if IsEnglishString(Str) then
Result := Str
else
begin
l_Length := Length(Str) * 2;
GetMem(l_WideString, l_Length);
StringToWideChar(Str, l_WideString, l_Length);
Result := Utf8Encode(Str);
GetMem(l_WideString, 0);
end;
end;
//其中的StringToWideChar和Utf8Encode在D7的System单元中自带.简单,方便.
http://www.cnblogs.com/qiubole/archive/2007/11/07/951807.html
看了一下SQLITE的源码,才发现,原来SQLITE中是用UTF8编码进行文件打开操作的.
所以,在传递文件名的时候,需要先进行编码.在DELPHI中,用以下的函数就可以.
function TranslateDBFile(Str: string): string;
var
tmp: UTF8String;
l: Integer;
l_WideString: PWideChar;
l_Length: Integer;
begin
if IsEnglishString(Str) then
Result := Str
else
begin
l_Length := Length(Str) * 2;
GetMem(l_WideString, l_Length);
StringToWideChar(Str, l_WideString, l_Length);
Result := Utf8Encode(Str);
GetMem(l_WideString, 0);
end;
end;
//其中的StringToWideChar和Utf8Encode在D7的System单元中自带.简单,方便.
http://www.cnblogs.com/qiubole/archive/2007/11/07/951807.html
相关文章推荐
- UniCode 下CString 转 char*,利用WideCharToMultiByte进行转换,中文乱码的解决方案
- Delphi数据类型转换(有几个字符串函数没见过,比如StringToWideChar和WideCharToString)
- SQLite 对中文路径的支持
- sqlite3问题2:中文路径的支持
- UTF8-GBK WideCharToMultiByte MultiByteToWideChar
- WideCharToMultiByte 和 MultiByteToWideChar 之中文打印问题
- 关于WideCharToMultiByte来解码UTF8
- python os.system() 支持中文路径名
- [C# Tip]How to: Convert System::String to wchar_t* or char*
- 利用wcstombs将中文wchar_t转换为char,模拟WideCharToMultiByte
- UniCode 下CString 转 char*,利用WideCharToMultiByte进行转换,中文乱码的解决方案
- UniCode 下CString 转 char*,利用WideCharToMultiByte进行转换,中文乱码的解决方案
- String.ToCharArray()方法中的内存优化技巧
- MultiByteToWideChar WideCharToMultiByte
- Nhibernate1.2的问题CProxyxxxInfoCannotbeConverted to System.String
- MultiByteToWideChar和WideCharToMultiByte用法详解
- MultiByteToWideChar和WideCharToMultiByte用法详解
- A SQL Function which used to split string by char
- String.ToCharArray()方法中的内存优化技巧
- MultiByteToWideChar和WideCharToMultiByte用法详解