Delphi7中存储unicode的BUG? 近日,在用delphi7做unicode的程序时发现了这样一个问题,就是使用TADOCommand组件执行sql语句时,如果sql语句中有unicode字符,存储在数据库里会出现乱码,使用TTntADOQuery也是一样(使用参数方式不会出现乱码,这里只讨论纯sql的方式)。但是TADOCommand本身是支持widestring的呀,CommandText属性也是widestring类型的,为什么会出现这个问题呢?我试着改变TADOCommand的几个属性值,发现了一个怪现象,只要把ParamCheck属性置为false就可以正常的存储unicode字符,而置为true时就出现乱码。为什么会出现这种情况?这个属性看起来和unicode本身没有任何关系,究竟是什么原因导致了乱码的发生呢?我通过研究TADOCommand所在的adodb.pas文件,发现了问题的所在,我们看一下bug所在的过程: procedure TADOCommand.AssignCommandText(const Value: WideString; Loading: Boolean); procedure InitParameters; var I: Integer; List: TParameters; NativeCommand: string; begin List := TParameters.Create(Self, TParameter); try NativeCommand := List.ParseSQL(Value, True); { Preserve existing values } List.AssignValues(Parameters); CommandObject.CommandText := NativeCommand; if not Loading and (Assigned(Connection) or (ConnectionString <> '''''''')) then begin try SetConnectionFlag(cfParameters, True); try { Retrieve additional parameter info from the server if supported } Parameters.InternalRefresh; { Use additional parameter info from server to initialize our list } if Parameters.Count = List.Count then for I := 0 to List.Count - 1 do begin List[I].DataType := Parameters[I].DataType; List[I].Size := Parameters[I].Size; List[I].NumericScale := Parameters[I].NumericScale; List[I].Precision := Parameters[I].Precision; List[I].Direction := Parameters[I].Direction; List[I].Attributes := Parameters[I].Attributes; end finally SetConnectionFlag(cfParameters, False); end; except { Ignore error if server cannot provide parameter info } end; if List.Count > 0 then Parameters.Assign(List); end; finally List.Free; end; end; [1] [2] 下一页 [聊天工具]小心Foxmail邮件模板BUG [聊天工具]OICQ---存在重大BUG? [系统软件]Explanation of UFT-8 and Unicode [系统软件]Windows记事本中的Bug [常用软件]解决压缩软件的Bug技巧 [VB.NET程序]在 VB 中使用 Unicode API [Delphi程序]Delphi 6 SOAP 源码中的BUG修正 [Delphi程序]改良控件-Delphi自带控件Bug的消除 [Delphi程序]不知您是笨蛋,还是我是笨蛋,关于Delphi的大Bug [Delphi程序]关于Delphi大Bug的更详细的例子
|