开发者

Prepare a syntactically invalid query

I want to check the syntax of a SQL query. I thought to do in preparing it, with DbCommand.Prepare method.

Unfortunately, no error or exception.

For example: SELECT * FORM table

开发者_如何学Python

Is there a way to check the syntax without executing the query ?

To make it perfect, it has to work on SQL Server, Oracle and IBM DB2


For SQL Server, you can use SET FMTONLY and/or SET NOEXEC

set fmtonly on
go
SELECT * FORM table
go
set fmtonly off


Generally only the database you're using is going to know whether a given query is valid or not. One standard and portable trick is to add a WHERE clause that guarantees nothing will be done, then execute the query; for example execute SELECT * FORM table WHERE 1=0 and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜