[Mono-list] escaping a string for sql

Howard Cole howard.cole@selestial.com
Tue, 08 Mar 2005 09:49:12 +0000


For postgres, you also need to replace "\"

    public string escape (string s)
    {
      s = s.Replace("\\", "\\\\"); // Replace \ with \\
      s = s.Replace("\'", "\'\'"); // Replace ' with '' (SQL Standard)
      //s = s.Replace("\"", "\\\""); not necessary if enclosed in single 
quotes.
      return s;
    }

Howard Cole
www.selestial.com