• 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

50.0
/src/main/java/io/github/torand/fastersql/dialect/Dialect.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.SQLException;
20
import java.util.List;
21
import java.util.Optional;
22

23
public interface Dialect {
24
    /**
25
     * Gets the name of the RDBMS product.
26
     * @return the name of the RDBMS product.
27
     */
28
    String getProductName();
29

30
    /**
31
     * Returns the _row offset clause_ formatted for a specific SQL dialect.
32
     * @return the _row offset clause_ formatted for a specific SQL dialect.
33
     */
34
    Optional<String> formatRowOffsetClause();
35

36
    /**
37
     * Returns the _row limit clause_ formatted for a specific SQL dialect.
38
     * @return the _row limit clause_ formatted for a specific SQL dialect.
39
     */
40
    Optional<String> formatRowLimitClause();
41

42
    /**
43
     * Returns the _row number_ literal formatted for a specific SQL dialect.
44
     * @return the _row number_ literal formatted for a specific SQL dialect.
45
     */
46
    Optional<String> formatRowNumLiteral();
47

48
    /**
49
     * Returns the 'to_number' function formatted for a specific SQL dialect.
50
     * @param operand the string expression to be evaluated as a number
51
     * @param precision the precision that represents the number of significant digits
52
     * @param scale the scale that that represents the number of digits after the decimal point. Must be less than or equal to the precision.
53
     * @return the 'to_number' function for a specific SQL dialect.
54
     */
55
    String formatToNumberFunction(String operand, int precision, int scale);
56

57
    /**
58
     * Returns the 'substring' function formatted for a specific SQL dialect.
59
     * @param operand the string expression to get substring from
60
     * @param startPos the start position (1-based) of the substring
61
     * @param length the length of the substring
62
     * @return the 'substring' function for a specific SQL dialect.
63
     */
64
    String formatSubstringFunction(String operand, int startPos, int length);
65

66
    /**
67
     * Returns the 'concat' function formatted for a specific SQL dialect.
68
     * @param operands the string expressions to concatenate
69
     * @return the 'concat' function for a specific SQL dialect.
70
     */
71
    String formatConcatFunction(List<String> operands);
72

73
    /**
74
     * Returns the 'length' function formatted for a specific SQL dialect.
75
     * @param operand the string expression to get length of
76
     * @return the 'length' function for a specific SQL dialect.
77
     */
78
    String formatLengthFunction(String operand);
79

80
    /**
81
     * Indicates whether a capability is supported by a specific SQL dialect.
82
     * @param capability the capability to check support for
83
     * @return true if specified capability is supported; else false
84
     */
85
    boolean supports(Capability capability);
86

87
    static Dialect fromConnection(Connection connection) {
88
        try {
89
            String productName = connection.getMetaData().getDatabaseProductName().toLowerCase();
5✔
90

91
            if (productName.contains("h2")) {
4!
UNCOV
92
                return new H2Dialect();
×
93
            } else if (productName.contains("mysql")) {
4!
94
                return new MySqlDialect();
×
95
            } else if (productName.contains("mariadb")) {
4!
96
                return new MariaDbDialect();
×
97
            } else if (productName.contains("postgresql")) {
4!
UNCOV
98
                return new PostgreSqlDialect();
×
99
            } else if (productName.contains("oracle")) {
4!
100
                return new OracleDialect();
4✔
101
            } else {
UNCOV
102
                throw new UnsupportedOperationException("Database with product name " + productName + " not supported");
×
103
            }
UNCOV
104
        } catch (SQLException e) {
×
UNCOV
105
            throw new RuntimeException("Failed to detect SQL dialect from connection metadata", e);
×
106
        }
107
    }
108
}
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