提交 31e9be53 编写于 作者: J jurgen

Numeric types qualifiers

Former-commit-id: b491d36a
上级 b91599bd
......@@ -20,6 +20,7 @@ package org.jkiss.dbeaver.tools.transfer.database;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSEntity;
......@@ -207,12 +208,9 @@ class DatabaseMappingAttribute implements DatabaseMappingObject {
}
}
if (dataKind == DBPDataKind.STRING) {
typeName += "(" + source.getMaxLength() + ")";
} else if (dataKind == DBPDataKind.NUMERIC) {
if (typeName.equals("DECIMAL") && source.getMaxLength() > 0 && source.getScale() > 0) {
typeName += "(" + source.getMaxLength() + "," + source.getScale() + ")";
}
String modifiers = SQLUtils.getColumnTypeModifiers(source, typeName, dataKind);
if (modifiers != null) {
typeName += modifiers;
}
return typeName;
}
......
......@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableColumn;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.utils.CommonUtils;
......@@ -50,23 +51,17 @@ public abstract class SQLTableColumnManager<OBJECT_TYPE extends JDBCTableColumn<
@Override
public void appendModifier(OBJECT_TYPE column, StringBuilder sql, DBECommandAbstract<OBJECT_TYPE> command) {
final String typeName = column.getTypeName();
DBPDataKind dataKind = column.getDataKind();
final DBSDataType dataType = findDataType(column.getDataSource(), typeName);
sql.append(' ').append(typeName);
if (dataType == null) {
log.debug("Type name '" + typeName + "' is not supported by driver"); //$NON-NLS-1$ //$NON-NLS-2$
} else if (dataType.getDataKind() == DBPDataKind.STRING) {
if (typeName.indexOf('(') == -1) {
final long maxLength = column.getMaxLength();
if (maxLength > 0) {
sql.append('(').append(maxLength).append(')');
}
}
} else if (typeName.equalsIgnoreCase("DECIMAL")) {
int scale = column.getScale();
int precision = column.getPrecision();
if (scale >= 0 && precision >= 0 && !(scale == 0 && precision == 0)) {
sql.append('(').append(precision).append(',').append(scale).append(')');
}
} else {
dataKind = dataType.getDataKind();
}
String modifiers = SQLUtils.getColumnTypeModifiers(column, typeName, dataKind);
if (modifiers != null) {
sql.append(modifiers);
}
}
};
......
......@@ -29,9 +29,7 @@ import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.utils.CommonUtils;
......@@ -386,4 +384,24 @@ public final class SQLUtils {
}
}
public static String getColumnTypeModifiers(DBSAttributeBase column, String typeName, DBPDataKind dataKind) {
if (dataKind == DBPDataKind.STRING) {
if (typeName.indexOf('(') == -1) {
final long maxLength = column.getMaxLength();
if (maxLength > 0) {
return "(" + maxLength + ")";
}
}
} else if (dataKind == DBPDataKind.NUMERIC) {
if (typeName.equalsIgnoreCase("DECIMAL") || typeName.equalsIgnoreCase("NUMERIC") || typeName.equalsIgnoreCase("NUMBER")) {
int scale = column.getScale();
int precision = column.getPrecision();
if (scale >= 0 && precision >= 0 && !(scale == 0 && precision == 0)) {
return "(" + precision + ',' + scale + ')';
}
}
}
return null;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册