Skip to content

Commit

Permalink
[db manager] Rename layer style entry when renaming gpkg tables (fixes
Browse files Browse the repository at this point in the history
…#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 9eca405
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/plugins/db_manager/db_plugins/gpkg/connector.py
Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit 9eca405

Please sign in to comment.