[Postgres] Update styles to match new layer name when layer is renamed #66391
[Postgres] Update styles to match new layer name when layer is renamed #66391JanCaha wants to merge 8 commits into
Conversation
| void QgsPostgresProviderConnection::renameTablePrivate( const QString &schema, const QString &name, const QString &newName ) const | ||
| { | ||
| executeSqlPrivate( u"ALTER TABLE %1.%2 RENAME TO %3"_s.arg( QgsPostgresConn::quotedIdentifier( schema ), QgsPostgresConn::quotedIdentifier( name ), QgsPostgresConn::quotedIdentifier( newName ) ) ); | ||
| executeSqlPrivate( u"UPDATE public.layer_styles SET f_table_name=%1 WHERE f_table_schema=%2 AND f_table_name=%3"_s |
There was a problem hiding this comment.
You may want to check if the style exists (e.g. with QgsProviderMetadata::styleExists ) before calling executeSqlPrivate on a not-existing table.
There was a problem hiding this comment.
I decided to use QgsPostgresUtils::tableExists with connection acqusition, since the name of style is not known forQgsProviderMetadata::styleExists and i did not want to use QgsPostgresRasterProviderMetadata::listStyles as it seemed like an overkill.
|
Does this also work if a layer is moved from one schema to another? |
|
@kewgis Actually no, but that would be another bug. It is in different part of the code...but I can take care of it. |
|
@elpaso the fix for style being pointed to the correct layer after moving to another schema was so small that i decided to include it here. Could you please reapprove this? Thank you |
There was a problem hiding this comment.
LGTM, there is only one thing you should probably check: executeSql (and private) can throw QgsProviderConnectionException, can you please check that in the unlikely event it happens the whole QGIS doesn't crash with an unhandled exception but the exception is catched somewhere up in the call stack?
Co-authored-by: Alessandro Pasotti <elpaso@itopen.it>
|
Fixed! |
Description
When PostgreSQL table is renamed (either from browser or from provider connection) the styles associated withe layer need to updated in layer_styles table to match the new layer name.
Funded by: Ocean Winds
Fixes #65360
AI tool usage