Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[postgres][browser] Implement field comment setting for postgres fields
  • Loading branch information
nyalldawson committed May 4, 2023
1 parent f9b6b30 commit 2dccf42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -133,6 +133,8 @@ void QgsPostgresProviderConnection::setDefaultCapabilities()
Qgis::SqlLayerDefinitionCapability::UnstableFeatureIds,
};

mCapabilities2 |= Qgis::DatabaseProviderConnectionCapability2::SetFieldComment;

// see https://www.postgresql.org/docs/current/ddl-system-columns.html
mIllegalFieldNames =
{
Expand Down Expand Up @@ -586,6 +588,16 @@ void QgsPostgresProviderConnection::deleteSpatialIndex( const QString &schema, c
QgsPostgresConn::quotedIdentifier( indexName ) ), false );
}

void QgsPostgresProviderConnection::setFieldComment( const QString &fieldName, const QString &schema, const QString &tableName, const QString &comment ) const
{
executeSqlPrivate( QStringLiteral( "COMMENT ON COLUMN %1.%2.%3 IS %4;" )
.arg( QgsPostgresConn::quotedIdentifier( schema ),
QgsPostgresConn::quotedIdentifier( tableName ),
QgsPostgresConn::quotedIdentifier( fieldName ),
QgsPostgresConn::quotedValue( comment )
) );
}

QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
{
checkCapability( Capability::Tables );
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresproviderconnection.h
Expand Up @@ -69,6 +69,7 @@ class QgsPostgresProviderConnection : public QgsAbstractDatabaseProviderConnecti
void createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options = QgsAbstractDatabaseProviderConnection::SpatialIndexOptions() ) const override;
bool spatialIndexExists( const QString &schema, const QString &name, const QString &geometryColumn ) const override;
void deleteSpatialIndex( const QString &schema, const QString &name, const QString &geometryColumn ) const override;
void setFieldComment( const QString &fieldName, const QString &schema, const QString &tableName, const QString &comment ) const override;
QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema,
const TableFlags &flags = TableFlags() ) const override;
QStringList schemas( ) const override;
Expand Down

0 comments on commit 2dccf42

Please sign in to comment.