DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: ahttp123
今日帖子: 22
在线用户: 10
导航: 论坛 -> 数据库专区 斑竹:liumazi,waterstone  
作者:
男 forjoylee (天地无缘) ★☆☆☆☆ -
普通会员
2015/3/30 11:17:10
标题:
让ZEOSDBO支持sqlite的GBK编码 浏览:1311
加入我的收藏
楼主: 修改ZPlainSqLiteDriver.pas

procedure TZSQLiteBaseDriver.LoadCodePages;  //Egonhugeist
begin
  { MultiByte }
  AddCodePage('UTF-8', 1, ceUTF8, zCP_UTF8);
  AddCodePage('UTF-16le', 2, ceUTF16, zCP_UTF16, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
  AddCodePage('UTF-16be', 3, ceUTF16, zCP_UTF16BE, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
  AddCodePage('UTF-16', 4, ceUTF16, zCP_UTF16, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
  AddCodePage('GBK', 3, ceAnsi, 936); {GB2312-80 Simplified Chinese} 
end;


修改ZDbcSqLite.pas

procedure TZSQLiteConnection.InternalCreate;
begin
  FMetadata := TZSQLiteDatabaseMetadata.Create(Self, Url);
  AutoCommit := True;
  TransactIsolationLevel := tiNone;
  // CheckCharEncoding('UTF-8');
  Open;
end;

procedure TZSQLiteConnection.Open;
var
  ErrorCode: Integer;
  ErrorMessage: PAnsiChar;
  LogMessage: string;
  SQL: AnsiString;
  Timeout_ms: Integer;
begin
  if not Closed then
    Exit;
  ErrorMessage := '';

  LogMessage := Format('CONNECT TO "%s" AS USER "%s"', [Database, User]);

{$IFDEF UNICODE}
  FHandle := GetPlainDriver.Open(PAnsiChar(AnsiString(UTF8Encode(Database))), 0, ErrorMessage);
{$ELSE}
  FHandle := GetPlainDriver.Open(PAnsiChar(Database), 0, ErrorMessage);
{$ENDIF}

  if FHandle = nil then
  begin
    CheckSQLiteError(GetPlainDriver, FHandle, SQLITE_ERROR, ErrorMessage,
      lcConnect, LogMessage);
  end;
  DriverManager.LogMessage(lcConnect, PlainDriver.GetProtocol, LogMessage);

  { Turn on encryption if requested }
  if StrToBoolEx(Info.Values['encrypted']) then
  begin
    {$IFDEF UNICODE}
    ErrorCode := GetPlainDriver.Key(FHandle, PAnsiChar(UTF8String(Password)), {$IFDEF WITH_STRLEN_DEPRECATED}AnsiStrings.{$ENDIF}StrLen(PAnsiChar(UTF8String(Password))));
    {$ELSE}
    ErrorCode := GetPlainDriver.Key(FHandle, PAnsiChar(Password), StrLen(PAnsiChar(Password)));
    {$ENDIF}
    CheckSQLiteError(GetPlainDriver, FHandle, ErrorCode, nil, lcConnect, 'SQLite.Key');
  end;

  { Set busy timeout if requested }
  Timeout_ms := StrToIntDef(Info.Values['busytimeout'], -1); 
  if Timeout_ms >= 0 then 
  begin 
    GetPlainDriver.BusyTimeout(FHandle, Timeout_ms);
  end; 

  try
    if ( FClientCodePage <> '' ) then
    begin
        SQL := 'PRAGMA encoding = ''UTF-8'''; 
        ErrorCode := GetPlainDriver.Execute(FHandle, PAnsiChar(SQL),
          nil, nil, ErrorMessage);
        CheckSQLiteError(GetPlainDriver, FHandle, ErrorCode, ErrorMessage, lcExecute, String(SQL));
    end;
----------------------------------------------
这家伙很懒,什么都没有留下。
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行58.59375毫秒 RSS