Skip to content

Commit f393b13

Browse files
committedMay 26, 2020
WFS provider: add more details to log message when creation of temporary SpatiaLite cache fails
Should help in the diagnosis of issue #36545
1 parent 3ac41e3 commit f393b13

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
 

‎src/providers/wfs/qgsbackgroundcachedshareddata.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,18 @@ bool QgsBackgroundCachedSharedData::createCache()
198198
if ( mDistinctSelect )
199199
cacheFields.append( QgsField( QgsBackgroundCachedFeatureIteratorConstants::FIELD_MD5, QVariant::String, QStringLiteral( "string" ) ) );
200200

201+
const auto logMessageWithReason = [this]( const QString & reason )
202+
{
203+
QgsMessageLog::logMessage( QStringLiteral( "%1: %2" ).arg( QObject::tr( "Cannot create temporary SpatiaLite cache." ) ).arg( reason ), mComponentTranslated );
204+
};
205+
201206
// Creating a SpatiaLite database can be quite slow on some file systems
202207
// so we create a GDAL in-memory file, and then copy it on
203208
// the file system.
204209
GDALDriverH hDrv = GDALGetDriverByName( "SQLite" );
205210
if ( !hDrv )
206211
{
207-
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache." ), mComponentTranslated );
212+
logMessageWithReason( QStringLiteral( "GDAL SQLite driver not available" ) );
208213
return false;
209214
}
210215
QString vsimemFilename;
@@ -215,7 +220,7 @@ bool QgsBackgroundCachedSharedData::createCache()
215220
GDALDatasetH hDS = GDALCreate( hDrv, vsimemFilename.toUtf8().constData(), 0, 0, 0, GDT_Unknown, const_cast<char **>( apszOptions ) );
216221
if ( !hDS )
217222
{
218-
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache." ), mComponentTranslated );
223+
logMessageWithReason( QStringLiteral( "GDALCreate() failed: %1" ).arg( CPLGetLastErrorMsg() ) );
219224
return false;
220225
}
221226
GDALClose( hDS );
@@ -224,7 +229,7 @@ bool QgsBackgroundCachedSharedData::createCache()
224229
vsi_l_offset nLength = 0;
225230
GByte *pabyData = VSIGetMemFileBuffer( vsimemFilename.toStdString().c_str(), &nLength, TRUE );
226231
Q_ASSERT( !QFile::exists( mCacheDbname ) );
227-
VSILFILE *fp = VSIFOpenL( mCacheDbname.toStdString().c_str(), "wb " );
232+
VSILFILE *fp = VSIFOpenL( mCacheDbname.toStdString().c_str(), "wb" );
228233
if ( fp )
229234
{
230235
VSIFWriteL( pabyData, 1, nLength, fp );
@@ -234,7 +239,7 @@ bool QgsBackgroundCachedSharedData::createCache()
234239
else
235240
{
236241
CPLFree( pabyData );
237-
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache" ), mComponentTranslated );
242+
logMessageWithReason( QStringLiteral( "Cannot copy file to %1: %2" ).arg( mCacheDbname ).arg( CPLGetLastErrorMsg() ) );
238243
return false;
239244
}
240245

@@ -245,6 +250,7 @@ bool QgsBackgroundCachedSharedData::createCache()
245250
spatialite_database_unique_ptr database;
246251
bool ret = true;
247252
int rc = database.open( mCacheDbname );
253+
QString failedSql;
248254
if ( rc == SQLITE_OK )
249255
{
250256
QString sql;
@@ -277,6 +283,7 @@ bool QgsBackgroundCachedSharedData::createCache()
277283
if ( rc != SQLITE_OK )
278284
{
279285
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
286+
if ( failedSql.isEmpty() ) failedSql = sql;
280287
ret = false;
281288
}
282289

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

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

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

@@ -314,6 +324,7 @@ bool QgsBackgroundCachedSharedData::createCache()
314324
if ( rc != SQLITE_OK )
315325
{
316326
QgsDebugMsg( QStringLiteral( "%1 failed" ).arg( sql ) );
327+
if ( failedSql.isEmpty() ) failedSql = sql;
317328
ret = false;
318329
}
319330
}
@@ -326,7 +337,7 @@ bool QgsBackgroundCachedSharedData::createCache()
326337
}
327338
if ( !ret )
328339
{
329-
QgsMessageLog::logMessage( QObject::tr( "Cannot create temporary SpatiaLite cache" ), mComponentTranslated );
340+
logMessageWithReason( QStringLiteral( "SQL request %1 failed" ).arg( failedSql ) );
330341
return false;
331342
}
332343

0 commit comments

Comments
 (0)
Please sign in to comment.