escapeSQL
This function is used by Ignition's Expression language.
Descriptionβ
Returns the given string with special SQL characters escaped. This function just replaces single quotes with two single quotes, and backslashes with two backslashes. See system.db.runPrepUpdate for a safer way to sanitize user input.
Syntaxβ
escapeSQL(string)
Parametersβ
| Type | Parameter | Description |
|---|---|---|
| String | string | The starting string. |
Resultsβ
String - A string that has been formatted so that single quotes are replaced with two single quotes, and backslashes are replaced with two backslashes.
Examplesβ
Code Snippet
"SELECT * FROM mytable WHERE option = '" + escapeSQL("Jim's Settings") + "'" // returns SELECT * FROM mytable WHERE option='Jim''s Settings'
Code Snippet
"SELECT * FROM mytable WHERE option = 'escapeSQL({Root Container.TextField.text}) + "'" //returns a query with sanitized user input from a text field.