mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-10 00:13:55 -04:00
[browser] Fix removal of views from postgres databases (fixes #29812)
For views one needs to use DROP VIEW sql command
This commit is contained in:
parent
2cf1624ff3
commit
d7fdbbedb3
@ -341,7 +341,9 @@ QList<QAction *> QgsPGLayerItem::actions( QWidget *parent )
|
||||
|
||||
bool QgsPGLayerItem::deleteLayer()
|
||||
{
|
||||
if ( QMessageBox::question( nullptr, QObject::tr( "Delete Table" ),
|
||||
QString typeName = mLayerProperty.isView ? tr( "View" ) : tr( "Table" );
|
||||
|
||||
if ( QMessageBox::question( nullptr, tr( "Delete %1" ).arg( typeName ),
|
||||
QObject::tr( "Are you sure you want to delete %1.%2?" ).arg( mLayerProperty.schemaName, mLayerProperty.tableName ),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
|
||||
return true;
|
||||
@ -350,11 +352,11 @@ bool QgsPGLayerItem::deleteLayer()
|
||||
bool res = ::deleteLayer( mUri, errCause );
|
||||
if ( !res )
|
||||
{
|
||||
QMessageBox::warning( nullptr, tr( "Delete Table" ), errCause );
|
||||
QMessageBox::warning( nullptr, tr( "Delete %1" ).arg( typeName ), errCause );
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information( nullptr, tr( "Delete Table" ), tr( "Table deleted successfully." ) );
|
||||
QMessageBox::information( nullptr, tr( "Delete %1" ).arg( typeName ), tr( "%1 deleted successfully." ).arg( typeName ) );
|
||||
if ( mParent )
|
||||
mParent->refresh();
|
||||
}
|
||||
|
@ -4690,6 +4690,28 @@ QGISEXTERN bool deleteLayer( const QString &uri, QString &errCause )
|
||||
return false;
|
||||
}
|
||||
|
||||
// handle deletion of views
|
||||
QString sqlViewCheck = QStringLiteral( "SELECT relkind FROM pg_class WHERE oid=regclass(%1)::oid" )
|
||||
.arg( QgsPostgresConn::quotedValue( schemaTableName ) );
|
||||
QgsPostgresResult resViewCheck( conn->PQexec( sqlViewCheck ) );
|
||||
QString type = resViewCheck.PQgetvalue( 0, 0 );
|
||||
if ( type == QLatin1String( "v" ) || type == QLatin1String( "m" ) )
|
||||
{
|
||||
QString sql = QString( "DROP VIEW %1" ).arg( schemaTableName );
|
||||
QgsPostgresResult result( conn->PQexec( sql ) );
|
||||
if ( result.PQresultStatus() != PGRES_COMMAND_OK )
|
||||
{
|
||||
errCause = QObject::tr( "Unable to delete view %1: \n%2" )
|
||||
.arg( schemaTableName,
|
||||
result.PQresultErrorMessage() );
|
||||
conn->unref();
|
||||
return false;
|
||||
}
|
||||
conn->unref();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// check the geometry column count
|
||||
QString sql = QString( "SELECT count(*) "
|
||||
"FROM geometry_columns, pg_class, pg_namespace "
|
||||
|
Loading…
x
Reference in New Issue
Block a user