提交 5f48478f 编写于 作者: L LonwoLonwo

#6178 sql server simple data type DDL added

上级 5d2e1cfe
......@@ -82,6 +82,8 @@ meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.fullTypeName.name = Typ
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.nullable.name = Nullable
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.collationName.name = Collation
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.assemblyType.name = Assembly Type
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.name = Table type
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.description = Is data type - table type
meta.org.jkiss.dbeaver.ext.mssql.model.session.SQLServerSession.id.name=ID
meta.org.jkiss.dbeaver.ext.mssql.model.session.SQLServerSession.hostName.name=Host
......
......@@ -12,6 +12,14 @@ meta.org.jkiss.dbeaver.ext.mssql.model.generic.SQLServerGenericSynonym.targetObj
meta.org.jkiss.dbeaver.ext.mssql.model.generic.SQLServerGenericTable.description.description = Tabellenbeschreibung
meta.org.jkiss.dbeaver.ext.mssql.model.generic.SQLServerGenericTable.description.name = Beschreibung
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.maxLength.name = L\u00E4nge
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.scale.name = Scala
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.precision.name = Pr\u00E4zision
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.fullTypeName.name = Typ
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.collationName.name = Kollation
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.name = Tabellentyp
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.description = Ist Datentyp - Tabellentyp
sqlserver.dialog.connection.header = SQL Server Verbindungseinstellungen
sybase.dialog.connection.header = Sybase Verbindungseinstellungen
......
......@@ -7,4 +7,13 @@ driver.sqlserver.description=Microsoft JDBC \u0434\u0440\u0430\u0439\u0432\u0435
driver.jTDS.description=\u0414\u0440\u0430\u0439\u0432\u0435\u0440 jTDS SQL Server (MSSQL)
driver.sqlserver.old.description=\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 Microsoft JDBC \u0434\u043B\u044F SQL Server (MSSQL). \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u0435\u0433\u043E \u0434\u043B\u044F SQL server \u043F\u043E\u0437\u0434\u043D\u0435\u0435 2005 \u0433\u043E\u0434\u0430 \u0438\u043B\u0438 \u0435\u0441\u043B\u0438 \u0441\u0442\u0430\u043D\u0434\u0430\u0440\u0442\u043D\u044B\u0435 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u044B \u043D\u0435 \u0440\u0430\u0431\u043E\u0442\u0430\u044E\u0442.
meta.org.jkiss.dbeaver.ext.mssql.tasks.SQLServerToolWithStatus$ToolStatus.message.name = \u0421\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435
\ No newline at end of file
meta.org.jkiss.dbeaver.ext.mssql.tasks.SQLServerToolWithStatus$ToolStatus.message.name = \u0421\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.schema.name = \u0421\u0445\u0435\u043C\u0430
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.name.name = \u0418\u043C\u044F
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.maxLength.name = \u0414\u043B\u0438\u043D\u0430
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.scale.name = \u041C\u0430\u0441\u0448\u0442\u0430\u0431
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.precision.name = \u0422\u043E\u0447\u043D\u043E\u0441\u0442\u044C
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.fullTypeName.name = \u0422\u0438\u043F
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.name = \u0422\u0430\u0431\u043B\u0438\u0447\u043D\u044B\u0439 \u0442\u0438\u043F
meta.org.jkiss.dbeaver.ext.mssql.model.SQLServerDataType.tableType.description = \u042F\u0432\u043B\u044F\u0435\u0442\u0441\u044F \u043B\u0438 \u0442\u0438\u043F \u0442\u0430\u0431\u043B\u0438\u0447\u043D\u044B\u043C
\ No newline at end of file
......@@ -54,6 +54,22 @@ public class SQLServerConstants {
public static final String TYPE_GEOGRAPHY = "geography";
public static final String TYPE_TIMESTAMP = "timestamp";
public static final String TYPE_IMAGE = "image";
public static final String TYPE_TINYINT = "tinyint";
public static final String TYPE_SMALLINT = "smallint";
public static final String TYPE_INT = "int";
public static final String TYPE_REAL = "real";
public static final String TYPE_MONEY = "money";
public static final String TYPE_FLOAT = "float";
public static final String TYPE_SQL_VARIANT = "sql_variant";
public static final String TYPE_BIT = "bit";
public static final String TYPE_DECIMAL = "decimal";
public static final String TYPE_NUMERIC = "numeric";
public static final String TYPE_SMALLMONEY = "smallmoney";
public static final String TYPE_BIGINT = "bigint";
public static final String TYPE_VARBINARY = "varbinary";
public static final String TYPE_BINARY = "binary";
public static final String TYPE_HIERARCHYID = "hierarchyid";
public static final String TYPE_XML = "xml";
public static final String PROP_AUTHENTICATION = DBConstants.INTERNAL_PROP_PREFIX + "authentication@";
public static final String PROP_SHOW_ALL_SCHEMAS = DBConstants.INTERNAL_PROP_PREFIX + "show-all-schemas@";
......
......@@ -203,7 +203,9 @@ public class SQLServerDataSource extends JDBCDataSource implements DBSInstanceCo
return dt;
}
}
log.debug("System data type " + systemTypeId + " not found");
if (systemTypeId != 243) { // 243 - ID of user defined types
log.debug("System data type " + systemTypeId + " not found");
}
SQLServerDataType sdt = new SQLServerDataType(this, String.valueOf(systemTypeId), systemTypeId, DBPDataKind.OBJECT, java.sql.Types.OTHER);
dataTypeCache.cacheObject(sdt);
return sdt;
......
......@@ -28,12 +28,14 @@ import org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.Locale;
import java.util.Map;
/**
......@@ -56,6 +58,7 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
private boolean nullable;
private boolean userType;
private boolean assemblyType;
private boolean tableType;
private String collationName;
private boolean persisted;
......@@ -74,6 +77,7 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
this.nullable = JDBCUtils.safeGetInt(dbResult, "is_nullable") != 0;
this.userType = JDBCUtils.safeGetInt(dbResult, "is_user_defined") != 0;
this.assemblyType = JDBCUtils.safeGetInt(dbResult, "is_assembly_type") != 0;
this.tableType = JDBCUtils.safeGetInt(dbResult, "is_table_type") != 0;
this.collationName = JDBCUtils.safeGetString(dbResult, "collation_name");
......@@ -133,7 +137,25 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
@Override
@Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBCException {
return "";
StringBuilder sql = new StringBuilder();
sql.append("-- DROP TYPE ").append(getFullyQualifiedName(DBPEvaluationContext.DDL)).append(";\n\n"); //$NON-NLS-1$ //$NON-NLS-2$
if (!tableType) {
sql.append("CREATE TYPE ").append(getFullyQualifiedName(DBPEvaluationContext.DDL)).append("\n").append("FROM ");
SQLServerDataType systemDataType = getSystemDataType();
String typeName = systemDataType.getName();
sql.append(typeName.toUpperCase(Locale.ENGLISH));
SQLServerTypedObject serverTypedObjects = new SQLServerTypedObject(typeName, getDataTypeIDByName(typeName), dataKind, scale, precision, maxLength);
String modifiers = SQLUtils.getColumnTypeModifiers(getDataSource(), serverTypedObjects, typeName, dataKind);
if (modifiers != null) {
sql.append(modifiers);
}
if (!nullable) {
sql.append(" NOT NULL;");
}
} else {
sql.append("-- Table types DDL not yet available");
}
return sql.toString();
}
@Override
......@@ -196,6 +218,11 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
}
@Property(viewable = false, order = 25)
public boolean isTableType() {
return tableType;
}
@Property(viewable = false, order = 26)
public String getCollationName() {
return collationName;
}
......@@ -255,24 +282,24 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
public static DBPDataKind getDataKindByName(String systemTypeName) {
switch (systemTypeName) {
case "char":
case "nchar":
case "ntext":
case "nvarchar":
case "varchar":
case "text":
case SQLServerConstants.TYPE_CHAR:
case SQLServerConstants.TYPE_NCHAR:
case SQLServerConstants.TYPE_NTEXT:
case SQLServerConstants.TYPE_NVARCHAR:
case SQLServerConstants.TYPE_VARCHAR:
case SQLServerConstants.TYPE_TEXT:
case "sysname":
return DBPDataKind.STRING;
case "tinyint":
case "bigint":
case "bit":
case "int":
case "numeric":
case "real":
case "smallint":
case "decimal":
case "float":
case SQLServerConstants.TYPE_TINYINT:
case SQLServerConstants.TYPE_BIGINT:
case SQLServerConstants.TYPE_BIT:
case SQLServerConstants.TYPE_INT:
case SQLServerConstants.TYPE_NUMERIC:
case SQLServerConstants.TYPE_REAL:
case SQLServerConstants.TYPE_SMALLINT:
case SQLServerConstants.TYPE_DECIMAL:
case SQLServerConstants.TYPE_FLOAT:
return DBPDataKind.NUMERIC;
case SQLServerConstants.TYPE_DATETIME:
......@@ -285,28 +312,28 @@ public class SQLServerDataType implements DBSDataType, SQLServerObject, DBPQuali
case SQLServerConstants.TYPE_DATETIMEOFFSET:
return DBPDataKind.STRING;
case "binary":
case "timestamp":
case SQLServerConstants.TYPE_BINARY:
case SQLServerConstants.TYPE_TIMESTAMP:
return DBPDataKind.BINARY;
case "image":
case "varbinary":
case SQLServerConstants.TYPE_IMAGE:
case SQLServerConstants.TYPE_VARBINARY:
return DBPDataKind.CONTENT;
case "uniqueidentifier":
case SQLServerConstants.TYPE_UNIQUEIDENTIFIER:
return DBPDataKind.STRING;
case SQLServerConstants.TYPE_GEOGRAPHY:
case SQLServerConstants.TYPE_GEOMETRY:
case "hierarchyid":
case SQLServerConstants.TYPE_HIERARCHYID:
return DBPDataKind.BINARY;
case "money":
case "smallmoney":
case "sql_variant":
case SQLServerConstants.TYPE_MONEY:
case SQLServerConstants.TYPE_SMALLMONEY:
case SQLServerConstants.TYPE_SQL_VARIANT:
return DBPDataKind.OBJECT;
case "xml":
case SQLServerConstants.TYPE_XML:
return DBPDataKind.CONTENT;
default:
......
......@@ -174,7 +174,9 @@ public class SQLServerDialect extends JDBCSQLDialect {
@Override
public String getColumnTypeModifiers(DBPDataSource dataSource, @NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
if (dataKind == DBPDataKind.DATETIME) {
if (SQLServerConstants.TYPE_DATETIME2.equalsIgnoreCase(typeName)) {
if (SQLServerConstants.TYPE_DATETIME2.equalsIgnoreCase(typeName) ||
SQLServerConstants.TYPE_TIME.equalsIgnoreCase(typeName) ||
SQLServerConstants.TYPE_DATETIMEOFFSET.equalsIgnoreCase(typeName)) {
Integer scale = column.getScale();
if (scale != null && scale != 0) {
return "(" + scale + ')';
......@@ -185,7 +187,9 @@ public class SQLServerDialect extends JDBCSQLDialect {
case SQLServerConstants.TYPE_CHAR:
case SQLServerConstants.TYPE_NCHAR:
case SQLServerConstants.TYPE_VARCHAR:
case SQLServerConstants.TYPE_NVARCHAR: {
case SQLServerConstants.TYPE_NVARCHAR:
case SQLServerConstants.TYPE_SQL_VARIANT:
case SQLServerConstants.TYPE_VARBINARY:{
long maxLength = column.getMaxLength();
if (maxLength == 0) {
return null;
......
package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
public class SQLServerTypedObject implements DBSTypedObject {
private String typeName;
private int typeId;
private DBPDataKind dataKind;
private int scale;
private int precision;
private int maxLength;
public SQLServerTypedObject(String typeName, int typeId, DBPDataKind dataKind, int scale, int precision, int maxLength) {
this.typeName = typeName;
this.typeId = typeId;
this.dataKind = dataKind;
this.scale = scale;
this.precision = precision;
this.maxLength = maxLength;
}
@Override
public String getTypeName() {
return typeName;
}
@Override
public String getFullTypeName() {
return typeName;
}
@Override
public int getTypeID() {
return typeId;
}
@Override
public DBPDataKind getDataKind() {
return dataKind;
}
@Override
public Integer getScale() {
return scale;
}
@Override
public Integer getPrecision() {
return precision;
}
@Override
public long getMaxLength() {
return maxLength;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册