Skip to content
Permalink
Browse files

WFS provider: add more details to log message when creation of tempor…

…ary SpatiaLite cache fails

Should help in the diagnosis of issue #36545
  • Loading branch information
rouault committed May 26, 2020
1 parent 3ac41e3 commit f393b13da7140f5e6ba6973e8dc56e5ee7554324
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/providers/wfs/qgsbackgroundcachedshareddata.cpp
@@ -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;
@@ -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 );
@@ -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 );
@@ -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;
}

@@ -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;
@@ -277,6 +283,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}

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

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

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

@@ -314,6 +324,7 @@ bool QgsBackgroundCachedSharedData::createCache()
if ( rc != SQLITE_OK )
{
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
if ( failedSql.isEmpty() ) failedSql = sql;
ret = false;
}
}
@@ -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;
}

0 comments on commit f393b13

Please sign in to comment.
You can’t perform that action at this time.