What SQL Escape does
SQL Escape escapes the characters that would otherwise end or break a SQL string or document, so that any text can be placed inside one.
SQL Escape examples
The built-in sample
Input
It's the user's choiceOutput
It''s the user''s choiceThis is the input that the Load sample button fills in.
Apostrophes are doubled, nothing else changes
Input
O'Brien's order: 100%_done \ okOutput
O''Brien''s order: 100%_done \ okOnly the single quotes change. The percent sign, the underscore and the backslash are passed through, which matters for LIKE patterns and for databases that treat a backslash as an escape character.
Each output was produced by running this tool on the input above it.
How it works
These characters are changed; everything else is left as it is:
| Character | Escaped form |
|---|---|
| ' | '' |
Details and limits
- Single quotes are doubled, which is the standard way to write a quote inside a SQL string literal.
- The surrounding quotes are not added. Write
'before and after the result yourself. - MySQL and MariaDB treat a backslash as an escape character in string literals by default. For those databases a backslash in the text must be doubled as well, which this tool does not do.
- Identifiers such as table and column names are quoted differently (
"name",`name`or[name], depending on the database). This tool is for string values only. - Escaping by hand is for one-off queries typed into a console. In application code, use parameterised queries.
Questions
Does escaping make a query safe from SQL injection?
Not reliably. Doubling quotes is correct for standard SQL string literals, but it does not cover backslash escapes in MySQL, numeric contexts or identifiers. Use parameterised queries in application code.