Skip to content

Commit

Permalink
drop fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
phborba committed Jun 27, 2017
1 parent 8ecbd7a commit c081edb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Factories/DbFactory/postgisDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ def dropDatabase(self, candidateName):
"""
self.checkAndOpenDb()
if self.checkSuperUser():
self.dropAllConections(candidateName)
sql = self.gen.dropDatabase(candidateName)
query = QSqlQuery(self.db)
if not query.exec_(sql):
Expand Down Expand Up @@ -3164,4 +3165,15 @@ def getPrimaryKeyColumn(self, tableName):
if not query.isActive():
raise Exception(self.tr("Problem getting primary key column: ")+query.lastError().text())
while query.next():
return query.value(0)
return query.value(0)

def dropAllConections(self, dbName):
"""
Terminates all database conections
"""
self.checkAndOpenDb()
if self.checkSuperUser():
sql = self.gen.dropAllConections(dbName)
query = QSqlQuery(self.db)
if not query.exec_(sql):
raise Exception(self.tr('Problem dropping database conections: ') + query.lastError().text())
7 changes: 7 additions & 0 deletions Factories/SqlFactory/postgisSqlGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,4 +1422,11 @@ def getPrimaryKeyColumn(self, tableName):

def getGeometryTablesCount(self):
sql = '''select count(*) from public.geometry_columns'''
return sql

def dropAllConections(self, dbName):
sql = """SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '{0}'
AND pid <> pg_backend_pid();""".format(dbName)
return sql
4 changes: 3 additions & 1 deletion ServerTools/batchDbManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def populateListWithDatabasesFromServer(self):
for (dbname, dbversion) in dbList:
if dbversion not in self.dbDict.keys():
dbversion = 'Non_EDGV'
self.dbDict[dbversion].append(dbname)
if dbname not in self.dbDict[dbversion]:
self.dbDict[dbversion].append(dbname)

def setDatabases(self):
self.populateListWithDatabasesFromServer()
Expand Down Expand Up @@ -164,6 +165,7 @@ def on_dropDatabasePushButton_clicked(self):
self.setDatabases()
header = self.tr('Drop operation complete. \n')
self.outputMessage(header, successList, exceptionDict)
self.dbsCustomSelector.setInitialState(self.dbsCustomSelector.fromLs)

@pyqtSlot(bool)
def on_upgradePostgisPushButton_clicked(self):
Expand Down

0 comments on commit c081edb

Please sign in to comment.