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

torand / FasterSQL / 16990059345

15 Aug 2025 12:34PM UTC coverage: 66.782% (-6.6%) from 73.399%
16990059345

push

github

torand
chore: access central snapshots

294 of 598 branches covered (49.16%)

Branch coverage included in aggregate %.

1638 of 2295 relevant lines covered (71.37%)

3.83 hits per line

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

45.1
/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 io.github.torand.fastersql.function.singlerow.cast.DataType;
19

20
import java.util.EnumSet;
21
import java.util.List;
22
import java.util.Optional;
23

24
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
25
import static io.github.torand.fastersql.dialect.Capability.FULL_OUTER_JOIN;
26
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
27
import static io.github.torand.fastersql.dialect.Capability.MODULO_OPERATOR;
28
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
29

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

36
    /**
37
     * Creates a Microsoft SQL Server {@link Dialect} implementation.
38
     */
39
    public SqlServerDialect() {
40
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, MODULO_OPERATOR, TRUNCATE_TABLE, FULL_OUTER_JOIN));
8✔
41
    }
1✔
42

43
    private SqlServerDialect(EnumSet<Capability> capabilities) {
2✔
44
        this.supportedCaps = EnumSet.copyOf(capabilities);
4✔
45
    }
1✔
46

47
    @Override
48
    public String getProductName() {
49
        return "SQL Server";
2✔
50
    }
51

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

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

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

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

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

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

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

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

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

106
    @Override
107
    public String formatCeilFunction(String operand) {
108
        return "ceiling(" + operand + ")";
3✔
109
    }
110

111
    @Override
112
    public String formatLnFunction(String operand) {
113
        return "log(" + operand + ")";
3✔
114
    }
115

116
    @Override
117
    public String formatRoundFunction(String operand) {
118
        return "round(" + operand + ", 0)";
3✔
119
    }
120

121
    @Override
122
    public String formatModuloFunction(String divisor, String dividend) {
123
        throw new UnsupportedOperationException("SQL Server does not support the mod() function (use the modulo infix operator instead)");
×
124
    }
125

126
    @Override
127
    public String formatCurrentDateFunction() {
128
        return "getdate()";
2✔
129
    }
130

131
    @Override
132
    public Optional<String> getDataType(DataType dataType) {
133
        // https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/equivalent-ansi-sql-data-types
134
        return Optional.ofNullable(switch(dataType.getIsoDataType()) {
8!
135
            case BOOLEAN -> "bit";
×
136
            case CHAR -> "char";
×
137
            case VARCHAR -> "varchar";
2✔
138
            case BIT, BIT_VARYING -> "binary";
×
139
            case NUMERIC -> null;
×
140
            case DECIMAL -> "decimal";
2✔
141
            case INTEGER -> "integer";
×
142
            case SMALLINT -> "smallint";
×
143
            case FLOAT, DOUBLE_PRECISION -> "float";
×
144
            case REAL -> "real";
×
145
            case DATE, TIME -> "datetime";
×
146
            case INTERVAL -> null;
×
147
            case CHARACTER_LARGE_OBJECT -> null;
×
148
            case BINARY_LARGE_OBJECT -> null;
×
149
        });
150
    }
151

152
    @Override
153
    public Optional<String> getConcatOperator() {
154
        return Optional.of("+");
3✔
155
    }
156

157
    @Override
158
    public boolean supports(Capability capability) {
159
        return supportedCaps.contains(capability);
5✔
160
    }
161
}
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