Results 1 to 7 of 7

Thread: QSqlDatabase and execution query time: increases each time!

  1. #1
    Join Date
    Mar 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QSqlDatabase and execution query time: increases each time!

    Hi at all,
    I'm sorry to be annoying but I'm new to qt and sometimes there is something that i really can't understand

    Specifically, I've a QSQLITE DB and when i try to do an insert or update query (no problem with select query) just like this:
    Qt Code:
    1. QString query = "UPDATE MovieDB SET ...etc...";
    2. QSqlQuery queryResult= QSqlQuery (db);
    3. queryResult.exec (query);
    4. std::cerr << qPrintable(queryResult.lastError().text());
    5. emit doneUp();
    To copy to clipboard, switch view to plain text mode 

    each time i invoke this function the time take to execute the query increase by one step.
    For example if the first time I take 0.5 seconds. the second time 1.0 seconds. then 1.5 seconds, and so on...
    I'm really in panic because I think there is nothing I can do to fix this...
    The lag problem, unluckily, it is only a query execution fault: in fact commenting that line [ queryResult.exec (query); ] the lag disapper.
    I don't know how to solve that.

    I appreciate every help, and thanks is advance.

    As usually sorry for my bad english

    Gianluigi

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSqlDatabase and execution query time: increases each time!

    Can you try if a transaction will increase performance?

    Qt Code:
    1. QString query = "UPDATE MovieDB SET ...etc...";
    2.  
    3. db.transaction();
    4.  
    5. QSqlQuery queryResult= QSqlQuery (db);
    6. queryResult.exec (query);
    7.  
    8. db.commit();
    9.  
    10. std::cerr << qPrintable(queryResult.lastError().text());
    11. emit doneUp();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QSqlDatabase and execution query time: increases each time!

    First of all: thanks for your reply!

    I've just tried: it do the same job -.-"

    I Think it is not a problem of performance itself...it is something like a bug in qsqlquery class...or a bug in the sqlite db...
    It seems like if every time it execute the query more than once...the first time it takes 0,5s, the second time i do the same query it take 1,0s, the third time 1,5s...it is linear...and it is very strange.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase and execution query time: increases each time!

    Can You create small compilable example with this behaviour ?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlDatabase and execution query time: increases each time!

    Sine the execution time constantly increases by the first "time duration", it sounds like you have somewhere an error in your code. Is your "QString query" always the same (with different values of course) or maybe you add new instructions to your query that the old ones also gets executed? How do you measure the time?

    Can you provide a minimal example reproducing your problem?

  6. #6
    Join Date
    Mar 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QSqlDatabase and execution query time: increases each time!

    Solved . Sorry for wasting your time
    Lykurg, you was right.
    The error was that the QObject::connect that calls the updatemethod (as a slot) was inserted in a for-cicle.
    I thought that even if the qobject::connect was setted 2,3 o more times the slot was called just one time. evidently I was wrong.
    The problem was something like this:
    Qt Code:
    1. QObject::connect(client SIGNAL(doUpdate(QString)), Database, SLOT (updateDB(QString)));
    2. QObject::connect(client SIGNAL(doUpdate(QString)), Database, SLOT (updateDB(QString)));
    3. .
    4. .
    5. .
    6. QObject::connect(client SIGNAL(doUpdate(QString)), Database, SLOT (updateDB(QString)));// n times the connect was setted
    To copy to clipboard, switch view to plain text mode 

    And then the update query will be executed N times for each single time that signal is emitted. I though instead that the query was executed just one time.
    I know that's stupid mistake i've done, but documentation lack in this point.

    Thanks at all and sorry again

    Gianluigi

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlDatabase and execution query time: increases each time!

    You can use Qt::UniqueConnection if you are unsure if the connection is already established and you only want the connection only once.

Similar Threads

  1. Replies: 1
    Last Post: 25th June 2010, 19:31
  2. Regerding execution of query
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 05:29
  3. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 10:10
  4. QSqlDatabase Time out no network to long....
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2007, 01:41
  5. <time.h>
    By mickey in forum General Programming
    Replies: 7
    Last Post: 3rd March 2006, 14:02

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.