Skip to content
Permalink
Browse files

[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.
  • Loading branch information
wonder-sk committed Apr 9, 2019
1 parent e2179b3 commit 9eca4059b8d09aab9eac5995f899a9bd07cd0083
Showing with 9 additions and 0 deletions.
  1. +9 −0 python/plugins/db_manager/db_plugins/gpkg/connector.py
@@ -620,6 +620,9 @@ def renameTable(self, table, new_table):
if new_table == tablename:
return True

quoted_table = self.quoteString(tablename)
quoted_table_new = self.quoteString(new_table)

if tablename.find('"') >= 0:
tablename = self.quoteId(tablename)
if new_table.find('"') >= 0:
@@ -629,6 +632,12 @@ def renameTable(self, table, new_table):
self.gdal_ds.ExecuteSQL('ALTER TABLE %s RENAME TO %s' % (tablename, new_table))
if gdal.GetLastErrorMsg() != '':
return False

# also rename any styles referring to this table
self.gdal_ds.ExecuteSQL('UPDATE layer_styles SET f_table_name = %s WHERE f_table_name = %s' % (quoted_table_new, quoted_table))
if gdal.GetLastErrorMsg() != '':
return False

# we need to reopen after renaming since OGR doesn't update its
# internal state
self._opendb()

0 comments on commit 9eca405

Please sign in to comment.
You can’t perform that action at this time.