Coding Cookbook/SQL Encode
Tools
General
Sister projects
In other projects
Encode various datatypes for safe usage in SQL commands.
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