Here you can find the source of quoteIdentifier(String s)
Parameter | Description |
---|---|
s | the string to have embedded quotes expanded. |
public static String quoteIdentifier(String s)
//package com.java2s; /*/*from ww w . j a v a 2 s . com*/ * Copyright (C) 2007 Rob Manning * manningr@users.sourceforge.net * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { /** * Contributed by Thomas Mueller to handle doubling quote characters found in an identifier. In H2 and * other dbs, the following statement creates a table with an embedded quote character: CREATE TABLE * "foo""bar" (someid int); However, what is returned by the driver for table name is: foo"bar The reason * is simple. Just like embedded quotes in SQL strings, such as: select 'I don''t know' from test * Similarly, embedded quote characters can also appear in identifiers such as table names, by doubling (or * quoting, if you will) the quote. * * @param s * the string to have embedded quotes expanded. * @return a new string with any embedded quotes doubled, or null if null is passed. * @author Thomas Mueller */ public static String quoteIdentifier(String s) { if (s == null) { return null; } StringBuilder buff = null; buff = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '"' && i != 0 && i != s.length() - 1) { buff.append(c); } buff.append(c); } String result = buff.toString(); return result; } }