Skip to content

Commit

Permalink
[OGR provider] Use OGR_F_IsFieldSetAndNotNull() when available.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rouault committed Jun 1, 2017
1 parent b3579ab commit 5fdde8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -33,6 +33,12 @@
// - mAttributeFields
// - mEncoding

// 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.
#ifndef OGRNullMarker
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
#endif

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

QVariant value;

if ( OGR_F_IsFieldSet( ogrFet, attindex ) )
if ( OGR_F_IsFieldSetAndNotNull( ogrFet, attindex ) )
{
switch ( mSource->mFields.at( attindex ).type() )
{
Expand Down
13 changes: 10 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -55,6 +55,13 @@ email : sherman at mrcc.com
#include <sys/vfs.h>
#endif

// 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.
#ifndef OGRNullMarker
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
#endif

static const QString TEXT_PROVIDER_KEY = "ogr";
static const QString TEXT_PROVIDER_DESCRIPTION =
QString( "OGR data provider" )
Expand Down Expand Up @@ -2595,7 +2602,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
OGRFeatureH f;
while (( f = OGR_L_GetNextFeature( l ) ) )
{
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
OGR_F_Destroy( f );

if ( limit >= 0 && uniqueValues.size() >= limit )
Expand Down Expand Up @@ -2637,7 +2644,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
return QVariant();
}

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

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down Expand Up @@ -2676,7 +2683,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
return QVariant();
}

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

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down

0 comments on commit 5fdde8a

Please sign in to comment.