diff --git a/src/core/providers/ogr/qgsogrfeatureiterator.cpp b/src/core/providers/ogr/qgsogrfeatureiterator.cpp index 699677eb330..5710527a029 100644 --- a/src/core/providers/ogr/qgsogrfeatureiterator.cpp +++ b/src/core/providers/ogr/qgsogrfeatureiterator.cpp @@ -277,22 +277,25 @@ 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 ) + // Install query logger + if ( QgsApplication::databaseQueryLog()->enabled() ) { - QgsDatabaseQueryLogEntry entry; - entry.initiatorClass = QStringLiteral( "QgsOgrFeatureIterator" ); - entry.origin = QGS_QUERY_LOG_ORIGIN; - entry.provider = QStringLiteral( "ogr" ); - entry.uri = *reinterpret_cast( 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( &mConn->path ) ); + 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( 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( &mConn->path ) ); + } #endif //start with first feature rewind();