#1 2017-02-13 10:22:38

StxLog
Member
From: France
Registered: 2015-09-14
Posts: 58

DateTime and Currency for GetFieldData in TSynVirtualDataSet

Hi AB,

We've added in GetFieldData for TSynVirtualDataSet the handle for Currency field (same as ftFloat) and corrected DateTime with which we had problems in conversions. Handle 30/12/1899 date as NULL.
Here is our overriden code integrated within getFieldData in SynVirtualDataSet.

begin
  result := false;
  OnlyTestForNull := (Buffer=nil);
  RowIndex := PRecInfo(ActiveBuffer).RowIndentifier;
  Data := GetRowFieldData(Field,RowIndex,DataLen,OnlyTestForNull);
  if Data=nil then // on success, points to Int64,Double,Blob,UTF8
    exit;
  result := true;
  if OnlyTestForNull then
    exit;
  Dest := pointer(Buffer); // works also if Buffer is [var] TValueBuffer
  case Field.DataType of
  ftBoolean:
    PWORDBOOL(Dest)^ := PBoolean(Data)^;
  ftInteger:
    PInteger(Dest)^ := PInteger(Data)^;
  ftLargeint, ftFloat, ftCurrency:
    PInt64(Dest)^ := PInt64(Data)^;
  ftDate,ftTime,ftDateTime: begin
    if PDateTime(Data)^ = 0 then begin
      result := false;
      exit;
    end;
    DataConvert(Field,Data,Dest,true);
  end;
  ftString: begin
    if DataLen<>0 then begin
      CurrentAnsiConvert.UTF8BufferToAnsi(Data,DataLen,Temp);
      DataLen := length(Temp);
      MaxLen := Field.DataSize-1; // without trailing #0
      if DataLen>MaxLen then
        DataLen := MaxLen;
      move(pointer(Temp)^,Dest^,DataLen);
    end;
    PAnsiChar(Dest)[DataLen] := #0;
  end;
  ftWideString: begin
    {$ifdef ISDELPHI2007ANDUP} // here Dest = PWideChar[] of DataSize bytes
    if DataLen=0 then
      PWideChar(Dest)^ := #0 else
      UTF8ToWideChar(Dest,Data,(Field.DataSize-2)shr 1,DataLen);
    {$else}          // here Dest is PWideString
    UTF8ToWideString(Data,DataLen,WideString(Dest^));
    {$endif}
  end;
  // ftBlob,ftMemo,ftWideMemo should be retrieved by CreateBlobStream()
  else raise EDatabaseError.CreateFmt('%s.GetFieldData DataType=%d',
         [ClassName,ord(Field.DataType)]);
  end;
end;

We would be glad if you think this is relevant.
Thanks.

edit: If you use this patch, I think DateTimeToNative inside SynVirtualDataset isn't used anymore.

Last edited by StxLog (2017-02-13 10:48:01)

Offline

#2 2017-02-14 09:10:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,274
Website

Re: DateTime and Currency for GetFieldData in TSynVirtualDataSet

Offline

#3 2017-07-25 19:21:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,274
Website

Re: DateTime and Currency for GetFieldData in TSynVirtualDataSet

Offline

#4 2017-07-26 09:59:11

zekeriye
Member
Registered: 2016-06-09
Posts: 11

Re: DateTime and Currency for GetFieldData in TSynVirtualDataSet

Thanks your great support ab;

Now; version 25-07-2017 reading correct datetime value from MSSQL 2008 R2 database.
this version solve ".. is not datetime value" error message.

Last edited by zekeriye (2017-07-26 10:00:17)

Offline

Board footer

Powered by FluxBB