[gdal-dev] Distinguish between empty result and error with OGRDataSource::ExecuteSQL

Dan Homerick danhomerick at gmail.com
Wed Oct 26 12:39:26 EDT 2011


On Tue, Oct 25, 2011 at 7:54 PM, Frank Warmerdam <warmerdam at pobox.com> wrote:
> On 11-10-25 04:50 PM, Dan Homerick wrote:
>> The ExecuteSQL method returns NULL when an error occurs, or if the
>> statement result is just empty...
>
> The normal approach to distinguishing would be to call CPLErrorReset()
> before calling ExecuteSQL().  Then if you get a NULL back interogate
> CPLGetLastErrorType().  If it is ERRTYP_FAILURE then an error occurred.

Thanks, that's just what I needed! It's CE_Failure, by the way.

> Note that the "ogr sql" implementation appears to return a layer even if
> the results is empty it just has no features.  Ideally other implementations
> of ExecuteSQL() would do the same.  Feel free to file a ticket if this is
> not the case.

The OGRDataSource documentation
(http://www.gdal.org/ogr/classOGRDataSource.html#a6acc228db6513784a56ce12334a8c33)
states that NULL is returned for statements "that have no results
set", which is subtly different than what I initially claimed, "if the
statement result is just empty" -- in practice, I think that a result
set with no columns comes back as NULL (e.g. from an INSERT
statement), but I think one that has no rows will come back as an
empty OGRLayer.

I think I'd mildly prefer something like an INSERT to return an empty
OGRLayer, but the current implementation doesn't appear to be a bug. I
should probably mention that I don't have much experience with
databases, so I don't have any sense of what's standard as far as
results from non-query statements.

Should I still open a ticket?

Cheers,
 - Dan


More information about the gdal-dev mailing list