Search code examples
databasedelphigeneratorfiredacaggregates

Can tfdquery.aggregates be used as autoIDgenerator


In Delphi the TFDQuery component has a property "aggregates" which represents a lightweight version of client side aggregate fields to Data Sets.

If you insert "MAX(ID)" you get a number that is one less than the next free number of the ID.

If this could be used to calculate the ID-Field it would be a very easy method to have an autogenerator for the ID-Field for every kind of database.

But I doubt because it is called "client side". I don't know exactly what that means. Doesn't it calculate the aggregate for the whole table but only for a local partition of the records? In the last case it could perhaps be used for an auto generator once it is correctly initialized.


Solution

  • If this could be used to calculate the ID-Field it would be a very easy method to have an autogenerator for the ID-Field for every kind of database.

    I am afraid not, at any rate, not for "every kind of database". The signifcance of "client-side" is that a client-side method of deriving a row id is no good for a shared database where different users might be attempting to add rows to the same table at the same time.

    For a multi-user database, it as always best you use whatever facility the server-side RDMS provides to provide ID-fields values. Some RDMSs like Interbase have so-called generators to do this reliably for you.