@@ -5926,7 +5926,7 @@ constructor TOrmTableJson.Create(const aSql: RawUtf8; JsonBuffer: PUtf8Char;
5926
5926
5927
5927
constructor TOrmTableJson.Create(const aSql, aJson: RawUtf8);
5928
5928
var
5929
- len: integer ;
5929
+ len: PtrInt ;
5930
5930
begin
5931
5931
len := length(aJson);
5932
5932
PrivateCopyChanged(pointer(aJson), len, { updatehash=} false);
@@ -5998,6 +5998,7 @@ function TOrmTableJson.ParseAndConvert(Buffer: PUtf8Char; BufferLen: PtrInt): bo
5998
5998
var
5999
5999
i, max, resmax, f: PtrInt;
6000
6000
P: PUtf8Char;
6001
+ datavoid: TOrmTableData; // used for all JSON "" values
6001
6002
info: TGetJsonField;
6002
6003
begin
6003
6004
result := false; // error on parsing
@@ -6006,6 +6007,7 @@ function TOrmTableJson.ParseAndConvert(Buffer: PUtf8Char; BufferLen: PtrInt): bo
6006
6007
(Buffer = nil ) then
6007
6008
exit;
6008
6009
// go to start of object
6010
+ datavoid := TOrmTableData(0 );
6009
6011
{ $ifndef NOPOINTEROFFSET}
6010
6012
fDataStart := Buffer; // before first value, to ensure offset=0 means nil
6011
6013
{ $endif NOPOINTEROFFSET}
@@ -6040,12 +6042,17 @@ function TOrmTableJson.ParseAndConvert(Buffer: PUtf8Char; BufferLen: PtrInt): bo
6040
6042
IsRowID(info.Value ) then
6041
6043
fFieldIndexID := i;
6042
6044
end ;
6045
+ datavoid := TOrmTableData(PtrUInt(info.Value ) + PtrUInt(info.ValueLen)
6046
+ { $ifndef NOPOINTEROFFSET} - PtrUInt(fDataStart) { $endif} ); // ^ = #0
6043
6047
f := 0 ;
6044
6048
for i := fFieldCount to max do
6045
6049
begin
6046
6050
// get a field value
6047
6051
info.GetJsonFieldOrObjectOrArray({ handleobjarr=} true, { normbool=} false);
6048
- SetResults(i, info.Value , info.ValueLen);
6052
+ if info.Value <> nil then
6053
+ SetResults(i, info.Value , info.ValueLen)
6054
+ else if info.WasString then // JSON null -> Value=nil
6055
+ fData[i] := datavoid; // JSON "" -> Value^=#0, ValueLen=0
6049
6056
if (info.Json = nil ) and
6050
6057
(i <> max) then
6051
6058
// failure (GetRowCountNotExpanded should have detected it)
@@ -6098,7 +6105,10 @@ function TOrmTableJson.ParseAndConvert(Buffer: PUtf8Char; BufferLen: PtrInt): bo
6098
6105
IsRowID(info.Value ) then
6099
6106
fFieldIndexID := f;
6100
6107
SetResults(f, info.Value , info.ValueLen);
6101
- if P = nil then
6108
+ if datavoid = TOrmTableData(0 ) then
6109
+ datavoid := TOrmTableData(PtrUInt(info.Value ) + PtrUInt(info.ValueLen)
6110
+ { $ifndef NOPOINTEROFFSET} - PtrUInt(fDataStart) { $endif} ); // ^ = #0
6111
+ if info.Json = nil then
6102
6112
break;
6103
6113
end
6104
6114
else
@@ -6119,7 +6129,10 @@ function TOrmTableJson.ParseAndConvert(Buffer: PUtf8Char; BufferLen: PtrInt): bo
6119
6129
fData := pointer(fJsonData);
6120
6130
end ;
6121
6131
info.GetJsonFieldOrObjectOrArray({ objarray=} true, { normbool=} false);
6122
- SetResults(max, info.Value , info.ValueLen);
6132
+ if info.Value <> nil then
6133
+ SetResults(max, info.Value , info.ValueLen)
6134
+ else if info.WasString then // JSON null -> Value=nil
6135
+ fData[max] := datavoid; // JSON "" -> Value^=#0, ValueLen=0
6123
6136
if info.Json = nil then
6124
6137
begin
6125
6138
// unexpected end
0 commit comments