HomeActive Query Builder - IntroductionCommon QuestionsValidating SQL query (syntax analysis only)

3.7. Validating SQL query (syntax analysis only)

To validate a query against specific SQL syntax with Active Query Builder .NET Edition, use the the ValidateQuery() method of appropriate syntax provider:

MSSQLSyntaxProvider syntax = new MSSQLSyntaxProvider();
string errorInfo = "";

if (!syntax.ValidateQuery("select * from Orders", ref errorInfo))

Having VCL or ActiveX Edition of Active Query Builder, you may assign SQL query text to the QueryBuilder.SyncSQL property in a try-except (try-catch) block.

  acQueryBuilder.SQL:='select * from Orders';
  on e:EacSQLError do
    ShowMessage('Unexpected token "'+e.ErrorTokenValue+'" in line '+IntToStr(e.ErrorPos.line);

Please note that Active Query Builder does not perform validation against specific database context, i.e. presence of table fields, function parameters, constants, etc. We believe that the best and only possible validator is the database server itself.

The fastest way to do that is to execute the query without data retrieval by calling the following method:


Of course, you can check if such database objects and fields are present in the database (using the QueryBuilder.QueryStatistics set of collections), but still there are many things we can recognize if a query is correct in terms of specific database or not.

You may instruct the component to generate parsing error for queries with unknown database objects using the QueryBuilder.ParsingErrorOnUnknownObjects property

Active Query Builder can parse SELECT statements only. For the rest of statements, it switches to the Sleep Mode. You may deny switching to this mode by setting the QueryBuilder.AllowSleepMode to false. Also you may set the event handler for the SleepModeChanged to perform necessary actions.

This page was: Helpful | Not Helpful