summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@jollamobile.com>2014-07-22 13:22:10 +0200
committerRobin Burchell <robin+qt@viroteck.net>2014-07-24 03:31:14 +0200
commit25978c7f9e6fa66c0c6e1d0f8d196ba79e72e8d9 (patch)
tree4afea5ffe303520bbff7caed6fe03911a3d574f2 /src
parent4fcd5a3da9ae47d158c42b7b5ad1cde15c406579 (diff)
Show timing of all executed SQL queries
This also coincidentally fixes logging of prepared queries, which previously weren't logged. Change-Id: I41b3559080662284699ac3dfa4fa4236342c61d2 Done-by: John Brooks <john.brooks@jollamobile.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/sql/kernel/qsqlquery.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index 6b13eb02ed..2b1bd5feb1 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -43,6 +43,8 @@
//#define QT_DEBUG_SQL
+#include "qdebug.h"
+#include "qelapsedtimer.h"
#include "qatomic.h"
#include "qsqlrecord.h"
#include "qsqlresult.h"
@@ -370,6 +372,10 @@ bool QSqlQuery::isNull(const QString &name) const
bool QSqlQuery::exec(const QString& query)
{
+#ifdef QT_DEBUG_SQL
+ QElapsedTimer t;
+ t.start();
+#endif
if (d->ref.load() != 1) {
bool fo = isForwardOnly();
*this = QSqlQuery(driver()->createResult());
@@ -391,10 +397,14 @@ bool QSqlQuery::exec(const QString& query)
qWarning("QSqlQuery::exec: empty query");
return false;
}
+
+ bool retval = d->sqlResult->reset(query);
#ifdef QT_DEBUG_SQL
- qDebug("\n QSqlQuery: %s", query.toLocal8Bit().constData());
+ qDebug().nospace() << "Executed query (" << t.elapsed() << "ms, " << d->sqlResult->size()
+ << " results, " << d->sqlResult->numRowsAffected()
+ << " affected): " << d->sqlResult->lastQuery();
#endif
- return d->sqlResult->reset(query);
+ return retval;
}
/*!
@@ -989,12 +999,22 @@ bool QSqlQuery::prepare(const QString& query)
*/
bool QSqlQuery::exec()
{
+#ifdef QT_DEBUG_SQL
+ QElapsedTimer t;
+ t.start();
+#endif
d->sqlResult->resetBindCount();
if (d->sqlResult->lastError().isValid())
d->sqlResult->setLastError(QSqlError());
- return d->sqlResult->exec();
+ bool retval = d->sqlResult->exec();
+#ifdef QT_DEBUG_SQL
+ qDebug().nospace() << "Executed prepared query (" << t.elapsed() << "ms, "
+ << d->sqlResult->size() << " results, " << d->sqlResult->numRowsAffected()
+ << " affected): " << d->sqlResult->lastQuery();
+#endif
+ return retval;
}
/*! \enum QSqlQuery::BatchExecutionMode