编码食谱/SQL 编码
外观
< 编码食谱
对各种数据类型进行编码以安全地用于 SQL 命令。
function SQLEncode (vInput)
dim CurrentLocale
select case VarType(vInput)
case 0,1 ' empty, null
SQLEncode = "NULL"
case 2,3 ' integer, longint
SQLEncode = vInput
case 4,5 ' single, double
CurrentLocale = GetLocale
SetLocale ("en-us")
SQLEncode = CStr(vInput)
SetLocale (CurrentLocale)
case 7 ' date
SQLEncode = "#" & _
DatePart("yyyy", vInput) & "-" & _
DatePart("m", vInput) & "-" & _
DatePart("d", vInput) & " " & _
DatePart("h", vInput) & ":" & _
DatePart("n", vInput) & ":" & _
DatePart("s", vInput) & "#"
case 8 ' string
SQLEncode = vInput
SQLEncode = Replace (SQLEncode, chr(0), "")
SQLEncode = Replace (SQLEncode, "'", "''")
SQLEncode = "'" & SQLEncode & "'"
end select
end function