首页 > 数据库技术 > 详细

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

时间:2016-10-04 01:22:09      阅读:461      评论:0      收藏:0      [点我收藏+]

最近用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 对中文路径的支持(用到了StringToWideChar和Utf8Encode在D7的System单元中自带)

原文:http://www.cnblogs.com/findumars/p/5929850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!