2

I have a database table in which I need to insert records. I'm using a updatable TClientDataset and everything works just fine.

Now, I need to add a dummy field; not a calculated one. One field where I can write the row state (just some information I will use before ApplyUpdates) but that is not part of the database table.

I've seen this illuminating post, but the added field is calculated and it is not possible to update and keep informations. It is not ok for me.

I've tried to add a 'dummy field' from the database select and fix the ProviderFlags to remove the pfUpdate.

cds.CommandText := 'SELECT 1 AS DUMMY , CUSTOMERS.* FROM CUSTOMERS';
cds.Open;
cds.FieldByName('DUMMY').ProviderFlags := [];

I've seen in the Provider.pas that before building the insert sql, the ProviderFlags is checked. This should work indeed, the problem is it seems that ProviderFlags is not updated from my statement above.

Please, do you know how to add a Field on the fly, that is writable but then ignored by the delphi database update process?

I'm using delphi 7.

Thanks for you help.

Community
  • 1
  • 1
Jako
  • 2,489
  • 3
  • 28
  • 38
  • 2
    Is there some reason why you can't just knock something up to hold a reference to the data row and your state structure. Save you a lot of messing about. – Tony Hopkinson Apr 25 '12 at 09:52
  • Because I do not have external data structure for state. Neither I want to create them apart from the dataset. The solution that Uwe Raabe propose is without pain and mess at all. – Jako Apr 25 '12 at 15:51
  • Neither of those seem problematic reasons to me, but the approach suggested by @Uwe looks even less of a problem. – Tony Hopkinson Apr 25 '12 at 17:02
  • one cannot set ProviderFlags this way on client side. you should either set it using optional param szPROVFLAGS or on provider side – Vladimir Ulchenko Apr 26 '12 at 05:50
  • @vavan, AFAIK you can indeed set TField.ProviderFlags on client side. The szPROVFLAGS is only used to transfer the provider flags through the dataset provider from 'server' to client as a field attribute. This happens during opening the dataset, so any changes to the field after that should remain valid. In addition this transfer is only done when the ProviderFlags on the provider side is different to the default [pfInWhere, pfInUpdate]. – Uwe Raabe Apr 26 '12 at 07:43
  • while you obviously can that won't help you to achieve required functionality. the problem is that no matter what you set on CDS side during applying the updates provider's side settings will be used – Vladimir Ulchenko Apr 26 '12 at 08:39

1 Answers1

6

Make the field an InternalCalc field and set its ProviderFlags to []. This makes the field writable to your application, but skips the field when updating the underlying database.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • Thanks Uwe! That's it! I've implemented this and worked like a charm. Anyway, I didn't need to set ProviderFlags. Making the field InternalCalc was sufficient – Jako Apr 26 '12 at 07:47