Skip to content

Commit

Permalink
wfs provider: fix invalid feature id assignment (fixes #29146)
Browse files Browse the repository at this point in the history
(cherry picked from commit 62b2406)
  • Loading branch information
jef-n committed Jun 17, 2019
1 parent 9cfc224 commit a8c171a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -1263,6 +1263,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
if ( stmt.step() == SQLITE_ROW )
{
f.setId( stmt.columnAsInt64( 0 ) );
Q_ASSERT( stmt.step() != SQLITE_ROW );
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -1054,6 +1054,8 @@ void QgsWFSSharedData::serializeFeatures( QVector<QgsWFSFeatureGmlIdPair> &featu
}
else
{
QString errorMsg;

auto sql = QgsSqlite3Mprintf( "SELECT qgisId, dbId FROM id_cache WHERE gmlid = '%q'",
gmlId.toUtf8().constData() );
auto stmt = mCacheIdDb.prepare( sql, resultCode );
Expand All @@ -1064,11 +1066,16 @@ void QgsWFSSharedData::serializeFeatures( QVector<QgsWFSFeatureGmlIdPair> &featu
QgsFeatureId oldDbId = stmt.columnAsInt64( 1 );
if ( dbId != oldDbId )
{
sql = QgsSqlite3Mprintf( "UPDATE id_cache SET dbId = NULL WHERE dbId = %lld",
dbId );
if ( mCacheIdDb.exec( sql, errorMsg ) != SQLITE_OK )
{
QgsMessageLog::logMessage( tr( "Problem when updating WFS id cache: %1 -> %2" ).arg( sql ).arg( errorMsg ), tr( "WFS" ) );
}

sql = QgsSqlite3Mprintf( "UPDATE id_cache SET dbId = %lld WHERE gmlid = '%q'",
dbId,
gmlId.toUtf8().constData() );
//QgsDebugMsg( QStringLiteral( "%1" ).arg( sql ) );
QString errorMsg;
if ( mCacheIdDb.exec( sql, errorMsg ) != SQLITE_OK )
{
QgsMessageLog::logMessage( tr( "Problem when updating WFS id cache: %1 -> %2" ).arg( sql ).arg( errorMsg ), tr( "WFS" ) );
Expand All @@ -1077,14 +1084,19 @@ void QgsWFSSharedData::serializeFeatures( QVector<QgsWFSFeatureGmlIdPair> &featu
}
else
{
sql = QgsSqlite3Mprintf( "UPDATE id_cache SET dbId = NULL WHERE dbId = %lld",
dbId );
if ( mCacheIdDb.exec( sql, errorMsg ) != SQLITE_OK )
{
QgsMessageLog::logMessage( tr( "Problem when updating WFS id cache: %1 -> %2" ).arg( sql ).arg( errorMsg ), tr( "WFS" ) );
}

qgisId = mNextCachedIdQgisId;
mNextCachedIdQgisId ++;
sql = QgsSqlite3Mprintf( "INSERT INTO id_cache (gmlid, dbId, qgisId) VALUES ('%q', %lld, %lld)",
gmlId.toUtf8().constData(),
dbId,
qgisId );
//QgsDebugMsg( QStringLiteral( "%1" ).arg( sql ) );
QString errorMsg;
if ( mCacheIdDb.exec( sql, errorMsg ) != SQLITE_OK )
{
QgsMessageLog::logMessage( tr( "Problem when updating WFS id cache: %1 -> %2" ).arg( sql ).arg( errorMsg ), tr( "WFS" ) );
Expand Down

0 comments on commit a8c171a

Please sign in to comment.