[Qgis-developer] QGIS stores, in the QGIS project, users logins and passwords from PostGis

Andreas Neumann a.neumann at carto.net
Mon Oct 22 23:22:46 PDT 2012


 Hi,

 I don't know how this works from Python, but you can manually load 
 Postgis layers without storing the password in the project file (just 
 uncheck the store user/password in PostgreSQL checkboxes). But the 
 drawback is, that when you reopen the project it will ask you for the 
 password.

 Sorry, I don't know if you can also do this from Python.

 Andreas

 On Tue, 23 Oct 2012 08:00:55 +0200, J. Gaspar Mora Navarro wrote:
> Hello,
>
> I can't find how avoid QGIS stores users logins and passwords from
> PostGis in the QGIS project.
> If I add the PostGis layer manualy from the QGIS menu, if I disable
> the store user name and store password options, works corretly, the
> user and password don't are stored. But if I add the layer using
> pyqgis from a plugin, the information is stored, and I dont know how
> avoid that.
>
> If I use this code:
>
>         uri = qgis.core.QgsDataSourceURI()
>         uri.setConnection(host, port, database, usuario, password)
>
>         # set database schema, table name, geometry column and
> optionaly subset (WHERE clause)
>         nombres=nombreCompletoTabla.split(".")
>         if len(nombres) < 2:
>             raise Exception("Falta el nombre del esquema en el nombre
> de la tabla")
>         esquema=nombres[0]
>         tabla=nombres[1]
>
>         uri.setDataSource(esquema, tabla, campoGeom,
> condicionSeleccion,campoGid)
>         vlayer = qgis.core.QgsVectorLayer(uri.uri(), tabla, 
> "postgres")
>         if not vlayer.isValid():
>             raise IOError, "Fallo al abrir la capa espacial"
>         # add layer to the registry
>         qgis.core.QgsMapLayerRegistry.instance().addMapLayer(vlayer)
>
> QGIS write that in the QGIS project:
>
>             <datasource>dbname='propiedad' host=localhost port=5432
> user='usuario' password='xeiraaixo' key='gid'
> table="src25830"."elem_interiores" (geom) sql=id_trabajo in (select
> id_trabajo from comun.trabajos where
> municipio='12032;Borriana/Burriana')</datasource>
>
>
> How can I avoid that from pyqgis?
>
> Thank you for your time.
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
 --
 Andreas Neumann
 Böschacherstrasse 10A
 8624 Grüt (Gossau ZH)
 Switzerland


More information about the Qgis-developer mailing list