Skip to content

Commit

Permalink
Merge pull request #4258 from rouault/ogr_isfieldsetandnotnull
Browse files Browse the repository at this point in the history
[OGR provider] Use OGR_F_IsFieldSetAndNotNull() when available.
  • Loading branch information
rouault committed Mar 15, 2017
2 parents e2d7181 + 47dd83d commit f18b898
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/core/qgsogrutils.cpp
Expand Up @@ -21,6 +21,13 @@
#include <QTextCodec>
#include <QUuid>

// 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;
Expand Down Expand Up @@ -119,7 +126,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() )
{
Expand Down
15 changes: 11 additions & 4 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -56,6 +56,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 = QStringLiteral( "ogr" );
static const QString TEXT_PROVIDER_DESCRIPTION =
QStringLiteral( "OGR data provider" )
Expand Down Expand Up @@ -2921,7 +2928,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(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
uniqueValues << ( OGR_F_IsFieldSetAndNotNull( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
OGR_F_Destroy( f );

if ( limit >= 0 && uniqueValues.size() >= limit )
Expand Down Expand Up @@ -2967,7 +2974,7 @@ QStringList QgsOgrProvider::uniqueStringsMatching( int index, const QString &sub
OGRFeatureH f;
while ( ( f = OGR_L_GetNextFeature( l ) ) )
{
if ( OGR_F_IsFieldSet( f, 0 ) )
if ( OGR_F_IsFieldSetAndNotNull( f, 0 ) )
results << textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) );
OGR_F_Destroy( f );

Expand Down Expand Up @@ -3010,7 +3017,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
return QVariant();
}

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

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down Expand Up @@ -3049,7 +3056,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const
return QVariant();
}

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

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down

0 comments on commit f18b898

Please sign in to comment.