Refresh tableView when new row inserted in DB



  • Hi,

    I have a tableview that display the result of a sql query and i want to refresh that view when a new row is inserted in the sql table.
    How can i do ?

    • refresh every n minutes (not sexy)

    • triggered event in DB emits a signal (SqlDriver subscribed DB notification)
      The problem with this solution is that, to receive signal, the DB need to be open() all the time (not good i think).

    Wich way is the best ?
    Any better solution ?

    Thanks



  • personally I'd give the DB a name in your app and leave it open.
    As an alternative you can run a QTcpServer/QLocalServer on your application, build a small utility that connects to it and sends the infos of what was updated and shell the utility from a stored procedure



  • Isn't it bad to let the app and the db connected all the time ?
    I thought that the right way to use a db was to connect just before the query and close just after.
    Am i wrong ?



  • In general terms yes but it depends on how busy the DB is. if your application will always be the only DB connection leaving it open is totally fine.
    The problem comes from how many connections your database allows: MS SQL Server allows 32767 connections at any given time, SQLite (this is a guess) just 1.

    If you are confident you will never run out of connections leave the DB open, otherwise use the TCP method

    Edit:
    Thinking about how it should work you'll probably need 2 utility apps:
    1 server always running on a known location (the database server machine?) that your main app will connect to
    1 client shelled from the stored procedure that sends the info to the server, the server bounces the infos to the main app



  • Ok, i think i'll leave the DB open all the time.

    Thank you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.