What characters should be escaped in sql string parameters

I need a complete list of characters that should be escaped in sql string parameters to prevent exceptions. I assume that I need to replace all offensive characters with a shielded version before passing it to the ObjectDataSource filter parameter.

+3
source share
4 answers

No, the ObjectDataSource object will handle all the escaping for you. Any parameterized query also does not require escaping.

+3
source

, 99% , - , , . - . , , (, MySQL mysql_real_escape_string).

+1

SQL: :

, . , , . , \x0000, , \x0000 .

, escape-. escape- .

\  

\  Backspace

\  

\  

\ g Carriage return

\ t Horizontal tab

\ v Vertical tab

\ "Quotation mark

\ Backslash

\ xhhhh Unicode character in hexadecimal notation

0
source

Here I used to get rid of the apostrophes. You can do the same with other offensive characters you encounter. (example in VB.Net)

Dim companyFilter = Trim(Me.ddCompany.SelectedValue)

If (Me.ddCompany.SelectedIndex > 0) Then
      filterString += String.Format("LegalName like '{0}'", companyFilter.Replace("'", "''"))
End If

Me.objectDataSource.FilterExpression = filterString

Me.displayGrid.DataBind()
0
source

Source: https://habr.com/ru/post/1712225/


All Articles