检查“何处” C#中的SQL子句 [英] Examining the "Where" clause of a SQL in C#

查看:55
本文介绍了检查“何处” C#中的SQL子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在确认从用户收到的文本框输入的SQL时遇到了困难,我们走了;用户正在输入具有大量条件的复杂SQL,在Where子句中输入子查询,我的部分是在输入SQL的Where子句中提取条件计数。

<对于下面的SQL,
,该值应返回为4,尽管我在子查询中使用了多个条件,但我需要获取已在Base SQL中使用的条件计数。(不应考虑Where子句中的子查询。



Hi,

I got stuck up in validating the SQL which has been received as a Text Box input from the User, here we go; User is entering the complex SQL with lot of Conditions, sub queries in a "Where" clause, and my portion is to extract the count of Conditions in the "Where" clause of a input SQL.

for the below SQL, the value should return as "4", though I have mulitple conditions used in the Sub Query, I need to get the count of Conditions that have been used in the Base SQL.(Sub Queries in the Where clause should not be taken into account)

Select *
from table_1
where c1=232 and c2=44 and c3 in (Select test from table_2 where table_2.col='Con_val") and rownum<=100;



为了实现SQL中Where条件的精确计数,C#中是否有任何预定义的方法或函数。



等待C#专家的回复。



提前致谢,

Priya


In order to achieve the exact count of Where conditions in a SQL, is there any predefined Method or function available in C#.

Awaiting for the response from C# experts.

Thanks in advance,
Priya

推荐答案

语句解析非常复杂。因为您需要遵循该特定实现的语法。即使这些实现声称与SQL:2001兼容,例如,确保语法中存在相当大的差异。因此,对于复杂且非常健壮的解决方案,您需要自己实现该RDBMS特定实现的查询解析器。可以在此处找到BNF表示法中Oracle查询语言的完整语法: http://docs.oracle .com / javaee / 5 / tutorial / doc / bnbuf.html [ ^ ]



这个可能是一个很好的起点:SQL Parser [ ^ ]
Statement parsing is quite complicated. Since you need to follow the syntax of that specific implementation. Even those implementation claim to be SQL:2001 compliant for example, for sure there will be considerable differences in the syntax. Thus for a complex and really robust solution, you need to implement yourself the query parser of that RDBMS specific implementation. The full syntax of Oracle query language in BNF notation can be found here: http://docs.oracle.com/javaee/5/tutorial/doc/bnbuf.html[^]

This one might be a good starting point: SQL Parser[^]


对IN,OR,AND使用Substring和string.count,以及在任何情况下使用的所有sql关键字。

但是在Where中没有计算条件。 cos如果您事先知道查询使用Sql Management Studio进行此类验证
use Substring and string.count for IN , OR , AND , and all the sql key words witch are using in where case .
but there is no seance to count Conditions in the "Where" . cos if you pre know the query use Sql Management Studio for this kind of validation


这篇关于检查“何处” C#中的SQL子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆