FireDac Query Field size does not update on sql change

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. Fields retrieved on design time

( 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.

Upvotes: 2

Views: 1413

Answers (2)

Ken White
Ken White

Reputation: 125708

This is standard behavior (not saying it's right, just that it's how things work) when using persistent fields (those created at design time with the Field Editor). Once the fields are created, they're not updated with changes unless they're deleted (again using the Field Editor); instead, the size is simply read from the definition of the field as stored in the .DFM. It's not FireDAC specific; it's been a problem forever when using persistent fields.

The easiest way to fix it is simply to use the Field Editor, delete the field definition, and re-add it.

Upvotes: 1

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.

Upvotes: 1

Related Questions