<div dir="ltr"><div>Hi Raymond,</div><div><br></div><div>I tested your samples and I cannot reproduce the issue on QGIS master and GDAL 3.4.</div><div><br></div><div>Here is the result of my query on your test file:</div><div><br></div><div>In [13]: md = QgsProviderRegistry.instance().providerMetadata('ogr')<br> ...: conn = md.createConnection('/home/xxxxx/Scaricati/soilext_db.gpkg', {})<br> ...: <br> ...: # Would expect this to return 4 columns: edit_id, timestamp, name, can_undo<br> ...: q = 'SELECT * FROM soilexc_edits ORDER BY edit_id'<br> ...: qr = conn.executeSql(q)<br> ...: <br> ...: <br> ...: # This does not return the edit_id field (Which is the PK)<br> ...: for rec in qr:<br> ...: print(rec)<br> ...: '''<br> ...: [PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]<br> ...: [PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]<br> ...: [PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]<br> ...: '''<br>[1, PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]<br>[2, PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]<br>[3, PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]<br>[4, PyQt5.QtCore.QDateTime(2022, 3, 30, 0, 0), 'purge', False]<br>[5, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]<br>[6, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]<br>[7, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]<br>[8, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]<br></div><div><br></div><div>the edit_id is actually in the results.</div><div><br></div><div>Cheers<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>