Skip to content

Commit 40c6896

Browse files
committedDec 18, 2018
check for GDAL Version and exclude by ifdef
1 parent de12239 commit 40c6896

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed
 

‎src/core/qgsogrutils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ QgsFields QgsOgrUtils::readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding )
152152
varType = QVariant::DateTime;
153153
break;
154154
case OFTString:
155+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
155156
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
156157
varType = QVariant::Map;
157158
else
158159
varType = QVariant::String;
159160
break;
161+
#endif
160162
default:
161163
varType = QVariant::String; // other unsupported, leave it as a string
162164
}

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
155155
ogrType = OFTDateTime;
156156
break;
157157
158-
//not sure if needed, but for consistency
158+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
159159
case QVariant::Map:
160160
ogrType = OFTString;
161161
ogrSubType = OFSTJSON;
162162
break;
163-
163+
#endif
164164
default:
165165
return false;
166166
}
@@ -1049,6 +1049,7 @@ void QgsOgrProvider::loadFields()
10491049
break;
10501050

10511051
case OFTString:
1052+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
10521053
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
10531054
{
10541055
ogrSubType = OFSTJSON;
@@ -1061,6 +1062,7 @@ void QgsOgrProvider::loadFields()
10611062
varType = QVariant::String;
10621063
}
10631064
break;
1065+
#endif
10641066
default:
10651067
varType = QVariant::String; // other unsupported, leave it as a string
10661068
}
@@ -1531,6 +1533,8 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
15311533
case OFTString:
15321534
{
15331535
QString stringValue;
1536+
1537+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
15341538
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
15351539
{
15361540
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( attrVal.toMap() ).toJson().data() );
@@ -1543,7 +1547,9 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
15431547
{
15441548
stringValue = attrVal.toString();
15451549
}
1546-
1550+
#else
1551+
stringValue = attrVal.toString();
1552+
#endif
15471553
QgsDebugMsgLevel( QStringLiteral( "Writing string attribute %1 with %2, encoding %3" )
15481554
.arg( qgisAttId )
15491555
.arg( attrVal.toString(),
@@ -1689,9 +1695,11 @@ bool QgsOgrProvider::addAttributeOGRLevel( const QgsField &field, bool &ignoreEr
16891695
case QVariant::Bool:
16901696
OGR_Fld_SetSubType( fielddefn.get(), OFSTBoolean );
16911697
break;
1698+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
16921699
case QVariant::Map:
16931700
OGR_Fld_SetSubType( fielddefn.get(), OFSTJSON );
16941701
break;
1702+
#endif
16951703
default:
16961704
break;
16971705
}
@@ -2121,6 +2129,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
21212129
case OFTString:
21222130
{
21232131
QString stringValue;
2132+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
21242133
if ( OGR_Fld_GetSubType( fd ) == OFSTJSON )
21252134
{
21262135
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( it2->toMap() ).toJson().data() );
@@ -2133,7 +2142,9 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
21332142
{
21342143
stringValue = it2->toString();
21352144
}
2136-
2145+
#else
2146+
stringValue = it2->toString();
2147+
#endif
21372148
OGR_F_SetFieldString( of.get(), f, textEncoding()->fromUnicode( stringValue ).constData() );
21382149
break;
21392150
}

‎tests/src/python/test_provider_ogr_gpkg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,9 @@ def testTransaction(self):
12311231
del vl2_external
12321232

12331233
def testJson(self):
1234+
if int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0):
1235+
return
1236+
12341237
tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
12351238
testdata_path = unitTestDataPath('provider')
12361239
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)

0 commit comments

Comments
 (0)
Please sign in to comment.