01: package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
02:
03: import java.sql.DatabaseMetaData;
04:
05: import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
06: import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
07:
08: /*
09: * Copyright (C) 2005 Gerd Wagner, Adin Aronson
10: * gerdwagner@users.sourceforge.net
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: */
26:
27: public class DatabaseSpecificEscape {
28: private static final IEscape[] _escapes = new IEscape[] {
29: new PostgreSQLEscape(), new MckoiSQLEscape() };
30:
31: private static interface IEscape {
32: public boolean productMatches(ISQLDatabaseMetaData md);
33:
34: public String escapeSQL(String sql);
35: }
36:
37: public static String escapeSQL(String sql, ISQLDatabaseMetaData md) {
38: for (int i = 0; i < _escapes.length; i++) {
39: if (_escapes[i].productMatches(md)) {
40: return _escapes[i].escapeSQL(sql);
41: }
42: }
43:
44: return sql;
45: }
46:
47: private static class PostgreSQLEscape implements IEscape {
48: public boolean productMatches(ISQLDatabaseMetaData md) {
49: return DialectFactory.isPostgreSQL(md);
50: }
51:
52: public String escapeSQL(String sql) {
53: return sql.replaceAll("\\\\", "\\\\\\\\");
54: }
55: }
56:
57: private static class MckoiSQLEscape implements IEscape {
58: public boolean productMatches(ISQLDatabaseMetaData md) {
59: return DialectFactory.isMcKoi(md);
60: }
61:
62: public String escapeSQL(String sql) {
63: return sql.replaceAll("\\\\", "\\\\\\\\");
64: }
65: }
66:
67: }
|