#1 2014-09-04 11:50:15

Gigo
Member
From: Split, Croatia
Registered: 2012-01-27
Posts: 16

TSQLRecord adding TDateTime fields

Overloaded TSQLRest.Add with SimpleFields array writes blank dates to database :

type
  TTestRec = class(TSQLRecord)
  private
    FDatePosted : TDateTime;
  published
    property DatePosted : TDateTime read FDatePosted write FDatePosted;
  end;

...

  TestRec := TTestRec.Create;
  try
    TestRec.DatePosted := Now;
    Client.Add(TestRec,true)        // will insert current time
  finally
    TestRec.Free;
  end;
  
...  
  Client.Add(TTestRec,[Now])    // will insert MinDateTime

  Client.Add(TTestRec,[DateTimeToIso8601(Now,true)])    // will insert current time

Seems that TSQLRecord.SimplePropertiesFill (actually VarRecToUTF8()) cannot distinguish TDateTime from Double and TSQLPropInfoRTTIDateTime.SetValue is calling Iso8601ToDateTimePUTF8CharVar with floating-point representation of TDateTime.
Maybe if we pass TSQLRecordClass to TSQLRecord.SimplePropertiesFill as second parameter we could distinguish TDateTime from Double using TSQLRecordClass ?

Offline

#2 2014-09-04 19:59:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TSQLRecord adding TDateTime fields

This is a limitation of "array of const" implementation in Delphi.
It can not distinguish TDateTime from Double.
Using DateTimeToIso8601() is a good workaround.

Note that you can use TModTime or TCreateTime auto-filled fields instead, if you need a field which contains the modification/creation row timestamp.

Offline

Board footer

Powered by FluxBB