Jump to content
Stano

Save the contents of the TFDMemTable to a DB table

Recommended Posts

My experiment (s)

  FMTSpace.UpdateOptions.UpdateTableName := 'DISTANCES';
  FMTSpace.UpdateOptions.EnableInsert := True;
  FMTSpace.UpdateOptions.UpdateChangedFields := True;
  FMTSpace.Active := True;
  FMTSpace.CachedUpdates := True;
///  Filling FMTSpace with data
  FMTSpace.ApplyUpdates(-1);

That's how it works for me. I consider it extra work.

  for var J := 0 to FRecordCount -1 do
  begin
    for K := 0 to qryDistanceIns.Params.Count -1 do
      qryDistanceIns.Params[K].Values[J] := FMTSpace.Fields.Fields[K].Value;

    FMTSpace.Next;
  end;

  try
    TFDFunction.QryExecute(qryDistanceIns, True);
  finally
    FreeAndNil(qryDistanceIns);
  end;

Unfortunately, the instructions and examples are more than brief. They are not complete. Thanks!

Share this post


Link to post

I haven't tried this and am just thinking out loud but couldn't you use a FDBatchMove component and save yourself some code? It seems like you could set up a Dataset Reader and Writer and then just tell it to go.

Share this post


Link to post

There was no other option than FDBatchMove. It already works for me. Thanks for the response.

Share this post


Link to post

There also is TFDDataSet.CopyDataSet, which takes any TDataSet as source. So if your target dataset is derived from TFDDataSet (like TFDQuery) this could be an option.

Share this post


Link to post

Not for me. The SQL has "0 AS X". The actual field type in DB is Float. Therefore, I always define the MemTable structure for each use. As I was explained, Pointer is passed to CopyDataSet. Field type data is lost. X will be ftInteger.
I don't have to deal with performance. These are just a few records / rows.

Share this post


Link to post
Guest

Sorry for barging in to you thread but i want to ask, do you have the sources for FireDAC?

Share this post


Link to post
Guest

So you have no way of finding out problems on your own. You have to post here or wait for Emba paid support? 1½ years for one fix if you are lucky?

I would not deploy something that way. The level of control is is the basement IMHO.

 

Yesterday i had to make an MVP using FireDAC and it was kind of "simple".

I spent 2 hours (!) to find out how to extract field result data from an FDCommand.

The docs where either not accessible (see other threads) or seriously lacking (local).

 

For me this is like working with blinders on.

 

My question is, how do you sleep at night when you cannot se the code?

Share this post


Link to post
1 minute ago, Dany Marmur said:

how do you sleep at night when you cannot se the code

This seems a little harsh. I use a lot of code that others have written and which I cannot see (or haven't looked at). I sleep just fine at night. I don't have time to personally look at and test everyone else's code but trust that it works as described. Of course, it's wise to test the finished product that uses unseen code modules to make sure the end result is what you're after.

 

In this case, there's a specific problem for which an answer is being sought and being able to see what the components do by looking at the code could help but will it actually take less time tracing through thousands of lines of unfamiliar classes than it would to post a question on a forum?

Share this post


Link to post
Guest

@corneliusdavid, yes. Most definitely. 30 years of Delphi usage and all the tickets... all of them, ALL, i had to make an MVP to get it fixed.

Without sources i would not have been able to help the vendor fix. They go... "you are confused".

You have a lot of trust in your 3rd party vendors. Me... i realize they are on the same level as myself.

For each 3rd party that i have deployed, i have worked with their support for 2 years before deploying.

I must "vett" each one to see if they are up to the task.

If you want "cases", i have some 🙂 not just some, but a lot.

 

Also, i will realize and cater for the fact that some applications in the Delphi-house-world is click-and-go. But that is not scalable neither maintainable.

Share this post


Link to post

I write here again that I am not a programmer. I seldom understand foreign code.
The reason for asking the question: it's hard to find something, especially FireDAC, in help. Examples are:

  1. about something other than the topic
  2. very complicated
  3. incomplete, possibly with errors

I couldn't find anything. I was successful later. I forgot to write it here. 

Thanks to all.

Share this post


Link to post
Guest

remembering that you can MAP/Rule your fields on FDManager (or in subclass like FDQuery on rule/map options) to convert automatically one type to other if necessary.

Edited by Guest

Share this post


Link to post

Defining field types in MemTable and retrieving data using CopyDataSet is the easiest for me.
Only now did I realize that I had written nonsense in Uwe Rabe's answer. I meant MemTable.Data := MyQuery.Data. No CopyDataSet. 

I apologise.

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

×