Skip to content

Commit c155c0b

Browse files
rouaultnyalldawson
authored andcommittedApr 1, 2023
Use gdal::dataset_unique_ptr to store return of GDALOpenEx() (fixes #52052)
This avoids an implicit case from OGRDataSourceH to GDALDatasetH, that doesn't work with all compilers
1 parent b29bb72 commit c155c0b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed
 

‎src/core/providers/ogr/qgsgeopackagedataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ QVector<QgsDataItem *> QgsGeoPackageCollectionItem::createChildren()
216216
{
217217
// sniff database to see if it's just empty, or if something went wrong
218218
// note that we HAVE to use update here, or GDAL won't open an empty database
219-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( path.toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
219+
gdal::dataset_unique_ptr hDS( GDALOpenEx( path.toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
220220
if ( !hDS )
221221
{
222222
QString errorMessage;

‎src/core/providers/ogr/qgsogrproviderconnection.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
// QgsOgrProviderResultIterator
4141
//
4242

43-
QgsOgrProviderResultIterator::QgsOgrProviderResultIterator( gdal::ogr_datasource_unique_ptr hDS, OGRLayerH ogrLayer )
43+
QgsOgrProviderResultIterator::QgsOgrProviderResultIterator( gdal::dataset_unique_ptr hDS, OGRLayerH ogrLayer )
4444
: mHDS( std::move( hDS ) )
4545
, mOgrLayer( ogrLayer )
4646
{
@@ -450,7 +450,7 @@ void QgsOgrProviderConnection::setDefaultCapabilities()
450450
mCapabilities |= RenameField;
451451
#endif
452452

453-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
453+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
454454
if ( !hDS )
455455
{
456456
// fallback to read only otherwise
@@ -459,18 +459,18 @@ void QgsOgrProviderConnection::setDefaultCapabilities()
459459

460460
if ( hDS )
461461
{
462-
if ( OGR_DS_TestCapability( hDS.get(), ODsCCurveGeometries ) )
462+
if ( GDALDatasetTestCapability( hDS.get(), ODsCCurveGeometries ) )
463463
mGeometryColumnCapabilities |= GeometryColumnCapability::Curves;
464464

465-
if ( OGR_DS_TestCapability( hDS.get(), ODsCMeasuredGeometries ) )
465+
if ( GDALDatasetTestCapability( hDS.get(), ODsCMeasuredGeometries ) )
466466
mGeometryColumnCapabilities |= GeometryColumnCapability::M;
467467

468468
if ( !mSingleTableDataset )
469469
{
470-
if ( OGR_DS_TestCapability( hDS.get(), ODsCCreateLayer ) )
470+
if ( GDALDatasetTestCapability( hDS.get(), ODsCCreateLayer ) )
471471
mCapabilities |= CreateVectorTable;
472472

473-
if ( OGR_DS_TestCapability( hDS.get(), ODsCDeleteLayer ) )
473+
if ( GDALDatasetTestCapability( hDS.get(), ODsCDeleteLayer ) )
474474
mCapabilities |= DropVectorTable;
475475
}
476476
}
@@ -521,7 +521,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsOgrProviderConnection::exe
521521

522522
QString errCause;
523523
// try first using an editable datasource
524-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
524+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
525525
if ( !hDS )
526526
{
527527
// fallback to read only otherwise
@@ -668,7 +668,7 @@ QList<QgsVectorDataProvider::NativeType> QgsOgrProviderConnection::nativeTypes()
668668
QStringList QgsOgrProviderConnection::fieldDomainNames() const
669669
{
670670
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,5,0)
671-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
671+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
672672
if ( !hDS )
673673
{
674674
// In some cases (empty geopackage for example), opening in read-only
@@ -730,7 +730,7 @@ QList<Qgis::FieldDomainType> QgsOgrProviderConnection::supportedFieldDomainTypes
730730
QgsFieldDomain *QgsOgrProviderConnection::fieldDomain( const QString &name ) const
731731
{
732732
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
733-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
733+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
734734
if ( !hDS )
735735
{
736736
// In some cases (empty geopackage for example), opening in read-only
@@ -808,7 +808,7 @@ void QgsOgrProviderConnection::addFieldDomain( const QgsFieldDomain &domain, con
808808
QgsMessageLog::logMessage( QStringLiteral( "Schema is not supported by OGR, ignoring" ), QStringLiteral( "OGR" ), Qgis::MessageLevel::Info );
809809
}
810810

811-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
811+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
812812
if ( hDS )
813813
{
814814
if ( OGRFieldDomainH ogrDomain = QgsOgrUtils::convertFieldDomain( &domain ) )
@@ -914,7 +914,7 @@ QList<QgsWeakRelation> QgsOgrProviderConnection::relationships( const QString &s
914914
}
915915

916916
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
917-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
917+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
918918
if ( !hDS )
919919
{
920920
// In some cases (empty geopackage for example), opening in read-only

‎src/core/providers/ogr/qgsogrproviderconnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
struct QgsOgrProviderResultIterator: public QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator
2929
{
3030

31-
QgsOgrProviderResultIterator( gdal::ogr_datasource_unique_ptr hDS, OGRLayerH ogrLayer );
31+
QgsOgrProviderResultIterator( gdal::dataset_unique_ptr hDS, OGRLayerH ogrLayer );
3232

3333
~QgsOgrProviderResultIterator();
3434

@@ -38,7 +38,7 @@ struct QgsOgrProviderResultIterator: public QgsAbstractDatabaseProviderConnectio
3838

3939
private:
4040

41-
gdal::ogr_datasource_unique_ptr mHDS;
41+
gdal::dataset_unique_ptr mHDS;
4242
OGRLayerH mOgrLayer;
4343
QgsFields mFields;
4444
QVariantList mNextRow;

‎src/providers/spatialite/qgsspatialiteproviderconnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsSpatiaLiteProviderConnecti
478478
}
479479

480480
QString errCause;
481-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( pathFromUri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
481+
gdal::dataset_unique_ptr hDS( GDALOpenEx( pathFromUri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
482482
if ( hDS )
483483
{
484484

@@ -584,7 +584,7 @@ void QgsSpatialiteProviderResultIterator::setFields( const QgsFields &fields )
584584
}
585585

586586

587-
QgsSpatialiteProviderResultIterator::QgsSpatialiteProviderResultIterator( gdal::ogr_datasource_unique_ptr hDS, OGRLayerH ogrLayer )
587+
QgsSpatialiteProviderResultIterator::QgsSpatialiteProviderResultIterator( gdal::dataset_unique_ptr hDS, OGRLayerH ogrLayer )
588588
: mHDS( std::move( hDS ) )
589589
, mOgrLayer( ogrLayer )
590590
{

‎src/providers/spatialite/qgsspatialiteproviderconnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
struct QgsSpatialiteProviderResultIterator: public QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator
2727
{
28-
QgsSpatialiteProviderResultIterator( gdal::ogr_datasource_unique_ptr hDS, OGRLayerH ogrLayer );
28+
QgsSpatialiteProviderResultIterator( gdal::dataset_unique_ptr hDS, OGRLayerH ogrLayer );
2929

3030
~QgsSpatialiteProviderResultIterator();
3131

@@ -35,7 +35,7 @@ struct QgsSpatialiteProviderResultIterator: public QgsAbstractDatabaseProviderCo
3535

3636
private:
3737

38-
gdal::ogr_datasource_unique_ptr mHDS;
38+
gdal::dataset_unique_ptr mHDS;
3939
OGRLayerH mOgrLayer;
4040
QgsFields mFields;
4141
QVariantList mNextRow;

0 commit comments

Comments
 (0)
Please sign in to comment.