Copy codeThe Code is as follows: <%
Class SQLString
'************************************
'Variable definition
'************************************
'Tablename ---- table name
'Isqltype ---- SQL statement type: 0-add, 1-Update, 2-delete, 3-Query
'Swhere ---- Condition
'Sorder ---- sorting method
'Ssql ---- Value
Private sTableName, iSQLType, sWhere, sOrder, sSQL
'************************************
'Class initialization/termination
'************************************
Private Sub Class_Initialize ()
STableName = ""
ISQLType = 0
SWhere = ""
SOrder = ""
SSQL = ""
End Sub
Private Sub Class_Terminate ()
End Sub
'************************************
'Attribute
'************************************
'Set the table name attributes
Public Property Let TableName (value)
STableName = value
End Property
'Set conditions
Public Property Let Where (value)
SWhere = value
End Property
'Set the sorting method
Public Property Let Order (value)
SOrder = value
End Property
'Set the query statement type
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 a 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 the 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
'Clear statement
Public Sub Clear ()
STableName = ""
ISQLType = 0
SWhere = ""
SOrder = ""
SSQL = ""
End Sub
End class
%>
Call example:
<%
Set a = new SQLString 'create a Class Object
A. TableName = "message" 'set the table name to message.
'A. where = "issend = 9"
'A. order = "issend desc"
A. SQLType = 0' set the query type to add records
A. AddField "incept", "'2 '"
A. AddField "sender", "'% 100 '"
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 a Class Object
A. TableName = "message" 'set the table name to message.
'A. where = "issend = 9"
'A. order = "issend desc"
A. SQLType = 0' set the query type to add records
A. AddField "incept", "'2 '"
A. AddField "sender", "'% 100 '"
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 a Class Object
A. TableName = "message" 'set the table name to message.
'A. where = "issend = 9"
'A. order = "issend desc"
A. SQLType = 0' set the query type to add records
A. AddField "incept", "'2 '"
A. AddField "sender", "'% 100 '"
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
%>