PDA

View Full Version : Automatic updating of SQLmodel



otternase
5th June 2010, 19:35
Hi

given the following problem:

I have a VIEW in a PostgreSQL Database which I want to display in a TableView in a Qt program. So I use a QSqlQueryModel and a QTableView, that far no problem...

But the content of the database can be changed externally and when this happens, the VIEW changes accordingly. But my model is not updated because it is not notified of the change of the database view and therefore the QTableView also doesn't change.

How can I achieve an automatic update of the model on changes in the database?

Thanks
Markus

schnitzel
5th June 2010, 19:57
Can the application that initiates the change to the database notify your program?

I'm not that familiar with PostgreSQL, but doesn't it support notification events? Check the 'notify' command.

good luck

otternase
5th June 2010, 22:21
> Can the application that initiates the change to the database notify your program?

that will unfortunately not work....

> I'm not that familiar with PostgreSQL, but doesn't it support notification events? Check the 'notify'
> command.

yes, PostgreSQL supports NOTIFY and Qt can subscribe to them. But there are two problems with this:

1) TRIGGER work only on tables, not on VIEWS, which means, the NOTIFY would have to be sent by the base tables instead of the aggregate VIEW. But because the base tables can change during runtime (REPLACE VIEW), this means a "management overhead"

2) much more important: while PostgreSQL seems to be able to sent a NOTIFY not only with name, but also with payload, QtSQL seems to omit the payload. This means after a NOTIFY I would have to reread the complete VIEW instead of only updating the row which changed. This means, that the View(s) which depend on the model would have to be redrawn completely, instead of only updating the part which changed?