Added README file
[metux-java.git] / util / SQL_Encode.java
blob4e87650e4bb8e5a71fb6aee2324991ebaf30d675
2 package org.de.metux.util;
4 public class SQL_Encode
6 public static String Text(String s)
8 if (s==null)
9 return null;
11 return "'"+escape(s)+"'";
14 public static String escape(String s)
16 if (s==null)
17 return "";
19 char[] chars = s.toCharArray();
21 String res = "";
22 for (int x=0; x<chars.length; x++)
24 switch (chars[x])
26 case '\'': res += "\\'"; break;
27 case '"': res += "\\\""; break;
28 default: res += chars[x]; break;
31 return res;
34 public static String Name(String s)
36 if (s==null)
37 return "";
38 return "\""+escape(s)+"\"";
41 public static String Float(float f)
43 return "'"+f+"'";
46 public static String Oid(long oid)
48 return String.valueOf(oid);