I found it by searching for information online, but I found some problems during debugging.
After some modifications, there are still some problems, but it can be used for general use.
The data type issue and the difference between SQL Server and access were not considered. I will improve it when I have time in the future. I don’t know how efficient it will be.
If anyone improves it, please send me a copy.
<%
'Class that generates SQL strings.
'Original work: Anonymous
'Improvement: aloxy
'E-mail:[email protected]
'OICQ:331622229
classSQLString
'************************************
'Variable definition
'************************************
'sTableName ---- table name
'iSQLType ----SQL statement type: 0-add, 1-update, 2-delete, 3-query
'sWhere ---- condition
'sOrder ---- sorting method
'sSQL ----ValuePrivate
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 conditions
Public Property Let Where(value)
sWhere=value
End Property
'Set sorting method
Public Property Let Order(value)
sOrder=value
End Property
'Set the type of query statementPublic
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
'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
'Clear statementPublic
Sub Clear()
sTableName=""
iSQLType=0
sWhere=""
sOrder=""
sSQL=""
End Sub
End class
%>
<%
'The following is an example of calling. For data type issues, please continue to modify the definition in the above class. If you have any questions, you can ask me.
set a =new SQLString 'Create 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 ", " 3 "
a.AddField " title ", " 4 "
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
%>