[Qgis-developer] Post-processing queries on postgis layers (after insert/delete/update)

Olivier Dalang olivier.dalang at gmail.com
Tue Mar 17 10:08:18 PDT 2015


Hi !

I have a database where I need to be able to run post-processing queries
after inserts/updates/deletes.

Up to now, I was doing this using postgres triggers, but I need to do it in
a more flexible way (I must be able to enable/disable the postprocessing
depending on user and clients preferences, and even be able to trigger it
on demand).


I'm able to run SQL queries after inserts using this signal :
QgsVectorLayer.committedFeaturesAdded(layerId, addedFeatures)

The problem is that the addedFeatures array contains the features in their
state BEFORE they were committed.
This means they have no ID assigned yet (since the ID is assigned by
postgres), and thus I'm not able to do my postprocessing specificaly on
those features.

Is there a way to achieve this ?
Things like lastInsertId() probably won't work since in most case several
features are commited at once.
I can only think of some ugly methods, like having a column with a
"postprocessing_todo" flag.

Actually, a great thing would be to have the committedFeaturesAdded
signal return
an array of database generated ids, which is easy to get (at least in
postgres) using this syntax :
INSERT INTO <table> (<fields>) VALUES (<values>) RETURNING <id field>

Any help would be much appreciated ;)

Bests,

Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150317/801cf385/attachment.html>


More information about the Qgis-developer mailing list