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

Frank Warmerdam warmerdam at pobox.com
Tue Oct 25 22:54:01 EDT 2011


On 11-10-25 04:50 PM, Dan Homerick wrote:
> GDAL-Dev,
>
> The ExecuteSQL method returns NULL when an error occurs, or if the
> statement result is just empty. I don't see any methods to get
> information on the last error, which leaves me wondering if there's a
> good way to distinguish the different causes for a NULL result.
>
> I've been prototyping using MS SQL Server, and it looks like the
> OGRODBCDataSource has a public getSession method (returning a
> CPLODBCSession), that I could use to get error information -- although
> this method is commented as being for internal use. Is there a better
> route, ideally one that is sure to be supported for all the various
> SQL drivers?

Dan,

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.

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.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/warmerda
and watch the world go round - Rush    | Geospatial Software Developer



More information about the gdal-dev mailing list