diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BinaryPresentationString.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BinaryPresentationString.java index 2c51b34d904d9c2e715b706e636a82608662a738..791a9cd4baf97cbb289a580bd90c1ad27c841b8b 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BinaryPresentationString.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/data/BinaryPresentationString.java @@ -19,6 +19,7 @@ package org.jkiss.dbeaver.model.impl.data; import org.jkiss.dbeaver.model.data.DBDBinaryPresentation; +import org.jkiss.dbeaver.utils.ContentUtils; /** * String presentation @@ -40,12 +41,13 @@ public class BinaryPresentationString implements DBDBinaryPresentation { @Override public String toString(byte[] bytes, int offset, int length) { - return null; + return ContentUtils.convertToString(bytes, offset, length); } @Override public byte[] toBytes(String string) { - return new byte[0]; + return ContentUtils.convertToBytes(string); } + } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentBytes.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentBytes.java index 3eb691651e11186e2b4d84147f86add7d7571917..5dbf49abe00d3ce0182b5d534577abe759836afb 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentBytes.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentBytes.java @@ -63,6 +63,11 @@ public class JDBCContentBytes extends JDBCContentAbstract implements DBDContentS this.data = this.originalData = data; } + public JDBCContentBytes(DBPDataSource dataSource, String data) { + super(dataSource); + this.data = this.originalData = DBUtils.getBinaryPresentation(dataSource).toBytes(data); + } + @Override public InputStream getContentStream() throws IOException diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentValueHandler.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentValueHandler.java index b38f5c092caa95a4fe62ba3debadcfe21789b6be..c3703c06e8b45965ac13961c619b5e2f8e4ce1a8 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentValueHandler.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/model/impl/jdbc/data/JDBCContentValueHandler.java @@ -33,6 +33,7 @@ import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.core.CoreMessages; import org.jkiss.dbeaver.core.DBeaverUI; import org.jkiss.dbeaver.ext.IContentEditorPart; +import org.jkiss.dbeaver.model.DBUtils; import org.jkiss.dbeaver.model.data.*; import org.jkiss.dbeaver.model.exec.DBCException; import org.jkiss.dbeaver.model.exec.DBCExecutionContext; @@ -56,6 +57,7 @@ import org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart; import org.jkiss.dbeaver.ui.editors.content.parts.ContentImageEditorPart; import org.jkiss.dbeaver.ui.editors.content.parts.ContentTextEditorPart; import org.jkiss.dbeaver.ui.editors.content.parts.ContentXMLEditorPart; +import org.jkiss.dbeaver.ui.preferences.PrefConstants; import org.jkiss.dbeaver.ui.properties.PropertySourceAbstract; import org.jkiss.dbeaver.utils.ContentUtils; import org.jkiss.dbeaver.utils.MimeTypes; @@ -187,7 +189,7 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler { case java.sql.Types.BINARY: case java.sql.Types.VARBINARY: case java.sql.Types.LONGVARBINARY: - return new JDBCContentBytes(context.getDataSource(), ContentUtils.convertToBytes((String) object)); + return new JDBCContentBytes(context.getDataSource(), (String) object); default: // String by default return new JDBCContentChars(context.getDataSource(), (String) object); @@ -288,7 +290,8 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler { if (cachedValue == null) { stringValue = ""; //$NON-NLS-1$ } else if (cachedValue instanceof byte[]) { - stringValue = ContentUtils.convertToString((byte[])cachedValue); + byte[] bytes = (byte[]) cachedValue; + stringValue = DBUtils.getBinaryPresentation(controller.getDataSource()).toString(bytes, 0, bytes.length); } else { stringValue = cachedValue.toString(); } @@ -319,7 +322,7 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler { } else { return new JDBCContentBytes( valueController.getDataSource(), - ContentUtils.convertToBytes(newValue)); + newValue); } } }; @@ -331,13 +334,12 @@ public class JDBCContentValueHandler extends JDBCAbstractValueHandler { { // Open LOB editor Object value = controller.getValue(); - /*if (value instanceof DBDContentCached) { + DBDValueController.EditType binaryEditType = DBDValueController.EditType.valueOf( + controller.getDataSource().getContainer().getPreferenceStore().getString(PrefConstants.RESULT_SET_BINARY_EDITOR_TYPE)); + if (binaryEditType != DBDValueController.EditType.EDITOR && value instanceof DBDContentCached) { // Use string editor for cached content return new TextViewDialog(controller); - } else */ - // Always use separate editor - // content could be an image or something huge so it is not an option to open text editor - if (value instanceof DBDContent) { + } else if (value instanceof DBDContent) { DBDContent content = (DBDContent)value; boolean isText = ContentUtils.isTextContent(content); List parts = new ArrayList(); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/data/TextViewDialog.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/data/TextViewDialog.java index 94c693a0024d959fbcc7578dce41251dc8e9667a..0d07fb485b0066da88394be43f805002c4d919fc 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/data/TextViewDialog.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/data/TextViewDialog.java @@ -293,9 +293,10 @@ public class TextViewDialog extends ValueViewDialog { } if (value instanceof byte[]) { // Binary - textEdit.setText(ContentUtils.convertToString((byte[]) value)); + byte[] bytes = (byte[]) value; + textEdit.setText(DBUtils.getBinaryPresentation(getValueController().getDataSource()).toString(bytes, 0, bytes.length)); if (hexEditControl != null) { - hexEditControl.setContent((byte[]) value); + hexEditControl.setContent(bytes); } } else { // Should be string @@ -307,7 +308,8 @@ public class TextViewDialog extends ValueViewDialog { String strValue = CommonUtils.toString(value); textEdit.setText(strValue); if (hexEditControl != null) { - setBinaryContent(strValue); + byte[] bytes = DBUtils.getBinaryPresentation(getValueController().getDataSource()).toBytes(strValue); + hexEditControl.setContent(bytes); } } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/utils/ContentUtils.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/utils/ContentUtils.java index 6986b419ab147c3eb2117efc56e42b0b0b34ded9..179d969677c6a331c87fb7de88fbb1cc9c2e6877 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/utils/ContentUtils.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/utils/ContentUtils.java @@ -550,10 +550,10 @@ public class ContentUtils { return fileEncoding; } - public static String convertToString(byte[] bytes) + public static String convertToString(byte[] bytes, int offset, int length) { - char[] chars = new char[bytes.length]; - for (int i = 0; i < bytes.length; i++) { + char[] chars = new char[length]; + for (int i = offset; i < offset + length; i++) { int b = bytes[i]; if (b < 0) { b = -b + 127;