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

#6026 Treat empty strings as NULL datetime/number

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