Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exportar tipos de campo GUID de SQLIte para String #45

Closed
ricardodarocha opened this issue May 27, 2020 · 2 comments
Closed

Exportar tipos de campo GUID de SQLIte para String #45

ricardodarocha opened this issue May 27, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@ricardodarocha
Copy link

Eu tenho uma tabela no SQLite com o seguinte campo do tipo GUID

CREATE TABLE Medicao (
Codigo INTEGER PRIMARY KEY AUTOINCREMENT ,
Indicador GUID NOT NULL REFERENCES Indicadores (ID) ON DELETE CASCADE
ON UPDATE CASCADE,
Valor DOUBLE(11,3) )

Embora seja sabido que Sqlite é um banco de dados não tipado, é possível usufruir da engine Firedac para detectar automaticamente campos "GUID" como UUID durante o método Autocreate dos fields, em um componente FDQuery por exemplo.

O método abaixo retornou o seguinte erro
"Cannot find type for field "indicador""

uses Dataset.Serialize;
function DataModule1.MeuJsonArray: TJsonArray;
begin
Query1.Open('select codigo, indicador from medicao');
MeuJsonArray := Query1.ToJsonArray();
end;

O erro ocorreu na seguinte linha

unit DataSet.Serialize.Export;

function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const IsChild: Boolean): TJSONArray;
....
case LField.DataType of
TFieldType.ftBoolean:
begin
case TDataSetSerializeUtils.BooleanFieldToType(TBooleanField(LField)) of
bfUnknown, bfBoolean:
Result.AddPair(LKey, TDataSetSerializeUtils.BooleanToJSON(LField.AsBoolean));
else
Result.AddPair(LKey, TJSONNumber.Create(LField.AsInteger));
end;
end;
TFieldType.ftInteger, TFieldType.ftSmallint, TFieldType.ftShortint:
Result.AddPair(LKey, TJSONNumber.Create(LField.AsInteger));
TFieldType.ftLongWord, TFieldType.ftAutoInc:
Result.AddPair(LKey, TJSONNumber.Create(LField.AsWideString));
TFieldType.ftLargeint:
Result.AddPair(LKey, TJSONNumber.Create(LField.AsLargeInt));
TFieldType.ftSingle, TFieldType.ftFloat:
Result.AddPair(LKey, TJSONNumber.Create(LField.AsFloat));
TFieldType.ftString, TFieldType.ftWideString, TFieldType.ftMemo, TFieldType.ftWideMemo:
Result.AddPair(LKey, TJSONString.Create(LField.AsWideString));
TFieldType.ftTimeStamp, TFieldType.ftDateTime, TFieldType.ftTime:
Result.AddPair(LKey, TJSONString.Create(DateToISO8601(LField.AsDateTime, TDataSetSerializeConfig.GetInstance.DateInputIsUTC)));
TFieldType.ftDate:
Result.AddPair(LKey, TJSONString.Create(FormatDateTime(TDataSetSerializeConfig.GetInstance.Export.FormatDate, LField.AsDateTime)));
TFieldType.ftCurrency:
Result.AddPair(LKey, TJSONString.Create(FormatCurr(TDataSetSerializeConfig.GetInstance.Export.FormatCurrency, LField.AsCurrency)));
TFieldType.ftFMTBcd, TFieldType.ftBCD:
Result.AddPair(LKey, TJSONNumber.Create(BcdToDouble(LField.AsBcd)));
TFieldType.ftDataSet:
begin
LNestedDataSet := TDataSetField(LField).NestedDataSet;
Result.AddPair(LKey, DataSetToJSONArray(LNestedDataSet));
end;
TFieldType.ftGraphic, TFieldType.ftBlob, TFieldType.ftOraBlob, TFieldType.ftStream:
Result.AddPair(LKey, TJSONString.Create(EncodingBlobField(LField)));
else
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [LKey]);
end;

incluir também
case LField.DataType of
...
TFieldType.ftGuid: Result.AddPair(LKey, TJSONString.Create(LField.AsWideString));

@viniciussanchez viniciussanchez added the enhancement New feature or request label May 27, 2020
@viniciussanchez
Copy link
Owner

Olá @ricardodarocha
Poderia fazer a modificação e enviar seu Pull Request?

@ricardodarocha
Copy link
Author

Enviado amigo, ate breve.

viniciussanchez added a commit that referenced this issue May 27, 2020
#45 - Incluí o tipo de campo ftGuid na serialização
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants