OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 44... Line 44...
44
import java.util.HashSet;
44
import java.util.HashSet;
45
import java.util.LinkedHashMap;
45
import java.util.LinkedHashMap;
46
import java.util.List;
46
import java.util.List;
47
import java.util.Map;
47
import java.util.Map;
48
import java.util.Map.Entry;
48
import java.util.Map.Entry;
-
 
49
import java.util.Objects;
49
import java.util.Set;
50
import java.util.Set;
50
import java.util.logging.Level;
51
import java.util.logging.Level;
51
import java.util.logging.Logger;
52
import java.util.logging.Logger;
52
import java.util.regex.Matcher;
53
import java.util.regex.Matcher;
53
import java.util.regex.Pattern;
54
import java.util.regex.Pattern;
Line 767... Line 768...
767
     * @param pattern a string with %, eg "SELECT * FROM %n where %f like '%%a%%'".
768
     * @param pattern a string with %, eg "SELECT * FROM %n where %f like '%%a%%'".
768
     * @param params the parameters, eg [ /TENSION/, |TENSION.LABEL| ].
769
     * @param params the parameters, eg [ /TENSION/, |TENSION.LABEL| ].
769
     * @return pattern with % replaced, eg SELECT * FROM "TENSION" where "TENSION.LABEL" like '%a%'.
770
     * @return pattern with % replaced, eg SELECT * FROM "TENSION" where "TENSION.LABEL" like '%a%'.
770
     */
771
     */
771
    public final String quote(final String pattern, Object... params) {
772
    public final String quote(final String pattern, Object... params) {
772
        return quote(this, pattern, params);
773
        return quote(this.getDBSystemRoot().getSyntax(), pattern, params);
773
    }
-
 
774
 
-
 
775
    // since Strings might not be quoted correctly
-
 
776
    @Deprecated
-
 
777
    public final static String quoteStd(final String pattern, Object... params) {
-
 
778
        return quote(null, pattern, params);
-
 
779
    }
774
    }
780
 
775
 
781
    static private final Pattern percent = Pattern.compile("%.");
776
    static private final Pattern percent = Pattern.compile("%.");
782
 
777
 
783
    private final static String quote(final SQLBase b, final String pattern, Object... params) {
778
    final static String quote(final SQLSyntax s, final String pattern, Object... params) {
784
        final SQLSyntax s = b == null ? null : SQLSyntax.get(b);
779
        Objects.requireNonNull(s, "Missing syntax");
785
        final Matcher m = percent.matcher(pattern);
780
        final Matcher m = percent.matcher(pattern);
786
        final StringBuffer sb = new StringBuffer();
781
        final StringBuffer sb = new StringBuffer();
787
        int i = 0;
782
        int i = 0;
788
        int lastAppendPosition = 0;
783
        int lastAppendPosition = 0;
789
        while (m.find()) {
784
        while (m.find()) {
Line 792... Line 787...
792
            if (modifier == '%') {
787
            if (modifier == '%') {
793
                replacement = "%";
788
                replacement = "%";
794
            } else {
789
            } else {
795
                final Object param = params[i++];
790
                final Object param = params[i++];
796
                if (modifier == 's') {
791
                if (modifier == 's') {
797
                    replacement = SQLSyntax.quoteString(s, param.toString());
792
                    replacement = s.quoteString(param.toString());
798
                } else if (modifier == 'i') {
793
                } else if (modifier == 'i') {
799
                    if (param instanceof SQLName)
794
                    if (param instanceof SQLName)
800
                        replacement = ((SQLName) param).quote();
795
                        replacement = ((SQLName) param).quote();
801
                    else
796
                    else
802
                        replacement = quoteIdentifier(param.toString());
797
                        replacement = quoteIdentifier(param.toString());