Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes #20547 : Fix error when using a spatialite layer with a non-int…
… primary key an a spatial index
  • Loading branch information
troopa81 committed Jan 10, 2019
1 parent e8b057b commit c478ba9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -423,7 +423,7 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
mbrFilter += QStringLiteral( "ymax >= %1" ).arg( qgsDoubleToString( mFilterRect.yMinimum() ) );
QString idxName = QStringLiteral( "idx_%1_%2" ).arg( mSource->mIndexTable, mSource->mIndexGeometry );
whereClause += QStringLiteral( "%1 IN (SELECT pkid FROM %2 WHERE %3)" )
.arg( quotedPrimaryKey(),
.arg( QStringLiteral( "ROWID" ),
QgsSqliteUtils::quotedIdentifier( idxName ),
mbrFilter );
}
Expand All @@ -432,7 +432,7 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
// using the MbrCache spatial index
QString idxName = QStringLiteral( "cache_%1_%2" ).arg( mSource->mIndexTable, mSource->mIndexGeometry );
whereClause += QStringLiteral( "%1 IN (SELECT rowid FROM %2 WHERE mbr = FilterMbrIntersects(%3))" )
.arg( quotedPrimaryKey(),
.arg( QStringLiteral( "ROWID" ),
QgsSqliteUtils::quotedIdentifier( idxName ),
mbr( mFilterRect ) );
}
Expand Down Expand Up @@ -506,7 +506,7 @@ bool QgsSpatiaLiteFeatureIterator::getFeature( sqlite3_stmt *stmt, QgsFeature &f
{
if ( ic == 0 )
{
if ( mHasPrimaryKey )
if ( mHasPrimaryKey && sqlite3_column_type( stmt, ic ) == SQLITE_INTEGER )
{
// first column always contains the ROWID (or the primary key)
QgsFeatureId fid = sqlite3_column_int64( stmt, ic );
Expand Down

0 comments on commit c478ba9

Please sign in to comment.