Update Read only SQL queries
Posted on 2005-04-19
I need practical soution to update read only sql queries. I usually fill DBgrids with multiple table queries that yields read only datasets. I want that the grid work as with a live query, edit and press enter and the table is updated.
The solution may be a function called by a dbgrid event (i.e. keypress), a field event or a dataset event. But I want it elegant, I mean, the less paramaters passed, the better. Doesn't matter if the update replace all the table record with unmodified fields, not only the changed one.
The related tables are mostly lookup tables, so if the function updates the id of the lookup record in the target table is OK. I don't need to mix updatable data from several tables, just one main table and the related lookup ones.
I always put an unique ID on the updated record, it can be used as a parameter to locate the record and make the changes in a second recordset.
I can develop this myself, but perhaps someone already has a nice solution.
It must be DB engine independent. I will adapt the proposed SQL if needed, or all the standard TTable or TQuery methods can be used.
I hope it is clear, thanks a lot!