Skip to content
Permalink
Browse files

DB manager PG connection proper API usage

Fixes #34132
  • Loading branch information
elpaso committed Jan 31, 2020
1 parent c89b511 commit a6e9050453084f06a9e42f456254ed87c43b6dcf
@@ -67,7 +67,7 @@ def __init__(self, uri, connection):
# QgsAbstractDatabaseProviderConnection instance
self.core_connection = md.findConnection(connection.connectionName())
if self.core_connection is None:
self.core_connection = md.createConnection(connection.connectionName(), uri.database())
self.core_connection = md.createConnection(uri, {})
self.has_raster = False
self.mapSridToName = {}
# To be removed when migration to new API is completed
@@ -181,7 +181,7 @@ def close(self):

class PostGisDBConnector(DBConnector):

def __init__(self, uri):
def __init__(self, uri, connection):
"""Creates a new PostgreSQL connector
:param uri: data source URI
@@ -203,8 +203,11 @@ def __init__(self, uri):
#self.passwd = uri.password()
self.host = uri.host()

md = QgsProviderRegistry.instance().providerMetadata('postgres')
self.core_connection = md.createConnection(uri.database())
md = QgsProviderRegistry.instance().providerMetadata(connection.providerName())
# QgsAbstractDatabaseProviderConnection instance
self.core_connection = md.findConnection(connection.connectionName())
if self.core_connection is None:
self.core_connection = md.createConnection(uri, {})

c = self._execute(None, u"SELECT current_user,current_database()")
self.user, self.dbname = self._fetchone(c)
@@ -112,7 +112,7 @@ def __init__(self, connection, uri):
Database.__init__(self, connection, uri)

def connectorsFactory(self, uri):
return PostGisDBConnector(uri)
return PostGisDBConnector(uri, self.connection())

def dataTablesFactory(self, row, db, schema=None):
return PGTable(row, db, schema)

0 comments on commit a6e9050

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