Skip to content

Commit 9eca405

Browse files
committed
[db manager] Rename layer style entry when renaming gpkg tables (fixes #21227)
This has been already fixed in master and backported to 3.6 using browser data items. However the fix can't be directly backported to QGIS 3.4 because in 3.4 geopackage data item does not support renaming.
1 parent e2179b3 commit 9eca405

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

python/plugins/db_manager/db_plugins/gpkg/connector.py

+9
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ def renameTable(self, table, new_table):
620620
if new_table == tablename:
621621
return True
622622

623+
quoted_table = self.quoteString(tablename)
624+
quoted_table_new = self.quoteString(new_table)
625+
623626
if tablename.find('"') >= 0:
624627
tablename = self.quoteId(tablename)
625628
if new_table.find('"') >= 0:
@@ -629,6 +632,12 @@ def renameTable(self, table, new_table):
629632
self.gdal_ds.ExecuteSQL('ALTER TABLE %s RENAME TO %s' % (tablename, new_table))
630633
if gdal.GetLastErrorMsg() != '':
631634
return False
635+
636+
# also rename any styles referring to this table
637+
self.gdal_ds.ExecuteSQL('UPDATE layer_styles SET f_table_name = %s WHERE f_table_name = %s' % (quoted_table_new, quoted_table))
638+
if gdal.GetLastErrorMsg() != '':
639+
return False
640+
632641
# we need to reopen after renaming since OGR doesn't update its
633642
# internal state
634643
self._opendb()

0 commit comments

Comments
 (0)