OtterMind/Chat2DB · error · ParamBusinessException
sql
sql
Error message
sql
What it means
Thrown by DbDmlExportServiceImpl.resolveSql when the chosen SQL source is blank. resolveSql picks param.getSql() when exportSize==CURRENT_PAGE (and that sql is non-blank), otherwise param.getOriginalSql(); if the picked value is blank it throws ParamBusinessException("sql") which resolves to 'The parameter: sql is incorrect'. Export cannot proceed without a SELECT statement to drive it.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDmlExportServiceImpl.java:99
}
if (ExportTypeEnum.EXCEL == exportType) {
exportExcel(param.getSql(), outputStream, param.getResultSetId());
return;
}
exportInsert(param, outputStream);
}
private DbType currentDruidDbType() {
return JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType());
}
private String resolveSql(DbDmlExportRequest param) {
ExportSizeEnum exportSize = EasyEnumUtils.getEnum(ExportSizeEnum.class, param.getExportSize());
String sql = exportSize == ExportSizeEnum.CURRENT_PAGE && StringUtils.isNotBlank(param.getSql())
? param.getSql()
: param.getOriginalSql();
if (StringUtils.isBlank(sql)) {
throw new ParamBusinessException("sql");
}
return sql;
}
private String buildFileName(String tableName) {
return URLEncoder.encode(
tableName + "_" + LocalDateTime.now().format(DatePattern.PURE_DATETIME_FORMATTER),
StandardCharsets.UTF_8)
.replaceAll("\\+", "%20");
}
private void exportCsv(String sql, OutputStream outputStream, Integer resultSetId) {
ExcelWrapper excelWrapper = new ExcelWrapper();
IValueProcessor valueProcessor = Chat2DBContext.getDbMetaData().getValueProcessor();
try {
ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(outputStream)
.charset(StandardCharsets.UTF_8)
.excelType(ExcelTypeEnum.CSV);View on GitHub (pinned to 5ee1e990e7)
Solutions
- For CURRENT_PAGE export, ensure param.getSql() carries the exact SQL that produced the displayed page.
- For full export, ensure originalSql is populated by the caller (re-query the saved SQL or the editor buffer).
- If you cannot recover SQL upstream, block the export action in the UI rather than submitting an empty value.
Example fix
// before
param.setExportSize(ExportSizeEnum.ALL.name());
// originalSql left blank
service.prepareExport(param); // -> ParamBusinessException("sql")
// after
param.setOriginalSql(savedSql);
service.prepareExport(param); Defensive patterns
Strategy: validation
Validate before calling
String sql = ExportSizeEnum.CURRENT_PAGE == EasyEnumUtils.getEnum(ExportSizeEnum.class, param.getExportSize())
&& StringUtils.isNotBlank(param.getSql())
? param.getSql()
: param.getOriginalSql();
if (StringUtils.isBlank(sql)) {
throw new ParamBusinessException("sql");
} Prevention
- Persist originalSql on every result set that can be exported.
- Disable the export button client-side when no SQL is available.
When it happens
Trigger: Exporting CURRENT_PAGE but the page's sql field was not carried over (e.g. result set had no originating SQL); exporting the full set when originalSql is empty because the result came from a console/ai path that did not persist it; a stale result-set id whose stored SQL was cleared.
Common situations: User opens a result set produced by AI/chart generation (originalSql not stored), then exports; switching exportSize between CURRENT_PAGE and full export on a row that only populates one of the two SQL fields.
Related errors
- exportType
- request.required
- largeCellValue.tokenRequired
- common.paramDetailError
- The baseURL is not valid!
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/9a8aa02a4e10f8ac.
Report an issue: GitHub.