Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Coding Cookbook/SQL Encode

From Wikibooks, open books for an open world
<Coding Cookbook

Encode various datatypes for safe usage in SQL commands.

VBScript solution

[edit |edit source]
function SQLEncode (vInput)dim CurrentLocaleselect case VarType(vInput)case 0,1  ' empty, nullSQLEncode = "NULL"case 2,3  ' integer, longintSQLEncode = vInputcase 4,5  ' single, doubleCurrentLocale = GetLocaleSetLocale ("en-us")SQLEncode = CStr(vInput)SetLocale (CurrentLocale)case 7    ' dateSQLEncode = "#" & _DatePart("yyyy", vInput) & "-" & _DatePart("m",    vInput) & "-" & _DatePart("d",    vInput) & " " & _DatePart("h",    vInput) & ":" & _DatePart("n",    vInput) & ":" & _DatePart("s",    vInput) & "#"case 8    ' stringSQLEncode = vInputSQLEncode = Replace (SQLEncode, chr(0), "")SQLEncode = Replace (SQLEncode, "'", "''")SQLEncode = "'" & SQLEncode & "'"end selectend function
Retrieved from "https://en.wikibooks.org/w/index.php?title=Coding_Cookbook/SQL_Encode&oldid=3267966"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp