Skip to content

Commit

Permalink
Update layer statistics when adding column to table in order to be di…
Browse files Browse the repository at this point in the history
…splayed by QGIS

fixes #13504
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 21, 2019
1 parent 83c0ea9 commit 49cb397
Show file tree
Hide file tree
Showing 3 changed files with 474 additions and 1 deletion.
16 changes: 15 additions & 1 deletion python/plugins/db_manager/db_plugins/spatialite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ def deleteTable(self, table):
self._execute(c, sql)
self._commit()

return True

def emptyTable(self, table):
""" delete all rows from table """
if self.isRasterTable(table):
Expand Down Expand Up @@ -494,6 +496,7 @@ def renameTable(self, table, new_table):
self._execute(c, sql)

self._commit()
return True

def moveTable(self, table, new_table, new_schema=None):
return self.renameTable(table, new_table)
Expand Down Expand Up @@ -571,7 +574,16 @@ def runVacuum(self):
def addTableColumn(self, table, field_def):
""" add a column to table """
sql = u"ALTER TABLE %s ADD %s" % (self.quoteId(table), field_def)
self._execute_and_commit(sql)
self._execute(None, sql)

sql = u"SELECT InvalidateLayerStatistics(%s)" % (self.quoteId(table))
self._execute(None, sql)

sql = u"SELECT UpdateLayerStatistics(%s)" % (self.quoteId(table))
self._execute(None, sql)

self._commit()
return True

def deleteTableColumn(self, table, column):
""" delete column from a table """
Expand All @@ -583,6 +595,8 @@ def deleteTableColumn(self, table, column):
sql = u"SELECT DiscardGeometryColumn(%s, %s)" % (self.quoteString(tablename), self.quoteString(column))
self._execute_and_commit(sql)

return True

def updateTableColumn(self, table, column, new_name, new_data_type=None, new_not_null=None, new_default=None):
return False # column editing not supported

Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ ADD_PYTHON_TEST(PyQgsConsole test_console.py)
ADD_PYTHON_TEST(PyQgsLayerDependencies test_layer_dependencies.py)
ADD_PYTHON_TEST(PyQgsVersionCompare test_versioncompare.py)
ADD_PYTHON_TEST(PyQgsDBManagerGpkg test_db_manager_gpkg.py)
ADD_PYTHON_TEST(PyQgsDBManagerSpatialite test_db_manager_spatialite.py)
ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
Expand Down
Loading

0 comments on commit 49cb397

Please sign in to comment.