• 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

30.43
/src/main/java/io/github/torand/fastersql/dialect/AccessDialect.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.POWER_OPERATOR;
28
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
29
import static io.github.torand.fastersql.dialect.Capability.SET_OPERATION_PARENTHESES;
30
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
31
import static java.util.Objects.isNull;
32

33
/**
34
 * Defines the <a href="https://support.microsoft.com/en-us/office/Queries-93fb69b7-cfc1-4f3e-ab56-b0a01523bb50#ID0EAABAAA=SQL_syntax&id0ebbd=sql_syntax">Microsoft Access</a> SQL dialect.
35
 */
36
public class AccessDialect implements Dialect {
37
    private final EnumSet<Capability> supportedCaps;
38

39
    /**
40
     * Creates a Microsoft Access {@link Dialect} implementation.
41
     */
42
    public AccessDialect() {
43
        this(EnumSet.of(LIMIT_OFFSET, SELECT_FOR_UPDATE, CONCAT_OPERATOR, POWER_OPERATOR, TRUNCATE_TABLE, FULL_OUTER_JOIN, SET_OPERATION_PARENTHESES));
30✔
44
    }
1✔
45

46
    private AccessDialect(EnumSet<Capability> capabilities) {
2✔
47
        this.supportedCaps = EnumSet.copyOf(capabilities);
4✔
48
    }
1✔
49

50
    @Override
51
    public String getProductName() {
52
        return "Access";
2✔
53
    }
54

55
    @Override
56
    public boolean offsetBeforeLimit() {
57
        return true;
2✔
58
    }
59

60
    @Override
61
    public Optional<String> formatRowOffsetClause() {
62
        return Optional.of("offset ? rows");
3✔
63
    }
64

65
    @Override
66
    public Optional<String> formatRowLimitClause() {
67
        return Optional.of("fetch next ? rows only");
3✔
68
    }
69

70
    @Override
71
    public Optional<String> formatRowNumLiteral() {
72
        return Optional.empty();
×
73
    }
74

75
    @Override
76
    public String formatToNumberFunction(String operand, int precision, int scale) {
77
        return "val(" + operand + ")";
3✔
78
    }
79

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

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

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

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

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

105
    @Override
106
    public String formatLnFunction(String operand) {
107
        return "ln(" + operand + ")";
3✔
108
    }
109

110
    @Override
111
    public String formatPowerFunction(String base, String exponent) {
112
        throw new UnsupportedOperationException("Access does not support the power() function (use the power infix operator instead)");
×
113
    }
114

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

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

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

130
    @Override
131
    public String formatCastFunction(String operand, DataType targetType) {
132
        // https://support.microsoft.com/en-us/office/type-conversion-functions-8ebb0e94-2d43-4975-bb13-87ac8d1a2202
133
        String function = switch(targetType.getIsoDataType()) {
6!
134
            case BOOLEAN -> "cbool";
×
135
            case CHAR -> "cstr";
×
136
            case VARCHAR -> "cstr";
2✔
137
            case BIT -> null;
×
138
            case BIT_VARYING -> null;
×
139
            case NUMERIC -> "cdec";
×
140
            case DECIMAL -> "cdec";
2✔
141
            case INTEGER -> "clng";
×
142
            case SMALLINT -> "cint";
×
143
            case FLOAT -> "csng";
×
144
            case REAL -> "cdbl";
×
145
            case DOUBLE_PRECISION -> "cdbl";
×
146
            case DATE -> "cdate";
×
147
            case TIME -> null;
×
148
            case INTERVAL -> null;
×
149
            case CHARACTER_LARGE_OBJECT -> null;
×
150
            case BINARY_LARGE_OBJECT -> null;
1✔
151
        };
152

153
        if (isNull(function)) {
3!
154
            throw new UnsupportedOperationException("Access does not support the %s data type".formatted(targetType.getIsoDataType().name()));
×
155
        }
156

157
        return "%s(%s)".formatted(function, operand);
13✔
158
    }
159

160
    @Override
161
    public Optional<String> getDataType(DataType dataType) {
162
        // https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/equivalent-ansi-sql-data-types
163
        return Optional.ofNullable(switch(dataType.getIsoDataType()) {
×
164
            case BOOLEAN -> "bit";
×
165
            case CHAR -> "char";
×
166
            case VARCHAR -> "text";
×
167
            case BIT, BIT_VARYING -> "binary";
×
168
            case NUMERIC -> null;
×
169
            case DECIMAL -> "numeric";
×
170
            case INTEGER -> "long";
×
171
            case SMALLINT -> "smallint";
×
172
            case FLOAT, DOUBLE_PRECISION -> "float";
×
173
            case REAL -> "real";
×
174
            case DATE, TIME -> "datetime";
×
175
            case INTERVAL -> null;
×
176
            case CHARACTER_LARGE_OBJECT -> null;
×
177
            case BINARY_LARGE_OBJECT -> null;
×
178
        });
179
    }
180

181
    @Override
182
    public Optional<String> getConcatOperator() {
183
        return Optional.of("&");
3✔
184
    }
185

186
    @Override
187
    public boolean supports(Capability capability) {
188
        return supportedCaps.contains(capability);
5✔
189
    }
190
}
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