Skip to content

Commit f18b898

Browse files
authoredMar 15, 2017
Merge pull request #4258 from rouault/ogr_isfieldsetandnotnull
[OGR provider] Use OGR_F_IsFieldSetAndNotNull() when available.
2 parents e2d7181 + 47dd83d commit f18b898

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed
 

‎src/core/qgsogrutils.cpp

Lines changed: 8 additions & 1 deletion
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

Lines changed: 11 additions & 4 deletions
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" )
@@ -2921,7 +2928,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
29212928
OGRFeatureH f;
29222929
while ( ( f = OGR_L_GetNextFeature( l ) ) )
29232930
{
2924-
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
2931+
uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
29252932
OGR_F_Destroy( f );
29262933

29272934
if ( limit >= 0 && uniqueValues.size() >= limit )
@@ -2967,7 +2974,7 @@ QStringList QgsOgrProvider::uniqueStringsMatching( int index, const QString &sub
29672974
OGRFeatureH f;
29682975
while ( ( f = OGR_L_GetNextFeature( l ) ) )
29692976
{
2970-
if ( OGR_F_IsFieldSet( f, 0 ) )
2977+
if ( OGR_F_IsFieldSetAndNotNull( f, 0 ) )
29712978
results << textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) );
29722979
OGR_F_Destroy( f );
29732980

@@ -3010,7 +3017,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
30103017
return QVariant();
30113018
}
30123019

3013-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
3020+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
30143021
OGR_F_Destroy( f );
30153022

30163023
OGR_DS_ReleaseResultSet( ogrDataSource, l );
@@ -3049,7 +3056,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const
30493056
return QVariant();
30503057
}
30513058

3052-
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
3059+
QVariant value = OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
30533060
OGR_F_Destroy( f );
30543061

30553062
OGR_DS_ReleaseResultSet( ogrDataSource, l );

0 commit comments

Comments
 (0)
Please sign in to comment.