• 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

37.04
/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 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.CURRENT_TIME;
25
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
26
import static io.github.torand.fastersql.dialect.Capability.MODULO_OPERATOR;
27
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
28
import static io.github.torand.fastersql.dialect.Capability.SET_OPERATION_PARENTHESES;
29
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
30

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

37
    /**
38
     * Creates a MySQL {@link Dialect} implementation.
39
     */
40
    public MySqlDialect() {}
3✔
41

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

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

52
    @Override
53
    public Optional<String> formatRowOffsetClause() {
54
        return Optional.of("offset ?");
3✔
55
    }
56

57
    @Override
58
    public Optional<String> formatRowLimitClause() {
59
        return Optional.of("limit ?");
3✔
60
    }
61

62
    @Override
63
    public Optional<String> formatRowNumLiteral() {
64
        return Optional.empty();
×
65
    }
66

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

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

77
    @Override
78
    public String formatSubstringFunction(String operand, int startPos, int length) {
79
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
80
    }
81

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

87
    @Override
88
    public String formatLengthFunction(String operand) {
89
        return "char_length(" + operand + ")";
3✔
90
    }
91

92
    @Override
93
    public String formatCeilFunction(String operand) {
94
        return "ceil(" + operand + ")";
3✔
95
    }
96

97
    @Override
98
    public String formatLnFunction(String operand) {
99
        return "ln(" + operand + ")";
3✔
100
    }
101

102
    @Override
103
    public String formatRoundFunction(String operand) {
104
        return "round(" + operand + ")";
3✔
105
    }
106

107
    @Override
108
    public String formatModuloFunction(String divisor, String dividend) {
109
        throw new UnsupportedOperationException("MySQL does not support the mod() function (use the modulo infix operator instead)");
×
110
    }
111

112
    @Override
113
    public String formatCurrentDateFunction() {
114
        return "current_date";
2✔
115
    }
116

117
    @Override
118
    public Optional<String> getDataType(DataType dataType) {
119
        // https://dev.mysql.com/doc/refman/8.4/en/data-types.html
120
        return Optional.ofNullable(switch(dataType.getIsoDataType()) {
8!
121
            case BOOLEAN -> "bool";
×
122
            case CHAR -> "char";
2✔
123
            case VARCHAR -> "varchar";
×
124
            case BIT -> "bit";
×
125
            case BIT_VARYING -> null;
×
126
            case NUMERIC -> "numeric";
×
127
            case DECIMAL -> "decimal";
2✔
128
            case INTEGER -> "integer";
×
129
            case SMALLINT -> "smallint";
×
130
            case FLOAT -> "float";
×
131
            case DOUBLE_PRECISION -> "double precision";
×
132
            case REAL -> "real";
×
133
            case DATE -> "date";
×
134
            case TIME -> "time";
×
135
            case INTERVAL -> null;
×
136
            case CHARACTER_LARGE_OBJECT -> "text";
×
137
            case BINARY_LARGE_OBJECT -> "blob";
×
138
        });
139
    }
140

141
    @Override
142
    public Optional<String> getConcatOperator() {
143
        return Optional.empty();
×
144
    }
145

146
    @Override
147
    public boolean supports(Capability capability) {
148
        return SUPPORTED_CAPS.contains(capability);
4✔
149
    }
150
}
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