Skip to content

Commit

Permalink
db manager: fix connection holding - idle in transaction (QGIS bug #7162
Browse files Browse the repository at this point in the history
)
  • Loading branch information
imincik committed May 13, 2014
1 parent 60e1a9b commit 0d3e5e4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
5 changes: 1 addition & 4 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, uri):

try:
self.connection = psycopg2.connect( self._connectionInfo().encode('utf-8') )
self.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
except self.connection_error_types(), e:
raise ConnectionError(e)

Expand Down Expand Up @@ -751,13 +752,9 @@ def runVacuum(self):

def runVacuumAnalyze(self, table):
""" run vacuum analyze on a table """
# vacuum analyze must be run outside transaction block - we have to change isolation level
self.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
sql = u"VACUUM ANALYZE %s" % self.quoteId(table)
c = self._execute(None, sql)
self._commit()
self.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)


def addTableColumn(self, table, field_def):
""" add a column to table """
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/db_manager/db_plugins/postgis/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def _createCursor(self):
fields_txt = u", ".join(self.fields)
table_txt = self.db.quoteId( (self.table.schemaName(), self.table.name) )

# create named cursor and run query
self.cursor = self.db._get_cursor(self.table.name)
self.cursor = self.db._get_cursor()
sql = u"SELECT %s FROM %s" % (fields_txt, table_txt)
self.db._execute(self.cursor, sql)

Expand Down

0 comments on commit 0d3e5e4

Please sign in to comment.