How to verify that a Query's where statement is valid

844
5
02-20-2013 06:46 PM
StephenLead
Regular Contributor III
What are the best options to check whether a query's where statement is valid?

Some ideas are:

- use regex or otherwise write a function to manually validate the SQL. A drawback is that the syntax of the query.where statement may be Esri-specific (eg % vs * depending on the dataset type, etc). Also, this will not verify that the statement will actually work - it may be valid SQL but not applicable to this layer.

- run the query, and use the execute statement's error callback. The problem is that you won't know until afterwards whether it was a valid statement.

- use executeForIds and specify a known ID in conjunction with the error callback. The problem is that I won't know a valid ID at runtime.

- use executeForCount to return the number of records. The problem is that for a large dataset, the executeForCount still has to find all resulting features, which can take a while.

It would be nice to have another option (eg QueryTask.validate) on the QueryTask, to verify that the query.where statement is valid. Another approach could be for Esri to add an option on executeForCount to break after the first feature is found (rather than waiting until all features have been found).

Any other suggestions?

Thanks,
Steve
0 Kudos
5 Replies
HaroldBostic
Occasional Contributor II
Are you stuck with just using the ESRI REST API, can you create your own validate service and call that.
0 Kudos
StephenLead
Regular Contributor III
Are you stuck with just using the ESRI REST API, can you create your own validate service and call that.


Hi Harold,

Are you aware of any examples of this?

Cheers,
Steve
0 Kudos
HaroldBostic
Occasional Contributor II
I am afraid not.  Are you looking to return true for valid SQL or looking for true when you have Valid SQL and a result can be returned?
0 Kudos
StephenLead
Regular Contributor III
I'd like something along the lines of the Verify option in ArcMap's Select By Attributes dialog:

[ATTACH=CONFIG]22065[/ATTACH]

This validates the statement before attempting to execute it.

Cheers,
Steve
0 Kudos
HaroldBostic
Occasional Contributor II
I still don't have a concrete example but a jumping off point would be to create a gp service that accepts your query then do something similar to this in your script http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000057000000

But instead of committing, just return true or false and possibly the error message if it was an invalid query.
Here's a resource for gp services http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/An_overview_of_geoprocessing_with_ArcG...
0 Kudos