Skip to content
Permalink
Browse files

[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
  • Loading branch information
rouault committed Jun 1, 2017
1 parent b3579ab commit 5fdde8a5ba89e4bb4ba4e008979a6b67742df9b0
Showing with 17 additions and 4 deletions.
  1. +7 −1 src/providers/ogr/qgsogrfeatureiterator.cpp
  2. +10 −3 src/providers/ogr/qgsogrprovider.cpp
@@ -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 )
@@ -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() )
{
@@ -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" )
@@ -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 )
@@ -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 );
@@ -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 );

0 comments on commit 5fdde8a

Please sign in to comment.
You can’t perform that action at this time.