提交 10fa7cd1 编写于 作者: A Anastasiya Volkova

#11489 check scale and precision for numeric/decimal columns

上级 c7be11aa
......@@ -84,6 +84,7 @@ public class SQLServerConstants {
public static final String TYPE_HIERARCHYID = "hierarchyid";
public static final String TYPE_XML = "xml";
public static final int MAX_NUMERIC_PRECISION = 38;
public static final int TABLE_TYPE_SYSTEM_ID = 243;
public static final String PROP_AUTHENTICATION = DBConstants.INTERNAL_PROP_PREFIX + "authentication@";
......
......@@ -184,7 +184,7 @@ public class SQLServerDialect extends JDBCSQLDialect {
}
@Override
public String getColumnTypeModifiers(DBPDataSource dataSource, @NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
public String getColumnTypeModifiers(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
if (dataKind == DBPDataKind.DATETIME) {
if (SQLServerConstants.TYPE_DATETIME2.equalsIgnoreCase(typeName) ||
SQLServerConstants.TYPE_TIME.equalsIgnoreCase(typeName) ||
......@@ -219,6 +219,20 @@ public class SQLServerDialect extends JDBCSQLDialect {
}
} else if (ArrayUtils.contains(PLAIN_TYPE_NAMES , typeName)) {
return null;
} else if (dataKind == DBPDataKind.NUMERIC &&
(SQLServerConstants.TYPE_NUMERIC.equals(typeName) || SQLServerConstants.TYPE_DECIMAL.equals(typeName))) {
// numeric and decimal - are synonyms in sql server
// The numeric precision has a range from 1 to 38. The default precision is 38.
// The scale has a range from 0 to p (precision). The scale can be specified only if the precision is specified. By default, the scale is zero
Integer precision = column.getPrecision();
if (precision < 1 || precision > SQLServerConstants.MAX_NUMERIC_PRECISION) {
precision = SQLServerConstants.MAX_NUMERIC_PRECISION;
}
Integer scale = column.getScale();
if (scale > precision) {
scale = precision;
}
return "(" + precision + "," + scale + ")";
}
return super.getColumnTypeModifiers(dataSource, column, typeName, dataKind);
......
......@@ -422,7 +422,7 @@ public class SQLServerSchema implements DBSSchema, DBPSaveableObject, DBPQualifi
.append("\nJOIN ").append(SQLServerUtils.getSystemTableName(owner.getDatabase(), "all_objects")).append(" t ON t.object_id=c.object_id")
.append("\nLEFT OUTER JOIN ").append(SQLServerUtils.getSystemTableName(owner.getDatabase(), "default_constraints")).append(" dc ON dc.parent_object_id=t.object_id AND dc.parent_column_id=c.column_id")
.append("\nLEFT OUTER JOIN ").append(SQLServerUtils.getExtendedPropsTableName(owner.getDatabase())).append(" ep ON ep.class=").append(SQLServerObjectClass.OBJECT_OR_COLUMN.getClassId()).append(" AND ep.major_id=t.object_id AND ep.minor_id=c.column_id AND ep.name='").append(SQLServerConstants.PROP_MS_DESCRIPTION).append("'");
sql.append("WHERE ");
sql.append(" WHERE ");
if (forTable != null) {
sql.append("t.object_id=?");
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册