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

Discussion created by stevel on Feb 20, 2013
Latest reply on Feb 21, 2013 by hbostic
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?