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

torand / FasterSQL / 15294773771

28 May 2025 08:01AM UTC coverage: 70.078% (+0.2%) from 69.877%
15294773771

Pull #31

github

web-flow
Merge 9f1c324c0 into 6be86da23
Pull Request #31: feat: add support for SQLite dialect

233 of 418 branches covered (55.74%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 12 files covered. (84.85%)

45 existing lines in 10 files now uncovered.

1212 of 1644 relevant lines covered (73.72%)

3.91 hits per line

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

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

23
/**
24
 * Defines an SQL dialect as implemented by a specific database vendor.
25
 */
26
public interface Dialect {
27
    /**
28
     * Gets the name of the RDBMS product.
29
     * @return the name of the RDBMS product.
30
     */
31
    String getProductName();
32

33
    /**
34
     * Indicates whether offset clause must be specified before limit clause; if supported.
35
     * @return whether offset clause must be specified before limit clause; if supported.
36
     */
37
    boolean offsetBeforeLimit();
38

39
    /**
40
     * Returns the _row offset clause_ formatted for a specific SQL dialect.
41
     * @return the _row offset clause_ formatted for a specific SQL dialect.
42
     */
43
    Optional<String> formatRowOffsetClause();
44

45
    /**
46
     * Returns the _row limit clause_ formatted for a specific SQL dialect.
47
     * @return the _row limit clause_ formatted for a specific SQL dialect.
48
     */
49
    Optional<String> formatRowLimitClause();
50

51
    /**
52
     * Returns the _row number_ literal formatted for a specific SQL dialect.
53
     * @return the _row number_ literal formatted for a specific SQL dialect.
54
     */
55
    Optional<String> formatRowNumLiteral();
56

57
    /**
58
     * Returns the 'to_number' function formatted for a specific SQL dialect.
59
     * @param operand the string expression to be evaluated as a number
60
     * @param precision the precision that represents the number of significant digits
61
     * @param scale the scale that that represents the number of digits after the decimal point. Must be less than or equal to the precision.
62
     * @return the 'to_number' function for a specific SQL dialect.
63
     */
64
    String formatToNumberFunction(String operand, int precision, int scale);
65

66
    /**
67
     * Returns the 'to_char' function formatted for a specific SQL dialect.
68
     * @param operand the expression to be evaluated as a string
69
     * @param format the vendor-specific format mask
70
     * @return the 'to_char' function for a specific SQL dialect.
71
     */
72
    String formatToCharFunction(String operand, String format);
73

74
    /**
75
     * Returns the 'substring' function formatted for a specific SQL dialect.
76
     * @param operand the string expression to get substring from
77
     * @param startPos the start position (1-based) of the substring
78
     * @param length the length of the substring
79
     * @return the 'substring' function for a specific SQL dialect.
80
     */
81
    String formatSubstringFunction(String operand, int startPos, int length);
82

83
    /**
84
     * Returns the 'concat' function formatted for a specific SQL dialect.
85
     * @param operands the string expressions to concatenate
86
     * @return the 'concat' function for a specific SQL dialect.
87
     */
88
    String formatConcatFunction(List<String> operands);
89

90
    /**
91
     * Returns the 'length' function formatted for a specific SQL dialect.
92
     * @param operand the string expression to get length of
93
     * @return the 'length' function for a specific SQL dialect.
94
     */
95
    String formatLengthFunction(String operand);
96

97
    /**
98
     * Returns the 'ceil' function formatted for a specific SQL dialect.
99
     * @param operand the numeric expression to get ceiling of
100
     * @return the 'ceil' function for a specific SQL dialect.
101
     */
102
    String formatCeilFunction(String operand);
103

104
    /**
105
     * Returns the 'round' function formatted for a specific SQL dialect.
106
     * @param operand the numeric expression to perform rounding on
107
     * @return the 'round' function for a specific SQL dialect.
108
     */
109
    String formatRoundFunction(String operand);
110

111
    /**
112
     * Returns the 'mod' function formatted for a specific SQL dialect.
113
     * @param divisor the numeric expression for divisor operand
114
     * @param dividend the numeric expression for dividend operand
115
     * @return the 'mod' function for a specific SQL dialect.
116
     */
117
    String formatModuloFunction(String divisor, String dividend);
118

119
    /**
120
     * Returns the 'current_date' system function formatted for a specific SQL dialect.
121
     * @return the 'current_date' function for a specific SQL dialect.
122
     */
123
    String formatCurrentDateFunction();
124

125
    /**
126
     * Returns the string concatenation operator for a specific SQL Dialect.
127
     * @return the string concatenation operator for a specific SQL Dialect.
128
     */
129
    Optional<String> getConcatOperator();
130

131
    /**
132
     * Indicates whether a capability is supported by a specific SQL dialect.
133
     * @param capability the capability to check support for
134
     * @return true if specified capability is supported; else false
135
     */
136
    boolean supports(Capability capability);
137

138
    /**
139
     * Creates the {@link Dialect} instance corresponding to database vendor associated with specified connection.
140
     * @param connection the connection.
141
     * @return the {@link Dialect} instance.
142
     */
143
    static Dialect fromConnection(Connection connection) {
144
        try {
145
            String productName = connection.getMetaData().getDatabaseProductName().toLowerCase();
5✔
146

147
            if (productName.contains("h2")) {
4✔
148
                return new H2Dialect().withCustomizations(connection);
6✔
149
            } else if (productName.contains("mysql")) {
4✔
150
                return new MySqlDialect();
4✔
151
            } else if (productName.contains("mariadb")) {
4✔
152
                return new MariaDbDialect();
4✔
153
            } else if (productName.contains("postgresql")) {
4✔
154
                return new PostgreSqlDialect();
4✔
155
            } else if (productName.contains("oracle")) {
4✔
156
                return new OracleDialect();
4✔
157
            } else if (productName.contains("sql server")) {
4✔
158
                return new SqlServerDialect();
4✔
159
            } else if (productName.contains("access")) {
4✔
160
                return new AccessDialect();
4✔
161
            } else if (productName.contains("sqlite")) {
4!
162
                return new SqliteDialect();
4✔
163
            } else {
164
                throw new UnsupportedOperationException("Database with product name " + productName + " not supported");
×
165
            }
UNCOV
166
        } catch (SQLException e) {
×
UNCOV
167
            throw new RuntimeException("Failed to detect SQL dialect from connection metadata", e);
×
168
        }
169
    }
170
}
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