%@ LANGUAGE="VBscript" %>
<%
'
' Words(iwords)
'
Dim Words(100)
If (Trim(Request.Form("query"))="") Then
query=""
SQL_Condition=""
Else
' Parse Query
'
' a) Remove confusing characters
'
query=CStr(Request.Form("query"))
query=Replace(query,"'","")
'
' b) Separate parentheses from words, do it by adding spaces, just in case
'
query=Replace(query,"("," ( ")
query=Replace(query,")"," ) ")
'
' c) Get rid of starting and ending blanks
'
query=Trim(query)
'
' d) split the string
'
Words(iword)=""
iword=0
iblank=1
For ichar=1 to Len(query)
charact=Mid(query,ichar,1)
' response.write("-" & CStr(ichar) & "-" & charact & "-
")
If charact<>" " Then
Words(iword)=Words(iword) & charact
iblank=0
Else
If iblank=0 Then ' new word: blank encountered where there was no blank before
iword=iword+1
End if
iblank=1
End if
Next
nwords=iword+1
'
' Prepare SQL Condition that will go at the end of statement
'
iandor=-1
SQL_Condition="("
For iwords=0 to nwords-1
one_word=UCase(CStr(Words(iwords)))
Select Case one_word
Case "("
If iandor=0 Then
SQL_Condition=SQL_Condition & " AND "
End If
SQL_Condition=SQL_Condition & one_word
iandor=2
Case ")"
iandor=2
SQL_Condition=SQL_Condition & one_word
Case "AND","OR","NOT"
SQL_Condition=SQL_Condition & " " & one_word & " "
iandor=1
Case Else
If iandor=0 Then
SQL_Condition=SQL_Condition & " AND "
End If
SQL_Condition=SQL_Condition & " UPPER(TEXT) LIKE " & "'%" & one_word & "%' "
iandor=0
End Select
Next
SQL_Condition=SQL_Condition & ")"
End if
response.write(SQL_Condition & "
")
'
%>