Results 1 to 12 of 12

Thread: long query executing

  1. #1
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default long query executing

    I execute query wich take about 5-6min. When I do this my application is freeze. Is there any chance to avoid this?

    I use firebird embeded database so I cant execut query in other thread.

    sory for my poor english.

  2. #2
    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: long query executing

    Why can't you execute the query in another thread?
    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.


  3. #3
    Join Date
    Oct 2010
    Location
    Grenoble, France
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: long query executing

    Yes, why not?
    Because execute your request in another thread is your only chance.
    You execute your request from the qt main loop (HMI thread) so your HMI is frozen until the request isn't finished.

    With a little bit of chance, and if you can do that, you can call QCoreApplication:rocessEvents() (static method)
    each time you can while you're executing your long treatment so the main loop will (try) to execute HMI request waiting for execution.
    Your HMI will execute some events (refresh some values for example) but your HMI will still look as frozen...

    Good luck

  4. #4
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: long query executing

    I cant use another thread because when I execute query I have open some sql table and cant close it. I use embeded firebird so I cant manage another connection to databse for second thread.
    Also I cant use rocessEvents() because I execute one statement (not in loop) and firebird engin do all work.

  5. #5
    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: long query executing

    If you do all queries in a separate thread, you don't have to worry about leaving an open table in the main thread.
    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.


  6. #6
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: long query executing

    so is it safe to do queries in separate thread with connection from main thread?

    I know I cant use one connection object for two queries running in the same time from two different threads.

  7. #7
    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: long query executing

    Quote Originally Posted by banita View Post
    so is it safe to do queries in separate thread with connection from main thread?
    If you're using Qt's SQL infrastructure then no but you can open the connection from the worker thread, right?
    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.


  8. #8
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: long query executing

    Should I create and open connection (con1) in thread which I use to execut queries?
    If I do that is it safe to use this connection(con1) to open and view sql table in main thread?

  9. #9
    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: long query executing

    Quote Originally Posted by banita View Post
    Should I create and open connection (con1) in thread which I use to execut queries?
    Yes.
    If I do that is it safe to use this connection(con1) to open and view sql table in main thread?
    No, it isn't.
    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.


  10. #10
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: long query executing

    so it is impossible to have open sql table in main thread and execute queries in other thread when I have one connection object. I cant close my table so I cant execute query in other thread(cant create another connection).

  11. #11
    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: long query executing

    Quote Originally Posted by banita View Post
    so it is impossible to have open sql table in main thread and execute queries in other thread when I have one connection object. I cant close my table so I cant execute query in other thread(cant create another connection).
    You can fetch the data for the table from the thread too. If that's not enough for you then sorry, you're out of luck.
    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.


  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: long query executing

    Is Firebird really limited to a single connection or am I missing something here? That doesn't seem to be the case from a quick glance at the docs.

    5 or 6 minutes to execute a single query on an embedded database seems a bit excessive. Is it trawling through billions of records or doing some convoluted outer-joining monstrosity? Can you do anything to speed this up? Indexes, temporary intermediate tables, split the work into stages etc.

Similar Threads

  1. problem while executing SQL query
    By sosanjay in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2009, 12:52
  2. Best way to abort long SQL query?
    By wdezell in forum Newbie
    Replies: 1
    Last Post: 11th September 2009, 22:05
  3. problem while executing Query
    By jjbabu in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 11:46
  4. Error executing SELECT query with QSQLITE
    By garfield85 in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2009, 18:05
  5. A problem with executing Qt 4.5.0
    By Dante in forum Installation and Deployment
    Replies: 20
    Last Post: 15th March 2009, 19:50

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.