vbscript| statement |vbscript <% @LANGUAGE = "VBScript" codepage= "936"%>
<% Option Explicit%>
<% Response.Buffer = True%>
<%
' ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////
' ///
'///filename: sqlbuilderforvbs
'///function: To build some simple SQL statements, combined with the form when the use, can be more convenient
'///program creator: Zeng Siyuan
'///Description: Simple SQL statement build ' class ', VBS version, as long as this annotation paragraph is retained, regardless of whether it involves business, you can use, reprint or reference
'///Date: 2005-1-8
' ///_________________________________________________________________________________________________
' ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////
%>
<%
On Error Resume Next
Class Queststringbuilder
Private Objfields
Private strTableName
Private Strpkey
Private Strpkeysort
Private strcondition
Private acontition ()
Private Stroperator
Private Strlogic
Private blnstate
'/-----Initialization-----/
Private Sub Class_Initialize ()
Set objfields = Server.CreateObject ("Scripting.Dictionary")
strTableName = Null
Strpkey = Null
Strpkeysort = Null
Strcondition = Null
ReDim acontition (1)
Stroperator = "="
Strlogic = "and"
Blnstate = False
End Sub
Private Sub Class_Terminate ()
Set Objfields = Nothing
strTableName = Null
Strpkey = Null
Strpkeysort = Null
Strcondition = Null
Erase acontition
Stroperator = Null
Strlogic = Null
Blnstate = False
End Sub
'/----field name processing----/
Private Function Processfield (ByVal Sfield)
Processfield = "[" & Sfield & "]"
End Function
'/-----field value processing-----/
Private Function processvalue (ByVal svalue)
Dim Tmptype:tmptype = VarType (svalue)
Select Case Tmptype
Case 2,3,4,5,11 ' numeric type, Boolean type
Processvalue = svalue
Case 8 ' character type
Processvalue = "'" & Safe (svalue) & "'"
Case Else ' other type
Processvalue = "'" & Safe (svalue) & "'"
End Select
End Function
'/-----Integrated treatment-----/
Private Function Process (ByRef obj, ByVal strtype)
Dim Keys:keys = obj. Keys
Dim items:items = obj. Items
Dim intcount:intcount = obj. Count
Dim tmp ()
ReDim tmp (1)
If intcount > 0 Then
Dim Tmparray (), I
ReDim Tmparray (intCount-1)
For I=0 to IntCount-1
Tmparray (i) = Keys (i) & "=" & Items (i)
Next
Select Case UCase (Trim (strtype))
Case "UPDATE"
Process = Join (Tmparray, ",")
Case "SELECT"
Process = Join (Keys, ",")
Case "INSERT"
TMP (0) = Join (Keys, ",")
TMP (1) = Join (Items, ",")
Process = tmp
Erase tmp
End Select
Erase Tmparray
Else
Select Case UCase (Trim (strtype))
Case "UPDATE"
Process = False
Case "SELECT"
Process = "*"
Case "INSERT"
Process = tmp
End Select
End If
End Function
'/-----A small safe handling-----
Private Function Safe (s)
Safe = Replace (S, "'", "" ")
End Function
'/-----Empty the last input parameter, but keep tablename-----/
Public Sub Clear ()
Objfields.removeall
' strTableName = Null
Strpkey = Null
Strpkeysort = Null
Strcondition = Null
Erase acontition
Stroperator = "="
Strlogic = "and"
Blnstate = False
End Sub
'/----Generate query statement----/
Public Function Getselect ()
Dim strsqltemplate:strsqltemplate = "SELECT {fields} from {table} {conditions} {by} {sort}"
Strsqltemplate = Replace (Strsqltemplate, "{fields}", Process (Objfields, "select")
If VarType (strtablename) = 1 Then Exit Function
Strsqltemplate = Replace (strsqltemplate, "{table}", strTableName)
If VarType (strcondition) <> 1 and Strcondition <> "" Then
Strsqltemplate = Replace (strsqltem