Skip to content

Commit d1edbc8

Browse files
rouaultnyalldawson
authored andcommittedMar 13, 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 bbe6cfb commit d1edbc8

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// QgsOgrProviderResultIterator
4343
//
4444

45-
QgsOgrProviderResultIterator::QgsOgrProviderResultIterator( gdal::ogr_datasource_unique_ptr hDS, OGRLayerH ogrLayer )
45+
QgsOgrProviderResultIterator::QgsOgrProviderResultIterator( gdal::dataset_unique_ptr hDS, OGRLayerH ogrLayer )
4646
: mHDS( std::move( hDS ) )
4747
, mOgrLayer( ogrLayer )
4848
{
@@ -455,7 +455,7 @@ void QgsOgrProviderConnection::setDefaultCapabilities()
455455
mCapabilities |= RenameField;
456456
#endif
457457

458-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
458+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
459459
if ( !hDS )
460460
{
461461
// fallback to read only otherwise
@@ -464,18 +464,18 @@ void QgsOgrProviderConnection::setDefaultCapabilities()
464464

465465
if ( hDS )
466466
{
467-
if ( OGR_DS_TestCapability( hDS.get(), ODsCCurveGeometries ) )
467+
if ( GDALDatasetTestCapability( hDS.get(), ODsCCurveGeometries ) )
468468
mGeometryColumnCapabilities |= GeometryColumnCapability::Curves;
469469

470-
if ( OGR_DS_TestCapability( hDS.get(), ODsCMeasuredGeometries ) )
470+
if ( GDALDatasetTestCapability( hDS.get(), ODsCMeasuredGeometries ) )
471471
mGeometryColumnCapabilities |= GeometryColumnCapability::M;
472472

473473
if ( !mSingleTableDataset )
474474
{
475-
if ( OGR_DS_TestCapability( hDS.get(), ODsCCreateLayer ) )
475+
if ( GDALDatasetTestCapability( hDS.get(), ODsCCreateLayer ) )
476476
mCapabilities |= CreateVectorTable;
477477

478-
if ( OGR_DS_TestCapability( hDS.get(), ODsCDeleteLayer ) )
478+
if ( GDALDatasetTestCapability( hDS.get(), ODsCDeleteLayer ) )
479479
mCapabilities |= DropVectorTable;
480480
}
481481
}
@@ -646,7 +646,7 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsOgrProviderConnection::exe
646646

647647
QString errCause;
648648
// try first using an editable datasource
649-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
649+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
650650
if ( !hDS )
651651
{
652652
// fallback to read only otherwise
@@ -793,7 +793,7 @@ QList<QgsVectorDataProvider::NativeType> QgsOgrProviderConnection::nativeTypes()
793793
QStringList QgsOgrProviderConnection::fieldDomainNames() const
794794
{
795795
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,5,0)
796-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
796+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
797797
if ( !hDS )
798798
{
799799
// In some cases (empty geopackage for example), opening in read-only
@@ -855,7 +855,7 @@ QList<Qgis::FieldDomainType> QgsOgrProviderConnection::supportedFieldDomainTypes
855855
QgsFieldDomain *QgsOgrProviderConnection::fieldDomain( const QString &name ) const
856856
{
857857
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
858-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
858+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
859859
if ( !hDS )
860860
{
861861
// In some cases (empty geopackage for example), opening in read-only
@@ -933,7 +933,7 @@ void QgsOgrProviderConnection::addFieldDomain( const QgsFieldDomain &domain, con
933933
QgsMessageLog::logMessage( QStringLiteral( "Schema is not supported by OGR, ignoring" ), QStringLiteral( "OGR" ), Qgis::MessageLevel::Info );
934934
}
935935

936-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
936+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
937937
if ( hDS )
938938
{
939939
if ( OGRFieldDomainH ogrDomain = QgsOgrUtils::convertFieldDomain( &domain ) )
@@ -1059,7 +1059,7 @@ QList<QgsWeakRelation> QgsOgrProviderConnection::relationships( const QString &s
10591059
}
10601060

10611061
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
1062-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
1062+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
10631063
if ( !hDS )
10641064
{
10651065
// In some cases (empty geopackage for example), opening in read-only
@@ -1111,7 +1111,7 @@ void QgsOgrProviderConnection::addRelationship( const QgsWeakRelation &relations
11111111
checkCapability( Capability::AddRelationship );
11121112

11131113
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
1114-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
1114+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
11151115
if ( hDS )
11161116
{
11171117
const QVariantMap leftParts = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) )->decodeUri( relationship.referencedLayerSource() );
@@ -1156,7 +1156,7 @@ void QgsOgrProviderConnection::updateRelationship( const QgsWeakRelation &relati
11561156
checkCapability( Capability::UpdateRelationship );
11571157

11581158
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
1159-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
1159+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
11601160
if ( hDS )
11611161
{
11621162
const QVariantMap leftParts = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) )->decodeUri( relationship.referencedLayerSource() );
@@ -1201,7 +1201,7 @@ void QgsOgrProviderConnection::deleteRelationship( const QgsWeakRelation &relati
12011201
checkCapability( Capability::DeleteRelationship );
12021202

12031203
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
1204-
gdal::ogr_datasource_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
1204+
gdal::dataset_unique_ptr hDS( GDALOpenEx( uri().toUtf8().constData(), GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
12051205
if ( hDS )
12061206
{
12071207
const QString relationshipName = relationship.name();

‎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.