Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is that leaving the sqlite db open for lifetime of the application is good approach

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 478 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kowtham Prabu
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • K Kowtham Prabu

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • HoMaH Offline
        HoMaH Offline
        HoMa
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kowtham Prabu
          wrote on last edited by
          #4

          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.

          JonBJ 1 Reply Last reply
          0
          • K Kowtham Prabu

            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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

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

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved