FireDAC equivalent of DBExpress briefcase model

淺唱寂寞╮ 提交于 2021-01-29 04:30:27

问题


I have been using DBExpress connections to various databases (mostly MSSQL, Sybase SQL) with:

SQLConnection -> SQLDataSet -> DataSetProvider -> ClientDataSet.

I need to connect to the databases in a fashion that does NOT write changes back to the tables.

So, the DataSetProvider has ResolveToDataSet:=false, and the ClientDataSet has LogChanges:=false (for performance).

In use I connect the SQLConnection, open the ClientDataSet, and then close the SQLConnection.

I can then manipulate the ClientDataSet without fear of changing the underlying table.

I'm new to FireDAC (XE8), and I'm looking to establish the same sort of scenario - load data into memory from a SQL query, and safely manipulate this data in memory without accidentally updating the source table(s).

I'm currently using: FDConnection -> FDQuery and a FDMemTable

The FDQuery has CachedUpdates := true and I perform:

FDQ.Open;
FDQ.FetchAll;
FDMemT.CloneCursor(FDQ,true,false);
FDQ.Close;

I think this is pretty much equivalent - I end up with the data in an FDMemTable such that editing the data will not be able to "write back" to tables.

One other issue - in the dbExpress scenario, I often add InternalCalc Fields to the ClientDataSet. It isn't clear to me that I can do that (and have persistent field names) if I'm performing a CloneCursor operation.

Is there a simpler way of ensuring the data never updates the database? Setting the FDQuery to read-only doesn't work - I often have to modify records (but do not wish to persist these changes).

TIA.

EdB


回答1:


There is a much easier way. Use the FDMemTable's CopyDataSet method. This will copy both the data and the metadata. Changes to the FDMemTable will not be written to the underlying dataset, and internal calc fields (and calculated field) will be copied as well, though you'll have to wire up the OnCalcFields event handler.

FDMemTable1.CopyDataSet( FDQuery1, [coStructure, coRestart, coAppend]);


来源:https://stackoverflow.com/questions/33354428/firedac-equivalent-of-dbexpress-briefcase-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!