<div dir="ltr">Hi !<div><br></div><div>Thanks for your answer. I tested in more details, and it works indeed on a normal table.</div><div><br></div><div>But in my scenario, I am editing a view, using some triggers to make the view editable.</div><div><br></div><div>Here's a simplified case, it consists of one table, one view, and triggers to insert/update/delete the view.:</div><div><br></div><div><a href="https://gist.github.com/olivierdalang/cad70df2d463d0b87566">https://gist.github.com/olivierdalang/cad70df2d463d0b87566</a><br></div><div><br></div><div>When I insert something using this query manually :</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace"><span style="font-size:12.8000001907349px;background-color:rgb(204,204,204)">INSERT INTO test_view (name) VALUES ('abc'),('def') RETURNING id</span></font></blockquote><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"><br></span></font><div>I get</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)">id <br></font><font face="monospace, monospace" style="background-color:rgb(204,204,204)">---<br></font><font face="monospace, monospace" style="background-color:rgb(204,204,204)">7  <br></font><font face="monospace, monospace" style="background-color:rgb(204,204,204)">8  </font></blockquote><div><br></div><div>So it seems my triggers are working correctly (note that one mustn't forget <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre">RETURNING id INTO NEW.id </span>in the insert trigger, without it we can't get the id back), and I was hoping that it would be transparent to QGIS.</div><div><br></div><div>But when testing in QGIS, I get no id for the view.</div><div><br></div><div>Here's how I test (in the python console) :</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="background-color:rgb(204,204,204)"><font face="monospace, monospace">def test(layerID, addedFeatures):</font> </span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="background-color:rgb(204,204,204)"><font face="monospace, monospace">    print( 'committedFeaturesAdded was triggered on layerID'+layerID )</font> </span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)">    for feat in addedFeatures: </font></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)">        print( 'testing id: %s' % str(<a href="http://feat.id">feat.id</a>()) )</font></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)">        print( 'testing attributes: %s' % str(feat.attributes()) )</font></blockquote><div> </div>Then this to display output when news features are commited  (run this once with the normal table selected, once with the view selected)</div><div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)"> iface.activeLayer().committedFeaturesAdded.connect( test )</font></blockquote><div><span style="font-size:medium;color:rgb(128,128,48)"><br></span></div>Then, add some features on the <b>table</b>, when you commit, you get :</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace" style="background-color:rgb(204,204,204)">committedFeaturesAdded was triggered on layerIDtest20150318181848185<br>testing id: 9</font><br style="font-family:monospace,monospace;background-color:rgb(204,204,204)"><span style="font-family:monospace,monospace;background-color:rgb(204,204,204)">testing attributes: [9, u'abc']</span><font face="monospace, monospace" style="background-color:rgb(204,204,204)"><br>testing id: 10</font> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:monospace,monospace;background-color:rgb(204,204,204)">testing attributes: [10, u'def']</span></blockquote><div><br></div><div>Then, add some features on the <b>view</b>, when you commit, you get :<br></div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="background-color:rgb(204,204,204)"><font face="monospace, monospace">committedFeaturesAdded was triggered on layerIDtest_view20150318181847398<br>testing id: 0<br>testing attributes: [NULL, u'abc']<br>testing id: 0<br>testing attributes: [NULL, u'def']</font></span></blockquote></div><div><br></div><div>So the ID isn't set...</div><div><br></div><div>Am I doing something wrong ?</div><div>Or is QGIS using some other way to get back the ID of a new feature ? Any idea of what that could be ?</div><div>I thought updatable views were more or less transparent to QGIS, and had very good results with views up to now.</div><div><br></div><div><br></div><div>Best regards,</div><div><br></div><div>Olivier</div><div><br></div><div><br></div><div><br></div><div><div class="gmail_extra"><br><pre style="color:rgb(0,0,0);font-size:medium"><span style="color:rgb(128,128,48)"><br></span></pre><div class="gmail_quote">2015-03-17 20:07 GMT+01:00 Jürgen E. <span dir="ltr"><<a href="mailto:jef@norbit.de" target="_blank">jef@norbit.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Olivier,<br>
<span><br>
On Tue, 17. Mar 2015 at 18:08:18 +0100, Olivier Dalang wrote:<br>
> I'm able to run SQL queries after inserts using this signal :<br>
> QgsVectorLayer.committedFeaturesAdded(layerId, addedFeatures)<br>
<br>
> The problem is that the addedFeatures array contains the features in their<br>
> state BEFORE they were committed.<br>
<br>
</span>Are you sure it is?  I didn't try, but the postgres provider already updates<br>
the feature ids of the features passed to QgsPostgresProvider::addFeatures and<br>
and emits those in committedFeaturesAdded afterwards when the commit is run.<br>
<span><font color="#888888"><br>
<br>
Jürgen<br>
<br>
--<br>
Jürgen E. Fischer           norBIT GmbH             Tel. <a href="tel:%2B49-4931-918175-31" value="+49493191817531" target="_blank">+49-4931-918175-31</a><br>
Dipl.-Inf. (FH)             Rheinstraße 13          Fax. <a href="tel:%2B49-4931-918175-50" value="+49493191817550" target="_blank">+49-4931-918175-50</a><br>
Software Engineer           D-26506 Norden             <a href="http://www.norbit.de" target="_blank">http://www.norbit.de</a><br>
QGIS release manager (PSC)  Germany                    IRC: jef on FreeNode<br>
</font></span><br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></blockquote></div><br></div></div></div></div>