Skip to content

Commit

Permalink
[CONJ-990] Setting timezone=UTC result in SQLSyntaxErrorException
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 25, 2022
1 parent 96fc0a6 commit fec0708
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java
Expand Up @@ -374,7 +374,7 @@ private void postConnectionQueries() throws SQLException {
throw exceptionFactory.create(
String.format(
"Setting configured timezone '%s' fail on server.\nLook at https://mariadb.com/kb/en/mysql_tzinfo_to_sql/ to load tz data on server, or set timezone=disable to disable setting client timezone.",
conf.timezone()));
conf.timezone()), "HY000", sqlException);
}
throw exceptionFactory.create("Initialization command fail", "08000", sqlException);
}
Expand Down Expand Up @@ -427,7 +427,13 @@ public String createSessionVariableQuery(String serverTz) {
if (mustSetTimezone) {
if (clientZoneId.getRules().isFixedOffset()) {
ZoneOffset zoneOffset = clientZoneId.getRules().getOffset(Instant.now());
sessionCommands.add("time_zone='" + zoneOffset.getId() + "'");
if (zoneOffset.getTotalSeconds() == 0) {
// specific for UTC timezone, server permitting only SYSTEM/UTC offset or named time zone
// not 'UTC'/'Z'
sessionCommands.add("time_zone='+00:00'");
} else {
sessionCommands.add("time_zone='" + zoneOffset.getId() + "'");
}
} else {
sessionCommands.add("time_zone='" + conf.timezone() + "'");
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java
Expand Up @@ -1093,6 +1093,17 @@ public void timezone() throws SQLException {
assertEquals("-08:00", rs.getString(1));
}

try (Connection con = createCon("timezone=UTC")) {
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT @@time_zone, @@system_time_zone");
rs.next();
String srvTz = rs.getString(1);
if ("SYSTEM".equals(rs.getString(1))) {
srvTz = rs.getString(2);
}
assertTrue("+00:00".equals(srvTz) || "UTC".equals(srvTz));
}

try (Connection con = createCon("timezone=disable")) {
con.isValid(1);
}
Expand Down

0 comments on commit fec0708

Please sign in to comment.