Skip to content

Commit e16adc9

Browse files
committed
Atualização para retirar dependencias do DataSetConverter4D, somente utilização da DataSetConverter4D.Util.pas;
Alterado a conversão para lowercase
1 parent eceacd2 commit e16adc9

7 files changed

Lines changed: 760 additions & 29 deletions

File tree

GenericQuery.dpk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ requires
4242
contains
4343
GenericQuery.Model.Connection in 'src\core\Connection\GenericQuery.Model.Connection.pas',
4444
GenericQuery in 'src\core\GenericQuery\GenericQuery.pas',
45-
Model.GenericQuery.Intf in 'src\interfaces\Model.GenericQuery.Intf.pas';
45+
Model.GenericQuery.Intf in 'src\interfaces\Model.GenericQuery.Intf.pas',
46+
DataSetToJSON in 'src\core\GenericQuery\DataSetToJSON.pas',
47+
DataSetConverter4D.Util in 'src\core\GenericQuery\DataSetConverter4D.Util.pas';
4648

4749
end.
4850

GenericQuery.dproj

Lines changed: 215 additions & 21 deletions
Large diffs are not rendered by default.

GenericQuery.dproj.local

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<BorlandProject>
33
<Transactions>
4-
</Transactions>
4+
<Transaction>2021/04/28 16:09:36.831,=C:\BrProjetos\GenericQuery\trunk\src\core\GenericQuery\DataSetConverter4D.Util.pas</Transaction>
5+
</Transactions>
56
</BorlandProject>

GenericQuery.identcache

88 Bytes
Binary file not shown.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
unit DataSetConverter4D.Util;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.DateUtils,
8+
System.JSON,
9+
Data.DB,
10+
DataSetToJSON;
11+
12+
function DateTimeToISOTimeStamp(const dateTime: TDateTime): string;
13+
function DateToISODate(const date: TDateTime): string;
14+
function TimeToISOTime(const time: TTime): string;
15+
16+
function ISOTimeStampToDateTime(const dateTime: string): TDateTime;
17+
function ISODateToDate(const date: string): TDate;
18+
function ISOTimeToTime(const time: string): TTime;
19+
20+
function NewDataSetField(dataSet: TDataSet; const fieldType: TFieldType; const fieldName: string;
21+
const size: Integer = 0; const origin: string = ''): TField;
22+
23+
function BooleanToJSON(const value: Boolean): TJSONValue;
24+
function BooleanFieldToType(const booleanField: TBooleanField): TBooleanFieldType;
25+
function DataSetFieldToType(const dataSetField: TDataSetField): TDataSetFieldType;
26+
27+
implementation
28+
29+
function DateTimeToISOTimeStamp(const dateTime: TDateTime): string;
30+
var
31+
fs: TFormatSettings;
32+
begin
33+
fs.TimeSeparator := ':';
34+
Result := FormatDateTime('yyyy-mm-dd hh:nn:ss', dateTime, fs);
35+
end;
36+
37+
function DateToISODate(const date: TDateTime): string;
38+
begin
39+
Result := FormatDateTime('YYYY-MM-DD', date);
40+
end;
41+
42+
function TimeToISOTime(const time: TTime): string;
43+
var
44+
fs: TFormatSettings;
45+
begin
46+
fs.TimeSeparator := ':';
47+
Result := FormatDateTime('hh:nn:ss', time, fs);
48+
end;
49+
50+
function ISOTimeStampToDateTime(const dateTime: string): TDateTime;
51+
begin
52+
Result := EncodeDateTime(StrToInt(Copy(dateTime, 1, 4)), StrToInt(Copy(dateTime, 6, 2)), StrToInt(Copy(dateTime, 9, 2)),
53+
StrToInt(Copy(dateTime, 12, 2)), StrToInt(Copy(dateTime, 15, 2)), StrToInt(Copy(dateTime, 18, 2)), 0);
54+
end;
55+
56+
function ISODateToDate(const date: string): TDate;
57+
begin
58+
Result := EncodeDate(StrToInt(Copy(date, 1, 4)), StrToInt(Copy(date, 6, 2)), StrToInt(Copy(date, 9, 2)));
59+
end;
60+
61+
function ISOTimeToTime(const time: string): TTime;
62+
begin
63+
Result := EncodeTime(StrToInt(Copy(time, 1, 2)), StrToInt(Copy(time, 4, 2)), StrToInt(Copy(time, 7, 2)), 0);
64+
end;
65+
66+
function NewDataSetField(dataSet: TDataSet; const fieldType: TFieldType; const fieldName: string;
67+
const size: Integer = 0; const origin: string = ''): TField;
68+
begin
69+
Result := DefaultFieldClasses[fieldType].Create(dataSet);
70+
Result.FieldName := fieldName;
71+
72+
if (Result.FieldName = '') then
73+
Result.FieldName := 'Field' + IntToStr(dataSet.FieldCount + 1);
74+
75+
Result.FieldKind := fkData;
76+
Result.DataSet := dataSet;
77+
Result.Name := dataSet.Name + Result.FieldName;
78+
Result.Size := size;
79+
Result.Origin := origin;
80+
81+
if (fieldType in [ftString, ftWideString]) and (size <= 0) then
82+
raise EDataSetToJSONException.CreateFmt('Size not defined for field "%s".', [fieldName]);
83+
end;
84+
85+
function BooleanToJSON(const value: Boolean): TJSONValue;
86+
begin
87+
if value then
88+
Result := TJSONTrue.Create
89+
else
90+
Result := TJSONFalse.Create;
91+
end;
92+
93+
function BooleanFieldToType(const booleanField: TBooleanField): TBooleanFieldType;
94+
const
95+
DESC_BOOLEAN_FIELD_TYPE: array [TBooleanFieldType] of string = ('Unknown', 'Boolean', 'Integer');
96+
var
97+
index: Integer;
98+
origin: string;
99+
begin
100+
Result := bfUnknown;
101+
origin := Trim(booleanField.Origin);
102+
for index := Ord(Low(TBooleanFieldType)) to Ord(High(TBooleanFieldType)) do
103+
if (LowerCase(DESC_BOOLEAN_FIELD_TYPE[TBooleanFieldType(index)]) = LowerCase(origin)) then
104+
Exit(TBooleanFieldType(index));
105+
end;
106+
107+
function DataSetFieldToType(const dataSetField: TDataSetField): TDataSetFieldType;
108+
const
109+
DESC_DATASET_FIELD_TYPE: array [TDataSetFieldType] of string = ('Unknown', 'JSONObject', 'JSONArray');
110+
var
111+
index: Integer;
112+
origin: string;
113+
begin
114+
Result := dfUnknown;
115+
origin := Trim(dataSetField.Origin);
116+
for index := Ord(Low(TDataSetFieldType)) to Ord(High(TDataSetFieldType)) do
117+
if (LowerCase(DESC_DATASET_FIELD_TYPE[TDataSetFieldType(index)]) = LowerCase(origin)) then
118+
Exit(TDataSetFieldType(index));
119+
end;
120+
121+
end.

0 commit comments

Comments
 (0)