OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 67 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.sql.model;
15
 
16
import org.openconcerto.utils.cc.IClosure;
17
 
18
import java.util.regex.Matcher;
19
import java.util.regex.Pattern;
20
 
21
public class PGSQLBase extends SQLBase {
22
 
83 ilm 23
    PGSQLBase(SQLServer server, String name, IClosure<? super DBSystemRoot> systemRootInit, String login, String pass, IClosure<? super SQLDataSource> dsInit) {
24
        super(server, name, systemRootInit, login, pass, dsInit);
17 ilm 25
    }
26
 
27
    // *** quoting
28
 
67 ilm 29
    static final Pattern BACKSLASH_PATTERN = Pattern.compile("\\", Pattern.LITERAL);
30
    static final String TWO_BACKSLASH_REPLACEMENT = Matcher.quoteReplacement("\\\\");
17 ilm 31
 
32
    @Override
33
    public final String quoteString(String s) {
34
        final String res = super.quoteString(s);
83 ilm 35
        if (s == null)
36
            return res;
17 ilm 37
        // see PostgreSQL Documentation 4.1.2.1 String Constants
38
        // escape \ by replacing them with \\
67 ilm 39
        final Matcher matcher = BACKSLASH_PATTERN.matcher(res);
17 ilm 40
        // only use escape form if needed (=> equals with other systems most of the time)
67 ilm 41
        return matcher.find() ? "E" + matcher.replaceAll(TWO_BACKSLASH_REPLACEMENT) : res;
17 ilm 42
    }
43
}