Skip to content
Permalink
Browse files
qgsvectorfilewriter.cpp: remove useless wrapper aroung OGROpen(), no …
…longer needed since we require GDAL >= 3.0
  • Loading branch information
rouault committed May 24, 2021
1 parent 9da78ed commit 786c3087ec23ee4e2ea0ce7228159bb7e09b11b2
Showing with 4 additions and 27 deletions.
  1. +4 −27 src/core/qgsvectorfilewriter.cpp
@@ -58,29 +58,6 @@
#include <cpl_string.h>
#include <gdal.h>

// Thin wrapper around OGROpen() to workaround a bug in GDAL < 2.3.1
// where a existing BNA file is wrongly reported to be openable in update mode
// but attempting to add features in it crashes the BNA driver.
static OGRDataSourceH myOGROpen( const char *pszName, int bUpdate, OGRSFDriverH *phDriver )
{
OGRSFDriverH hDriver = nullptr;
OGRDataSourceH hDS = OGROpen( pszName, bUpdate, &hDriver );
if ( hDS && bUpdate )
{
QString drvName = OGR_Dr_GetName( hDriver );
if ( drvName == QLatin1String( "BNA" ) )
{
OGR_DS_Destroy( hDS );
if ( phDriver )
*phDriver = nullptr;
return nullptr;
}
}
if ( phDriver )
*phDriver = hDriver;
return hDS;
}

QgsField QgsVectorFileWriter::FieldValueConverter::fieldDefinition( const QgsField &field )
{
return field;
@@ -369,7 +346,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
if ( action == CreateOrOverwriteFile )
mDS.reset( OGR_Dr_CreateDataSource( poDriver, vectorFileName.toUtf8().constData(), options ) );
else
mDS.reset( myOGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr ) );
mDS.reset( OGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr ) );

if ( options )
{
@@ -4104,7 +4081,7 @@ QStringList QgsVectorFileWriter::concatenateOptions( const QMap<QString, QgsVect
QgsVectorFileWriter::EditionCapabilities QgsVectorFileWriter::editionCapabilities( const QString &datasetName )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return QgsVectorFileWriter::EditionCapabilities();
QString drvName = OGR_Dr_GetName( hDriver );
@@ -4144,7 +4121,7 @@ bool QgsVectorFileWriter::targetLayerExists( const QString &datasetName,
const QString &layerNameIn )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return false;

@@ -4162,7 +4139,7 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString &datasetName,
const QgsAttributeList &attributes )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return false;
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS.get(), layerName.toUtf8().constData() );

0 comments on commit 786c308

Please sign in to comment.