OtterMind/Chat2DB · error · IllegalArgumentException
Invalid SQL Server view attribute: {viewAttribute}
Error message
Invalid SQL Server view attribute: {viewAttribute} What it means
Thrown by SqlServerSqlBuilder.validateViewAttribute when the supplied view attribute string matches none of the SqlServerViewAttributeOptionEnum names (compared case-insensitively). The method exists to whitelist only known view options before they are embedded into generated DDL.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/builder/SqlServerSqlBuilder.java:475
.append(SQLConstants.SINGLE_QUOTE).append(SqlServerIdentifierProcessor.INSTANCE.escapeString(viewName)).append(SQLConstants.SINGLE_QUOTE);
}
return createViewSqlBuilder.toString();
}
@Override
public String buildExplain(String sql) {
return SQL_SET_SHOWPLAN_XML_ON_SEMICOLON_GO + sql + SQL_GO_SET_SHOWPLAN_XML_OFF_SEMICOLON;
}
private static void validateViewAttribute(String viewAttribute) {
for (SqlServerViewAttributeOptionEnum option : SqlServerViewAttributeOptionEnum.values()) {
if (option.name().equalsIgnoreCase(viewAttribute)) {
return;
}
}
throw new IllegalArgumentException("Invalid SQL Server view attribute: " + viewAttribute);
}
}
View on GitHub (pinned to 5ee1e990e7)
Solutions
- Set viewAttribute to a value that matches a SqlServerViewAttributeOptionEnum name exactly (case-insensitive).
- If no view attribute applies, pass null/blank rather than an arbitrary string if the caller path supports omission.
- Extend SqlServerViewAttributeOptionEnum if a legitimate SQL Server option is missing.
Example fix
// before
view.setAttribute("SCHEMABINDINGS"); // typo
// -> Invalid SQL Server view attribute
// after
view.setAttribute("SCHEMABINDING"); // matches enum name Defensive patterns
Strategy: type-guard
Validate before calling
boolean ok = Arrays.stream(SqlServerViewAttributeOptionEnum.values())
.anyMatch(o -> o.name().equalsIgnoreCase(viewAttribute));
if (StringUtils.isNotBlank(viewAttribute) && !ok) {
throw new IllegalArgumentException("Unsupported view attribute: " + viewAttribute);
} Type guard
static boolean isSupportedSqlServerViewAttribute(String v) {
return v != null && Arrays.stream(SqlServerViewAttributeOptionEnum.values())
.anyMatch(o -> o.name().equalsIgnoreCase(v));
} Prevention
- Pass only enum names for view attributes.
- Extend the enum if a legitimate SQL Server option is missing.
- Validate at the UI/API boundary.
When it happens
Trigger: Calling the view-DDL builder with a viewAttribute that is not one of the recognized SqlServerViewAttributeOptionEnum values - e.g. a free-text option, a typo, or a value from another dialect.
Common situations: UI passing a label instead of the enum name; cross-dialect metadata carrying an unsupported option; version mismatch where the enum lacks a newly added SQL Server view attribute.
Related errors
- Source table DDL is empty
- Invalid SQL Server collation name: {collation}
- Invalid SQL Server index column sort order: {ascOrDesc}
- Invalid DB2 index column ordering: {ascOrDesc}
- Unsupported DM VARCHAR unit: {unit}
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/c0e48729a48e5b7c.
Report an issue: GitHub.