// Add CAST( VAR/CHAR/BINARY(0) to VAR/CHAR/BINARY(1) )
List<FemViewColumn> columnList =
Util.cast(view.getFeature(), FemViewColumn.class);
boolean updateSql = false;
if (columnList.size() > 0) {
SqlBuilder buf = new SqlBuilder(SqlDialect.EIGENBASE, "SELECT");
int k = 0;
for (RelDataTypeField field : analyzedSql.resultType.getFields()) {
String targetType = null;
SqlTypeName sqlType = field.getType().getSqlTypeName();
SqlTypeFamily typeFamily =
SqlTypeFamily.getFamilyForSqlType(sqlType);
if ((typeFamily == SqlTypeFamily.CHARACTER)
|| (typeFamily == SqlTypeFamily.BINARY))
{
if (field.getType().getPrecision() == 0) {
// Can't have precision of 0
// Add cast so there is precision of 1
targetType = sqlType.name() + "(1)";
updateSql = true;
}
}
FemViewColumn viewColumn = columnList.get(k);
if (k > 0) {
buf.append(", ");
}
if (targetType == null) {
buf.identifier(field.getName());
} else {
buf.append(" CAST(");
buf.identifier(field.getName());
buf.append(" AS ");
buf.append(targetType);
buf.append(")");
}
buf.append(" AS ");
buf.identifier(viewColumn.getName());
k++;
}
buf.append(" FROM (").append(analyzedSql.canonicalString).append(
")");
if (updateSql) {
analyzedSql.canonicalString = buf.toSqlString();
}
}
}