Skip to content

Commit

Permalink
Better boolean support detection for GDAL >= 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 12, 2017
1 parent c15ef22 commit bbc3055
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -466,20 +466,32 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri )
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), QStringLiteral( "datetime" ), QVariant::DateTime );
}

bool supportsBoolean = false;

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,3,0)
const char *pszDataTypes = GDALGetMetadataItem( mOgrOrigLayer->driver(), GDAL_DMD_CREATIONFIELDDATASUBTYPES, nullptr );
if ( pszDataTypes && strstr( pszDataTypes, "Boolean" ) )
supportsBoolean = true;
#else
if ( mGDALDriverName == QLatin1String( "GeoJSON" ) ||
mGDALDriverName == QLatin1String( "GML" ) ||
mGDALDriverName == QLatin1String( "CSV" ) ||
mGDALDriverName == QLatin1String( "PostgreSQL" ) ||
mGDALDriverName == QLatin1String( "PGDump" ) ||
mGDALDriverName == QLatin1String( "SQLite" ) ||
mGDALDriverName == QLatin1String( "GPKG" ) )
{
supportsBoolean = true;
}
#endif

if ( supportsBoolean )
{
// boolean data type
nativeTypes
<< QgsVectorDataProvider::NativeType( tr( "Boolean" ), QStringLiteral( "bool" ), QVariant::Bool, -1, -1, -1, -1 );
}


setNativeTypes( nativeTypes );

QgsOgrConnPool::instance()->ref( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ) ) );
Expand Down

0 comments on commit bbc3055

Please sign in to comment.