|
15 | 15 | import java.util.List; |
16 | 16 | import java.util.Properties; |
17 | 17 | import java.util.Set; |
| 18 | +import java.util.regex.Matcher; |
| 19 | +import java.util.regex.Pattern; |
18 | 20 |
|
19 | 21 | /** |
20 | 22 | * JDBC driver for ClickHouse. |
21 | 23 | */ |
22 | 24 | public class Driver implements java.sql.Driver { |
23 | 25 | private static final Logger log = LoggerFactory.getLogger(Driver.class); |
24 | 26 | public static final String driverVersion; |
| 27 | + public static final int majorVersion; |
| 28 | + public static final int minorVersion; |
25 | 29 | private final DataSourceImpl dataSource; |
26 | 30 |
|
27 | 31 | public static String frameworksDetected = null; |
@@ -54,12 +58,32 @@ public static String getFrameworksDetected() { |
54 | 58 | //If the version is not available, set it to 1.0 |
55 | 59 | if (tempDriverVersion == null || tempDriverVersion.isEmpty()) { |
56 | 60 | log.warn("ClickHouse JDBC driver version is not available"); |
57 | | - tempDriverVersion = "1.0"; |
| 61 | + tempDriverVersion = "1.0.0"; |
58 | 62 | } |
59 | 63 |
|
60 | 64 | driverVersion = tempDriverVersion; |
61 | 65 | log.info("ClickHouse JDBC driver version: {}", driverVersion); |
62 | 66 |
|
| 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 | + |
63 | 87 | //Load the driver |
64 | 88 | //load(); //Commented out to avoid loading the driver multiple times, because we're referenced in V1 |
65 | 89 | } |
@@ -109,23 +133,21 @@ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws |
109 | 133 | } |
110 | 134 |
|
111 | 135 | public static int getDriverMajorVersion() { |
112 | | - return Integer.parseInt(driverVersion.split("\\.")[0]); |
| 136 | + return majorVersion; |
113 | 137 | } |
114 | 138 |
|
115 | 139 | @Override |
116 | 140 | public int getMajorVersion() { |
117 | | - //Convert the version string to an integer |
118 | | - return Integer.parseInt(driverVersion.split("\\.")[0]); |
| 141 | + return majorVersion; |
119 | 142 | } |
120 | 143 |
|
121 | 144 | public static int getDriverMinorVersion() { |
122 | | - return Integer.parseInt(driverVersion.split("\\.")[1]); |
| 145 | + return minorVersion; |
123 | 146 | } |
124 | 147 |
|
125 | 148 | @Override |
126 | 149 | public int getMinorVersion() { |
127 | | - //Convert the version string to an integer |
128 | | - return Integer.parseInt(driverVersion.split("\\.")[1]); |
| 150 | + return minorVersion; |
129 | 151 | } |
130 | 152 |
|
131 | 153 | @Override |
|
0 commit comments