Skip to content

Commit 1eec3b9

Browse files
committed
[processing] fixed ogr import to postgis when origin layer is a database
1 parent 97b7406 commit 1eec3b9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

python/plugins/processing/algs/gdal/OgrAlgorithm.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ def ogrConnectionString(self, uri):
6262
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
6363
# key='gid' estimatedmetadata=true srid=4326 type=MULTIPOLYGON
6464
# table="t4" (geom) sql=
65-
s = re.sub(''' sslmode=.+''', '', unicode(layer.source()))
66-
ogrstr = 'PG:%s' % s
65+
dsUri = QgsDataSourceURI(layer.dataProvider().dataSourceUri())
66+
connInfo = dsUri.connectionInfo()
67+
(success, user, passwd ) = QgsCredentials.instance().get(connInfo, None, None)
68+
if success:
69+
QgsCredentials.instance().put(connInfo, user, passwd)
70+
ogrstr = ("PG:dbname='%s' host='%s' port='%s' user='%s' password='%s'"
71+
% (dsUri.database(), dsUri.host(), dsUri.port(), user, passwd))
6772
else:
6873
ogrstr = unicode(layer.source()).split("|")[0]
6974
return '"' + ogrstr + '"'
@@ -72,7 +77,7 @@ def ogrLayerName(self, uri):
7277
if 'host' in uri:
7378
regex = re.compile('(table=")(.+?)(\.)(.+?)"')
7479
r = regex.search(uri)
75-
return r.groups()[1] + '.' + r.groups()[3]
80+
return '"' + r.groups()[1] + '.' + r.groups()[3] +'"'
7681
elif 'dbname' in uri:
7782
regex = re.compile('(table=")(.+?)"')
7883
r = regex.search(uri)
@@ -83,3 +88,4 @@ def ogrLayerName(self, uri):
8388
return r.groups()[1]
8489
else:
8590
return os.path.basename(os.path.splitext(uri)[0])
91+

0 commit comments

Comments
 (0)