DBGrid refresh when new records appear in the table lazarus / 16-Databases ---------------------------------------------------------------------- Vodnik · 2020-09-14 18:58 I'm using TDBGrid to output data from Informix DB via ODBC driver. Dataset Close / Open is used to reread the data from the DB on user's request. Now I have to make DBGrid to refresh automatically. Of course, I can initiate Dataset Close / Open every minute with Timer. But maybe there is a more clever solution available? E.g., update the DBGrid only when new record is added to the underlying table. And not to load the whole table, but only the new records. (Old records are never changed. Old records are deleted after a year, while I have to output data for current day only) ---------------------------------------------------------------------- madref · 2020-09-15 07:55 How do you know there are new records? If you know that you can do a refresh of your DBGrid ---------------------------------------------------------------------- Vodnik · 2020-09-15 09:07 Quote from: madref on September 15, 2020, 09:55:04 amHow do you know there are new records? This is what I'm asking for. I'm not an expert in DB engines, I just supposed that DB engine may provide some event when the monitored table is changed (not sure this will work via ODBC). In a worse case, application can request number of records in a table and re-read the whole table (or better only delta) when it changes. I hoped this is a common task when working with DBs and it have a well-known solution. ---------------------------------------------------------------------- JanRoza · 2020-09-15 09:24 I take it your DBGrid has a Tdatasource on which it is based. The Tdatasource has an event called OnDataChange, that's the place you can code your action (DBGrid.refresh or something like that). In the Object Properties of the datasource click the tab titled 'Events' and doubleclick in the column behind 'OnDataChange'. Hope this helps you. ---------------------------------------------------------------------- rvk · 2020-09-15 10:13 Quote from: JanRoza on September 15, 2020, 11:24:13 amThe Tdatasource has an event called OnDataChange, that's the place you can code your action (DBGrid.refresh or something like that). In the Object Properties of the datasource click the tab titled 'Events' and doubleclick in the column behind 'OnDataChange'. TDatasource.OnDataChange has nothing to do with changing data in the database. It is called when your program changes a field-value. https://www.freepascal.org/docs- html/current/fcl/db/tdatasource.ondatachange.html TS wants to have a trigger for when data on the server-side changes. And that's very specific to what database is used. i.e. Firebird has monitor-events for that. Not sure about Informix DB but via an ODBC drive it would really pose a challenge (i.e. not even sure it's possible). And even if it was possible, you would also need to examine what type of transaction is used. Without closing and opening a new transaction, new and changed records might not even be available to the current transaction. ---------------------------------------------------------------------- af0815 · 2020-09-15 10:38 one possible soloution is, to use a trigger and write the actual date in a simple flagging table with one row. The query to that simple table will normally held in memory and an access to this table/field willbe without stressing the server. if a new row araise the trigger will change the field. Polling will be the only way to get information. Callback are normally not implemented with serverbased DBs ---------------------------------------------------------------------- rvk · 2020-09-15 10:41 Quote from: af0815 on September 15, 2020, 12:38:21 pmCallback are normally not implemented with serverbased DBs Actually the are. See https://firebirdsql.org/file/documentation/papers_presentations/Po wer_Firebird_events.pdf And I'm sure Oracle, Microsoft SQL Server etc have them too. But the problem is implementing them. And especially through ODBC which TS is using.