Skip to content

Commit

Permalink
TEIIDDES-2240 Correctly sets fixed-length == TRUE and native type ==
Browse files Browse the repository at this point in the history
CHAR when char native type and length > 1 is defined as datatype for
both JDBC import and Teiid Connection import
  • Loading branch information
blafond committed Jul 9, 2014
1 parent 585323d commit 640594d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,13 @@ private void processTeiidColumnOptions(List<AstNode> optionNodes, RelationalColu
private void resolveColumnDatatype(RelationalColumn column, String nativeType) {
if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.INTEGER) && nativeType.equalsIgnoreCase(TYPES_UPPER.INT) ) {
column.setDatatype(nativeType);
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.STRING) && nativeType.equalsIgnoreCase(TYPES_UPPER.CHAR ) ) {
column.setDatatype(nativeType);
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.STRING) && nativeType.equalsIgnoreCase(TYPES_UPPER.CHAR) ) {
// Some DB's have columns of type "char(10)" and need to be converted to String type
if( column.getLength() > 1 ) {
column.setDatatype(TYPES_UPPER.STRING);
} else {
column.setDatatype(nativeType);
}
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.VARBINARY) && nativeType.equalsIgnoreCase(TYPES_UPPER.BINARY ) ) {
column.setDatatype(TYPES_UPPER.OBJECT.toLowerCase());
} else if( column.getDatatype().equalsIgnoreCase(TYPES_UPPER.TIMESTAMP) && nativeType.equalsIgnoreCase(TYPES_UPPER.DATETIME ) ) {
Expand All @@ -799,7 +804,7 @@ private void resolveColumnDatatype(RelationalColumn column, String nativeType) {


// Not enough info in DDL to determine if fixed length data type so calling it here
column.setLengthFixed(isFixedLength(column.getDatatype()));
column.setLengthFixed(isFixedLength(column.getNativeType()));

// From RelationalModelProcessor....
if (column.getSearchability().equalsIgnoreCase(RelationalConstants.SEARCHABILITY.ALL_EXCEPT_LIKE) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,10 +1264,6 @@ protected void createColumns( final JdbcTable tableNode,
// final int position = results.getInt(row,16);
// final String isNullable = results.getString(row,17);

if (type == Types.CHAR && columnSize > 1 ) {
type = Types.VARCHAR;
typeName = "varchar"; //$NON-NLS-1$
}

final Column column = this.factory.createColumn();
// Add the column to the table
Expand Down Expand Up @@ -1322,7 +1318,15 @@ protected void setColumnInfo( final Column column,
// Set the type information ...
column.setFixedLength(isFixedLength(type, typeName));
column.setNativeType(typeName);
final EObject datatype = findType(type, typeName, columnSize, columnSize, numDecDigits, problems);

// Need to check if native type CHAR (Oracle, etc...) has length > 1, then treat as String and FIXED LENGTH
String delegateNativeTypeName = typeName;
// To find STRING, need to use VARCHAR instead of CHAR
if (type == Types.CHAR && columnSize > 1 ) {
delegateNativeTypeName = "varchar"; //$NON-NLS-1$
}

final EObject datatype = findType(type, delegateNativeTypeName, columnSize, columnSize, numDecDigits, problems);
if (datatype != null) {
column.setType(datatype);
}
Expand Down Expand Up @@ -2201,19 +2205,14 @@ protected void createParameters( final JdbcProcedure procNode,
String name = results.getString(row, 3); // COLUMN_NAME
final short columnType = results.getShort(row, 4); // COLUMN_TYPE
short type = results.getShort(row, 5); // DATA_TYPE
String typeName = results.getString(row, 6); // TYPE_NAME
final String typeName = results.getString(row, 6); // TYPE_NAME
final int precision = results.getInt(row, 7); // PRECISION
final int length = results.getInt(row, 8); // LENGTH
final int scale = results.getInt(row, 9); // SCALE
final int radix = results.getInt(row, 10); // RADIX
final short nullable = results.getShort(row, 11); // NULLABLE
final String remarks = results.getString(row, 12); // REMARKS


if (type == Types.CHAR && length > 1 ) {
type = Types.VARCHAR;
typeName = "varchar"; //$NON-NLS-1$
}

final boolean resultSetColumn = isProcedureResultColumn(columnType, type, typeName);
if (!resultSetColumn) {
Expand Down Expand Up @@ -2308,39 +2307,46 @@ protected void createParameters( final JdbcProcedure procNode,
annotation.setDescription(remarks);
}
} else {
final Column param = this.factory.createColumn();
param.setOwner(procResult);
setNameAndNameInSource(param, name, procNode, context, true, problems);
final Column column = this.factory.createColumn();
column.setOwner(procResult);
setNameAndNameInSource(column, name, procNode, context, true, problems);

// Set the type information ...
param.setNativeType(typeName);
final EObject datatype = findType(type, typeName, length, precision, scale, problems);
column.setNativeType(typeName);
// Need to check if native type CHAR (Oracle, etc...) has length > 1, then treat as String and FIXED LENGTH
String delegateNativeTypeName = typeName;
// To find STRING, need to use VARCHAR instead of CHAR
if (type == Types.CHAR && length > 1 ) {
delegateNativeTypeName = "varchar"; //$NON-NLS-1$
}

final EObject datatype = findType(type, delegateNativeTypeName, length, length, scale, problems);
if (datatype != null) {
param.setType(datatype);
column.setType(datatype);
}

// Set the length, precision and scale ...
param.setLength(length);
param.setPrecision(precision);
param.setScale(scale);
param.setRadix(radix);
column.setLength(length);
column.setPrecision(precision);
column.setScale(scale);
column.setRadix(radix);

// Set the nullability
switch (nullable) {
case DatabaseMetaData.procedureNoNulls:
param.setNullable(NullableType.NO_NULLS_LITERAL);
column.setNullable(NullableType.NO_NULLS_LITERAL);
break;
case DatabaseMetaData.procedureNullable:
param.setNullable(NullableType.NULLABLE_LITERAL);
column.setNullable(NullableType.NULLABLE_LITERAL);
break;
default:
param.setNullable(NullableType.NULLABLE_UNKNOWN_LITERAL);
column.setNullable(NullableType.NULLABLE_UNKNOWN_LITERAL);
break;
}

// Set the description (after adding column to table)...
if (remarks != null && remarks.trim().length() != 0) {
final Annotation annotation = ModelResourceContainerFactory.createNewAnnotation(param,
final Annotation annotation = ModelResourceContainerFactory.createNewAnnotation(column,
contents.getAnnotationContainer(true));
annotation.setDescription(remarks);
}
Expand Down

0 comments on commit 640594d

Please sign in to comment.