Skip to content

Commit

Permalink
Renamed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Jul 25, 2019
1 parent 0245a3b commit 0bc0eec
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 105 deletions.
106 changes: 53 additions & 53 deletions src/core/DataSet.Serialize.DS.Impl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,32 @@ function TDataSetSerialize.ToJSONObject: TJSONObject;

function TDataSetSerialize.DataSetToJSONArray(const DataSet: TDataSet): TJSONArray;
var
BookMark: TBookmark;
LBookMark: TBookmark;
begin
if DataSet.IsEmpty then
Exit(TJSONArray.Create);
try
Result := TJSONArray.Create;
BookMark := DataSet.BookMark;
LBookMark := DataSet.BookMark;
DataSet.First;
while not DataSet.Eof do
begin
Result.AddElement(DataSetToJSONObject(DataSet));
DataSet.Next;
end;
finally
if DataSet.BookmarkValid(BookMark) then
DataSet.GotoBookmark(BookMark);
DataSet.FreeBookmark(BookMark);
if DataSet.BookmarkValid(LBookMark) then
DataSet.GotoBookmark(LBookMark);
DataSet.FreeBookmark(LBookMark);
end;
end;

function TDataSetSerialize.DataSetToJSONObject(const DataSet: TDataSet): TJSONObject;
var
I: Integer;
Key: string;
NestedDataSet: TDataSet;
BooleanFieldType: TBooleanFieldType;
LKey: string;
LNestedDataSet: TDataSet;
LBooleanFieldType: TBooleanFieldType;
begin
Result := TJSONObject.Create;
if not Assigned(DataSet) or DataSet.IsEmpty then
Expand All @@ -172,46 +172,46 @@ function TDataSetSerialize.DataSetToJSONObject(const DataSet: TDataSet): TJSONOb
begin
if (not DataSet.Fields[I].Visible) or DataSet.Fields[I].IsNull then
Continue;
Key := DataSet.Fields[I].FieldName;
LKey := DataSet.Fields[I].FieldName;
case DataSet.Fields[I].DataType of
TFieldType.ftBoolean:
begin
BooleanFieldType := TDataSetSerializeUtils.BooleanFieldToType(TBooleanField(DataSet.Fields[I]));
case BooleanFieldType of
LBooleanFieldType := TDataSetSerializeUtils.BooleanFieldToType(TBooleanField(DataSet.Fields[I]));
case LBooleanFieldType of
bfUnknown, bfBoolean:
Result.AddPair(Key, TDataSetSerializeUtils.BooleanToJSON(DataSet.Fields[I].AsBoolean));
Result.AddPair(LKey, TDataSetSerializeUtils.BooleanToJSON(DataSet.Fields[I].AsBoolean));
else
Result.AddPair(Key, TJSONNumber.Create(DataSet.Fields[I].AsInteger));
Result.AddPair(LKey, TJSONNumber.Create(DataSet.Fields[I].AsInteger));
end;
end;
TFieldType.ftInteger, TFieldType.ftSmallint, TFieldType.ftShortint:
Result.AddPair(Key, TJSONNumber.Create(DataSet.Fields[I].AsInteger));
Result.AddPair(LKey, TJSONNumber.Create(DataSet.Fields[I].AsInteger));
TFieldType.ftLongWord, TFieldType.ftAutoInc:
Result.AddPair(Key, TJSONNumber.Create(DataSet.Fields[I].AsWideString));
Result.AddPair(LKey, TJSONNumber.Create(DataSet.Fields[I].AsWideString));
TFieldType.ftLargeint:
Result.AddPair(Key, TJSONNumber.Create(DataSet.Fields[I].AsLargeInt));
Result.AddPair(LKey, TJSONNumber.Create(DataSet.Fields[I].AsLargeInt));
TFieldType.ftSingle, TFieldType.ftFloat:
Result.AddPair(Key, TJSONNumber.Create(DataSet.Fields[I].AsFloat));
Result.AddPair(LKey, TJSONNumber.Create(DataSet.Fields[I].AsFloat));
TFieldType.ftString, TFieldType.ftWideString, TFieldType.ftMemo, TFieldType.ftWideMemo:
Result.AddPair(Key, TJSONString.Create(DataSet.Fields[I].AsWideString));
Result.AddPair(LKey, TJSONString.Create(DataSet.Fields[I].AsWideString));
TFieldType.ftDate, TFieldType.ftTimeStamp, TFieldType.ftDateTime, TFieldType.ftTime:
Result.AddPair(Key, TJSONString.Create(DateToISO8601(DataSet.Fields[I].AsDateTime)));
Result.AddPair(LKey, TJSONString.Create(DateToISO8601(DataSet.Fields[I].AsDateTime)));
TFieldType.ftCurrency:
Result.AddPair(Key, TJSONString.Create(FormatCurr('0.00##', DataSet.Fields[I].AsCurrency)));
Result.AddPair(LKey, TJSONString.Create(FormatCurr('0.00##', DataSet.Fields[I].AsCurrency)));
TFieldType.ftFMTBcd, TFieldType.ftBCD:
Result.AddPair(Key, TJSONNumber.Create(BcdToDouble(DataSet.Fields[I].AsBcd)));
Result.AddPair(LKey, TJSONNumber.Create(BcdToDouble(DataSet.Fields[I].AsBcd)));
TFieldType.ftDataSet:
begin
NestedDataSet := TDataSetField(DataSet.Fields[I]).NestedDataSet;
LNestedDataSet := TDataSetField(DataSet.Fields[I]).NestedDataSet;
if Trim(DataSet.Fields[I].AsString).StartsWith('{') then
Result.AddPair(Key, DataSetToJSONObject(NestedDataSet))
Result.AddPair(LKey, DataSetToJSONObject(LNestedDataSet))
else if Trim(DataSet.Fields[I].AsString).StartsWith('[') then
Result.AddPair(Key, DataSetToJSONArray(NestedDataSet));
Result.AddPair(LKey, DataSetToJSONArray(LNestedDataSet));
end;
TFieldType.ftGraphic, TFieldType.ftBlob, TFieldType.ftStream:
Result.AddPair(Key, TJSONString.Create(EncodingBlobField(DataSet.Fields[I])));
Result.AddPair(LKey, TJSONString.Create(EncodingBlobField(DataSet.Fields[I])));
else
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [Key]);
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [LKey]);
end;
end;
end;
Expand All @@ -224,22 +224,22 @@ destructor TDataSetSerialize.Destroy;

function TDataSetSerialize.EncodingBlobField(const Field: TField): string;
var
MemoryStream: TMemoryStream;
StringStream: TStringStream;
LMemoryStream: TMemoryStream;
LStringStream: TStringStream;
begin
MemoryStream := TMemoryStream.Create;
LMemoryStream := TMemoryStream.Create;
try
TBlobField(Field).SaveToStream(MemoryStream);
MemoryStream.Position := 0;
StringStream := TStringStream.Create;
TBlobField(Field).SaveToStream(LMemoryStream);
LMemoryStream.Position := 0;
LStringStream := TStringStream.Create;
try
TNetEncoding.Base64.Encode(MemoryStream, StringStream);
Result := StringStream.DataString;
TNetEncoding.Base64.Encode(LMemoryStream, LStringStream);
Result := LStringStream.DataString;
finally
StringStream.Free;
LStringStream.Free;
end;
finally
MemoryStream.Free;
LMemoryStream.Free;
end;
end;

Expand Down Expand Up @@ -274,28 +274,28 @@ function TDataSetSerialize.SetDataSet(const DataSet: TDataSet; const Owns: Boole
function TDataSetSerialize.SaveStructure: TJSONArray;
var
I: Integer;
JSONObject: TJSONObject;
DataSet: TDataSet;
LJSONObject: TJSONObject;
LDataSet: TDataSet;
begin
Result := nil;
DataSet := GetDataSet;
if DataSet.FieldCount <= 0 then
LDataSet := GetDataSet;
if LDataSet.FieldCount <= 0 then
Exit;
Result := TJSONArray.Create;
for I := 0 to Pred(DataSet.FieldCount) do
for I := 0 to Pred(LDataSet.FieldCount) do
begin
JSONObject := TJSONObject.Create;
JSONObject.AddPair('FieldName', TJSONString.Create(DataSet.Fields[I].FieldName));
JSONObject.AddPair('DisplayLabel', TJSONString.Create(DataSet.Fields[I].DisplayLabel));
JSONObject.AddPair('DataType', TJSONString.Create(GetEnumName(TypeInfo(TFieldType), Integer(DataSet.Fields[I].DataType))));
JSONObject.AddPair('Size', TJSONNumber.Create(DataSet.Fields[I].SIZE));
JSONObject.AddPair('Key', TJSONBool.Create(pfInKey in DataSet.Fields[I].ProviderFlags));
JSONObject.AddPair('Origin', TJSONString.Create(DataSet.Fields[I].ORIGIN));
JSONObject.AddPair('Required', TJSONBool.Create(DataSet.Fields[I].Required));
JSONObject.AddPair('Visible', TJSONBool.Create(DataSet.Fields[I].Visible));
JSONObject.AddPair('ReadOnly', TJSONBool.Create(DataSet.Fields[I].ReadOnly));
JSONObject.AddPair('AutoGenerateValue', TJSONString.Create(GetEnumName(TypeInfo(TAutoRefreshFlag), Integer(DataSet.Fields[I].AutoGenerateValue))));
Result.AddElement(JSONObject);
LJSONObject := TJSONObject.Create;
LJSONObject.AddPair('FieldName', TJSONString.Create(LDataSet.Fields[I].FieldName));
LJSONObject.AddPair('DisplayLabel', TJSONString.Create(LDataSet.Fields[I].DisplayLabel));
LJSONObject.AddPair('DataType', TJSONString.Create(GetEnumName(TypeInfo(TFieldType), Integer(LDataSet.Fields[I].DataType))));
LJSONObject.AddPair('Size', TJSONNumber.Create(LDataSet.Fields[I].SIZE));
LJSONObject.AddPair('Key', TJSONBool.Create(pfInKey in LDataSet.Fields[I].ProviderFlags));
LJSONObject.AddPair('Origin', TJSONString.Create(LDataSet.Fields[I].ORIGIN));
LJSONObject.AddPair('Required', TJSONBool.Create(LDataSet.Fields[I].Required));
LJSONObject.AddPair('Visible', TJSONBool.Create(LDataSet.Fields[I].Visible));
LJSONObject.AddPair('ReadOnly', TJSONBool.Create(LDataSet.Fields[I].ReadOnly));
LJSONObject.AddPair('AutoGenerateValue', TJSONString.Create(GetEnumName(TypeInfo(TAutoRefreshFlag), Integer(LDataSet.Fields[I].AutoGenerateValue))));
Result.AddElement(LJSONObject);
end;
end;

Expand Down
96 changes: 48 additions & 48 deletions src/core/DataSet.Serialize.JSON.Impl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -189,63 +189,63 @@ implementation

procedure TJSONSerialize.JSONObjectToDataSet(const JSON: TJSONObject; const DataSet: TDataSet; const Merging: Boolean);
var
Field: TField;
JSONValue: TJSONValue;
NestedDataSet: TDataSet;
BooleanValue: Boolean;
LField: TField;
LJSONValue: TJSONValue;
LNestedDataSet: TDataSet;
LBooleanValue: Boolean;
begin
if (not Assigned(JSON)) or (not Assigned(DataSet)) then
Exit;
if Merging then
DataSet.Edit
else
DataSet.Append;
for Field in DataSet.Fields do
for LField in DataSet.Fields do
begin
if Field.ReadOnly then
if LField.ReadOnly then
Continue;

if not (JSON.TryGetValue(Field.FieldName, JSONValue) or JSON.TryGetValue(LowerCase(Field.FieldName), JSONValue)) then
if not (JSON.TryGetValue(LField.FieldName, LJSONValue) or JSON.TryGetValue(LowerCase(LField.FieldName), LJSONValue)) then
Continue;

if JSONValue is TJSONNull then
if LJSONValue is TJSONNull then
begin
Field.Clear;
LField.Clear;
Continue;
end;
case Field.DataType of
case LField.DataType of
TFieldType.ftBoolean:
if JSONValue.TryGetValue<Boolean>(BooleanValue) then
Field.AsBoolean := BooleanValue;
if LJSONValue.TryGetValue<Boolean>(LBooleanValue) then
LField.AsBoolean := LBooleanValue;
TFieldType.ftInteger, TFieldType.ftSmallint, TFieldType.ftShortint, TFieldType.ftLongWord:
Field.AsInteger := StrToIntDef(JSONValue.Value, 0);
LField.AsInteger := StrToIntDef(LJSONValue.Value, 0);
TFieldType.ftLargeint, TFieldType.ftAutoInc:
Field.AsLargeInt := StrToInt64Def(JSONValue.Value, 0);
LField.AsLargeInt := StrToInt64Def(LJSONValue.Value, 0);
TFieldType.ftCurrency:
Field.AsCurrency := StrToCurr(JSONValue.Value);
LField.AsCurrency := StrToCurr(LJSONValue.Value);
TFieldType.ftFloat, TFieldType.ftFMTBcd, TFieldType.ftBCD, TFieldType.ftSingle:
Field.AsFloat := StrToFloat(JSONValue.Value);
LField.AsFloat := StrToFloat(LJSONValue.Value);
TFieldType.ftString, TFieldType.ftWideString, TFieldType.ftMemo, TFieldType.ftWideMemo:
Field.AsString := JSONValue.Value;
LField.AsString := LJSONValue.Value;
TFieldType.ftDate, TFieldType.ftTimeStamp, TFieldType.ftDateTime, TFieldType.ftTime:
Field.AsDateTime := ISO8601ToDate(JSONValue.Value);
LField.AsDateTime := ISO8601ToDate(LJSONValue.Value);
TFieldType.ftDataSet:
begin
NestedDataSet := TDataSetField(Field).NestedDataSet;
if JSONValue is TJSONObject then
JSONObjectToDataSet(JSONValue as TJSONObject, NestedDataSet, False)
else if JSONValue is TJSONArray then
LNestedDataSet := TDataSetField(LField).NestedDataSet;
if LJSONValue is TJSONObject then
JSONObjectToDataSet(LJSONValue as TJSONObject, LNestedDataSet, False)
else if LJSONValue is TJSONArray then
begin
NestedDataSet.First;
while not NestedDataSet.Eof do
NestedDataSet.Delete;
JSONArrayToDataSet(JSONValue as TJSONArray, NestedDataSet);
LNestedDataSet.First;
while not LNestedDataSet.Eof do
LNestedDataSet.Delete;
JSONArrayToDataSet(LJSONValue as TJSONArray, LNestedDataSet);
end;
end;
TFieldType.ftGraphic, TFieldType.ftBlob, TFieldType.ftStream:
LoadBlobFieldFromStream(Field, JSONValue);
LoadBlobFieldFromStream(LField, LJSONValue);
else
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [Field.FieldName]);
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [LField.FieldName]);
end;
end;
DataSet.Post;
Expand All @@ -264,7 +264,7 @@ procedure TJSONSerialize.ToDataSet(const DataSet: TDataSet);
function TJSONSerialize.Validate(const DataSet: TDataSet; const Lang: TLanguageType = enUS): TJSONArray;
var
I: Integer;
JSONValue: string;
LJSONValue: string;
begin
if not Assigned(FJSONObject) then
raise EDataSetSerializeException.Create(JSON_NOT_DIFINED);
Expand All @@ -276,9 +276,9 @@ function TJSONSerialize.Validate(const DataSet: TDataSet; const Lang: TLanguageT
for I := 0 to Pred(DataSet.Fields.Count) do
if DataSet.Fields.Fields[I].Required then
begin
if FJSONObject.TryGetValue(DataSet.Fields.Fields[I].FieldName, JSONValue) then
if FJSONObject.TryGetValue(DataSet.Fields.Fields[I].FieldName, LJSONValue) then
begin
if JSONValue.Trim.IsEmpty then
if LJSONValue.Trim.IsEmpty then
Result.AddElement(AddFieldNotFound(DataSet.Fields.Fields[I].FieldName, DataSet.Fields.Fields[I].DisplayLabel, Lang));
end
else
Expand All @@ -288,21 +288,21 @@ function TJSONSerialize.Validate(const DataSet: TDataSet; const Lang: TLanguageT

procedure TJSONSerialize.LoadBlobFieldFromStream(const Field: TField; const JSONValue: TJSONValue);
var
StringStream: TStringStream;
MemoryStream: TMemoryStream;
LStringStream: TStringStream;
LMemoryStream: TMemoryStream;
begin
StringStream := TStringStream.Create((JSONValue as TJSONString).Value);
LStringStream := TStringStream.Create((JSONValue as TJSONString).Value);
try
StringStream.Position := 0;
MemoryStream := TMemoryStream.Create;
LStringStream.Position := 0;
LMemoryStream := TMemoryStream.Create;
try
TNetEncoding.Base64.Decode(StringStream, MemoryStream);
TBlobField(Field).LoadFromStream(MemoryStream);
TNetEncoding.Base64.Decode(LStringStream, LMemoryStream);
TBlobField(Field).LoadFromStream(LMemoryStream);
finally
MemoryStream.Free;
LMemoryStream.Free;
end;
finally
StringStream.Free;
LStringStream.Free;
end;
end;

Expand Down Expand Up @@ -357,16 +357,16 @@ procedure TJSONSerialize.ClearJSON;

procedure TJSONSerialize.JSONArrayToDataSet(const JSON: TJSONArray; const DataSet: TDataSet);
var
JSONValue: TJSONValue;
LJSONValue: TJSONValue;
begin
if (not Assigned(JSON)) or (not Assigned(DataSet)) then
Exit;
for JSONValue in JSON do
for LJSONValue in JSON do
begin
if (JSONValue is TJSONArray) then
JSONArrayToDataSet(JSONValue as TJSONArray, DataSet)
if (LJSONValue is TJSONArray) then
JSONArrayToDataSet(LJSONValue as TJSONArray, DataSet)
else
JSONObjectToDataSet(JSONValue as TJSONObject, DataSet, False);
JSONObjectToDataSet(LJSONValue as TJSONObject, DataSet, False);
end;
DataSet.First;
end;
Expand Down Expand Up @@ -399,7 +399,7 @@ procedure TJSONSerialize.Merge(const DataSet: TDataSet);

procedure TJSONSerialize.JSONArrayToStructure(const JSONArray: TJSONArray; const DataSet: TDataSet);
var
JSONValue: TJSONValue;
LJSONValue: TJSONValue;
begin
if not Assigned(DataSet) then
raise EDataSetSerializeException.Create(DATASET_NOT_DIFINED);
Expand All @@ -408,8 +408,8 @@ procedure TJSONSerialize.JSONArrayToStructure(const JSONArray: TJSONArray; const
if DataSet.FieldCount > 0 then
raise EDataSetSerializeException.Create(PREDEFINED_FIELDS);
try
for JSONValue in JSONArray do
TDataSetSerializeUtils.NewDataSetField(DataSet, LoadFieldStructure(JSONValue));
for LJSONValue in JSONArray do
TDataSetSerializeUtils.NewDataSetField(DataSet, LoadFieldStructure(LJSONValue));
finally
JSONArray.Free;
end;
Expand Down
8 changes: 4 additions & 4 deletions src/providers/Providers.DataSet.Serialize.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ class function TDataSetSerializeUtils.BooleanFieldToType(const BooleanField: TBo
class function TDataSetSerializeUtils.CreateValidIdentifier(const Name: string): string;
var
I: Integer;
Character: Char;
LCharacter: Char;
begin
I := 0;
SetLength(Result, Length(name));
for Character in name do
for LCharacter in name do
begin
if CharInSet(Character, ['A' .. 'Z', 'a' .. 'z', '0' .. '9', '_']) then
if CharInSet(LCharacter, ['A' .. 'Z', 'a' .. 'z', '0' .. '9', '_']) then
begin
Inc(I);
Result[I] := Character;
Result[I] := LCharacter;
end;
end;
SetLength(Result, I);
Expand Down

0 comments on commit 0bc0eec

Please sign in to comment.