<% Class SqlString '************************************ ' Variable definition '************************************ ' sTableName----table name ' isqltype----SQL statement type: 0-Add, 1-update, 2-delete, 3-query ' Swhere----conditions ' Sorder----Sorting method ' sSQL----value Private Stablename,isqltype,swhere,sorder,ssql '************************************ ' Class initialization/end '************************************ Private Sub Class_Initialize () Stablename= "" Isqltype=0 Swhere= "" Sorder= "" Ssql= "" End Sub Private Sub Class_Terminate () End Sub '************************************ ' Property '************************************ ' Set the properties of the table name Public Property Let TableName (value) Stablename=value End Property ' Set condition Public Property Let Where (value) Swhere=value End Property ' Set sort style Public Property Let order (value) Sorder=value End Property ' Set the type of the query statement Public Property Let SqlType (value) Isqltype=value Select Case Isqltype Case 0 Ssql= INSERT INTO {&*#}0 ({&*#}1) VALUES ({&*#}2) Case 1 Ssql= "Update {&*#}0 set {&*#}1={&*#}2" Case 2 Ssql= "Delete from {&*#}0" Case 3 Ssql= "Select {&*#}1 from {&*#}0") End Select End Property '************************************ ' function '************************************ ' Add field (field name, field value) Public Sub AddField (sfieldname,svalue) Select Case Isqltype Case 0 Ssql=replace (sSQL, "{&*#}1", Sfieldname & ", {&*#}1") Ssql=replace (sSQL, "{&*#}2", "" & Svalue & ", {&*#}2") Case 1 Ssql=replace (sSQL, "{&*#}1", sfieldname) Ssql=replace (sSQL, "{&*#}2", "" & Svalue & ", {&*#}1={&*#}2") Case 3 Ssql=replace (sSQL, "{&*#}1", Sfieldname & ", {&*#}1") End Select End Sub ' Modified function to return a string value ' Return SQL statement Public Function Returnsql () Ssql=replace (sSQL, "{&*#}0", stablename) Select Case Isqltype Case 0 Ssql=replace (sSQL, ", {&*#}1", "") Ssql=replace (sSQL, ", {&*#}2", "") Case 1 Ssql=replace (sSQL, ", {&*#}1={&*#}2", "") Case 3 Ssql=replace (sSQL, ", {&*#}1", "") End Select If swhere<> "" and isqltype<>0 Then Ssql=ssql & "where" & Swhere End If If sorder<> "" and isqltype<>0 Then Ssql=ssql & "ORDER BY" & Sorder End If Returnsql=ssql End Function ' Return SQL statement Public Function ReturnSQL1 () Ssql=replace (sSQL, "{&*#}0", stablename) Select Case Isqltype Case 0 Ssql=replace (sSQL, ", {&*#}1", "") Ssql=replace (sSQL, ", {&*#}2", "") Case 1 Ssql=replace (sSQL, ", {&*#}1={&*#}2", "") Case 3 Ssql=replace (sSQL, ", {&*#}1", "") End Select If swhere<> "" and isqltype<>0 Then Ssql=ssql & "where" & Swhere End If If sorder<> "" and isqltype<>0 Then Ssql=ssql & "ORDER BY" & Sorder End If Returnsql=ssql End Function ' Empty statement Public Sub Clear () Stablename= "" Isqltype=0 Swhere= "" Sorder= "" Ssql= "" End Sub End Class %> Call Example: <% Set a =new sqlstring ' Create class object A.tablename= ' message ' Sets the table name as message ' a.where= ' issend = 9 " ' a.order= ' issend desc ' A.sqltype=0 ' Set query type to add record A.addfield "Incept", "' 2 '" A.addfield "Sender", "'%3% '" A.addfield "title", "#" &now& "#" A.addfield "Sender", "5" A.addfield "Content", "6" A.addfield "Sendtime", "7" A.addfield "Flag", 8 A.addfield "Issend", 9 Response.Write A.returnsql Set a=nothing %> <% Set a =new sqlstring ' Create class object A.tablename= ' message ' Sets the table name as message ' a.where= ' issend = 9 " ' a.order= ' issend desc ' A.sqltype=0 ' Set query type to add record A.addfield "Incept", "' 2 '" A.addfield "Sender", "'%3% '" A.addfield "title", "#" &now& "#" A.addfield "Sender", "5" A.addfield "Content", "6" A.addfield "Sendtime", "7" A.addfield "Flag", 8 A.addfield "Issend", 9 Response.Write A.returnsql Set a=nothing %> <% Set a =new sqlstring ' Create class object A.tablename= ' message ' Sets the table name as message ' a.where= ' issend = 9 " ' a.order= ' issend desc ' A.sqltype=0 ' Set query type to add record A.addfield "Incept", "' 2 '" A.addfield "Sender", "'%3% '" A.addfield "title", "#" &now& "#" A.addfield "Sender", "5" A.addfield "Content", "6" A.addfield "Sendtime", "7" A.addfield "Flag", 8 A.addfield "Issend", 9 Response.Write A.returnsql Set a=nothing %> |