Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is that leaving the sqlite db open for lifetime of the application is good approach



  • From the same thread, is that good approach to open and closing the database using different connection name. What are the consequences, if we leave the database open for the lifetime of the application vs opening and closing every time after each DDL operation. Based on the research, opening and closing of the connection is a costliest operation which is acceptable if the db is accessed from different thread.


  • Lifetime Qt Champion

    @Kowtham-Prabu You can simply open one connection in each thread and keep these connections open as long as their threads are running...



  • I do that - and I have a RAII class, which closes the connection with the "right" name in destructor when leaving scope. With that I have a pretty good overview which connections are open, which are closed. This is mainly important, because I use sqlite databases and need to copy the underlying files every now and then. For that I can make sure to have all connections closed.
    Another advantage: If I need to debug, why a connection is not closed, I just enumerate all connections and know from the name, where the bug happens.
    Best regards
    HoM



  • Thanks for the reply. Is that opening a database once through out the application life time is good approach over opening and closing the connection every time when a query to be executed. Could not see the advantage/disadvantages here with this approach.



  • @Kowtham-Prabu
    Personally I would not open/close a database each time I want to execute a query. Unless queries are very infrequent.


Log in to reply