HomeActive Query BuilderValidate SQL for ActiveX Edition

Validate SQL for ActiveX Edition


Hi,

How do you validate the sql query for syntax errors using javascript? I am using the ActiveX Edition.

Also is it possible to validate that the objects exist within the current db?
Richard | email
May 3 2010, 10:34 PM
For example, in our "Demos\HTMLDemo\AQBDemo2.htm" replace OnSQLBlur event handler by this one:

function OnSQLBlur(){
try {
window.document.Form1.qb.SQL =
window.document.Form1.sql.value;
}
catch(err) {
alert('Incorrect SQL!\n'+err.description);
}
}

And don't forget to turn off Query Builder's "sleep mode" - add the following to the "<OBJECT id="qb" ...>" tag:

<PARAM NAME="AllowSleepMode" VALUE="0">

After these changes, when you entered incorrect SQL "select select", you will get alert box with the text:

Incorrect SQL!
Invalid select statement.
Unexpected token "select" at line 1, pos 8
Vitaly Sotnikov | email
8 hours, 33 mins since original post
Great, thanks Vitaly that seems to be working as expected.

Does anyone know how to validate the actual table/objects that is being used in the query is valid/exist eg:

select * from blah

In this case, the object blah does not exist but the syntax is correct so Vitaly's code example wont complain about that. Does anyone know how to handle this for ActiveX Edition using Javascript?
Richard | email
22 hours, 24 mins since original post
To deny parsing of queries with objects that aren't present in the Metadata Container, you should set the ParsingErrorOnUnknownObjects property to True. Another way is to check for illegal objects before execution using the QueryStatistics.UsedDatabaseObjects collection.
Sergey Smagin | email
1 day, 6 hours since original post
This topic is closed