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

torand / FasterSQL / 13393719904

18 Feb 2025 03:08PM UTC coverage: 60.439% (+0.5%) from 59.964%
13393719904

push

github

torand
test: MySQL specific testing of insert clause

160 of 346 branches covered (46.24%)

Branch coverage included in aggregate %.

4 of 11 new or added lines in 6 files covered. (36.36%)

859 of 1340 relevant lines covered (64.1%)

3.4 hits per line

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

35.71
/src/main/java/io/github/torand/fastersql/dialect/H2Dialect.java
1
/*
2
 * Copyright (c) 2024 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.sql.Connection;
19
import java.sql.PreparedStatement;
20
import java.sql.SQLException;
21
import java.util.EnumSet;
22
import java.util.List;
23
import java.util.Optional;
24

25
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
26
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
27
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
28

29
/**
30
 * Defines the H2 SQL dialect.
31
 *
32
 * <a href="https://www.h2database.com/html/grammar.html" />
33
 */
34
public class H2Dialect implements Dialect {
3✔
35
    private static final EnumSet<Capability> SUPPORTED_CAPS = EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR);
5✔
36

37
    @Override
38
    public String getProductName() {
39
        return "H2";
2✔
40
    }
41

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

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

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

57
    @Override
58
    public Optional<String> formatRowNumLiteral() {
59
        return Optional.of("rownum()");
×
60
    }
61

62
    @Override
63
    public String formatToNumberFunction(String operand, int precision, int scale) {
64
        StringBuilder mask = new StringBuilder();
×
65
        if (precision-scale > 0) {
×
66
            mask.append(generate("9", precision-scale));
×
67
        }
68
        if (scale > 0) {
×
69
            mask.append(".").append(generate("9", scale));
×
70
        }
71

72
        return "to_number(" + operand + ", '" + mask + "')";
×
73
    }
74

75
    @Override
76
    public String formatToCharFunction(String operand, String format) {
77
        return "to_char(" + operand + ", " + format + ")";
4✔
78
    }
79

80
    @Override
81
    public String formatSubstringFunction(String operand, int startPos, int length) {
82
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
83
    }
84

85
    @Override
86
    public String formatConcatFunction(List<String> operands) {
NEW
87
        throw new UnsupportedOperationException("H2 does not support the concat() function (use the concat infix operator instead)");
×
88
    }
89

90
    @Override
91
    public String formatLengthFunction(String operand) {
92
        return "char_length(" + operand + ")";
3✔
93
    }
94

95
    @Override
96
    public boolean supports(Capability capability) {
97
        return SUPPORTED_CAPS.contains(capability);
4✔
98
    }
99

100
    public static void setupCustomizations(Connection connection) {
101
        try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE ALIAS IF NOT EXISTS TO_NUMBER FOR \"io.github.torand.fastersql.dialect.H2CustomFunctions.toNumber\"")) {
×
102
            preparedStatement.execute();
×
103
        } catch (SQLException e) {
×
104
            throw new RuntimeException("Failed to setup H2 customizations", e);
×
105
        }
×
106
    }
×
107
}
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