I want to create SQL queries in a language like Java or C#. Everybody knowns that you must not do this:
sql = "SELECT * FROM T WHERE A='" + someString + "'"
Because this allows code injection, for example with:
someString = "xxx';DROP TABLE T;DECLARE @A CHAR(3) ='xxx"
Everybody knowns you must use proper SQL parameters provided by the standard apis available in most languages.
But for some reason that is too complex to explain (please assume my reasons are good), I can't or don't want to use proper parameters and need to stick to the dangerous method of formatting the string myself.
My question is simple. Is the following safe:
sql = "SELECT * FROM T WHERE A='" + someString.Replace("'","''") + "'"
If you think this depends to on the RDBMS, please stick to MySQL.