国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

一個改進的ASP生成SQL 命令字符串的類

2019-11-18 19:27:42
字體:
來源:轉載
供稿:網友

網上找資料發現的,但是調試的時候發現有一些問題,
改了一下,還有一定的問題,但是可以做一般使用了。
沒有考慮數據類型的問題,還有SQL Server 和access的區別,以后有時間再改進吧,不知道效率怎么樣。
如果有朋友改進,也麻煩給我發一份。
<%
'生成SQL字符串的類。
'原作:無名氏
'改進:aloxy
'E-mail:szyjJ@hotmail.com
'OICQ:331622229
class SQLString
'************************************
'變量定義
'************************************
'sTableName ---- 表名
'iSQLType ----SQL語句類型:0-增加,1-更新,2-刪除,3-查詢
'sWhere ---- 條件
'sOrder ---- 排序方式
'sSQL ----值

PRivate sTableName,iSQLType,sWhere,sOrder,sSQL

'************************************
'類初始化/結束
'************************************

Private Sub Class_Initialize()
sTableName=""
iSQLType=0
sWhere=""
sOrder=""
sSQL=""
End Sub

Private Sub Class_Terminate()

End Sub

'************************************
'屬性
'************************************
'設置表名的屬性
Public Property Let TableName(value)
sTableName=value
End Property
'設置條件
Public Property Let Where(value)
sWhere=value
End Property
'設置排序方式
Public Property Let Order(value)
sOrder=value
End Property
'設置查詢語句的類型

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

'************************************
'函數
'************************************
'增加字段(字段名稱,字段值)

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

'返回SQL語句
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

'清空語句

Public Sub Clear()
sTableName=""
iSQLType=0
sWhere=""
sOrder=""
sSQL=""
End Sub
End class
%>

<%
'下面是調用的例子,數據類型的問題請繼續修改上面的類里的定義,如果有問題可以問我
set a =new SQLString '創建類對象
a.TableName=" message " '設置表名為message
'a.where=" issend =9"
'a.order=" issend desc"
a.SQLType=0 '設置查詢類型為增加記錄
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
%>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麻阳| 新源县| 石泉县| 海丰县| 固安县| 郓城县| 阳山县| 胶州市| 临海市| 灌阳县| 乾安县| 大关县| 平乡县| 鹤壁市| 资溪县| 屏东县| 龙州县| 柘城县| 丹寨县| 香港| 崇信县| 额敏县| 宁德市| 绵竹市| 星座| 板桥市| 双峰县| 潼关县| 铁岭县| 岱山县| 栾川县| 美姑县| 柞水县| 宁陵县| 花莲县| 桃源县| 望奎县| 龙胜| 刚察县| 潜江市| 扎兰屯市|