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 Mar 20, 2017
1 parent 06e336b commit 8e71f1ec9e333a1fca218d2e5272a901f1a41e4e
Showing with 18 additions and 4 deletions.
  1. +8 −1 src/core/qgsogrutils.cpp
  2. +10 −3 src/providers/ogr/qgsogrprovider.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() )
{
@@ -57,6 +57,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" )
@@ -2913,7 +2920,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 )
@@ -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 );

0 comments on commit 8e71f1e

Please sign in to comment.