@@ -62,8 +62,13 @@ def ogrConnectionString(self, uri):
62
62
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
63
63
# key='gid' estimatedmetadata=true srid=4326 type=MULTIPOLYGON
64
64
# 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 ))
67
72
else :
68
73
ogrstr = unicode (layer .source ()).split ("|" )[0 ]
69
74
return '"' + ogrstr + '"'
@@ -72,7 +77,7 @@ def ogrLayerName(self, uri):
72
77
if 'host' in uri :
73
78
regex = re .compile ('(table=")(.+?)(\.)(.+?)"' )
74
79
r = regex .search (uri )
75
- return r .groups ()[1 ] + '.' + r .groups ()[3 ]
80
+ return '"' + r .groups ()[1 ] + '.' + r .groups ()[3 ] + '"'
76
81
elif 'dbname' in uri :
77
82
regex = re .compile ('(table=")(.+?)"' )
78
83
r = regex .search (uri )
@@ -83,3 +88,4 @@ def ogrLayerName(self, uri):
83
88
return r .groups ()[1 ]
84
89
else :
85
90
return os .path .basename (os .path .splitext (uri )[0 ])
91
+
0 commit comments