Skip to content

Commit

Permalink
#2866 MySQL: year data type reading/editing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Jan 11, 2019
1 parent 17e17b4 commit cb361a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down
Expand Up @@ -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 {
Expand Down

0 comments on commit cb361a3

Please sign in to comment.