Skip to content
Permalink
Browse files

Merge pull request #6130 from elpaso/bugfix-17915-geopackage-delete-w…

…rong-layer

[bugfix] Fixes 17915 geopackage delete wrong layer
  • Loading branch information
elpaso committed Jan 22, 2018
2 parents 5016142 + f235e93 commit f69c1cfc496f63ca12151b447cf97fa38d4eb18c
Showing with 65 additions and 57 deletions.
  1. +21 −21 src/providers/ogr/qgsgeopackagedataitems.cpp
  2. +44 −36 src/providers/ogr/qgsogrprovider.cpp
@@ -379,11 +379,11 @@ bool QgsGeoPackageCollectionItem::deleteGeoPackageRasterLayer( const QString &ur
layerName.toUtf8().constData(),
layerName.toUtf8().constData() );
status = sqlite3_exec(
database.get(), /* An open database */
sql, /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
&errmsg /* Error msg written here */
database.get(), /* An open database */
sql, /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
&errmsg /* Error msg written here */
);
sqlite3_free( sql );
// Remove from optional tables, may silently fail
@@ -396,11 +396,11 @@ bool QgsGeoPackageCollectionItem::deleteGeoPackageRasterLayer( const QString &ur
tableName.toUtf8().constData(),
layerName.toUtf8().constData() );
( void )sqlite3_exec(
database.get(), /* An open database */
database.get(), /* An open database */
sql, /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
);
sqlite3_free( sql );
}
@@ -409,34 +409,34 @@ bool QgsGeoPackageCollectionItem::deleteGeoPackageRasterLayer( const QString &ur
char *sql = sqlite3_mprintf( "DELETE FROM gpkg_2d_gridded_coverage_ancillary WHERE tile_matrix_set_name = '%q'",
layerName.toUtf8().constData() );
( void )sqlite3_exec(
database.get(), /* An open database */
database.get(), /* An open database */
sql, /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
);
sqlite3_free( sql );
}
{
char *sql = sqlite3_mprintf( "DELETE FROM gpkg_2d_gridded_tile_ancillary WHERE tpudt_name = '%q'",
layerName.toUtf8().constData() );
( void )sqlite3_exec(
database.get(), /* An open database */
database.get(), /* An open database */
sql, /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
);
sqlite3_free( sql );
}
// Vacuum
{
( void )sqlite3_exec(
database.get(), /* An open database */
database.get(), /* An open database */
"VACUUM", /* SQL to be evaluated */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
nullptr, /* Callback function */
nullptr, /* 1st argument to callback */
nullptr /* Error msg written here */
);
}

@@ -5741,57 +5741,65 @@ QGISEXTERN bool deleteLayer( const QString &uri, QString &errCause )
subsetString,
ogrGeometryType );


GDALDatasetH hDS = GDALOpenEx( filePath.toLocal8Bit().data(), GDAL_OF_RASTER | GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr );
if ( hDS && ( ! layerName.isEmpty() || layerIndex != -1 ) )
{
if ( layerIndex == -1 )
// If we have got a name we convert it into an index
if ( ! layerName.isEmpty() )
{
layerIndex = -1;
for ( int i = 0; i < GDALDatasetGetLayerCount( hDS ); i++ )
{
OGRLayerH hL = GDALDatasetGetLayer( hDS, i );
if ( layerName == QString( OGR_L_GetName( hL ) ) )
{
layerIndex = i;
break;
}
}
}
OGRErr error = GDALDatasetDeleteLayer( hDS, layerIndex );
switch ( error )
// Do delete!
if ( layerIndex != -1 )
{
case OGRERR_NOT_ENOUGH_DATA:
errCause = QObject::tr( "Not enough data to deserialize" );
break;
case OGRERR_NOT_ENOUGH_MEMORY:
errCause = QObject::tr( "Not enough memory" );
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
errCause = QObject::tr( "Unsupported geometry type" );
break;
case OGRERR_UNSUPPORTED_OPERATION:
errCause = QObject::tr( "Unsupported operation" );
break;
case OGRERR_CORRUPT_DATA:
errCause = QObject::tr( "Corrupt data" );
break;
case OGRERR_FAILURE:
errCause = QObject::tr( "Failure" );
break;
case OGRERR_UNSUPPORTED_SRS:
errCause = QObject::tr( "Unsupported SRS" );
break;
case OGRERR_INVALID_HANDLE:
errCause = QObject::tr( "Invalid handle" );
break;
case OGRERR_NON_EXISTING_FEATURE:
errCause = QObject::tr( "Non existing feature" );
break;
default:
case OGRERR_NONE:
errCause = QObject::tr( "Success" );
break;
OGRErr error = GDALDatasetDeleteLayer( hDS, layerIndex );
switch ( error )
{
case OGRERR_NOT_ENOUGH_DATA:
errCause = QObject::tr( "Not enough data to deserialize" );
break;
case OGRERR_NOT_ENOUGH_MEMORY:
errCause = QObject::tr( "Not enough memory" );
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
errCause = QObject::tr( "Unsupported geometry type" );
break;
case OGRERR_UNSUPPORTED_OPERATION:
errCause = QObject::tr( "Unsupported operation" );
break;
case OGRERR_CORRUPT_DATA:
errCause = QObject::tr( "Corrupt data" );
break;
case OGRERR_FAILURE:
errCause = QObject::tr( "Failure" );
break;
case OGRERR_UNSUPPORTED_SRS:
errCause = QObject::tr( "Unsupported SRS" );
break;
case OGRERR_INVALID_HANDLE:
errCause = QObject::tr( "Invalid handle" );
break;
case OGRERR_NON_EXISTING_FEATURE:
errCause = QObject::tr( "Non existing feature" );
break;
default:
case OGRERR_NONE:
errCause = QObject::tr( "Success" );
break;
}
errCause = QObject::tr( "GDAL result code: %1" ).arg( errCause );
return error == OGRERR_NONE;
}
errCause = QObject::tr( "GDAL result code: %1" ).arg( errCause );
return error == OGRERR_NONE;
}
// This should never happen:
errCause = QObject::tr( "Layer not found: %1" ).arg( uri );

0 comments on commit f69c1cf

Please sign in to comment.
You can’t perform that action at this time.