提交 e885c6a9 编写于 作者: S Serge Rider

#6026 Treat empty strings as NULL datetime/number

上级 0b2845a0
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ext.oracle.data;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.oracle.model.OracleConstants;
......@@ -50,7 +51,7 @@ public class OracleTimestampValueHandler extends JDBCDateTimeValueHandler {
}
@Override
public Object getValueFromObject(DBCSession session, DBSTypedObject type, Object object, boolean copy) throws DBCException {
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
if (object != null) {
String className = object.getClass().getName();
if (className.startsWith(OracleConstants.TIMESTAMP_CLASS_NAME)) {
......
......@@ -27,7 +27,6 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.impl.data.formatters.DefaultDataFormatter;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Date;
......@@ -54,12 +53,16 @@ public abstract class DateTimeCustomValueHandler extends DateTimeValueHandler {
} else if (object instanceof Date) {
return copy ? ((Date)object).clone() : object;
} else if (object instanceof String) {
String strValue = (String)object;
if (strValue.isEmpty()) {
// NULL date
return null;
}
if (session != null && session.getDataSource().getContainer().getPreferenceStore().getBoolean(ModelPreferences.RESULT_NATIVE_DATETIME_FORMAT)) {
// Do not use formatter for native format
return object;
}
String strValue = (String)object;
try {
return getFormatter(type).parseValue(strValue, null);
} catch (ParseException e) {
......
......@@ -56,7 +56,7 @@ public class JDBCDateTimeValueHandler extends DateTimeCustomValueHandler {
}
@Override
public Object getValueFromObject(DBCSession session, DBSTypedObject type, Object object, boolean copy) throws DBCException {
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
Object value = super.getValueFromObject(session, type, object, copy);
if (value instanceof Date) {
switch (type.getTypeID()) {
......
......@@ -313,7 +313,12 @@ public class JDBCNumberValueHandler extends JDBCAbstractValueHandler implements
} else if (object instanceof Number) {
return object;
} else if (object instanceof String) {
return DBValueFormatting.convertStringToNumber((String) object, getNumberType(type), formatter);
String strValue = (String) object;
if (strValue.isEmpty()) {
// Empty string means NULL value
return null;
}
return DBValueFormatting.convertStringToNumber(strValue, getNumberType(type), formatter);
} else if (object instanceof Boolean) {
return (Boolean) object ? 1 : 0;
} else {
......
......@@ -381,21 +381,23 @@ class ResultSetFilterPanel extends Composite implements IContentProposalProvider
{
String displayName = getActiveSourceQuery();
if (prevQuery == null || !prevQuery.equals(displayName)) {
loadFiltersHistory(displayName);
prevQuery = displayName;
}
Pattern mlCommentsPattern = Pattern.compile("/\\*.*\\*/", Pattern.DOTALL);
Matcher m = mlCommentsPattern.matcher(displayName);
if (m.find()) {
displayName = m.replaceAll("");
}
if (displayName != null) {
if (prevQuery == null || !prevQuery.equals(displayName)) {
loadFiltersHistory(displayName);
prevQuery = displayName;
}
Pattern mlCommentsPattern = Pattern.compile("/\\*.*\\*/", Pattern.DOTALL);
Matcher m = mlCommentsPattern.matcher(displayName);
if (m.find()) {
displayName = m.replaceAll("");
}
displayName = displayName.replaceAll("--.+", "");
displayName = CommonUtils.compactWhiteSpaces(displayName);
activeDisplayName = CommonUtils.notEmpty(CommonUtils.truncateString(displayName, 200));
if (CommonUtils.isEmpty(activeDisplayName)) {
activeDisplayName = ResultSetViewer.DEFAULT_QUERY_TEXT;
displayName = displayName.replaceAll("--.+", "");
displayName = CommonUtils.compactWhiteSpaces(displayName);
activeDisplayName = CommonUtils.notEmpty(CommonUtils.truncateString(displayName, 200));
if (CommonUtils.isEmpty(activeDisplayName)) {
activeDisplayName = ResultSetViewer.DEFAULT_QUERY_TEXT;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册