Skip to content
Permalink
Browse files

Merge pull request #5055 from boundlessgeo/gpkg-fix-delete-layers

Geopackage: fix crash when deleting raster layers
  • Loading branch information
elpaso committed Aug 21, 2017
2 parents b8d2a17 + 4d3c7e5 commit 1a42c4fa1f16fe5c9e06e5f8492ffc0e73b16086
Showing with 14 additions and 13 deletions.
  1. +14 −13 src/providers/ogr/qgsgeopackagedataitems.cpp
@@ -586,7 +586,7 @@ bool QgsGeoPackageRasterLayerItem::executeDeleteLayer( QString &errCause )
else
{
// Remove table
char *errmsg = NULL;
char *errmsg = nullptr;
char *sql = sqlite3_mprintf(
"DROP table %w;"
"DELETE FROM gpkg_contents WHERE table_name = '%q';"
@@ -605,20 +605,21 @@ bool QgsGeoPackageRasterLayerItem::executeDeleteLayer( QString &errCause )
);
sqlite3_free( sql );
// Remove from optional tables, may silently fail
for ( const auto tableName : QStringList()
<< QStringLiteral( "gpkg_extensions" )
<< QStringLiteral( "gpkg_metadata_reference" ) )
QStringList optionalTables;
optionalTables << QStringLiteral( "gpkg_extensions" )
<< QStringLiteral( "gpkg_metadata_reference" );
for ( const auto tableName : optionalTables )
{
char *sql = sqlite3_mprintf( "DELETE FROM table %w WHERE table_name = '%q",
tableName.toUtf8().constData(),
layerName.toUtf8().constData() );
status = sqlite3_exec(
handle, /* An open database */
sql, /* SQL to be evaluated */
NULL, /* Callback function */
NULL, /* 1st argument to callback */
NULL /* Error msg written here */
);
sqlite3_exec(
handle, /* An open database */
sql, /* SQL to be evaluated */
NULL, /* Callback function */
NULL, /* 1st argument to callback */
NULL /* Error msg written here */
);
sqlite3_free( sql );
}
if ( status == SQLITE_OK )
@@ -627,9 +628,9 @@ bool QgsGeoPackageRasterLayerItem::executeDeleteLayer( QString &errCause )
}
else
{
errCause = tr( "There was an error deleting the layer: %1" ).arg( errmsg );
sqlite3_free( errmsg );
errCause = tr( "There was an error deleting the layer: %1" ).arg( QString::fromUtf8( errmsg ) );
}
sqlite3_free( errmsg );
}
sqlite3_close( handle );
}

0 comments on commit 1a42c4f

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