Skip to content

Commit 277d1fd

Browse files
authored
Merge pull request #1992 from ClickHouse/tweak-version-handling
2 parents bf1284d + e57d390 commit 277d1fd

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/Driver.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
import java.util.List;
1616
import java.util.Properties;
1717
import java.util.Set;
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
1820

1921
/**
2022
* JDBC driver for ClickHouse.
2123
*/
2224
public class Driver implements java.sql.Driver {
2325
private static final Logger log = LoggerFactory.getLogger(Driver.class);
2426
public static final String driverVersion;
27+
public static final int majorVersion;
28+
public static final int minorVersion;
2529
private final DataSourceImpl dataSource;
2630

2731
public static String frameworksDetected = null;
@@ -54,12 +58,32 @@ public static String getFrameworksDetected() {
5458
//If the version is not available, set it to 1.0
5559
if (tempDriverVersion == null || tempDriverVersion.isEmpty()) {
5660
log.warn("ClickHouse JDBC driver version is not available");
57-
tempDriverVersion = "1.0";
61+
tempDriverVersion = "1.0.0";
5862
}
5963

6064
driverVersion = tempDriverVersion;
6165
log.info("ClickHouse JDBC driver version: {}", driverVersion);
6266

67+
int tmpMajorVersion;
68+
int tmpMinorVersion;
69+
70+
try {
71+
Matcher m = Pattern.compile("(\\d+)(\\.\\d+)(\\.\\d+)").matcher(driverVersion);
72+
if (m.find()) {
73+
tmpMajorVersion = Integer.parseInt(m.group(1));
74+
tmpMinorVersion = Integer.parseInt(m.group(2).substring(1));
75+
} else {
76+
tmpMajorVersion = 0;
77+
tmpMinorVersion = 0;
78+
}
79+
} catch (Exception e) {
80+
tmpMajorVersion = 0;
81+
tmpMinorVersion = 0;
82+
}
83+
84+
majorVersion = tmpMajorVersion;
85+
minorVersion = tmpMinorVersion;
86+
6387
//Load the driver
6488
//load(); //Commented out to avoid loading the driver multiple times, because we're referenced in V1
6589
}
@@ -109,23 +133,21 @@ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws
109133
}
110134

111135
public static int getDriverMajorVersion() {
112-
return Integer.parseInt(driverVersion.split("\\.")[0]);
136+
return majorVersion;
113137
}
114138

115139
@Override
116140
public int getMajorVersion() {
117-
//Convert the version string to an integer
118-
return Integer.parseInt(driverVersion.split("\\.")[0]);
141+
return majorVersion;
119142
}
120143

121144
public static int getDriverMinorVersion() {
122-
return Integer.parseInt(driverVersion.split("\\.")[1]);
145+
return minorVersion;
123146
}
124147

125148
@Override
126149
public int getMinorVersion() {
127-
//Convert the version string to an integer
128-
return Integer.parseInt(driverVersion.split("\\.")[1]);
150+
return minorVersion;
129151
}
130152

131153
@Override

0 commit comments

Comments
 (0)