mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-28 00:05:04 -04:00
GPKG Browser VACUUM menu item
Fixes #19895 - Garbage-collection is not performed after deletion of vector layer from geopackage By design, VACUUM (being a potentially time-consuming operation) was automatically performed only after deleting a raster while when deleting a vector layer it was not executed. This commit adds a menu item in the browser that allows the user to perform this operation on the DB.
This commit is contained in:
parent
1b2d885a03
commit
b51cb21d1a
@ -469,6 +469,44 @@ bool QgsGeoPackageCollectionItem::deleteGeoPackageRasterLayer( const QString &ur
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsGeoPackageCollectionItem::vacuumGeoPackageDb()
|
||||||
|
{
|
||||||
|
QString errCause;
|
||||||
|
// Better safe than sorry
|
||||||
|
if ( ! mPath.isEmpty( ) )
|
||||||
|
{
|
||||||
|
char *errmsg = nullptr;
|
||||||
|
sqlite3_database_unique_ptr database;
|
||||||
|
int status = database.open_v2( mPath, SQLITE_OPEN_READWRITE, nullptr );
|
||||||
|
if ( status != SQLITE_OK )
|
||||||
|
{
|
||||||
|
errCause = sqlite3_errmsg( database.get() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
( void )sqlite3_exec(
|
||||||
|
database.get(), /* An open database */
|
||||||
|
"VACUUM", /* SQL to be evaluated */
|
||||||
|
nullptr, /* Callback function */
|
||||||
|
nullptr, /* 1st argument to callback */
|
||||||
|
&errmsg /* Error msg written here */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( status == SQLITE_OK && ! errmsg )
|
||||||
|
{
|
||||||
|
QMessageBox::information( nullptr, tr( "Database compact (VACUUM)" ), tr( "Database <b>%1</b> has been compacted successfully." ).arg( mName ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errCause = tr( "There was an error compacting (VACUUM) the database <b>%1</b>: %2" )
|
||||||
|
.arg( mName )
|
||||||
|
.arg( QString::fromUtf8( errmsg ) );
|
||||||
|
QMessageBox::warning( nullptr, tr( "Database compact (VACUUM)" ), errCause );
|
||||||
|
}
|
||||||
|
sqlite3_free( errmsg );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QgsGeoPackageConnectionItem::QgsGeoPackageConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
|
QgsGeoPackageConnectionItem::QgsGeoPackageConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
|
||||||
: QgsGeoPackageCollectionItem( parent, name, path )
|
: QgsGeoPackageCollectionItem( parent, name, path )
|
||||||
{
|
{
|
||||||
@ -500,6 +538,11 @@ QList<QAction *> QgsGeoPackageConnectionItem::actions( QWidget *parent )
|
|||||||
connect( actionAddTable, &QAction::triggered, this, &QgsGeoPackageConnectionItem::addTable );
|
connect( actionAddTable, &QAction::triggered, this, &QgsGeoPackageConnectionItem::addTable );
|
||||||
lst.append( actionAddTable );
|
lst.append( actionAddTable );
|
||||||
|
|
||||||
|
// Run VACUUM
|
||||||
|
QAction *actionVacuumDb = new QAction( tr( "Compact database (VACUUM)" ), parent );
|
||||||
|
connect( actionVacuumDb, &QAction::triggered, this, &QgsGeoPackageConnectionItem::vacuumGeoPackageDb );
|
||||||
|
lst.append( actionVacuumDb );
|
||||||
|
|
||||||
|
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
@ -88,14 +88,18 @@ class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
|
|||||||
//! Returns the layer type from \a geometryType
|
//! Returns the layer type from \a geometryType
|
||||||
static QgsLayerItem::LayerType layerTypeFromDb( const QString &geometryType );
|
static QgsLayerItem::LayerType layerTypeFromDb( const QString &geometryType );
|
||||||
|
|
||||||
//! Delete a geopackage layer
|
//! Deletes a geopackage layer
|
||||||
static bool deleteGeoPackageRasterLayer( const QString &uri, QString &errCause );
|
static bool deleteGeoPackageRasterLayer( const QString &uri, QString &errCause );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
#ifdef HAVE_GUI
|
#ifdef HAVE_GUI
|
||||||
void addTable();
|
void addTable();
|
||||||
void addConnection();
|
void addConnection();
|
||||||
void deleteConnection();
|
void deleteConnection();
|
||||||
|
//! Compacts (VACUUM) a geopackage database
|
||||||
|
void vacuumGeoPackageDb();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user