mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Added support for TSQLTimeStampOffset in dataset derialization and deserialization
This commit is contained in:
parent
cbc971aaf6
commit
fea6b0c273
@ -129,6 +129,8 @@ type
|
||||
fCompanyName: NullableString;
|
||||
[MVCTableField('city')]
|
||||
fCity: string;
|
||||
[MVCTableField('last_contact_timestamp')]
|
||||
fLastContact: NullableTDateTime;
|
||||
[MVCTableField('rating')]
|
||||
fRating: NullableInt32;
|
||||
[MVCTableField('note')]
|
||||
@ -141,6 +143,7 @@ type
|
||||
property Code: NullableString read fCode write fCode;
|
||||
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
||||
property City: string read fCity write fCity;
|
||||
property LastContact: NullableTDateTime read fLastContact write fLastContact;
|
||||
property Rating: NullableInt32 read fRating write fRating;
|
||||
property Note: string read fNote write fNote;
|
||||
end;
|
||||
|
@ -55,7 +55,6 @@ object MainForm: TMainForm
|
||||
TabOrder = 2
|
||||
WantReturns = False
|
||||
WordWrap = False
|
||||
ExplicitHeight = 610
|
||||
end
|
||||
object btnRelations: TButton
|
||||
Left = 8
|
||||
|
@ -238,6 +238,7 @@ begin
|
||||
lCustomer.CompanyName := 'Google Inc.';
|
||||
lCustomer.City := 'Montain View, CA';
|
||||
lCustomer.Note := 'Μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην 😁';
|
||||
lCustomer.LastContact := Now();
|
||||
lCustomer.Insert;
|
||||
lID := lCustomer.ID;
|
||||
Log('Just inserted Customer ' + lID.ToString);
|
||||
@ -250,6 +251,7 @@ begin
|
||||
Assert(not lCustomer.Code.HasValue);
|
||||
lCustomer.Code.Value := '5678';
|
||||
lCustomer.Note := lCustomer.Note + sLineBreak + 'Code changed to 5678 🙂';
|
||||
lCustomer.LastContact.Clear;
|
||||
lTestNote := lCustomer.Note;
|
||||
lCustomer.Update;
|
||||
Log('Just updated Customer ' + lID.ToString);
|
||||
@ -261,6 +263,8 @@ begin
|
||||
try
|
||||
lCustomer.LoadByPK(lID);
|
||||
lCustomer.Code.Value := '😉9012🙂';
|
||||
Assert(lCustomer.LastContact.IsNull);
|
||||
lCustomer.LastContact := Now();
|
||||
lCustomer.Update;
|
||||
finally
|
||||
lCustomer.Free;
|
||||
@ -271,6 +275,8 @@ begin
|
||||
lCustomer.LoadByPK(lID);
|
||||
Assert(lCustomer.Code.Value = '😉9012🙂');
|
||||
Assert(lCustomer.Note = lTestNote);
|
||||
Assert(lCustomer.LastContact.HasValue);
|
||||
lCustomer.LastContact := Now();
|
||||
lCustomer.Update;
|
||||
finally
|
||||
lCustomer.Free;
|
||||
|
@ -109,12 +109,11 @@ begin
|
||||
// calling http://localhost:8080/customserializationtype
|
||||
|
||||
DMVC
|
||||
.Serializers
|
||||
.Items[TMVCMediaType.APPLICATION_JSON]
|
||||
.Serializer(TMVCMediaType.APPLICATION_JSON)
|
||||
.RegisterTypeSerializer(TypeInfo(TNullableRecordAlias), TNullableAliasSerializer.Create);
|
||||
|
||||
// This line registers custom serializers for TBitmap, TPngImage (Only MSWindows) and TJPEGImage (Only MSWindows)
|
||||
RegisterOptionalCustomTypesSerializersForJSON(DMVC.Serializers);
|
||||
RegisterOptionalCustomTypesSerializers(DMVC.Serializer(TMVCMediaType.APPLICATION_JSON));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1014,6 +1014,10 @@ begin
|
||||
AJSONObject.S[lFName] := DateTimeToISOTimeStamp
|
||||
(SQLTimeStampToDateTime(ADataSet.Fields[lField.I].AsSQLTimeStamp));
|
||||
|
||||
ftTimeStampOffset:
|
||||
AJSONObject.S[lFName] := DateTimeToISOTimeStamp
|
||||
(SQLTimeStampOffsetToDateTime(ADataSet.Fields[lField.I].AsSQLTimeStampOffset));
|
||||
|
||||
ftCurrency:
|
||||
AJSONObject.F[lFName] := ADataSet.Fields[lField.I].AsCurrency;
|
||||
|
||||
@ -1069,7 +1073,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
else
|
||||
raise EMVCSerializationException.CreateFmt('Cannot find type for field "%s"', [lField.FieldName]);
|
||||
raise EMVCSerializationException.CreateFmt('Cannot find type for field "%s" - TFieldType = %s', [lField.FieldName, GetEnumName(TypeInfo(TFieldType), Ord(lField.DataType))]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -2246,6 +2250,9 @@ begin
|
||||
TFieldType.ftDateTime, TFieldType.ftTimeStamp:
|
||||
Field.AsDateTime := ISOTimeStampToDateTime(AJSONObject.S[lName]);
|
||||
|
||||
TFieldType.ftTimeStampOffset:
|
||||
Field.AsSQLTimeStampOffset := StrToSQLTimeStampOffset(AJSONObject.S[lName]);
|
||||
|
||||
TFieldType.ftTime:
|
||||
Field.AsDateTime := ISOTimeToTime(AJSONObject.S[lName]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user