Skip to content
Permalink
Browse files

check for GDAL Version and exclude by ifdef

  • Loading branch information
signedav committed Dec 18, 2018
1 parent de12239 commit 40c6896fb976c8dc8ed1b5ec7eeef684f0534243
Showing with 20 additions and 4 deletions.
  1. +2 −0 src/core/qgsogrutils.cpp
  2. +15 −4 src/providers/ogr/qgsogrprovider.cpp
  3. +3 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -152,11 +152,13 @@ QgsFields QgsOgrUtils::readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding )
varType = QVariant::DateTime;
break;
case OFTString:
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
varType = QVariant::Map;
else
varType = QVariant::String;
break;
#endif
default:
varType = QVariant::String; // other unsupported, leave it as a string
}
@@ -155,12 +155,12 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
ogrType = OFTDateTime;
break;
//not sure if needed, but for consistency
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
case QVariant::Map:
ogrType = OFTString;
ogrSubType = OFSTJSON;
break;
#endif
default:
return false;
}
@@ -1049,6 +1049,7 @@ void QgsOgrProvider::loadFields()
break;

case OFTString:
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
{
ogrSubType = OFSTJSON;
@@ -1061,6 +1062,7 @@ void QgsOgrProvider::loadFields()
varType = QVariant::String;
}
break;
#endif
default:
varType = QVariant::String; // other unsupported, leave it as a string
}
@@ -1531,6 +1533,8 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
case OFTString:
{
QString stringValue;

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
{
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( attrVal.toMap() ).toJson().data() );
@@ -1543,7 +1547,9 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
{
stringValue = attrVal.toString();
}

#else
stringValue = attrVal.toString();
#endif
QgsDebugMsgLevel( QStringLiteral( "Writing string attribute %1 with %2, encoding %3" )
.arg( qgisAttId )
.arg( attrVal.toString(),
@@ -1689,9 +1695,11 @@ bool QgsOgrProvider::addAttributeOGRLevel( const QgsField &field, bool &ignoreEr
case QVariant::Bool:
OGR_Fld_SetSubType( fielddefn.get(), OFSTBoolean );
break;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
case QVariant::Map:
OGR_Fld_SetSubType( fielddefn.get(), OFSTJSON );
break;
#endif
default:
break;
}
@@ -2121,6 +2129,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
case OFTString:
{
QString stringValue;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fd ) == OFSTJSON )
{
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( it2->toMap() ).toJson().data() );
@@ -2133,7 +2142,9 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
{
stringValue = it2->toString();
}

#else
stringValue = it2->toString();
#endif
OGR_F_SetFieldString( of.get(), f, textEncoding()->fromUnicode( stringValue ).constData() );
break;
}
@@ -1231,6 +1231,9 @@ def testTransaction(self):
del vl2_external

def testJson(self):
if int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0):
return

tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
testdata_path = unitTestDataPath('provider')
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)

0 comments on commit 40c6896

Please sign in to comment.
You can’t perform that action at this time.