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

torand / FasterSQL / 15346133148

30 May 2025 11:50AM UTC coverage: 70.397% (+0.1%) from 70.298%
15346133148

push

github

torand
chore: test javadoc publish

235 of 420 branches covered (55.95%)

Branch coverage included in aggregate %.

1237 of 1671 relevant lines covered (74.03%)

3.9 hits per line

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

80.95
/src/main/java/io/github/torand/fastersql/dialect/SqlServerDialect.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.MODULO_OPERATOR;
25
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
26

27
/**
28
 * Defines the <a href="https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16">Microsoft SQL Server</a> SQL dialect.
29
 */
30
public class SqlServerDialect implements Dialect {
31
    private final EnumSet<Capability> supportedCaps;
32

33
    /**
34
     * Creates a Microsoft SQL Server {@link Dialect} implementation.
35
     */
36
    public SqlServerDialect() {
37
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, MODULO_OPERATOR, TRUNCATE_TABLE));
7✔
38
    }
1✔
39

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

44
    @Override
45
    public String getProductName() {
46
        return "SQL Server";
2✔
47
    }
48

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

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

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

70
    /**
71
     * SQL Server has the ROW_NUMBER() function but must be combined with OVER() in this context.
72
     */
73
    @Override
74
    public Optional<String> formatRowNumLiteral() {
75
        return Optional.empty();
×
76
    }
77

78
    @Override
79
    public String formatToNumberFunction(String operand, int precision, int scale) {
80
        return "cast(" + operand + " as numeric(" + precision + "," + scale + "))";
5✔
81
    }
82

83
    @Override
84
    public String formatToCharFunction(String operand, String format) {
85
        throw new UnsupportedOperationException("SQL Server does not support the to_char() function");
×
86
    }
87

88
    @Override
89
    public String formatSubstringFunction(String operand, int startPos, int length) {
90
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
91
    }
92

93
    @Override
94
    public String formatConcatFunction(List<String> operands) {
95
        throw new UnsupportedOperationException("SQL Server does not support the concat() function (use the concat infix operator instead)");
×
96
    }
97

98
    @Override
99
    public String formatLengthFunction(String operand) {
100
        return "len(" + operand + ")";
3✔
101
    }
102

103
    @Override
104
    public String formatCeilFunction(String operand) {
105
        return "ceiling(" + operand + ")";
3✔
106
    }
107

108
    @Override
109
    public String formatRoundFunction(String operand) {
110
        return "round(" + operand + ", 0)";
3✔
111
    }
112

113
    @Override
114
    public String formatModuloFunction(String divisor, String dividend) {
115
        throw new UnsupportedOperationException("SQL Server does not support the mod() function (use the modulo infix operator instead)");
×
116
    }
117

118
    @Override
119
    public String formatCurrentDateFunction() {
120
        return "getdate()";
2✔
121
    }
122

123
    @Override
124
    public Optional<String> getConcatOperator() {
125
        return Optional.of("+");
3✔
126
    }
127

128
    @Override
129
    public boolean supports(Capability capability) {
130
        return supportedCaps.contains(capability);
5✔
131
    }
132
}
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