#1 2020-06-01 16:53:56

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

TNullableDateTime field in TSQLRecord

I have the TNullableDateTime field in a TSQLRecord, which is mapped to the TIMESTAMP FB field.
After retrieving a record from DB (FillPrepare and FillOne) I see ISO8601 datetime value from the debugger.
Direct assigning

LLastUpdate := LSQLParty.LastUpdate;

causes runtime conversion error, and

LLastUpdate := NullableDateTimeToValue(LSQLParty.LastUpdate);

also doesn't work, because VType = 256.
Therefore I have to handle it like this

if not NullableDateTimeIsEmptyOrNull(LSQLParty.LastUpdate) then
LLastUpdate := Iso8601ToDateTime(LSQLParty.LastUpdate);

Is this done so by design, or I have misunderstood smth?

[Delphi 10.4, Win64, Zeos r6580, FB 2.5.9]

Offline

#2 2020-06-02 13:50:36

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: TNullableDateTime field in TSQLRecord

ok, will it slow down significantly (or brake smth), if in SynCommons.GetVariantFromJSON procedure instead of

  with TVarData(Value) do begin
    // found no numerical value -> return a string in the expected format
    VType := varString;
    VString := nil; // avoid GPF below when assigning a string variable to VAny
    FastSetString(RawUTF8(VString),JSON,StrLen(JSON));
  end;

will be smth like

  with TVarData(Value) do
    if IsIso8601(JSON, StrLen(JSON)) then begin
      VType := varDate;
      VDate := Iso8601ToDateTimePUTF8Char(JSON, StrLen(JSON));
    end else begin
      // found no numerical value -> return a string in the expected format
      VType := varString;
      VString := nil; // avoid GPF below when assigning a string variable to VAny
      FastSetString(RawUTF8(VString),JSON,StrLen(JSON));
    end;

NullableDateTimeToValue works good then, even with null value.

Maybe my suggestion is not optimized or/and wrongly formatted, but I at least tried...

Offline

#3 2020-06-02 16:41:48

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

Re: TNullableDateTime field in TSQLRecord

Now I get your problem.
I guess the bug should rather be fixed in TSQLPropInfoRTTIVariant.

Please check https://synopse.info/fossil/info/64eda8fc9d

Offline

#4 2020-06-02 17:41:45

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: TNullableDateTime field in TSQLRecord

Yes, all is good, now. Thank you! smile

Offline

Board footer

Powered by FluxBB