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:
Code:
QString query
= "UPDATE MovieDB SET ...etc...";
queryResult.exec (query);
std::cerr << qPrintable(queryResult.lastError().text());
emit doneUp();
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
Re: QSqlDatabase and execution query time: increases each time!
Can you try if a transaction will increase performance?
Code:
QString query
= "UPDATE MovieDB SET ...etc...";
db.transaction();
queryResult.exec (query);
db.commit();
std::cerr << qPrintable(queryResult.lastError().text());
emit doneUp();
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.
Re: QSqlDatabase and execution query time: increases each time!
Can You create small compilable example with this behaviour ?
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?
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:
Code:
.
.
.
QObject::connect(client
SIGNAL(doUpdate
(QString)), Database,
SLOT (updateDB
(QString)));
// n times the connect was setted
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
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.