Results 1 to 3 of 3

Thread: Database Connetions

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Database Connetions

    Hi guys,

    The documentation talks about how to open connections, execute SQL queries, however no further discussion is provided in terms of the processing that happens in the background. When you open the connection to a database db.open, what actually happens/what does that mean? I don't understand how long this connection to the database should last. Does it close at the end of the function i.e. once all the function local variables get pulled off the stack or does it remain active and you're able to just db.exec at will in other functions?

    Also, any thoughts on globally declaring a database object?

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Database Connetions

    If you are not using an embedded db or sqllite, a tcp connection is established at db.open.
    A db connection must be closed otherwise it will remain active. The database itself might decide to close a connection after certain timeout if so configured.
    Instead of globally declaring a database object, you can re-use QSqlDatabase::database for a default. Or by string. Remember the rules about sharing and passing on QSqlDatabase in threading though.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Database Connetions

    Quote Originally Posted by Atomic_Sheep View Post
    When you open the connection to a database db.open, what actually happens/what does that mean? I don't understand how long this connection to the database should last. Does it close at the end of the function i.e. once all the function local variables get pulled off the stack or does it remain active and you're able to just db.exec at will in other functions?
    This is all dependent on the underlying SQL driver.

    Also, any thoughts on globally declaring a database object?
    That's usually a bad idea. You can always retrieve the connection object with a static QSqlDatabase::database() call.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt Qml database
    By ganeshgladish in forum Newbie
    Replies: 0
    Last Post: 5th June 2013, 18:43
  2. QSQLITE database changes not showing up in database
    By Cyrebo in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2013, 23:18
  3. Replies: 2
    Last Post: 27th August 2012, 03:27
  4. [SOLVED] database opened .. database not open
    By kapitanluffy in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 10:39
  5. Replies: 9
    Last Post: 20th May 2010, 09:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.