[Qgis-developer] How to get QGIS database connection name from layer

Hugo Mercier hugo.mercier at oslandia.com
Fri Oct 9 06:31:23 PDT 2015


Hi,

DB connection details are stored in QSettings.
For instance
s = QSettings()
s.beginGroup('PostgreSQL/connections')

you can then list connections by s.childGroups()

Does it help ?

On 09/10/2015 14:33, Spencer Gardner wrote:
> In an answer yesterday I learned that I can use DB Manager via Python to
> work with my PostGIS database. 
> 
> Within the Processing framework, I need to get a reference to a database
> based on an input layer. In the past, I could accomplish this by parsing
> the layer's URI. However, it appears that DB Manager refers to databases
> using the DB's connection name as given in QGIS. How can I refer to my
> database from one of its tables that exists as a layer in QGIS?
> 
> Here's an example:
> 
> Table name: foo
> Database name in PostgreSQL: bar
> Connection name in QGIS: baz
> 
> I need to get "baz" based on a QGIS layer that points to "foo".
> 
> Thanks for any help!
> 
> 
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
> 



More information about the Qgis-developer mailing list