[QGIS-Developer] Access DB manager connection details in a python plugins

Etienne Trimaille etienne.trimaille at gmail.com
Thu Jul 22 23:32:40 PDT 2021


Can you clarify what you need from DBManager?
Widgets ? Features ?
Or do you mean to be able to list DB connections and launch SQL queries ?

You should avoid importing code from the DbManager plugin as it is removed
step by step.
Use the database API :
https://qgis.org/api/classQgsAbstractDatabaseProviderConnection.html

metadata = QgsProviderRegistry.instance().providerMetadata('postgres')
connection = metadata.findConnection("name_of_connection)
connection.executeSql("SELECT ....")



Le jeu. 22 juil. 2021 à 22:09, Florian El Ahdab <felahdab at gmail.com> a
écrit :

> Hi.
>
> I would like to take advantage of the db manager from a python plugin.
> That would allow me to avoid handling the database configuration myself and
> would make the overall ui more consistent for the user.
>
> I can't find any relevant reference to do that.
>
> Has anyone achieved anything like that ?
>
> Regards.
> Florian.
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210723/b0861b3a/attachment.html>


More information about the QGIS-Developer mailing list