Skip to content

Commit c478ba9

Browse files
committedJan 10, 2019
fixes #20547 : Fix error when using a spatialite layer with a non-int primary key an a spatial index
1 parent e8b057b commit c478ba9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎src/providers/spatialite/qgsspatialitefeatureiterator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
423423
mbrFilter += QStringLiteral( "ymax >= %1" ).arg( qgsDoubleToString( mFilterRect.yMinimum() ) );
424424
QString idxName = QStringLiteral( "idx_%1_%2" ).arg( mSource->mIndexTable, mSource->mIndexGeometry );
425425
whereClause += QStringLiteral( "%1 IN (SELECT pkid FROM %2 WHERE %3)" )
426-
.arg( quotedPrimaryKey(),
426+
.arg( QStringLiteral( "ROWID" ),
427427
QgsSqliteUtils::quotedIdentifier( idxName ),
428428
mbrFilter );
429429
}
@@ -432,7 +432,7 @@ QString QgsSpatiaLiteFeatureIterator::whereClauseRect()
432432
// using the MbrCache spatial index
433433
QString idxName = QStringLiteral( "cache_%1_%2" ).arg( mSource->mIndexTable, mSource->mIndexGeometry );
434434
whereClause += QStringLiteral( "%1 IN (SELECT rowid FROM %2 WHERE mbr = FilterMbrIntersects(%3))" )
435-
.arg( quotedPrimaryKey(),
435+
.arg( QStringLiteral( "ROWID" ),
436436
QgsSqliteUtils::quotedIdentifier( idxName ),
437437
mbr( mFilterRect ) );
438438
}
@@ -506,7 +506,7 @@ bool QgsSpatiaLiteFeatureIterator::getFeature( sqlite3_stmt *stmt, QgsFeature &f
506506
{
507507
if ( ic == 0 )
508508
{
509-
if ( mHasPrimaryKey )
509+
if ( mHasPrimaryKey && sqlite3_column_type( stmt, ic ) == SQLITE_INTEGER )
510510
{
511511
// first column always contains the ROWID (or the primary key)
512512
QgsFeatureId fid = sqlite3_column_int64( stmt, ic );

0 commit comments

Comments
 (0)
Please sign in to comment.