[QGIS-Developer] Catch PostgreSQL logs in pyqgis

Johannes Kröger (WhereGroup) johannes.kroeger at wheregroup.com
Mon Mar 4 23:53:42 PST 2024


Hi Matteo,

https://api.qgis.org/api/master/classQgsDatabaseQueryLog.html does have 
appropriate signals (queryFinished and queryStarted, both include the 
query) but it looks like they are not documented in the Python API 
https://qgis.org/pyqgis/master/core/QgsDatabaseQueryLog.html

It *looks* like they are exposed though. So try


def do_something_with(query):
   ...
query_log = QgsApplication.databaseQueryLog()
query_log.queryFinished.connect(do_something_with)


If that does not work, maybe the debugging panel itself has a signal you 
can connect to as a hacky workaround.

Cheers, Hannes

On 04.03.24 17:54, Matteo Ghetta via QGIS-Developer wrote:
> Hi devs,
>
> I'm looking for a way in pyqgis to catch the (raw) queries that QGIS 
> is sending to the PostgreSQL provider when a table is edited: for 
> example the raw "INSERT ... INTO ...", "UPDATE ...".
>
> Basically what the Development Panel is listing when enabled. Is there 
> a way in pyqgis?
>
> Cheers and thanks for any suggestion!
>
> Matteo
>
> _______________________________________________
> 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

-- 
Johannes Kröger / GIS-Entwickler/-Berater

*********************************************
FOSSGIS Konferenz
20.-23. März 2024 in Hamburg
https://www.fossgis-konferenz.de/2024/

WhereGroup-Beiträge auf der FOSSGIS
https://wheregroup.com/unternehmen/aktuelles/
*********************************************

WhereGroup GmbH
c/o KK03 GmbH
Lange Reihe 29
20099 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroeger at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------



More information about the QGIS-Developer mailing list