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

Spencer Gardner spencergardner at gmail.com
Fri Oct 9 05:33:49 PDT 2015


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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20151009/5e8457ad/attachment.html>


More information about the Qgis-developer mailing list