Skip to content

Commit 5fdde8a

Browse files
committed
[OGR provider] Use OGR_F_IsFieldSetAndNotNull() when available.
Starting with GDAL 2.2, there are 2 concepts: unset fields and null fields whereas previously there was only unset fields. For QGIS purposes, both states (unset/null) are equivalent. Cherry-picked from 47dd83d
1 parent b3579ab commit 5fdde8a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎src/providers/ogr/qgsogrfeatureiterator.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
// - mAttributeFields
3434
// - mEncoding
3535

36+
// Starting with GDAL 2.2, there are 2 concepts: unset fields and null fields
37+
// whereas previously there was only unset fields. For QGIS purposes, both
38+
// states (unset/null) are equivalent.
39+
#ifndef OGRNullMarker
40+
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
41+
#endif
3642

3743
QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
3844
: QgsAbstractFeatureIteratorFromSource<QgsOgrFeatureSource>( source, ownSource, request )
@@ -335,7 +341,7 @@ void QgsOgrFeatureIterator::getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature
335341

336342
QVariant value;
337343

338-
if ( OGR_F_IsFieldSet( ogrFet, attindex ) )
344+
if ( OGR_F_IsFieldSetAndNotNull( ogrFet, attindex ) )
339345
{
340346
switch ( mSource->mFields.at( attindex ).type() )
341347
{

‎src/providers/ogr/qgsogrprovider.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ email : sherman at mrcc.com
5555
#include <sys/vfs.h>
5656
#endif
5757

58+
// Starting with GDAL 2.2, there are 2 concepts: unset fields and null fields
59+
// whereas previously there was only unset fields. For QGIS purposes, both
60+
// states (unset/null) are equivalent.
61+
#ifndef OGRNullMarker
62+
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
63+
#endif
64+
5865
static const QString TEXT_PROVIDER_KEY = "ogr";
5966
static const QString TEXT_PROVIDER_DESCRIPTION =
6067
QString( "OGR data provider" )
@@ -2595,7 +2602,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
25952602
OGRFeatureH f;
25962603
while (( f = OGR_L_GetNextFeature( l ) ) )
25972604
{
2598-
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
2605+
uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
25992606
OGR_F_Destroy( f );
26002607

26012608
if ( limit >= 0 && uniqueValues.size() >= limit )
@@ -2637,7 +2644,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
26372644
return QVariant();
26382645
}
26392646

2640-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
2647+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
26412648
OGR_F_Destroy( f );
26422649

26432650
OGR_DS_ReleaseResultSet( ogrDataSource, l );
@@ -2676,7 +2683,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
26762683
return QVariant();
26772684
}
26782685

2679-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
2686+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
26802687
OGR_F_Destroy( f );
26812688

26822689
OGR_DS_ReleaseResultSet( ogrDataSource, l );

0 commit comments

Comments
 (0)