国产探花免费观看_亚洲丰满少妇自慰呻吟_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收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 嘉兴市| 游戏| 习水县| 布拖县| 平和县| 会昌县| 蒲江县| 鹤山市| 木兰县| 叶城县| 合江县| 武夷山市| 四子王旗| 霍城县| 婺源县| 湟源县| 延寿县| 清涧县| 清水河县| 南充市| 安平县| 密云县| 大兴区| 青河县| 天柱县| 广东省| 洛扎县| 孝昌县| 南乐县| 顺昌县| 灵台县| 开化县| 琼结县| 容城县| 汝阳县| 惠水县| 巫溪县| 宾阳县| 元谋县| 通城县| 桦甸市|