<div dir="ltr"><div>Hi Raymond,</div><div><br></div><div>I'll have a look but keep in mind that for GPKG the implementation uses GDAL/OGR to execute the queries, there might be some fid/id handling that messes up with the returned fields.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 1, 2022 at 8:28 AM Raymond Nijssen <<a href="mailto:r.nijssen@terglobo.nl">r.nijssen@terglobo.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">For a workaround I found that selecting this way:<br>
<br>
SELECT<br>
edit_id + 0 AS edit_id,<br>
timestamp,<br>
name<br>
FROM<br>
...<br>
<br>
The +0 seem to makes QGIS (or GDAL?) unaware of edit_id being the PK <br>
field and it does return it. Works both in 3.10 and 3.25.<br>
<br>
Raymond<br>
<br>
<br>
<br>
On 31-03-2022 18:15, Alessandro Pasotti wrote:<br>
> Hi Raymond,<br>
> <br>
> your code looks good.<br>
> <br>
> Can you provide a test file?<br>
> <br>
> There are some test in core here: <br>
> <a href="https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py</a> <br>
> <<a href="https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py</a>><br>
> <br>
> <br>
> On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via QGIS-Developer <br>
> <<a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.org</a> <mailto:<a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.org</a>>> <br>
> wrote:<br>
> <br>
> Hi devs,<br>
> <br>
> I'm working on a plugin that connects to a custom table (without<br>
> geometry) in a GPKG. When I'm sending queries to it, I keep on getting<br>
> unexpected results. Somehow the id field is missing, sometimes it<br>
> appears twice (!). And this seems to be different between QGIS 3.10 and<br>
> 3.25. (I think it changed since 3.22).<br>
> <br>
> Here is a piece of my code:<br>
> <br>
> <br>
> fn = '/path/to/test.gpkg'<br>
> md = QgsProviderRegistry.instance().providerMetadata('ogr')<br>
> conn = md.createConnection(fn, {})<br>
> <br>
> q = 'select * from test_table;'<br>
> qr = conn.executeSql(q)<br>
> print(qr) # No id field in result<br>
> <br>
> <br>
> <br>
> Before diving into the QGIS code I'd like to check if this is the<br>
> way to<br>
> go. Or should i use another way to query that GPKG (SQLite) db?<br>
> <br>
> <br>
> Kind regards,<br>
> Raymond<br>
> _______________________________________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a>><br>
> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> <<a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> <<a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>><br>
> <br>
> <br>
> <br>
> -- <br>
> Alessandro Pasotti<br>
> QCooperative: <a href="http://www.qcooperative.net" rel="noreferrer" target="_blank">www.qcooperative.net</a> <<a href="https://www.qcooperative.net" rel="noreferrer" target="_blank">https://www.qcooperative.net</a>><br>
> ItOpen: <a href="http://www.itopen.it" rel="noreferrer" target="_blank">www.itopen.it</a> <<a href="http://www.itopen.it" rel="noreferrer" target="_blank">http://www.itopen.it</a>><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Alessandro Pasotti</div><div>QCooperative: <a href="https://www.qcooperative.net" target="_blank">www.qcooperative.net</a><br></div>ItOpen: <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div></div>