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

torand / FasterSQL / 14972998308

12 May 2025 01:04PM UTC coverage: 67.475% (+0.3%) from 67.194%
14972998308

Pull #27

github

web-flow
Merge d0df0a4c0 into 1f1b3df71
Pull Request #27: feat: add support for SQL Server dialect

219 of 418 branches covered (52.39%)

Branch coverage included in aggregate %.

51 of 64 new or added lines in 13 files covered. (79.69%)

1144 of 1602 relevant lines covered (71.41%)

3.81 hits per line

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

76.19
/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

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

34
    public SqlServerDialect() {
35
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, MODULO_OPERATOR));
6✔
36
    }
1✔
37

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

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

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

52
    /**
53
     * Row offset clause is supported from SQL Server 2012 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 SQL Server 2012 onwards
62
     */
63
    @Override
64
    public Optional<String> formatRowLimitClause() {
65
        return Optional.of("fetch next ? rows only");
3✔
66
    }
67

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

76
    @Override
77
    public String formatToNumberFunction(String operand, int precision, int scale) {
NEW
78
        return "cast(" + operand + " as numeric(" + precision + "," + scale + "))";
×
79
    }
80

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

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

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

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

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

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

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

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

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

126
    @Override
127
    public boolean supports(Capability capability) {
128
        return supportedCaps.contains(capability);
5✔
129
    }
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc