From 8e71f1ec9e333a1fca218d2e5272a901f1a41e4e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 14 Mar 2017 15:40:05 +0100 Subject: [PATCH] [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 47dd83dd75c7f86fa59510a4b65c453f27fb3771 --- src/core/qgsogrutils.cpp | 9 ++++++++- src/providers/ogr/qgsogrprovider.cpp | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/qgsogrutils.cpp b/src/core/qgsogrutils.cpp index 3df9d8a9f615..859661eaf9e1 100644 --- a/src/core/qgsogrutils.cpp +++ b/src/core/qgsogrutils.cpp @@ -30,6 +30,13 @@ #define FROM8(x) QString::fromLocal8Bit(x) #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 + QgsFeature QgsOgrUtils::readOgrFeature( OGRFeatureH ogrFet, const QgsFields& fields, QTextCodec* encoding ) { QgsFeature feature; @@ -132,7 +139,7 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField if ( ok ) *ok = true; - if ( OGR_F_IsFieldSet( ogrFet, attIndex ) ) + if ( OGR_F_IsFieldSetAndNotNull( ogrFet, attIndex ) ) { switch ( fields.at( attIndex ).type() ) { diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index a019d60e522d..0a529d78342f 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -57,6 +57,13 @@ email : sherman at mrcc.com #include #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" ) @@ -2913,7 +2920,7 @@ void QgsOgrProvider::uniqueValues( int index, QList &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 ) @@ -2955,7 +2962,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 ); @@ -2994,7 +3001,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 );