Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spatialite wrong feature count #37277

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5742,7 +5742,21 @@ bool QgsSpatiaLiteProvider::getTableSummaryAbstractInterface( gaiaVectorLayerPtr
{
mLayerExtent.set( lyr->ExtentInfos->MinX, lyr->ExtentInfos->MinY,
lyr->ExtentInfos->MaxX, lyr->ExtentInfos->MaxY );
mNumberFeatures = lyr->ExtentInfos->Count;
// This can be wrong! see: GH #29264
// mNumberFeatures = lyr->ExtentInfos->Count;
// Note: the unique ptr here does not own the handle, it is just used for the convenience
// methods available within the class.
sqlite3_database_unique_ptr slPtr;
slPtr.reset( sqliteHandle() );
int resultCode;
sqlite3_statement_unique_ptr stmt { slPtr.prepare( QStringLiteral( "SELECT COUNT(1) FROM %2" ).arg( mQuery ), resultCode )};
if ( resultCode == SQLITE_OK )
{
stmt.step();
mNumberFeatures = sqlite3_column_int64( stmt.get(), 0 );
}
// Note: the pointer handle is owned by the provider, releasing it
slPtr.release();
elpaso marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand All @@ -5762,7 +5776,7 @@ bool QgsSpatiaLiteProvider::getTableSummary()
int columns;
char *errMsg = nullptr;

QString sql = QStringLiteral( "SELECT Count(*)%1 FROM %2" )
QString sql = QStringLiteral( "SELECT Count(1)%1 FROM %2" )
.arg( mGeometryColumn.isEmpty() ? QString() : QStringLiteral( ",Min(MbrMinX(%1)),Min(MbrMinY(%1)),Max(MbrMaxX(%1)),Max(MbrMaxY(%1))" ).arg( QgsSqliteUtils::quotedIdentifier( mGeometryColumn ) ),
mQuery );

Expand Down