Skip to content

Commit

Permalink
WFS provider: add more details to log message when creation of tempor…
Browse files Browse the repository at this point in the history
…ary SpatiaLite cache fails

Should help in the diagnosis of issue qgis#36545
  • Loading branch information
rouault committed May 26, 2020
1 parent bcea438 commit 96867bf
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/providers/wfs/qgsbackgroundcachedshareddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,18 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( mDistinctSelect )
cacheFields.append( QgsField( QgsBackgroundCachedFeatureIteratorConstants::FIELD_MD5, QVariant::String, QStringLiteral( "string" ) ) );

const auto logMessageWithReason = [this]( const QString & reason )
{
QgsMessageLog::logMessage( QStringLiteral( "%1: %2" ).arg( QObject::tr( "Cannot create temporary SpatiaLite cache." ) ).arg( reason ), mComponentTranslated );
};

// Creating a SpatiaLite database can be quite slow on some file systems
// so we create a GDAL in-memory file, and then copy it on
// the file system.
GDALDriverH hDrv = GDALGetDriverByName( "SQLite" );
if ( !hDrv )
{
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache." ), mComponentTranslated );
logMessageWithReason( QStringLiteral( "GDAL SQLite driver not available" ) );
return false;
}
QString vsimemFilename;
Expand All @@ -215,7 +220,7 @@ bool QgsBackgroundCachedSharedData::createCache()
GDALDatasetH hDS = GDALCreate( hDrv, vsimemFilename.toUtf8().constData(), 0, 0, 0, GDT_Unknown, const_cast<char **>( apszOptions ) );
if ( !hDS )
{
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache." ), mComponentTranslated );
logMessageWithReason( QStringLiteral( "GDALCreate() failed: %1" ).arg( CPLGetLastErrorMsg() ) );
return false;
}
GDALClose( hDS );
Expand All @@ -224,7 +229,7 @@ bool QgsBackgroundCachedSharedData::createCache()
vsi_l_offset nLength = 0;
GByte *pabyData = VSIGetMemFileBuffer( vsimemFilename.toStdString().c_str(), &nLength, TRUE );
Q_ASSERT( !QFile::exists( mCacheDbname ) );
VSILFILE *fp = VSIFOpenL( mCacheDbname.toStdString().c_str(), "wb " );
VSILFILE *fp = VSIFOpenL( mCacheDbname.toStdString().c_str(), "wb" );
if ( fp )
{
VSIFWriteL( pabyData, 1, nLength, fp );
Expand All @@ -234,7 +239,7 @@ bool QgsBackgroundCachedSharedData::createCache()
else
{
CPLFree( pabyData );
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache" ), mComponentTranslated );
logMessageWithReason( QStringLiteral( "Cannot copy file to %1: %2" ).arg( mCacheDbname ).arg( CPLGetLastErrorMsg() ) );
return false;
}

Expand All @@ -245,6 +250,7 @@ bool QgsBackgroundCachedSharedData::createCache()
spatialite_database_unique_ptr database;
bool ret = true;
int rc = database.open( mCacheDbname );
QString failedSql;
if ( rc == SQLITE_OK )
{
QString sql;
Expand Down Expand Up @@ -277,6 +283,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}

Expand All @@ -285,6 +292,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}

Expand All @@ -293,6 +301,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}

Expand All @@ -304,6 +313,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}

Expand All @@ -314,6 +324,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}
}
Expand All @@ -326,7 +337,7 @@ bool QgsBackgroundCachedSharedData::createCache()
}
if ( !ret )
{
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache" ), mComponentTranslated );
logMessageWithReason( QStringLiteral( "SQL request %1 failed" ).arg( failedSql ) );
return false;
}

Expand Down

0 comments on commit 96867bf

Please sign in to comment.