码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-10-04 01:24:33      阅读:222      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!