Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should bomb out when given multiple -sql arguments, instead of randomly executing one #9415

Open
jidanni opened this issue Mar 7, 2024 · 8 comments

Comments

@jidanni
Copy link
Contributor

jidanni commented Mar 7, 2024

What is the bug?

As per #9394, the programs should bomb out when given multiple -sql arguments, instead of the current behavior of simply "randomly" executing one of them as if that was the only one given.

Stopping it is a better idea than attempting to document this aberrant behavior.

@jratike80
Copy link
Collaborator

I do not remember any user feedback about surprises with giving multiple -sql arguments. I believe that it is not a very common problem, and I also believe that it has made some trouble for someone sometimes.

Definition of aberrant seems to be "different from what is typical or usual". It is typical and usual for GDAL that users are not protected against giving several times arguments that can be used only once. I do not mean that it is perfect solution to force users to read the documentation.

@jidanni
Copy link
Contributor Author

jidanni commented Mar 7, 2024

All I know is -sql statement1 -sql statement2 is equivalent to -sql 'statement1; statement2;' and that causes an error to be raised.

@jratike80
Copy link
Collaborator

Another variation:
ogrinfo test.gpkg test -where fid=1 -where fid=2

What error do you see with -sql 'statement1; statement2;'? I do not see any

ogrinfo pyykkitarkastus.gpkg -sql "select * from pyykkitarkastus where fid=2;select * from pyykkitarkastus where fid=1"
INFO: Open of `pyykkitarkastus.gpkg'
      using driver `GPKG' successful.

Layer name: SELECT
Geometry: Point
Feature Count: 1

...

@rouault
Copy link
Member

rouault commented Mar 8, 2024

Wondering if we shouldn't investigate on using a "standard" argument parser that would provide all the convenient logic, such as erroring out if provided multiple arguments when this is not expected. https://github.com/p-ranav/argparse could be a candidate to investigate

@jidanni
Copy link
Contributor Author

jidanni commented Mar 9, 2024

What error do you see with -sql 'statement1; statement2;'? I do not see any

$ ogr2ogr o.csv x.csv -sql 'SELECT 1 FROM x; SELECT 2 FROM x;'
ERROR 1: SQL Expression Parsing Error: syntax error, unexpected $undefined, expecting end of string. Occurred around :
SELECT 1 FROM x; SELECT 2 FROM x;
               ^

@jratike80
Copy link
Collaborator

Ok, that seems to happen with the OGRSQL dialect.

@mdsumner
Copy link
Contributor

mdsumner commented Mar 21, 2024

indeed the multiple instances of arguments in various utils has bitten me a few times

@rouault
Copy link
Member

rouault commented Apr 19, 2024

Check of single -sql instance is now effective in ogrinfo, ogr2ogr and gdal_grid which have been converted to the argparse framework. Still remaining gdal_rasterize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants