Skip to content

Commit 47dd83d

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.
1 parent 2654c72 commit 47dd83d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/core/qgsogrutils.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#include <QTextCodec>
2222
#include <QUuid>
2323

24+
// Starting with GDAL 2.2, there are 2 concepts: unset fields and null fields
25+
// whereas previously there was only unset fields. For QGIS purposes, both
26+
// states (unset/null) are equivalent.
27+
#ifndef OGRNullMarker
28+
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
29+
#endif
30+
2431
QgsFeature QgsOgrUtils::readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding )
2532
{
2633
QgsFeature feature;
@@ -119,7 +126,7 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
119126
if ( ok )
120127
*ok = true;
121128

122-
if ( OGR_F_IsFieldSet( ogrFet, attIndex ) )
129+
if ( OGR_F_IsFieldSetAndNotNull( ogrFet, attIndex ) )
123130
{
124131
switch ( fields.at( attIndex ).type() )
125132
{

src/providers/ogr/qgsogrprovider.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ email : sherman at mrcc.com
5656
#include <sys/vfs.h>
5757
#endif
5858

59+
// Starting with GDAL 2.2, there are 2 concepts: unset fields and null fields
60+
// whereas previously there was only unset fields. For QGIS purposes, both
61+
// states (unset/null) are equivalent.
62+
#ifndef OGRNullMarker
63+
#define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
64+
#endif
65+
5966
static const QString TEXT_PROVIDER_KEY = QStringLiteral( "ogr" );
6067
static const QString TEXT_PROVIDER_DESCRIPTION =
6168
QStringLiteral( "OGR data provider" )
@@ -2867,7 +2874,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
28672874
OGRFeatureH f;
28682875
while ( ( f = OGR_L_GetNextFeature( l ) ) )
28692876
{
2870-
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
2877+
uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
28712878
OGR_F_Destroy( f );
28722879

28732880
if ( limit >= 0 && uniqueValues.size() >= limit )
@@ -2913,7 +2920,7 @@ QStringList QgsOgrProvider::uniqueStringsMatching( int index, const QString &sub
29132920
OGRFeatureH f;
29142921
while ( ( f = OGR_L_GetNextFeature( l ) ) )
29152922
{
2916-
if ( OGR_F_IsFieldSet( f, 0 ) )
2923+
if ( OGR_F_IsFieldSetAndNotNull( f, 0 ) )
29172924
results << textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) );
29182925
OGR_F_Destroy( f );
29192926

@@ -2956,7 +2963,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
29562963
return QVariant();
29572964
}
29582965

2959-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
2966+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
29602967
OGR_F_Destroy( f );
29612968

29622969
OGR_DS_ReleaseResultSet( ogrDataSource, l );
@@ -2995,7 +3002,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const
29953002
return QVariant();
29963003
}
29973004

2998-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
3005+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
29993006
OGR_F_Destroy( f );
30003007

30013008
OGR_DS_ReleaseResultSet( ogrDataSource, l );

0 commit comments

Comments
 (0)