Opened 11 years ago
Closed 11 years ago
#4870 closed defect (fixed)
Broken SQL passed to -sql and run by PostgreSQL driver result in SUCCESS exit code
Reported by: | strk | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 1.10.0 |
Component: | Utilities | Version: | 1.9.2 |
Severity: | normal | Keywords: | ogr2ogr sql |
Cc: |
Description
Requesting an invalid SQL to the PG driver throws an error message on stderr but doesn't trigger FAILURE exit code. Example:
$ ogr2ogr -f ES'RI Shapefile' tmp 'PG:dbname=template1' -sql 'select as foo' && echo SUCCESS ERROR 1: ERROR: syntax error at or near "as" LINE 1: select as foo ^ SUCCESS
Attachments (1)
Change History (8)
comment:1 by , 11 years ago
comment:3 by , 11 years ago
Ok, so ExecuteSQL correctly returns NULL, bug apps/ogr2ogr.cpp doesn't seem to be considering that NULL as a sign of a fatal failure. In which cases it isn't fatal ?
by , 11 years ago
Attachment: | 0001-Have-ogr2ogr-exit-with-FAILURE-code-on-broken-sql-48.patch added |
---|
proposed patch
comment:4 by , 11 years ago
I made the patch against 1.9.2 -- also tried to provide a pull request but it looks like my git version of gdal is still not setup correctly
comment:5 by , 11 years ago
NULL is a legit return value for ExecuteSQL() in some cases like INSERT, UPDATE, VACCUUM, etc.. statements. But that's more for the ogrinfo -sql case. In ogr2ogr, only SELECT makes sense, and SELECT should never return NULL on success (even if there are 0 rows returned).
In case I missed something (which would be a corner use case), to be really safe, one approach would be to exit(1) only if NULL has been returned by ExecuteSQL() and that CPLGetLastErrorNo() != 0.
comment:6 by , 11 years ago
My patch is for ogr2ogr.cpp so wouldn't affect ogrinfo. I confirm CPLGetLastErrorNo() !=0 in my case so I'm fine with that addition. Want me to send another patch or can you do that ?
comment:7 by , 11 years ago
Component: | default → Utilities |
---|---|
Keywords: | ogr2ogr sql added |
Milestone: | → 2.0.0 |
Resolution: | → fixed |
Status: | new → closed |
Fix committed in r25149
I don't see traces of OGRPGDataSource::ExecuteSQL being called by the above commandline, is it expected ?