Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer;
  5. import java.io.Serializable;
  6. public class SQLUtil implements Serializable {
  7. /**
  8. * Escapes different special characters in strings that are passed to SQL.
  9. * Replaces the following:
  10. *
  11. * <list> <li>' is replaced with ''</li> <li>\x00 is removed</li> <li>\ is
  12. * replaced with \\</li> <li>" is replaced with \"</li> <li>
  13. * \x1a is removed</li> </list>
  14. *
  15. * Also note! The escaping done here may or may not be enough to prevent any
  16. * and all SQL injections so it is recommended to check user input before
  17. * giving it to the SQLContainer/TableQuery.
  18. *
  19. * @param constant
  20. * @return \\\'\'
  21. */
  22. public static String escapeSQL(String constant) {
  23. if (constant == null) {
  24. return null;
  25. }
  26. String fixedConstant = constant;
  27. fixedConstant = fixedConstant.replaceAll("\\\\x00", "");
  28. fixedConstant = fixedConstant.replaceAll("\\\\x1a", "");
  29. fixedConstant = fixedConstant.replaceAll("'", "''");
  30. fixedConstant = fixedConstant.replaceAll("\\\\", "\\\\\\\\");
  31. fixedConstant = fixedConstant.replaceAll("\\\"", "\\\\\"");
  32. return fixedConstant;
  33. }
  34. }