SQLite 对中文路径的支持(用到了StringToWideChar和Utf8Encode在D7的System单元中自带)

最近用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

原文地址:https://www.cnblogs.com/findumars/p/5929850.html