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

首頁 > 編程 > ASP > 正文

一個ASP(VBScript)簡單SQL語句構建"類"

2024-05-04 11:06:14
字體:
來源:轉載
供稿:網友
<%@language="vbscript" codepage="936"%>
<% option explicit %>
<% response.buffer = true %>
<%
' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' ///
' /// 文件名: sqlbuilderforvbs
' /// 作用: 構建一些簡單的sql語句,結合在提交表單時使用,可以較方便
' /// 程式編寫者: 曾思源
' /// 說明: 簡單sql語句構建“類”,vbs版,只要保留本注釋段,無論是否涉及商業,您可以任意使用,轉載或引用
' /// 日期: 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

'/-----初始化-----/

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

' /----字段名處理----/

private function processfield(byval sfield)
processfield = "[" & sfield & "]"
end function

' /-----字段值處理-----/

private function processvalue(byval svalue)
dim tmptype : tmptype = vartype(svalue)
select case tmptype
case 2,3,4,5,11 ' 數字類型,布爾類型
processvalue = svalue
case 8 ' 字符類型
processvalue = "'" & safe(svalue) & "'"
case else ' 其它類型
processvalue = "'" & safe(svalue) & "'"
end select
end function

' /-----綜合處理-----/

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

' /-----小小的安全處理-----/

private function safe(s)
safe = replace(s,"'","''")
end function

' /-----清空上一次輸入的參數,但保留tablename-----/

public sub clear()
objfields.removeall
'strtablename = null
strpkey = null
strpkeysort = null
strcondition = null
erase acontition
stroperator = "="
strlogic = " and "
blnstate = false
end sub

' /----生成查詢語句----/

public function getselect()
dim strsqltemplate : strsqltemplate = "select {fields} from {table} {conditions} {orderby} {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

  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 萝北县| 珲春市| 克拉玛依市| 南召县| 娄烦县| 祁连县| 渝北区| 定日县| 乃东县| 南汇区| 水城县| 尖扎县| 二连浩特市| 南靖县| 汽车| 文水县| 岱山县| 五大连池市| 岳阳市| 上蔡县| 玛沁县| 玉林市| 乌兰察布市| 鹤壁市| 秀山| 翼城县| 黄石市| 西昌市| 汽车| 凤山市| 额敏县| 宜兴市| 彭水| 慈利县| 蓬莱市| 德惠市| 瑞金市| 平乐县| 马公市| 麦盖提县| 栾城县|