Jump to content
marc.guillot

Use CreateDataset to activate an empty dataset on a FDQuery in Offline mode

Recommended Posts

I would like to add an Offline mode to an existing application, and to do so I need to be able to activate empty datasets on FDQuerys while in that Offline mode.
 
But when I try calling CreateDataset to activate those empty datasets it always tries to open the connection, which fails because the server is unavailable at the moment.

 

If I replace the Connection with a Dummy Connection, the CreateDatasets still fails because although it successfully opens the dummy connection it raises an exception that the original table has not been found, so my guess is that CreateDataset tries to retrieve metadata instead of using the persistent fields to create the empty dataset.

 

I try to remove the fetching of Metadata from the FDQuery.FetchOptions, but I can't make it work (I always get either a Server not found exception or a Table not found when I use a dummy connection). Example :

 

DataModule.Cn.Offline;
DataModule.Cn.FetchOptions.Items := [];
DataModule.Cn.FetchOptions.Cache := [];
DataModule.Cn.FetchOptions.AutoFetchAll := afDisable;
DataModule.QCustomer.Offline;
DataModule.QCustomer.CachedUpdates := True;
DataModule.QCustomer.FetchOptions.Items := [];
DataModule.QCustomer.FetchOptions.Cache := [];
DataModule.QCustomer.FetchOptions.AutoFetchAll := afDisable;
DataModule.QCustomer.CreateDataSet;

I know that usually you would use FDMemtables for offline datasets, but TFDMemTable and TFDQuery both derive from the same TFDDataset which already implements the in-memory mode, so duplicating all my components to TFDMemTable doesn't seem to provide any additional benefit.

 

Do you know if it's possible to disable the metadata retrieving in order to activate empty datasets on FDQuerys while their connection is not available ?.

 

Thank you.

Share this post


Link to post

You may have to provide a value in ResourceOptions.PersistentFileName to allow storing the structure and data from the last retrieved records when online. If you deploy a basic file with just the structure (best created from an online connection during development) that may fit your needs.

  • Like 1

Share this post


Link to post

Thanks Uwe.

 

We could make it work this way, but it seems a bit unconvenient (and I would like to work entirely in memory and not populate and depend on the file system).

 

I'm looking to replace those FDQuerys with a custom component based on FDMemTable (with a FDTableAdapter and FDCommand subcomponents), so they will be the purposed fully in-memory dataset but still capable to retrieve & update data from the database through the TFDTableAdapter.

 

So far the main issue I've found is that once a FDMemTable has a FDTableAdaptar and FDCommand it will also open the database connection when you call its CreateDataset method. But there is the workaround of having it blanking the Adapter property before calling inherited CreateDataset, so it creates the new dataset entirely in-memory without trying to connect to the database.

Edited by marc.guillot

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×