Install query logger only when needed

This commit is contained in:
Alessandro Pasotti 2022-12-28 13:15:02 +01:00
parent 43de538d95
commit b4d73caba8

View File

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