I intend to write a GUI application backed by SQL. Several of the
windows display status that would best be represented as a database
view. What I've been thinking about is how to update the GUI when the
view changes.
First the obvious approach: polling. Every X seconds re-execute the
query and redraw the GUI. Certainly this will work, and I might still
do this. For windows with very large state, however, this is not very
desirable.
The approach I'd much prefer is to register a trigger to update the
GUI as follows:
create temp view StatusWidget as select .... some query ...;
create temp trigger StatusWidgetUpdate after update on StatusWidget
for each row
begin
select statusWidgetUpdateFn(OLD.key, NEW.key, NEW.value1,
NEW.value2, ...);
end;
ditto for Add/Delete
Then I create custom functions 'statusWidget{Add,Update,Delete}Fn'
that take the values and update the GUI.
Thus, a window simply provides the VIEW definition and insert/update/
delete callbacks. Some support code creates the view and insert()s
the current contents. Then it hooks the triggers invoking the methods
to catch future updates. On widget death, the view and triggers are
dropped.
It seems to me this would be a very bug-free way to design even
complicated applications. Whenever you create a window, back its
state with SQLite. Actions taken by the network or the user simply
modify state in the database. This in turn updates all the relevant
GUI windows automatically. You don't need to track the changes; you
let the database do it. This is only possible since callback
functions can be bound to triggers. AFAIK, no other database can do
this, since the triggers exist on the server-side.
However, the problem I'm running into is that I can't create before/
after triggers on a view:
SQL error: cannot create BEFORE trigger on view: main.popup
SQL error: cannot create AFTER trigger on view: main.popup
This isn't documented as an unimplemented SQL feature, so is this a bug?
If SQLite doesn't support triggers on views, does anyone know of a
database which does AND allows triggers to invoke a client-side
callback? Is supporting triggers on views planned for the future? Can
I help?
Thanks.
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------