• 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

77.78
/src/main/java/io/github/torand/fastersql/dialect/MySqlDialect.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.CURRENT_TIME;
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.SELECT_FOR_UPDATE;
26
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
27

28
/**
29
 * Defines the <a href="https://dev.mysql.com/doc/refman/8.4/en/">MySQL</a> SQL dialect.
30
 */
31
public class MySqlDialect implements Dialect {
32
    private static final EnumSet<Capability> SUPPORTED_CAPS = EnumSet.of(LIMIT_OFFSET, CURRENT_TIME, MODULO_OPERATOR, SELECT_FOR_UPDATE, TRUNCATE_TABLE);
8✔
33

34
    /**
35
     * Creates a MySQL {@link Dialect} implementation.
36
     */
37
    public MySqlDialect() {}
3✔
38

39
    @Override
40
    public String getProductName() {
41
        return "MySQL";
2✔
42
    }
43

44
    @Override
45
    public boolean offsetBeforeLimit() {
46
        return false;
2✔
47
    }
48

49
    @Override
50
    public Optional<String> formatRowOffsetClause() {
51
        return Optional.of("offset ?");
3✔
52
    }
53

54
    @Override
55
    public Optional<String> formatRowLimitClause() {
56
        return Optional.of("limit ?");
3✔
57
    }
58

59
    @Override
60
    public Optional<String> formatRowNumLiteral() {
61
        return Optional.empty();
×
62
    }
63

64
    @Override
65
    public String formatToNumberFunction(String operand, int precision, int scale) {
66
        return "cast(" + operand + " as decimal(" + precision + "," + scale + "))";
5✔
67
    }
68

69
    @Override
70
    public String formatToCharFunction(String operand, String format) {
71
        throw new UnsupportedOperationException("MySQL does not support the to_char() function");
×
72
    }
73

74
    @Override
75
    public String formatSubstringFunction(String operand, int startPos, int length) {
76
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
77
    }
78

79
    @Override
80
    public String formatConcatFunction(List<String> operands) {
81
        return "concat(%s)".formatted(String.join(", ", operands));
11✔
82
    }
83

84
    @Override
85
    public String formatLengthFunction(String operand) {
86
        return "char_length(" + operand + ")";
3✔
87
    }
88

89
    @Override
90
    public String formatCeilFunction(String operand) {
91
        return "ceil(" + operand + ")";
3✔
92
    }
93

94
    @Override
95
    public String formatRoundFunction(String operand) {
96
        return "round(" + operand + ")";
3✔
97
    }
98

99
    @Override
100
    public String formatModuloFunction(String divisor, String dividend) {
101
        throw new UnsupportedOperationException("MySQL does not support the mod() function (use the modulo infix operator instead)");
×
102
    }
103

104
    @Override
105
    public String formatCurrentDateFunction() {
106
        return "current_date";
2✔
107
    }
108

109
    @Override
110
    public Optional<String> getConcatOperator() {
111
        return Optional.empty();
×
112
    }
113

114
    @Override
115
    public boolean supports(Capability capability) {
116
        return SUPPORTED_CAPS.contains(capability);
4✔
117
    }
118
}
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