我正在做动态报告系统。对于前端,我使用 Asp.net 和 oracle 作为后端。项目要求是,用户可以在 TextBox 中编写查询,并且当在WHERE关键字之后从查询中单击按钮时,所有参数都被拆分。当 ( AND | OR | , ) 将在查询中找到时,拆分将根据模式进行。
例如:-
select * from EmpInfo where age >= 40, active='A' and rownum < 15
结果会
age >= 40
active='A'
rownum < 15
但是如果我在 where 之后使用子查询,那么同样的模式也会遵循
例如:-
select * from EmpInfo where age in (select age from Emp_pns where age >= 60 ), active='A' and rownum < 15
结果会
age >= 60
active='A'
rownum < 15
这是我的示例代码,我尽我所能,但我没有得到完美的解决方案。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim query As String = TextBox1.Text.ToLower
getParameter(query)
For i As Integer = 0 To ListBox2.Items.Count - 1
ListBox1.Items.Add(ListBox2.Items(i).Text)
Next
End Sub
Public Sub getParameter(ByVal argument As String)
Dim query As String = argument
Static Dim tempString As String
If query.Contains("order by") Or query.Contains("group by") Then
Dim mtch As Match = Regex.Match(query, "(?<=where)(.*)(?=order by|group by)")
Dim mtchString As String = mtch.Groups(1).Value
tempString = mtchString
If mtchString.Length >= 1 Then
Dim bindlist As String() = Regex.Split(mtchString, " and | or |,")
ListBox1.DataSource = bindlist
ListBox1.DataBind()
getParameter(tempString)
End If
Else
Dim mtch As Match = Regex.Match(query, "(?<=where)(.*)")
Dim mtchString As String = mtch.Groups(1).Value
Dim bindlist As String() = Regex.Split(s, " and | or |,")
ListBox2.DataSource = bindlist
ListBox2.DataBind()
End If
End Sub