Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread Pedro Camargo via QGIS-Developer
Hey Aron,

                  This does look/feel like one of those "Been there. Done that. 
It's hard..." type of things.



VERY interesting proposal, @Hannes. Both would be awesome features if they ever 
came to fruition!



Cheers,

Pedro




 On Wed, 06 Apr 2022 22:01:15 +1000 Aron Gergely  
wrote 



@Pedro:
 Tried it today on Windows w OSGeo QGIS and failed right away. But
  in a different way:
 
 If I launch OSGeo QGIS and ask for the python executable's path
  (sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks
  like entry point is for QGIS.  So subprocess calls that and a new
  QGIS window opens.
 
 Not feeling like tackling this and probably other cases.
 So back to download+including those bins I reckon.
 
 @Johannes:
 Thank you. Yes realizing that now..
 
 
 Cheers,
 Aron
 
 
 

On 06-04-2022 12:12, Johannes Kröger
  (WhereGroup) wrote:

Trying to find a smart way to install Python dependencies for
the users that will not potentially not work or even break stuff
is a very hard thing(tm). Check out these two QEPs for a lot of
discussion and possible approaches:
 
 https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202
 https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179
Cheers, Hannes

Am 06.04.22 um 00:10 schrieb Pedro
Camargo via QGIS-Developer:

Hey Aron,

                   I did explore that route, but I found
out that it would fail when the user did not have
administrator rights (or even if QGIS had not been ran as
administrator on Windows).  Did you find it to be different?



Cheers,

Pedro







 On Wed, 06 Apr 2022 03:28:09
  +1000 Aron Gergely mailto:aron.gerg...@rasterra.nl wrote 



Thank you, I checked out your plugin - yes that seems
  also a good way.
 I already had the logic to detect, throw message,
  guide to dialog, etc... implemented similar to yours.
 
 But I wanted to let pip manage the actual package, so
  I went with the subprocess+pip route. Here is a
  minimum working example:

import subprocess
import sys


try:
subprocess.check_call((sys.executable, '-m', 'pip', 'install', 'h3<=3.99'))
except subprocess.CalledProcessError as e:
raise e  # handle any errors here instead



I connected it to a button in a dialog. And catch
  stdout, stderr and the exit code of the subprocess so
  I can show the user what is happening.
 
 Have not yet tried on other platforms than Linux. But
  sys.executable is there to solve the ambiguity of
  python executable path.
 
 
 Best regards,
 Aron
 
 






-- 
Johannes Kröger / GIS-Entwickler/-Berater

-
Schon gewusst? 
In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software 
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
-

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

mailto:johannes.kroe...@wheregroup.com
http://www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm 
Amtsgericht Bonn, HRB 9885
---



-- 
 Kind Regards,
 
 Aron Gergely
 +31 (0) 6 38 70 97 66
 
 Rasterra | http://www.rasterra.nl___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread Aron Gergely via QGIS-Developer

@Andrea
Thank you - I posted my case to that issue.

@Benjamin
Thanks, wow this looks comprehensive.

I thought of that shutil way but dismissed it, I'd have to try then for 
'python', 'python3'. And it would not work in case
user set up a shell alias (say, python3.9) for the python executable in 
their env.

Although in that case they probably know how to install packages themselves.

I see shutil tries for the python command here: 
https://bitbucket.org/hu-geomatics/enmap-box/src/966a75ffbe903775c03f54e5dc0e663dfb98b2de/enmapbox/dependencycheck.py#lines-166:178


Did this give you any trouble when you rolled it out to the users?

Best regards,
Aron

On 06-04-2022 15:17, Benjamin Jakimow wrote:


Hi Aron,

with the EnMAP-Box plugin we are confronted with missing PIP packages 
quite often. Therefore we implemented a "PIP Package Installer" 
(screenshot below, source code here: 
https://bitbucket.org/hu-geomatics/enmap-box/src/develop/enmapbox/dependencycheck.py)


In case of missing admin rights you can use the PIP "--user" argument 
to install packages to the user's home folder


D:\OSGeo4W\bin\python3.EXE -m pip install --user lightgbm

The absolute python executable path can be retrieved with 
"shutil.which('python') "




Greetings,

Benjamin

On 2022-04-06 14:01, Aron Gergely via QGIS-Developer wrote:


@Pedro:
Tried it today on Windows w OSGeo QGIS and failed right away. But in 
a different way:


If I launch OSGeo QGIS and ask for the python executable's path 
(sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks 
like entry point is for QGIS.  So subprocess calls that and a new 
QGIS window opens.


Not feeling like tackling this and probably other cases.
So back to download+including those bins I reckon.

@Johannes:
Thank you. Yes realizing that now..


Cheers,
Aron



On 06-04-2022 12:12, Johannes Kröger (WhereGroup) wrote:


Trying to find a smart way to install Python dependencies for the 
users that will not potentially not work or even break stuff is a 
very hard thing(tm). Check out these two QEPs for a lot of 
discussion and possible approaches:


https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202 

https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179 



Cheers, Hannes

Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:

Hey Aron,
                   I did explore that route, but I found out that 
it would fail when the user did not have administrator rights (or 
even if QGIS had not been ran as administrator on Windows).  Did 
you find it to be different?

Cheers,
Pedro
 On Wed, 06 Apr 2022 03:28:09 +1000 *Aron Gergely 
 * wrote 



Thank you, I checked out your plugin - yes that seems also a
good way.
I already had the logic to detect, throw message, guide to
dialog, etc... implemented similar to yours.

But I wanted to let pip manage the actual package, so I went
with the subprocess+pip route. Here is a minimum working example:

import subprocess
import sys


try:
 subprocess.check_call((sys.executable, '-m', 'pip', 'install', 
'h3<=3.99'))
except subprocess.CalledProcessErroras e:
 raise e# handle any errors here instead

I connected it to a button in a dialog. And catch stdout,
stderr and the exit code of the subprocess so I can show the
user what is happening.

Have not yet tried on other platforms than Linux. But
sys.executable is there to solve the ambiguity of python
executable path.


Best regards,
Aron



--
Johannes Kröger / GIS-Entwickler/-Berater

-
Schon gewusst?

In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/  
-

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroe...@wheregroup.com  
www.wheregroup.com  
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
---

--
Kind Regards,

Aron Gergely
+31 (0) 6 38 70 97 66

*Rasterra* | www.rasterra.nl 

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



--
--
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu 
Berlin


e-mail: benjamin.jaki...@geo.hu-berlin.de

phone:  +49 (0) 30 2093 6894
mobile: +49 (0) 157 5656 8477
fax:    +49 (0) 30 2093 6848
mail:   Unter den Linden 

Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread Benjamin Jakimow via QGIS-Developer



Hi Aron,

with the EnMAP-Box plugin we are confronted with missing PIP packages 
quite often. Therefore we implemented a "PIP Package Installer" 
(screenshot below, source code here: 
https://bitbucket.org/hu-geomatics/enmap-box/src/develop/enmapbox/dependencycheck.py)


In case of missing admin rights you can use the PIP "--user" argument to 
install packages to the user's home folder


D:\OSGeo4W\bin\python3.EXE -m pip install --user lightgbm

The absolute python executable path can be retrieved with 
"shutil.which('python') "


Greetings,

Benjamin

On 2022-04-06 14:01, Aron Gergely via QGIS-Developer wrote:


@Pedro:
Tried it today on Windows w OSGeo QGIS and failed right away. But in a 
different way:


If I launch OSGeo QGIS and ask for the python executable's path 
(sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks like 
entry point is for QGIS.  So subprocess calls that and a new QGIS 
window opens.


Not feeling like tackling this and probably other cases.
So back to download+including those bins I reckon.

@Johannes:
Thank you. Yes realizing that now..

Cheers,
Aron

On 06-04-2022 12:12, Johannes Kröger (WhereGroup) wrote:

Trying to find a smart way to install Python dependencies for the users 
that will not potentially not work or even break stuff is a very hard 
thing(tm). Check out these two QEPs for a lot of discussion and 
possible approaches:


https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202
https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179

Cheers, Hannes

Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:

Hey Aron,
I did explore that route, but I found out that it would fail when the 
user did not have administrator rights (or even if QGIS had not been 
ran as administrator on Windows).  Did you find it to be different?


Cheers,
Pedro

 On Wed, 06 Apr 2022 03:28:09 +1000 Aron Gergely 
 wrote 


Thank you, I checked out your plugin - yes that seems also a good way.
I already had the logic to detect, throw message, guide to dialog, 
etc... implemented similar to yours.


But I wanted to let pip manage the actual package, so I went with the 
subprocess+pip route. Here is a minimum working example:


import subprocess
import sys

try:
subprocess.check_call((sys.executable, '-m', 'pip', 'install', 
'h3<=3.99'))

except subprocess.CalledProcessError as e:
raise e  # handle any errors here instead

I connected it to a button in a dialog. And catch stdout, stderr and 
the exit code of the subprocess so I can show the user what is 
happening.


Have not yet tried on other platforms than Linux. But sys.executable is 
there to solve the ambiguity of python executable path.


Best regards,
Aron


--
Johannes Kröger / GIS-Entwickler/-Berater

-
Schon gewusst?

In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
-

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroe...@wheregroup.com
www.wheregroup.com [1]
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
---

--
Kind Regards,

Aron Gergely
+31 (0) 6 38 70 97 66

Rasterra | www.rasterra.nl [2]

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

--
--
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu 
Berlin


e-mail: benjamin.jaki...@geo.hu-berlin.de

phone:  +49 (0) 30 2093 6894
mobile: +49 (0) 157 5656 8477
fax:+49 (0) 30 2093 6848
mail:   Unter den Linden 6 | 10099 Berlin | Germany
room: 2'222

Links:
--
[1] http://www.wheregroup.com
[2] http://www.rasterra.nl___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread Andrea Giudiceandrea via QGIS-Developer

Hi Aron,
have you already read the issue report 
https://github.com/qgis/QGIS/issues/45646 ?


Regards.

Andrea

Il 06/04/2022 14:01, Aron Gergely via QGIS-Developer ha scritto:


@Pedro:
Tried it today on Windows w OSGeo QGIS and failed right away. But in a 
different way:


If I launch OSGeo QGIS and ask for the python executable's path 
(sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks like 
entry point is for QGIS.  So subprocess calls that and a new QGIS 
window opens.



___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread Aron Gergely via QGIS-Developer

@Pedro:
Tried it today on Windows w OSGeo QGIS and failed right away. But in a 
different way:


If I launch OSGeo QGIS and ask for the python executable's path 
(sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks like 
entry point is for QGIS.  So subprocess calls that and a new QGIS window 
opens.


Not feeling like tackling this and probably other cases.
So back to download+including those bins I reckon.

@Johannes:
Thank you. Yes realizing that now..


Cheers,
Aron



On 06-04-2022 12:12, Johannes Kröger (WhereGroup) wrote:


Trying to find a smart way to install Python dependencies for the 
users that will not potentially not work or even break stuff is a very 
hard thing(tm). Check out these two QEPs for a lot of discussion and 
possible approaches:


https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202
https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179

Cheers, Hannes

Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:

Hey Aron,
                   I did explore that route, but I found out that it 
would fail when the user did not have administrator rights (or even 
if QGIS had not been ran as administrator on Windows).  Did you find 
it to be different?


Cheers,
Pedro



 On Wed, 06 Apr 2022 03:28:09 +1000 *Aron Gergely 
* wrote 


Thank you, I checked out your plugin - yes that seems also a good
way.
I already had the logic to detect, throw message, guide to
dialog, etc... implemented similar to yours.

But I wanted to let pip manage the actual package, so I went with
the subprocess+pip route. Here is a minimum working example:

import subprocess
import sys


try:
 subprocess.check_call((sys.executable, '-m', 'pip', 'install', 
'h3<=3.99'))
except subprocess.CalledProcessErroras e:
 raise e# handle any errors here instead

I connected it to a button in a dialog. And catch stdout, stderr
and the exit code of the subprocess so I can show the user what
is happening.

Have not yet tried on other platforms than Linux. But
sys.executable is there to solve the ambiguity of python
executable path.


Best regards,
Aron



--
Johannes Kröger / GIS-Entwickler/-Berater

-
Schon gewusst?

In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
-

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroe...@wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
---

--
Email Signature Kind Regards,

Aron Gergely
+31 (0) 6 38 70 97 66

*Rasterra* | www.rasterra.nl___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] QgsDissolveAlgorithm error LNK2001

2022-04-06 Thread SSchmidt--- via QGIS-Developer
Hello to all,

for my c++ plugin I need to include the qgsalgorithmdissolve.h.

Thats why I include for linking the library 
..\..\analysis\RelWithDebInfo\qgis_analysis.lib

and give it additional library path to:
C:/Entwicklung/QuantumGIS/build/src/analysis
C:/Entwicklung/QuantumGIS/build/src/analysis/RelWithDebInfo

But anyway I get linking errors:
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual void __cdecl QgsDissolveAlgorithm::initAlgorithm(class 
QMap const &)" 
(?initAlgorithm@QgsDissolveAlgorithm@@UEAAXAEBV?$QMap@VQString@@VQVariant@Z)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QString __cdecl 
QgsDissolveAlgorithm::name(void)const " 
(?name@QgsDissolveAlgorithm@@UEBA?AVQString@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QString __cdecl 
QgsDissolveAlgorithm::displayName(void)const " 
(?displayName@QgsDissolveAlgorithm@@UEBA?AVQString@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QStringList __cdecl 
QgsDissolveAlgorithm::tags(void)const " 
(?tags@QgsDissolveAlgorithm@@UEBA?AVQStringList@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QString __cdecl 
QgsDissolveAlgorithm::group(void)const " 
(?group@QgsDissolveAlgorithm@@UEBA?AVQString@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QString __cdecl 
QgsDissolveAlgorithm::groupId(void)const " 
(?groupId@QgsDissolveAlgorithm@@UEBA?AVQString@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QString __cdecl 
QgsDissolveAlgorithm::shortHelpString(void)const " 
(?shortHelpString@QgsDissolveAlgorithm@@UEBA?AVQString@@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""public: virtual class QgsDissolveAlgorithm * __cdecl 
QgsDissolveAlgorithm::createInstance(void)const " 
(?createInstance@QgsDissolveAlgorithm@@UEBAPEAV1@XZ)".
DlgZoomMappeSave.obj : error LNK2001: Nicht aufgelöstes externes Symbol 
""protected: virtual class QMap __cdecl 
QgsDissolveAlgorithm::processAlgorithm(class QMap const &,class QgsProcessingContext &,class QgsProcessingFeedback 
*)" 
(?processAlgorithm@QgsDissolveAlgorithm@@MEAA?AV?$QMap@VQString@@VQVariantAEBV2@AEAVQgsProcessingContext@@PEAVQgsProcessingFeedback@@@Z)".

What do I miss?

Freundliche Grüße aus Leipzig
Susann Schmidt
Softwareentwicklung 

**

GFI - Gesellschaft für Informationstechnologie mbH
Philipp-Rosenthal-Straße 9
D-04103 Leipzig
Geschäftsführer: Andreas Richter
Amtsgericht Leipzig HRB 12054
USt.-IdNr.: DE179049354 Steuer-Nr.: 231/109/06412
Tel. 0341 961 3310Fax 0341 961 3311   Mail i...@gfi-gis.de
Web  www.gfi-gis.de
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

2022-04-06 Thread WhereGroup
Trying to find a smart way to install Python dependencies for the users 
that will not potentially not work or even break stuff is a very hard 
thing(tm). Check out these two QEPs for a lot of discussion and possible 
approaches:


https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202
https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179

Cheers, Hannes

Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:

Hey Aron,
                   I did explore that route, but I found out that it 
would fail when the user did not have administrator rights (or even if 
QGIS had not been ran as administrator on Windows).  Did you find it 
to be different?


Cheers,
Pedro



 On Wed, 06 Apr 2022 03:28:09 +1000 *Aron Gergely 
* wrote 


Thank you, I checked out your plugin - yes that seems also a good way.
I already had the logic to detect, throw message, guide to dialog,
etc... implemented similar to yours.

But I wanted to let pip manage the actual package, so I went with
the subprocess+pip route. Here is a minimum working example:

import subprocess
import sys


try:
 subprocess.check_call((sys.executable, '-m', 'pip', 'install', 
'h3<=3.99'))
except subprocess.CalledProcessErroras e:
 raise e# handle any errors here instead

I connected it to a button in a dialog. And catch stdout, stderr
and the exit code of the subprocess so I can show the user what is
happening.

Have not yet tried on other platforms than Linux. But
sys.executable is there to solve the ambiguity of python
executable path.


Best regards,
Aron



--
Johannes Kröger / GIS-Entwickler/-Berater

-
Schon gewusst?

In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
-

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroe...@wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
---



OpenPGP_0xBF7B268A77C202D5.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Unexpected results from GPKG table query using executeSql()

2022-04-06 Thread Raymond Nijssen via QGIS-Developer

Hi Alessandro,

Thanks for looking into this!
My QGIS-master + GDAL 3.0.4 returns the same result for that query.


But in QGIS-master, when I try:

q = 'SELECT *, edit_id FROM soilexc_edits ORDER BY edit_id'

I get:
[0, 1, PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), 'test1', True]
[1, 2, PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), 'test2', True]
[2, 3, PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), 'test3', True]

I would expect:
[0, PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), 'test1', True, 0]



The point is I'm building a plugin that should work in multiple QGIS 
versions (from 3.10), so I'm trying to write queries that will work for 
any version and that seems very hard.


For now the edit_id+0 workaround does the trick.

BTW, Another thing I bumped into is the QDateTime in the result always 
having the time 00:00. Is that some known limitation?


Kind regards,
Raymond


On 06-04-2022 10:14, Alessandro Pasotti wrote:

Hi Raymond,

I tested your samples and I cannot reproduce the issue on QGIS master 
and GDAL 3.4.


Here is the result of my query on your test file:

In [13]: md = QgsProviderRegistry.instance().providerMetadata('ogr')
     ...: conn = 
md.createConnection('/home/x/Scaricati/soilext_db.gpkg', {})

     ...:
     ...: # Would expect this to return 4 columns: edit_id, timestamp, 
name, can_undo

     ...: q = 'SELECT * FROM soilexc_edits ORDER BY edit_id'
     ...: qr = conn.executeSql(q)
     ...:
     ...:
     ...: # This does not return the edit_id field (Which is the PK)
     ...: for rec in qr:
     ...:     print(rec)
     ...: '''
     ...: [PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]
     ...: [PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]
     ...: [PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]
     ...: '''
[1, PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]
[2, PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]
[3, PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]
[4, PyQt5.QtCore.QDateTime(2022, 3, 30, 0, 0), 'purge', False]
[5, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[6, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[7, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[8, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]

the edit_id is actually in the results.

Cheers


On Fri, Apr 1, 2022 at 8:28 AM Raymond Nijssen > wrote:


For a workaround I found that selecting this way:

SELECT
    edit_id + 0 AS edit_id,
    timestamp,
    name
FROM
    ...

The +0 seem to makes QGIS (or GDAL?) unaware of edit_id being the PK
field and it does return it. Works both in 3.10 and 3.25.

Raymond



On 31-03-2022 18:15, Alessandro Pasotti wrote:
 > Hi Raymond,
 >
 > your code looks good.
 >
 > Can you provide a test file?
 >
 > There are some test in core here:
 >

https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py



 >

>
 >
 >
 > On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via QGIS-Developer
 > mailto:qgis-developer@lists.osgeo.org>
>>
 > wrote:
 >
 >     Hi devs,
 >
 >     I'm working on a plugin that connects to a custom table (without
 >     geometry) in a GPKG. When I'm sending queries to it, I keep
on getting
 >     unexpected results. Somehow the id field is missing, sometimes it
 >     appears twice (!). And this seems to be different between
QGIS 3.10 and
 >     3.25. (I think it changed since 3.22).
 >
 >     Here is a piece of my code:
 >
 >
 >     fn = '/path/to/test.gpkg'
 >     md = QgsProviderRegistry.instance().providerMetadata('ogr')
 >     conn = md.createConnection(fn, {})
 >
 >     q = 'select * from test_table;'
 >     qr = conn.executeSql(q)
 >     print(qr) # No id field in result
 >
 >
 >
 >     Before diving into the QGIS code I'd like to check if this is the
 >     way to
 >     go. Or should i use another way to query that GPKG (SQLite) db?
 >
 >
 >     Kind regards,
 >     Raymond
 >     ___
 >     QGIS-Developer mailing list
 > QGIS-Developer@lists.osgeo.org

>
 >     List info:
https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Unexpected results from GPKG table query using executeSql()

2022-04-06 Thread Alessandro Pasotti via QGIS-Developer
Hi Raymond,

I tested your samples and I cannot reproduce the issue on QGIS master and
GDAL 3.4.

Here is the result of my query on your test file:

In [13]: md = QgsProviderRegistry.instance().providerMetadata('ogr')
...: conn =
md.createConnection('/home/x/Scaricati/soilext_db.gpkg', {})
...:
...: # Would expect this to return 4 columns: edit_id, timestamp, name,
can_undo
...: q = 'SELECT * FROM soilexc_edits ORDER BY edit_id'
...: qr = conn.executeSql(q)
...:
...:
...: # This does not return the edit_id field (Which is the PK)
...: for rec in qr:
...: print(rec)
...: '''
...: [PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]
...: [PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]
...: [PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]
...: '''
[1, PyQt5.QtCore.QDateTime(2022, 3, 1, 0, 0), '', True]
[2, PyQt5.QtCore.QDateTime(2022, 3, 2, 0, 0), '', True]
[3, PyQt5.QtCore.QDateTime(2022, 3, 3, 0, 0), '', True]
[4, PyQt5.QtCore.QDateTime(2022, 3, 30, 0, 0), 'purge', False]
[5, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[6, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[7, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]
[8, PyQt5.QtCore.QDateTime(2022, 3, 31, 0, 0), 'test_new', True]

the edit_id is actually in the results.

Cheers


On Fri, Apr 1, 2022 at 8:28 AM Raymond Nijssen 
wrote:

> For a workaround I found that selecting this way:
>
> SELECT
>edit_id + 0 AS edit_id,
>timestamp,
>name
> FROM
>...
>
> The +0 seem to makes QGIS (or GDAL?) unaware of edit_id being the PK
> field and it does return it. Works both in 3.10 and 3.25.
>
> Raymond
>
>
>
> On 31-03-2022 18:15, Alessandro Pasotti wrote:
> > Hi Raymond,
> >
> > your code looks good.
> >
> > Can you provide a test file?
> >
> > There are some test in core here:
> >
> https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py
> > <
> https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py
> >
> >
> >
> > On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via QGIS-Developer
> > mailto:qgis-developer@lists.osgeo.org>>
>
> > wrote:
> >
> > Hi devs,
> >
> > I'm working on a plugin that connects to a custom table (without
> > geometry) in a GPKG. When I'm sending queries to it, I keep on
> getting
> > unexpected results. Somehow the id field is missing, sometimes it
> > appears twice (!). And this seems to be different between QGIS 3.10
> and
> > 3.25. (I think it changed since 3.22).
> >
> > Here is a piece of my code:
> >
> >
> > fn = '/path/to/test.gpkg'
> > md = QgsProviderRegistry.instance().providerMetadata('ogr')
> > conn = md.createConnection(fn, {})
> >
> > q = 'select * from test_table;'
> > qr = conn.executeSql(q)
> > print(qr) # No id field in result
> >
> >
> >
> > Before diving into the QGIS code I'd like to check if this is the
> > way to
> > go. Or should i use another way to query that GPKG (SQLite) db?
> >
> >
> > Kind regards,
> > Raymond
> > ___
> > QGIS-Developer mailing list
> > QGIS-Developer@lists.osgeo.org  QGIS-Developer@lists.osgeo.org>
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > 
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > 
> >
> >
> >
> > --
> > Alessandro Pasotti
> > QCooperative: www.qcooperative.net 
> > ItOpen: www.itopen.it 
>


-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer