Skip to content

Commit

Permalink
OGR: Add SQL query logger
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Dec 28, 2022
1 parent 2712aed commit e166ae4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgsogrtransaction.h"
#include "qgssymbol.h"
#include "qgsgeometryengine.h"
#include "qgsdbquerylog.h"

#include <QTextCodec>
#include <QFile>
Expand Down Expand Up @@ -279,6 +280,23 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
std::sort( mRequestAttributes.begin(), mRequestAttributes.end() );
}

// Install query logger
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,7,0)
GDALDatasetSetQueryLoggerFunc( mConn->ds, [ ]( const char *pszSQL, const char *pszError, int64_t lNumRecords, int64_t lExecutionTimeMilliseconds, void *pQueryLoggerArg )
{
QgsDatabaseQueryLogEntry entry;
entry.initiatorClass = QStringLiteral( "QgsOgrFeatureIterator" );
entry.origin = QGS_QUERY_LOG_ORIGIN;
entry.provider = QStringLiteral( "ogr" );
entry.uri = *reinterpret_cast<QString *>( pQueryLoggerArg );
entry.query = QString( pszSQL );
entry.error = QString( pszError );
entry.startedTime = QDateTime::currentMSecsSinceEpoch() - lExecutionTimeMilliseconds;
entry.fetchedRows = lNumRecords;
QgsApplication::databaseQueryLog()->log( entry );
QgsApplication::databaseQueryLog()->finished( entry );
}, reinterpret_cast<void *>( &mConn->path ) );
#endif
//start with first feature
rewind();

Expand Down
1 change: 1 addition & 0 deletions src/core/providers/ogr/qgsogrfeatureiterator.h
Expand Up @@ -126,6 +126,7 @@ class QgsOgrFeatureIterator final: public QgsAbstractFeatureIteratorFromSource<Q
bool fetchFeatureWithId( QgsFeatureId id, QgsFeature &feature ) const;

void resetReading();

};

///@endcond
Expand Down

0 comments on commit e166ae4

Please sign in to comment.