模式更改后,Firedac查询字段列表未更新 [英] Firedac Query Field list not updated after Schema change
问题描述
我正在用SQL创建一个临时表,然后向其中添加一个新字段。似乎Firedac正在缓存此临时表的字段列表。
以下代码为我提供了 FDQuery5:找不到字段'Available'。
I am creating a temp table in SQL and then adding a new field to it. It seems Firedac is caching the field list for this temp table.
The following code gives me "FDQuery5: Field 'Available' not found."
FDQuery5.Connection := FDConnection1;
FDConnection1.ExecSQL('Select StockNo into #Temp from Stock');
FDQuery5.SQL.Text := 'Select * From #Temp';
FDQuery5.open;
FDConnection1.ExecSQL('Alter Table #Temp add Available Char(1)');
FDQuery5.Close;
FDQuery5.open;
ShowMessage(FDQuery5.FieldByName('Available').AsString);
使用带有Firedac的XE5。
我尝试了Connection.RefreshMetadataCache,并从FetchOptions.Cache中删除了fiMeta。
using XE5 with Firedac. I have tried Connection.RefreshMetadataCache and I have removed fiMeta from FetchOptions.Cache.
如果修改SQL,我可以让Firedac识别新字段。文本。这是不可取的,因为我的应用程序需要在很多地方进行修改。
I can get Firedac to recognise the new field if I modify the SQL.Text. This is undesirable as my application will need modifying in quite a few places.
推荐答案
在调用FDQuery5之后,查询仍处于准备状态。 。这意味着,它还缓存结果集结构。要准备查询,请用FDQuery5.Disconnect替换FDQuery5.Close。
The query remains prepared after you call FDQuery5.Close. That means, it caches also result set structure. To prepare the query replace FDQuery5.Close with FDQuery5.Disconnect.
这篇关于模式更改后,Firedac查询字段列表未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!