[Pas2js] issue with json null values in fcl-web sqldbrestdata.pp
Michael Van Canneyt
michael at freepascal.org
Tue Oct 6 22:14:34 CEST 2020
On Tue, 6 Oct 2020, Simone Giacomelli wrote:
> Dear coders,
>
> I think I found a fix for a problem (?) in the function SetParamFromData
> below.
>
> The problem is that when one has a json null in D:TJSONData, the procedure
> will raise an exception and halt the post for the record.
> See the comments below in the code for further explanation.
>
> This is the link to the trunk:
> https://svn.freepascal.org/svn/fpc/trunk/packages/fcl-web/src/restbridge/sqldbrestdata.pp
> so you can check the original code.
>
> Is this an advisable and acceptable change?
Yes, it totally is.
I am surprised to see this popping up, because I distinctly
remember I had alread fixed this in a production system.
(although not in the exact same manner)
I will check the code again, and adapt it.
Thank you for pointing it out !
Michael.
>
> Best regards
> Simone Giacomelli
>
>
> [code=pascal]
>
> procedure TSQLDBRestDBHandler.SetParamFromData(P: TParam; F:
> TSQLDBRestField;
> D: TJSONData);
>
> Var
> S : String;
>
> begin
> // if Assigned(D) then // <-------
> // S:=D.AsString; // <------- if it's JSON null it will raise an
> exception
> if not Assigned(D) or D.IsNull then // <------- added "D.IsNull" because
> of JSON null
> P.Clear
> else if Assigned(F) then
> Case F.FieldType of
> rftInteger : P.AsInteger:=D.AsInteger;
> rftLargeInt : P.AsLargeInt:=D.AsInt64;
> rftFloat : P.AsFloat:=D.AsFloat;
> rftDate :
> P.AsDateTime:=ScanDateTime(GetString(rpDateFormat),D.AsString);
> rftTime :
> P.AsDateTime:=ScanDateTime(GetString(rpTimeFormat),D.AsString);
> rftDateTime :
> P.AsDateTime:=ScanDateTime(GetString(rpDateTimeFormat),D.AsString);
> rftString : P.AsString:=D.AsString;
> rftBoolean : P.AsBoolean:=D.AsBoolean;
> rftBlob :
> {$IFNDEF VER3_0}
> P.AsBlob:=BytesOf(DecodeStringBase64(D.AsString));
> {$ELSE}
> P.AsBlob:=DecodeStringBase64(D.AsString);
> {$ENDIF}
> else
> P.AsString:=D.AsString;
> end
> else
> P.AsString:=D.AsString;
> end;
>
> [/code]
> --
> Simone
>
More information about the Pas2js
mailing list