Skip to content

Commit fbc9873

Browse files
committed
test Coverage addition
1 parent 6c2213a commit fbc9873

File tree

13 files changed

+120
-45
lines changed

13 files changed

+120
-45
lines changed

src/main/java/org/mariadb/jdbc/client/ConnectionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static Socket standardSocket(Configuration conf, HostAddress hostAddress)
104104
(Class<? extends SocketFactory>) Class.forName(socketFactoryName);
105105
Constructor<? extends SocketFactory> constructor = socketFactoryClass.getConstructor();
106106
socketFactory = constructor.newInstance();
107-
if (socketFactoryClass.isInstance(ConfigurableSocketFactory.class)) {
107+
if (socketFactory instanceof ConfigurableSocketFactory) {
108108
((ConfigurableSocketFactory) socketFactory).setConfiguration(conf, hostAddress.host);
109109
}
110110
return socketFactory.createSocket();

src/main/java/org/mariadb/jdbc/util/ClientParser.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,6 @@ public List<byte[]> getQueryParts() {
228228
return queryParts;
229229
}
230230

231-
public boolean isQueryMultiValuesRewritable() {
232-
return isQueryMultiValuesRewritable;
233-
}
234-
235-
public boolean isQueryMultipleRewritable() {
236-
return isQueryMultipleRewritable;
237-
}
238-
239-
public boolean isRewriteType() {
240-
return rewriteType;
241-
}
242-
243231
public int getParamCount() {
244232
return paramCount;
245233
}

src/main/java/org/mariadb/jdbc/util/NativeSql.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.mariadb.jdbc.client.context.Context;
2727
import org.mariadb.jdbc.util.constants.ServerStatus;
2828

29-
public class NativeSql {
29+
public final class NativeSql {
3030

3131
public static String parse(String sql, Context context) throws SQLException {
3232
if (!sql.contains("{")) {

src/main/java/org/mariadb/jdbc/util/ParameterList.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public void set(int index, Parameter<?> element) {
3636
if (index + 1 > length) length = index + 1;
3737
}
3838

39-
public void clear() {
40-
length = 0;
41-
Arrays.fill(elementData, null);
42-
}
43-
4439
public int size() {
4540
return length;
4641
}

src/main/java/org/mariadb/jdbc/util/Security.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
package org.mariadb.jdbc.util;
2323

24-
public class Security {
24+
public final class Security {
2525

2626
/**
2727
* Parse the option "sessionVariable" to ensure having no injection. semi-column not in string

src/main/java/org/mariadb/jdbc/util/Version.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,19 @@ public final class Version {
3333
public static final String qualifier;
3434

3535
static {
36-
InputStream inputStream = null;
3736
String tmpVersion = "5.5.0";
38-
try {
39-
Properties prop = new Properties();
40-
inputStream = Version.class.getClassLoader().getResourceAsStream("mariadb.properties");
41-
if (inputStream != null) {
42-
prop.load(inputStream);
43-
} else {
37+
try (InputStream inputStream =
38+
Version.class.getClassLoader().getResourceAsStream("mariadb.properties")) {
39+
if (inputStream == null) {
4440
System.out.println("property file 'mariadb.properties' not found in the classpath");
4541
}
46-
47-
// get the property value and print it out
42+
Properties prop = new Properties();
43+
prop.load(inputStream);
4844
tmpVersion = prop.getProperty("version");
49-
} catch (Exception e) {
50-
// eat
51-
} finally {
52-
try {
53-
inputStream.close();
54-
} catch (IOException ioe) {
55-
// eat
56-
}
45+
} catch (IOException e) {
46+
e.printStackTrace();
5747
}
48+
5849
version = tmpVersion;
5950
int major = 0;
6051
int minor = 0;

src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
public class OptionAliases {
22+
public final class OptionAliases {
2323

2424
public static final Map<String, String> OPTIONS_ALIASES;
2525

src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,14 @@ public void testValuesForPartition() throws Exception {
310310
+ "(PARTITION test_p201605 VALUES LESS THAN ('2016-06-01'))"
311311
});
312312
}
313+
314+
@Test
315+
public void testParse() throws Exception {
316+
checkParsing(
317+
"INSERT INTO `myTable` VALUES ('\\n\"\\'', \"'\\\n\\\"\") \n // comment\n , ('a', 'b') # EOL comment",
318+
0,
319+
new String[] {
320+
"INSERT INTO `myTable` VALUES ('\\n\"\\'', \"'\\\n\\\"\") \n // comment\n , ('a', 'b') # EOL comment"
321+
});
322+
}
313323
}

src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public void testSessionVariable() throws SQLException {
6868
}
6969

7070
try (Connection connection =
71-
createCon("sessionVariables=session_track_system_variables='some\\';f,ff'")) {
71+
createCon("sessionVariables=session_track_system_variables='some\\';f,\"ff'")) {
72+
Statement stmt = connection.createStatement();
73+
ResultSet rs = stmt.executeQuery("SELECT @@session_track_system_variables");
74+
assertTrue(rs.next());
75+
}
76+
try (Connection connection =
77+
createCon("sessionVariables=session_track_system_variables=\"some\\\";f,'ff'\"")) {
7278
Statement stmt = connection.createStatement();
7379
ResultSet rs = stmt.executeQuery("SELECT @@session_track_system_variables");
7480
assertTrue(rs.next());

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.mariadb.jdbc.Configuration;
3737
import org.mariadb.jdbc.Connection;
3838
import org.mariadb.jdbc.Statement;
39+
import org.mariadb.jdbc.integration.util.SocketFactoryTest;
3940

4041
@DisplayName("Connection Test")
4142
public class ConnectionTest extends Common {
@@ -106,17 +107,19 @@ public void autoCommit() throws SQLException {
106107
public void nativeSQL() throws SQLException {
107108
String[] inputs =
108109
new String[] {
109-
"select {fn timestampdiff(SQL_TSI_HOUR, {fn convert('SQL_', SQL_INTEGER)})}",
110+
"select {fn TIMESTAMPDIFF ( SQL_TSI_HOUR, {fn convert('SQL_', SQL_INTEGER)})}, {fn TIMESTAMPDIFF (HOUR, {fn convert ('sQL_' , SQL_INTEGER)})}",
110111
"{call foo({fn now()})}",
111-
"{ call foo({fn now()})}",
112-
"{\r\n call foo({fn now()})}",
112+
"{ call foo({fn now()})}",
113+
"{\r\ncall foo({fn now()})}",
114+
"{\r\n call foo({fn now()})}",
113115
"{call foo(/*{fn now()}*/)}",
114-
"{call foo({fn now() /* -- * */ -- test \n })}",
116+
"{CALL foo({fn now() /* -- * */ -- test \n })}",
115117
"{?=call foo({fn now()})}",
116118
"SELECT 'David_' LIKE 'David|_' {escape '|'}",
117119
"select {fn dayname ({fn abs({fn now()})})}",
118120
"{d '1997-05-24'}",
119121
"{d'1997-05-24'}",
122+
"{\nt'10:30:29'}",
120123
"{t '10:30:29'}",
121124
"{t'10:30:29'}",
122125
"{ts '1997-05-24 10:30:29.123'}",
@@ -128,19 +131,21 @@ public void nativeSQL() throws SQLException {
128131
};
129132
String[] outputs =
130133
new String[] {
131-
"select timestampdiff(HOUR, convert('SQL_', INTEGER))",
134+
"select TIMESTAMPDIFF ( HOUR, convert('SQL_', INTEGER)), TIMESTAMPDIFF (HOUR, convert ('sQL_' , INTEGER))",
135+
"call foo(now())",
132136
"call foo(now())",
133137
"call foo(now())",
134138
"call foo(now())",
135139
"call foo(/*{fn now()}*/)",
136-
"call foo(now() /* -- * */ -- test \n )",
140+
"CALL foo(now() /* -- * */ -- test \n )",
137141
"?=call foo(now())",
138142
"SELECT 'David_' LIKE 'David|_' escape '|'",
139143
"select dayname (abs(now()))",
140144
"'1997-05-24'",
141145
"'1997-05-24'",
142146
"'10:30:29'",
143147
"'10:30:29'",
148+
"'10:30:29'",
144149
"'1997-05-24 10:30:29.123'",
145150
"'1997-05-24 10:30:29.123'",
146151
"'{string data with { or } will not be altered'",
@@ -921,4 +926,11 @@ public boolean isLocalConnection(String testName) {
921926

922927
return isLocal;
923928
}
929+
930+
@Test
931+
public void socketFactoryTest() throws SQLException {
932+
try (Connection conn = createCon("socketFactory=" + SocketFactoryTest.class.getName())) {
933+
conn.isValid(1);
934+
}
935+
}
924936
}

0 commit comments

Comments
 (0)