• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / FasterSQL / 13393719904

18 Feb 2025 03:08PM UTC coverage: 60.439% (+0.5%) from 59.964%
13393719904

push

github

torand
test: MySQL specific testing of insert clause

160 of 346 branches covered (46.24%)

Branch coverage included in aggregate %.

4 of 11 new or added lines in 6 files covered. (36.36%)

859 of 1340 relevant lines covered (64.1%)

3.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.71
/src/main/java/io/github/torand/fastersql/dialect/OracleDialect.java
1
/*
2
 * Copyright (c) 2024 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.dialect;
17

18
import java.util.EnumSet;
19
import java.util.List;
20
import java.util.Optional;
21

22
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
23
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
24
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
25

26
/**
27
 * Defines the Oracle SQL dialect.
28
 *
29
 * <a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/" />
30
 */
31
public class OracleDialect implements Dialect {
32
    private final EnumSet<Capability> supportedCaps;
33

34
    public OracleDialect() {
35
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR));
5✔
36
    }
1✔
37

38
    private OracleDialect(EnumSet<Capability> capabilities) {
2✔
39
        this.supportedCaps = EnumSet.copyOf(capabilities);
4✔
40
    }
1✔
41

42
    @Override
43
    public String getProductName() {
44
        return "Oracle";
2✔
45
    }
46

47
    @Override
48
    public boolean offsetBeforeLimit() {
49
        return true;
2✔
50
    }
51

52
    /**
53
     * Row offset clause is supported from Oracle 12c onwards
54
     */
55
    @Override
56
    public Optional<String> formatRowOffsetClause() {
57
        return Optional.of("offset ? rows");
3✔
58
    }
59

60
    /**
61
     * Row limit clause is supported from Oracle 12c onwards
62
     */
63
    @Override
64
    public Optional<String> formatRowLimitClause() {
65
        return Optional.of("fetch next ? rows only");
3✔
66
    }
67

68
    @Override
69
    public Optional<String> formatRowNumLiteral() {
70
        return Optional.of("rownum");
3✔
71
    }
72

73
    @Override
74
    public String formatToNumberFunction(String operand, int precision, int scale) {
75
        StringBuilder mask = new StringBuilder();
×
76
        if (precision-scale > 0) {
×
77
            mask.append(generate("9", precision-scale));
×
78
        }
79
        if (scale > 0) {
×
80
            mask.append(".").append(generate("9", scale));
×
81
        }
82

83
        return "to_number(" + operand + ", '" + mask + "')";
×
84
    }
85

86
    @Override
87
    public String formatToCharFunction(String operand, String format) {
88
        return "to_char(" + operand + ", " + format + ")";
4✔
89
    }
90

91
    @Override
92
    public String formatSubstringFunction(String operand, int startPos, int length) {
93
        return "substr(" + operand + ", " + startPos + ", " + length + ")";
5✔
94
    }
95

96
    @Override
97
    public String formatConcatFunction(List<String> operands) {
NEW
98
        throw new UnsupportedOperationException("Oracle does not support the concat() function (use the concat infix operator instead)");
×
99
    }
100

101
    @Override
102
    public String formatLengthFunction(String operand) {
103
        return "length(" + operand + ")";
3✔
104
    }
105

106
    @Override
107
    public boolean supports(Capability capability) {
108
        return supportedCaps.contains(capability);
5✔
109
    }
110

111
    /**
112
     * Row offset and limit clauses are supported from Oracle 12c onwards.
113
     * Invoke this method when using previous versions of Oracle, to simulate these clauses with subqueries.
114
     */
115
    public OracleDialect withLegacyRowLimiting() {
116
        EnumSet<Capability> reducedCaps = EnumSet.copyOf(supportedCaps);
4✔
117
        reducedCaps.remove(LIMIT_OFFSET);
4✔
118
        return new OracleDialect(reducedCaps);
5✔
119
    }
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc