提交 60989c1f 编写于 作者: S Serge Rider

#10055 Workaround for MySQL serverTimezone problem


Former-commit-id: 321158df
上级 515d27f4
...@@ -82,6 +82,8 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti ...@@ -82,6 +82,8 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti
private volatile boolean hasStatistics; private volatile boolean hasStatistics;
private boolean containsCheckConstraintTable; private boolean containsCheckConstraintTable;
private transient boolean inServerTimezoneHandle;
public MySQLDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container) public MySQLDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container)
throws DBException { throws DBException {
super(monitor, container, new MySQLDialect()); super(monitor, container, new MySQLDialect());
...@@ -123,9 +125,9 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti ...@@ -123,9 +125,9 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti
} }
String serverTZ = connectionInfo.getProviderProperty(MySQLConstants.PROP_SERVER_TIMEZONE); String serverTZ = connectionInfo.getProviderProperty(MySQLConstants.PROP_SERVER_TIMEZONE);
// if (CommonUtils.isEmpty(serverTZ) && getContainer().getDriver().getId().equals(MySQLConstants.DRIVER_ID_MYSQL8)) { if (CommonUtils.isEmpty(serverTZ) && inServerTimezoneHandle/*&& getContainer().getDriver().getId().equals(MySQLConstants.DRIVER_ID_MYSQL8)*/) {
// serverTZ = "UTC"; serverTZ = "UTC";
// } }
if (!CommonUtils.isEmpty(serverTZ)) { if (!CommonUtils.isEmpty(serverTZ)) {
props.put("serverTimezone", serverTZ); props.put("serverTimezone", serverTZ);
} }
...@@ -400,7 +402,27 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti ...@@ -400,7 +402,27 @@ public class MySQLDataSource extends JDBCDataSource implements DBPObjectStatisti
@Override @Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullable JDBCExecutionContext context, @NotNull String purpose) throws DBCException { protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullable JDBCExecutionContext context, @NotNull String purpose) throws DBCException {
Connection mysqlConnection = super.openConnection(monitor, context, purpose); Connection mysqlConnection;
try {
mysqlConnection = super.openConnection(monitor, context, purpose);
} catch (DBCException e) {
if (e.getCause() instanceof SQLException &&
SQLState.SQL_01S00.getCode().equals (((SQLException) e.getCause()).getSQLState()) &&
CommonUtils.isEmpty(getContainer().getActualConnectionConfiguration().getProviderProperty(MySQLConstants.PROP_SERVER_TIMEZONE)))
{
// Workaround for nasty problem with MySQL 8 driver and serverTimezone error
log.debug("Error connecting without serverTimezone. Trying to set serverTimezone=UTC. Original error: " + e.getMessage());
inServerTimezoneHandle = true;
try {
mysqlConnection = super.openConnection(monitor, context, purpose);
} catch (DBCException e2) {
inServerTimezoneHandle = false;
throw e2;
}
} else {
throw e;
}
}
if (!getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CLIENT_NAME_DISABLE)) { if (!getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CLIENT_NAME_DISABLE)) {
// Provide client info // Provide client info
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册