mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Log execSql from connections API
This commit is contained in:
parent
98d5c263ff
commit
485cd0a15d
@ -46,6 +46,8 @@ Constructor for QgsDatabaseQueryLogEntry.
|
||||
|
||||
QString error;
|
||||
|
||||
bool canceled;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -201,7 +201,7 @@ void QgsDatabaseQueryLoggerQueryGroup::setFinished( const QgsDatabaseQueryLogEnt
|
||||
{
|
||||
if ( query.error.isEmpty() )
|
||||
{
|
||||
mStatus = Status::Complete;
|
||||
mStatus = query.canceled ? Status::Canceled : Status::Complete;
|
||||
addKeyValueNode( QObject::tr( "Total time (ms)" ), QLocale().toString( query.finishedTime - query.startedTime ) );
|
||||
if ( query.fetchedRows != -1 )
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "qgsfeedback.h"
|
||||
#include "qgsogrutils.h"
|
||||
#include "qgsfielddomain.h"
|
||||
#include "qgsdbquerylog.h"
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QRegularExpression>
|
||||
@ -351,8 +352,11 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities()
|
||||
QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnection::executeGdalSqlPrivate( const QString &sql, QgsFeedback *feedback ) const
|
||||
{
|
||||
|
||||
QgsDatabaseQueryLogWrapper logWrapper( sql, uri(), providerKey(), QStringLiteral( "QgsGeoPackageProviderConnection" ), QGS_QUERY_LOG_ORIGIN );
|
||||
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
{
|
||||
logWrapper.setCanceled();
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
}
|
||||
|
||||
@ -363,6 +367,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnecti
|
||||
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
{
|
||||
logWrapper.setCanceled();
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
}
|
||||
|
||||
@ -379,9 +384,9 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnecti
|
||||
results.setQueryExecutionTime( std::chrono::duration_cast<std::chrono::milliseconds>( end - begin ).count() );
|
||||
|
||||
gdal::ogr_feature_unique_ptr fet;
|
||||
|
||||
if ( fet.reset( OGR_L_GetNextFeature( ogrLayer ) ), fet )
|
||||
{
|
||||
|
||||
// pk column name
|
||||
QString pkColumnName;
|
||||
|
||||
@ -453,11 +458,13 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnecti
|
||||
|
||||
if ( ! errCause.isEmpty() )
|
||||
{
|
||||
logWrapper.setError( errCause );
|
||||
throw QgsProviderConnectionException( QObject::tr( "Error executing SQL statement %1: %2" ).arg( sql, errCause ) );
|
||||
}
|
||||
|
||||
OGR_L_ResetReading( ogrLayer );
|
||||
iterator->nextRow();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -475,6 +482,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnecti
|
||||
|
||||
if ( !errCause.isEmpty() )
|
||||
{
|
||||
logWrapper.setError( errCause );
|
||||
throw QgsProviderConnectionException( QObject::tr( "Error executing SQL %1: %2" ).arg( sql, errCause ) );
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,8 @@ class CORE_EXPORT QgsDatabaseQueryLogEntry
|
||||
QString origin;
|
||||
|
||||
/**
|
||||
* Number of fetched rows
|
||||
* Number of fetched/affected rows.
|
||||
* \warning Not all providers support this information.
|
||||
*/
|
||||
long long fetchedRows = -1;
|
||||
|
||||
@ -89,6 +90,11 @@ class CORE_EXPORT QgsDatabaseQueryLogEntry
|
||||
*/
|
||||
QString error;
|
||||
|
||||
/**
|
||||
* Canceled flag for user canceled queries.
|
||||
*/
|
||||
bool canceled = false;
|
||||
|
||||
private:
|
||||
|
||||
static QAtomicInt sQueryId;
|
||||
@ -247,6 +253,11 @@ class QgsDatabaseQueryLogWrapper
|
||||
mEntry.error = error;
|
||||
}
|
||||
|
||||
void setCanceled( )
|
||||
{
|
||||
mEntry.canceled = true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
QgsDatabaseQueryLogEntry mEntry;
|
||||
|
@ -1365,15 +1365,20 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsOracleProviderConnection::
|
||||
|
||||
QSqlQuery qry( *pconn.get() );
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
|
||||
QgsDatabaseQueryLogWrapper logWrapper { sql, uri(), providerKey(), QStringLiteral( "QgsAbstractDatabaseProviderConnection" ), QGS_QUERY_LOG_ORIGIN };
|
||||
|
||||
if ( !qry.exec( sql ) )
|
||||
{
|
||||
logWrapper.setError( qry.lastError().text() );
|
||||
throw QgsProviderConnectionException( QObject::tr( "SQL error: %1 returned %2" )
|
||||
.arg( qry.lastQuery(),
|
||||
qry.lastError().text() ) );
|
||||
}
|
||||
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
logWrapper.setCanceled();
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
|
||||
if ( qry.isActive() )
|
||||
{
|
||||
|
@ -1359,6 +1359,7 @@ PGresult *QgsPostgresConn::PQexec( const QString &query, bool logError, bool ret
|
||||
.arg( query ).arg( errorStatus ).arg( PQresultErrorMessage( res ) ) );
|
||||
}
|
||||
}
|
||||
logWrapper->setFetchedRows( PQntuples( res ) );
|
||||
return res;
|
||||
}
|
||||
if ( PQstatus() != CONNECTION_OK )
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsfeedback.h"
|
||||
#include "qgsdbquerylog.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QTextCodec>
|
||||
@ -466,8 +467,11 @@ void QgsSpatiaLiteProviderConnection::setDefaultCapabilities()
|
||||
QgsAbstractDatabaseProviderConnection::QueryResult QgsSpatiaLiteProviderConnection::executeSqlPrivate( const QString &sql, QgsFeedback *feedback ) const
|
||||
{
|
||||
|
||||
QgsDatabaseQueryLogWrapper logWrapper( sql, uri(), providerKey(), QStringLiteral( "QgsSpatiaLiteProviderConnection" ), QGS_QUERY_LOG_ORIGIN );
|
||||
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
{
|
||||
logWrapper.setCanceled();
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
}
|
||||
|
||||
@ -478,6 +482,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsSpatiaLiteProviderConnecti
|
||||
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
{
|
||||
logWrapper.setCanceled();
|
||||
return QgsAbstractDatabaseProviderConnection::QueryResult();
|
||||
}
|
||||
|
||||
@ -540,6 +545,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsSpatiaLiteProviderConnecti
|
||||
|
||||
if ( ! errCause.isEmpty() )
|
||||
{
|
||||
logWrapper.setError( errCause );
|
||||
throw QgsProviderConnectionException( QObject::tr( "Error executing SQL statement %1: %2" ).arg( sql, errCause ) );
|
||||
}
|
||||
|
||||
@ -562,6 +568,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsSpatiaLiteProviderConnecti
|
||||
|
||||
if ( !errCause.isEmpty() )
|
||||
{
|
||||
logWrapper.setError( errCause );
|
||||
throw QgsProviderConnectionException( QObject::tr( "Error executing SQL %1: %2" ).arg( sql, errCause ) );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user