gdal icon indicating copy to clipboard operation
gdal copied to clipboard

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

Open jidanni opened this issue 1 year ago • 8 comments

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.

jidanni avatar Mar 07 '24 09:03 jidanni

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.

jratike80 avatar Mar 07 '24 10:03 jratike80

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

jidanni avatar Mar 07 '24 10:03 jidanni

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

...

jratike80 avatar Mar 07 '24 11:03 jratike80

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

rouault avatar Mar 08 '24 00:03 rouault

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;
               ^

jidanni avatar Mar 09 '24 11:03 jidanni

Ok, that seems to happen with the OGRSQL dialect.

jratike80 avatar Mar 09 '24 11:03 jratike80

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

mdsumner avatar Mar 21 '24 18:03 mdsumner

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

rouault avatar Apr 19 '24 12:04 rouault