16#ifndef QGSDBQUERYLOG_H
17#define QGSDBQUERYLOG_H
61 quint64 startedTime = 0;
66 quint64 finishedTime = 0;
86 long long fetchedRows = -1;
96 bool canceled =
false;
100 static QAtomicInt sQueryId;
106#include "qgsconfig.h"
107constexpr int sQueryLoggerFilePrefixLength = CMAKE_SOURCE_DIR[
sizeof( CMAKE_SOURCE_DIR ) - 1] ==
'/' ?
sizeof( CMAKE_SOURCE_DIR ) + 1 :
sizeof( CMAKE_SOURCE_DIR );
108#define QgsSetQueryLogClass(entry, _class) entry.initiatorClass = _class; entry.origin = QString(QString( __FILE__ ).mid( sQueryLoggerFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + ")");
109#define QGS_QUERY_LOG_ORIGIN QString(QString( __FILE__ ).mid( sQueryLoggerFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + ")")
211 static bool sEnabled;
221class QgsDatabaseQueryLogWrapper
226 QgsDatabaseQueryLogWrapper(
const QString &query,
const QString &uri,
const QString &provider,
const QString &initiatorClass,
const QString &origin )
230 mEntry.origin = origin;
231 mEntry.initiatorClass = initiatorClass;
232 mEntry.provider = provider;
236 ~QgsDatabaseQueryLogWrapper( )
241 void setFetchedRows(
long long fetchedRows )
243 mEntry.fetchedRows = fetchedRows;
246 void setQuery(
const QString &query )
248 mEntry.query = query;
251 void setError(
const QString &error )
253 mEntry.error = error;
258 mEntry.canceled =
true;
Encapsulates a logged database query.
QString query
The logged database query (e.g. the SQL query)
QString provider
Provider key.
QString initiatorClass
The QGIS class which initiated the query.
QString origin
Code file location for the query origin.
QString error
Error reported by the provider, normally blank.
Handles logging of database queries.
static void log(const QgsDatabaseQueryLogEntry &query)
Logs a database query as starting.
static bool enabled()
Returns true if logging is enabled.
static void setEnabled(bool enabled)
Enables query logging.
void queryFinished(const QgsDatabaseQueryLogEntry &query)
Emitted whenever a database query has finished executing.
static void finished(const QgsDatabaseQueryLogEntry &query)
Records that the database query has finished.
void queryStarted(const QgsDatabaseQueryLogEntry &query)
Emitted whenever a database query is started.
constexpr int sQueryLoggerFilePrefixLength
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)