Permalink
Browse files

#2866 MySQL: year data type reading/editing fix

  • Loading branch information...
serge-rider committed Jan 11, 2019
1 parent 17e17b4 commit cb361a39046e626a8ebb5f73a02962f7c4b60c3d
@@ -26,6 +26,7 @@
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.DBCStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCDateTimeValueHandler;
import org.jkiss.dbeaver.model.messages.ModelMessages;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
@@ -53,6 +54,19 @@ public MySQLDateTimeValueHandler(DBDDataFormatterProfile formatterProfile)

@Override
public Object fetchValueObject(@NotNull DBCSession session, @NotNull DBCResultSet resultSet, @NotNull DBSTypedObject type, int index) throws DBCException {
if (MySQLConstants.TYPE_YEAR.equalsIgnoreCase(type.getTypeName()) && resultSet instanceof JDBCResultSet) {
JDBCResultSet dbResults = (JDBCResultSet) resultSet;
try {
int year = dbResults.getInt(index + 1);
if (dbResults.wasNull()) {
return null;
} else {
return year;
}
} catch (SQLException e) {
log.debug("Error reading year value", e);
}
}
return super.fetchValueObject(session, resultSet, type, index);
}

@@ -71,7 +85,7 @@ public void bindValueObject(@NotNull DBCSession session, @NotNull DBCStatement s
catch (SQLException e) {
throw new DBCException(ModelMessages.model_jdbc_exception_could_not_bind_statement_parameter, e);
}
} else if (MySQLConstants.TYPE_YEAR.equals(type.getTypeName())) {
} else if (MySQLConstants.TYPE_YEAR.equalsIgnoreCase(type.getTypeName())) {
try {
JDBCPreparedStatement dbStat = (JDBCPreparedStatement)statement;
if (value instanceof Number) {
@@ -86,7 +86,7 @@ public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedO
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format)
{
if (value == null || value instanceof String) {
if (value == null || value instanceof String || value instanceof Number) {
return super.getValueDisplayString(column, value, format);
}
try {

0 comments on commit cb361a3

Please sign in to comment.