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

torand / FasterSQL / 15294773771

28 May 2025 08:01AM UTC coverage: 70.078% (+0.2%) from 69.877%
15294773771

Pull #31

github

web-flow
Merge 9f1c324c0 into 6be86da23
Pull Request #31: feat: add support for SQLite dialect

233 of 418 branches covered (55.74%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 12 files covered. (84.85%)

45 existing lines in 10 files now uncovered.

1212 of 1644 relevant lines covered (73.72%)

3.91 hits per line

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

87.88
/src/main/java/io/github/torand/fastersql/dialect/OracleDialect.java
1
/*
2
 * Copyright (c) 2024-2025 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.dialect.Capability.NULL_ORDERING;
25
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
26
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
27
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
28

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

37
    public OracleDialect() {
38
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, NULL_ORDERING, SELECT_FOR_UPDATE, TRUNCATE_TABLE));
8✔
39
    }
1✔
40

41
    private OracleDialect(EnumSet<Capability> capabilities) {
2✔
42
        this.supportedCaps = EnumSet.copyOf(capabilities);
4✔
43
    }
1✔
44

45
    @Override
46
    public String getProductName() {
47
        return "Oracle";
2✔
48
    }
49

50
    @Override
51
    public boolean offsetBeforeLimit() {
52
        return true;
2✔
53
    }
54

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

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

71
    @Override
72
    public Optional<String> formatRowNumLiteral() {
73
        return Optional.of("rownum");
3✔
74
    }
75

76
    @Override
77
    public String formatToNumberFunction(String operand, int precision, int scale) {
78
        StringBuilder mask = new StringBuilder();
4✔
79
        if (precision-scale > 0) {
4!
80
            mask.append(generate("9", precision-scale));
8✔
81
        }
82
        if (scale > 0) {
2!
UNCOV
83
            mask.append(".").append(generate("9", scale));
×
84
        }
85

86
        return "to_number(" + operand + ", '" + mask + "')";
5✔
87
    }
88

89
    @Override
90
    public String formatToCharFunction(String operand, String format) {
91
        return "to_char(" + operand + ", " + format + ")";
4✔
92
    }
93

94
    @Override
95
    public String formatSubstringFunction(String operand, int startPos, int length) {
96
        return "substr(" + operand + ", " + startPos + ", " + length + ")";
5✔
97
    }
98

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

104
    @Override
105
    public String formatLengthFunction(String operand) {
106
        return "length(" + operand + ")";
3✔
107
    }
108

109
    @Override
110
    public String formatCeilFunction(String operand) {
111
        return "ceil(" + operand + ")";
3✔
112
    }
113

114
    @Override
115
    public String formatRoundFunction(String operand) {
116
        return "round(" + operand + ")";
3✔
117
    }
118

119
    @Override
120
    public String formatModuloFunction(String divisor, String dividend) {
121
        return "mod(" + divisor + ", " + dividend + ")";
4✔
122
    }
123

124
    @Override
125
    public String formatCurrentDateFunction() {
126
        return "current_date";
2✔
127
    }
128

129
    @Override
130
    public Optional<String> getConcatOperator() {
131
        return Optional.of("||");
3✔
132
    }
133

134
    @Override
135
    public boolean supports(Capability capability) {
136
        return supportedCaps.contains(capability);
5✔
137
    }
138

139
    /**
140
     * Enables emulating OFFSET and LIMIT constructs for older Oracle versions.
141
     * Row offset and limit clauses are supported from Oracle 12c onwards.
142
     * Invoke this method when using previous versions of Oracle, to simulate these clauses with subqueries.
143
     * @return the modified dialect.
144
     */
145
    public OracleDialect withLegacyRowLimiting() {
146
        EnumSet<Capability> reducedCaps = EnumSet.copyOf(supportedCaps);
4✔
147
        reducedCaps.remove(LIMIT_OFFSET);
4✔
148
        return new OracleDialect(reducedCaps);
5✔
149
    }
150
}
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