From f4548273973c2d39def1be1822176488af0d7af1 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Tue, 19 Feb 2019 15:26:32 +0100 Subject: [PATCH] Explain why the workaround for GPKG/SQLite is necessary I've talked to Even for this one --- src/providers/ogr/qgsogrprovider.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index 8736ee35a9b..e2508c3c4bb 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -3622,6 +3622,9 @@ QSet QgsOgrProvider::uniqueValues( int index, int limit ) const QByteArray sql = "SELECT DISTINCT " + quotedIdentifier( textEncoding()->fromUnicode( fld.name() ) ); // GPKG/SQLite fid + // For GPKG an SQLITE drivers PK fields are not exposed as real fields, (and OGR_F_GetFID only + // works with GPKG), so we are adding an extra column that will become index 0 + // See https://issues.qgis.org/issues/21311 if ( ( mGDALDriverName == QLatin1String( "GPKG" ) || mGDALDriverName == QLatin1String( "SQLite" ) ) && mFirstFieldIsFid && index == 0 ) { @@ -3649,7 +3652,6 @@ QSet QgsOgrProvider::uniqueValues( int index, int limit ) const while ( f.reset( l->GetNextFeature() ), f ) { uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f.get(), 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f.get(), 0 ) ) ) : QVariant( fld.type() ) ); - if ( limit >= 0 && uniqueValues.size() >= limit ) break; }