[QGIS-Developer] core API to fetch query output fields from SQL query?

Sandro Santilli strk at kbt.io
Thu Jan 9 03:32:19 PST 2020


Hi all,
some of you might know already I've been working on improving the
DBManager SQL Window so so not rely on "psycopg2" when interacting
with PostgreSQL backend. This work is in progress in this PR:

  https://github.com/qgis/QGIS/pull/33225

The advice, from Alessandro, was to use the new core API for this:

  https://qgis.org/api/classQgsAbstractDatabaseProviderConnection.html

Using that API does give a more stable interaction (automatic
reconnect on connection loss) but has a lack of features currently
used by SQLWindow, which are:

  1. Extracting names of fields returned by a query
  2. Chunk retrival of results (useful for large result sets)

Alessandro proposed to use QgsVectorLayer to solve the first issue:

  https://qgis.org/api/classQgsVectorLayer.html

but I did not find a way to create a QgsDataSourceURI for a generic query
(when a Geometry field might not even exist).

Can anyone help with doing this ?
Or, have another suggestion as to how to solve both issues ?

Thanks in advance.

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   https://strk.kbt.io/services.html


More information about the QGIS-Developer mailing list