use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.
the class PostgreValueParser method prepareToParseArray.
private static Object prepareToParseArray(DBCSession session, DBSTypedObject arrayType, String string) throws DBCException {
DBSDataType arrayDataType = arrayType instanceof DBSDataType ? (DBSDataType) arrayType : ((DBSTypedObjectEx) arrayType).getDataType();
try {
DBSDataType componentType = arrayDataType.getComponentType(session.getProgressMonitor());
if (componentType == null) {
log.error("Can't get component type from array '" + arrayType.getFullTypeName() + "'");
return string;
} else {
if (componentType instanceof PostgreDataType) {
checkAmountOfBrackets(string);
List<Object> itemStrings = parseArrayString(string, ",");
return startTransformListOfValuesIntoArray(session, (PostgreDataType) componentType, itemStrings);
} else {
log.error("Incorrect type '" + arrayType.getFullTypeName() + "'");
return string;
}
}
} catch (Exception e) {
throw new DBCException("Error extracting array '" + arrayType.getFullTypeName() + "' items", e);
}
}
use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.
the class MySQLTableColumn method loadInfo.
private void loadInfo(ResultSet dbResult) throws DBException {
name = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_NAME);
ordinalPosition = JDBCUtils.safeGetInt(dbResult, MySQLConstants.COL_ORDINAL_POSITION);
String typeName = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_DATA_TYPE);
assert typeName != null;
String keyTypeName = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_KEY);
if (!CommonUtils.isEmpty(keyTypeName)) {
try {
keyType = KeyType.valueOf(keyTypeName);
} catch (IllegalArgumentException e) {
log.debug(e);
}
}
setTypeName(typeName);
setValueType(MySQLUtils.typeNameToValueType(typeName));
DBSDataType dataType = getDataSource().getLocalDataType(typeName);
this.charLength = JDBCUtils.safeGetLong(dbResult, MySQLConstants.COL_CHARACTER_MAXIMUM_LENGTH);
if (this.charLength <= 0) {
if (dataType != null) {
setMaxLength(CommonUtils.toInt(dataType.getPrecision()));
}
} else {
setMaxLength(this.charLength);
}
this.comment = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_COMMENT);
this.required = !"YES".equals(JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_IS_NULLABLE));
this.setScale(JDBCUtils.safeGetInteger(dbResult, MySQLConstants.COL_NUMERIC_SCALE));
this.setPrecision(JDBCUtils.safeGetInteger(dbResult, MySQLConstants.COL_NUMERIC_PRECISION));
String defaultValue = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_DEFAULT);
if (defaultValue != null) {
switch(getDataKind()) {
case STRING:
// Although I didn't reproduce that locally - perhaps depends on server config.
if (!SQLConstants.NULL_VALUE.equals(defaultValue) && !SQLUtils.isStringQuoted(defaultValue)) {
defaultValue = SQLUtils.quoteString(getDataSource(), defaultValue);
}
break;
case DATETIME:
if (!defaultValue.isEmpty() && Character.isDigit(defaultValue.charAt(0))) {
defaultValue = "'" + defaultValue + "'";
}
break;
}
setDefaultValue(defaultValue);
}
this.collation = getDataSource().getCollation(JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLLATION_NAME));
this.extraInfo = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_EXTRA);
this.autoGenerated = extraInfo != null && extraInfo.contains(MySQLConstants.EXTRA_AUTO_INCREMENT);
this.fullTypeName = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLUMN_TYPE);
if (!CommonUtils.isEmpty(fullTypeName) && (isTypeEnum() || isTypeSet())) {
enumValues = parseEnumValues(fullTypeName);
}
if (!getDataSource().isMariaDB() && getDataSource().isServerVersionAtLeast(5, 7)) {
genExpression = JDBCUtils.safeGetString(dbResult, "GENERATION_EXPRESSION");
}
for (String modifier : CommonUtils.notEmpty(fullTypeName).toLowerCase().split(" ")) {
switch(modifier) {
case "zerofill":
modifiers |= DBSTypedObject.TYPE_MOD_NUMBER_LEADING_ZEROES;
break;
case "unsigned":
modifiers |= DBSTypedObject.TYPE_MOD_NUMBER_UNSIGNED;
break;
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.
the class JDBCArrayValueHandler method createNewValueObject.
@Override
public Object createNewValueObject(@NotNull DBCSession session, @NotNull DBSTypedObject type) throws DBCException {
DBSDataType dataType;
if (type instanceof DBSDataType) {
dataType = (DBSDataType) type;
} else if (type instanceof DBSTypedObjectEx) {
dataType = ((DBSTypedObjectEx) type).getDataType();
} else {
throw new DBCException("Can't determine array element data type: " + type.getFullTypeName());
}
try {
DBSDataType componentType = dataType.getComponentType(session.getProgressMonitor());
if (componentType == null) {
throw new DBCException("Can't determine component data type from " + dataType.getFullTypeName());
}
Array array = ((JDBCSession) session).createArrayOf(componentType.getFullTypeName(), new Object[0]);
return getValueFromObject(session, type, array, false, false);
} catch (Exception e) {
throw new DBCException("Error creating JDBC array " + type.getFullTypeName());
}
}
use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.
the class JDBCStructValueHandler method getValueFromObject.
@Override
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy, boolean validateValue) throws DBCException {
if (object instanceof JDBCComposite) {
return copy ? ((JDBCComposite) object).cloneValue(session.getProgressMonitor()) : object;
}
String typeName;
try {
if (object instanceof Struct) {
typeName = ((Struct) object).getSQLTypeName();
} else {
typeName = type.getTypeName();
}
} catch (SQLException e) {
throw new DBCException(e, session.getExecutionContext());
}
DBSDataType dataType = null;
try {
dataType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), typeName);
} catch (DBException e) {
log.debug("Error resolving data type '" + typeName + "'", e);
}
if (dataType == null) {
if (object instanceof Struct) {
return new JDBCCompositeDynamic(session, (Struct) object, null);
} else {
return new JDBCCompositeUnknown(session, object);
}
}
if (object == null) {
return new JDBCCompositeStatic(session, dataType, new JDBCStructImpl(dataType.getTypeName(), null, ""));
} else if (object instanceof Struct) {
return new JDBCCompositeStatic(session, dataType, (Struct) object);
} else {
return new JDBCCompositeUnknown(session, object);
}
}
use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.
the class JDBCDataSource method getDefaultDataTypeName.
@Override
public String getDefaultDataTypeName(@NotNull DBPDataKind dataKind) {
String typeName = getStandardSQLDataTypeName(dataKind);
DBSDataType dataType = getLocalDataType(typeName);
if (dataType == null) {
// Try to find first data type of this kind
for (DBSDataType type : getLocalDataTypes()) {
if (type.getDataKind() == dataKind) {
return type.getName();
}
}
}
return typeName;
}
Aggregations