Skip to content
Permalink
Browse files

Update layer statistics when adding column to table in order to be di…

…splayed by QGIS

fixes #13504
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 21, 2019
1 parent 83c0ea9 commit 49cb397f89511535bc772abd69a767e84024690a
@@ -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):
@@ -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)
@@ -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 """
@@ -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

@@ -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)

0 comments on commit 49cb397

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