this may sound stupid and i can be missing something important, but here it goes.
I'm migrating an old software from BDE to Firedac and i noticed some strange behaviors (XE6 VCL - Firedac ).
Imagine this:
We have a Query that has a simple sql (SQL1), this query is defined in design time and has all fields retrieved (3 fields - cod, des and img). In runtime, i execute this query, and check a cod field size, works great. Then i change the sql(SQL2) and proceed to check the new cod field size, this also works. But if i change again the sql to the SQL1 and check the size of cod field it assumes the same size of the second query field size.
I have tested it in a small project and this also happens, as follows.
( I placed 2 buttons and a label to check the size)
procedure TForm1.SQL1Click(Sender: TObject);
begin
FDQuery1.Close;
FDQuery1.SQL.Clear;
FDQuery1.SQL.Text:='select grefcod as cod, grefdesc as des, grefimg as img from wtv';
FDQuery1.Open;
sLabelFX1.Caption:=IntToStr(FDQuery1.FindField('COD').Size);
end;
procedure TForm1.SQL2Click(Sender: TObject);
begin
FDQuery1.Close;
FDQuery1.SQL.Clear;
FDQuery1.SQL.Text:='select ATRBcod as cod, ATRBdes as des from wtv2 ';
FDQuery1.Open;
sLabelFX1.Caption:=IntToStr(FDQuery1.FindField('COD').Size);
end;
First i call SQL1Click, cod size is 20;
Second i call SQL2Click, cod size is 5;
Last, i call again SQL1Click and cod size is 5 -> Wrong.
Edit: The Real size of SQL1 cod is 20 varchar, and the real size of SQL2 is 5 varchar .
Its strange, and sorry if i couldn't explain it better. Anyway, if i delete the retrieved fields on design time the problem doesn't exist, and i just need to change the way i get the fields, but since this is a giant software, that is not something i would like to do.
This issue was resolved by setting the Query option 'Update Persistent' to true on FieldOptions.
I dont really know if this behavior was intended but now its working.