{"record":{"id":"9a8aa02a4e10f8ac","repo":"OtterMind/Chat2DB","slug":"sql","errorCode":"sql","errorMessage":"sql","messagePattern":"sql","errorType":"validation","errorClass":"ParamBusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDmlExportServiceImpl.java","lineNumber":99,"sourceCode":"        }\n        if (ExportTypeEnum.EXCEL == exportType) {\n            exportExcel(param.getSql(), outputStream, param.getResultSetId());\n            return;\n        }\n        exportInsert(param, outputStream);\n    }\n\n    private DbType currentDruidDbType() {\n        return JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType());\n    }\n\n    private String resolveSql(DbDmlExportRequest param) {\n        ExportSizeEnum exportSize = EasyEnumUtils.getEnum(ExportSizeEnum.class, param.getExportSize());\n        String sql = exportSize == ExportSizeEnum.CURRENT_PAGE && StringUtils.isNotBlank(param.getSql())\n                ? param.getSql()\n                : param.getOriginalSql();\n        if (StringUtils.isBlank(sql)) {\n            throw new ParamBusinessException(\"sql\");\n        }\n        return sql;\n    }\n\n    private String buildFileName(String tableName) {\n        return URLEncoder.encode(\n                        tableName + \"_\" + LocalDateTime.now().format(DatePattern.PURE_DATETIME_FORMATTER),\n                        StandardCharsets.UTF_8)\n                .replaceAll(\"\\\\+\", \"%20\");\n    }\n\n    private void exportCsv(String sql, OutputStream outputStream, Integer resultSetId) {\n        ExcelWrapper excelWrapper = new ExcelWrapper();\n        IValueProcessor valueProcessor = Chat2DBContext.getDbMetaData().getValueProcessor();\n        try {\n            ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(outputStream)\n                    .charset(StandardCharsets.UTF_8)\n                    .excelType(ExcelTypeEnum.CSV);","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDmlExportServiceImpl.java#L81-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nparam.setExportSize(ExportSizeEnum.ALL.name());\n// originalSql left blank\nservice.prepareExport(param); // -> ParamBusinessException(\"sql\")\n\n// after\nparam.setOriginalSql(savedSql);\nservice.prepareExport(param);","handlingStrategy":"validation","validationCode":"String sql = ExportSizeEnum.CURRENT_PAGE == EasyEnumUtils.getEnum(ExportSizeEnum.class, param.getExportSize())\n        && StringUtils.isNotBlank(param.getSql())\n        ? param.getSql()\n        : param.getOriginalSql();\nif (StringUtils.isBlank(sql)) {\n    throw new ParamBusinessException(\"sql\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Persist originalSql on every result set that can be exported.","Disable the export button client-side when no SQL is available."],"tags":["validation","request-validation","export","sql"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}