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

torand / FasterSQL / 13367709795

17 Feb 2025 10:06AM UTC coverage: 58.785% (+2.0%) from 56.762%
13367709795

push

github

torand
feat: support length function

148 of 338 branches covered (43.79%)

Branch coverage included in aggregate %.

10 of 17 new or added lines in 7 files covered. (58.82%)

66 existing lines in 9 files now uncovered.

829 of 1324 relevant lines covered (62.61%)

3.33 hits per line

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

0.0
/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

UNCOV
29
public class H2Dialect implements Dialect {
×
UNCOV
30
    private static final EnumSet<Capability> SUPPORTED_CAPS = EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR);
×
31

32
    @Override
33
    public String getProductName() {
UNCOV
34
        return "H2";
×
35
    }
36

37
    @Override
38
    public Optional<String> formatRowOffsetClause() {
UNCOV
39
        return Optional.of("offset ?");
×
40
    }
41

42
    @Override
43
    public Optional<String> formatRowLimitClause() {
UNCOV
44
        return Optional.of("limit ?");
×
45
    }
46

47
    @Override
48
    public Optional<String> formatRowNumLiteral() {
UNCOV
49
        return Optional.of("rownum()");
×
50
    }
51

52
    @Override
53
    public String formatToNumberFunction(String operand, int precision, int scale) {
54
        StringBuilder mask = new StringBuilder();
×
UNCOV
55
        if (precision-scale > 0) {
×
56
            mask.append(generate("9", precision-scale));
×
57
        }
UNCOV
58
        if (scale > 0) {
×
UNCOV
59
            mask.append(".").append(generate("9", scale));
×
60
        }
61

UNCOV
62
        return "to_number(" + operand + ", '" + mask + "')";
×
63
    }
64

65
    @Override
66
    public String formatSubstringFunction(String operand, int startPos, int length) {
UNCOV
67
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
×
68
    }
69

70
    @Override
71
    public String formatConcatFunction(List<String> operands) {
UNCOV
72
        throw new UnsupportedOperationException("Use the concat infix operator for H2");
×
73
    }
74

75
    @Override
76
    public String formatLengthFunction(String operand) {
NEW
77
        return "char_length(" + operand + ")";
×
78
    }
79

80
    @Override
81
    public boolean supports(Capability capability) {
82
        return SUPPORTED_CAPS.contains(capability);
×
83
    }
84

85
    public static void setupCustomizations(Connection connection) {
UNCOV
86
        try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE ALIAS IF NOT EXISTS TO_NUMBER FOR \"io.github.torand.fastersql.dialect.H2CustomFunctions.toNumber\"")) {
×
UNCOV
87
            preparedStatement.execute();
×
UNCOV
88
        } catch (SQLException e) {
×
UNCOV
89
            throw new RuntimeException("Failed to setup H2 customizations", e);
×
UNCOV
90
        }
×
UNCOV
91
    }
×
92
}
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