{"record":{"id":"84b1727520d79799","repo":"OtterMind/Chat2DB","slug":"datasource-sqlanalysiserror","errorCode":"dataSource.sqlAnalysisError","errorMessage":"dataSource.sqlAnalysisError","messagePattern":"dataSource\\.sqlAnalysisError","errorType":"validation","errorClass":"BusinessException","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":189,"sourceCode":"            IValueProcessor valueProcessor = Chat2DBContext.getDbMetaData().getValueProcessor();\n            DefaultSQLExecutor.getInstance().execute(Chat2DBContext.getConnection(), param.getSql(),\n                    headerList -> headerList.forEach(header -> headerColumns.add(header.getName())),\n                    dataList -> {\n                        String insertSql = sqlBuilder.dml().buildInsert(SingleInsertSqlRequest.builder()\n                                .databaseName(databaseName)\n                                .schemaName(schemaName)\n                                .tableName(tableName)\n                                .columnList(headerColumns)\n                                .valueList(dataList)\n                                .build());\n                        printWriter.println(insertSql + \";\");\n                    }, valueProcessor::getJdbcSqlValueString, false, param.getResultSetId());\n        }\n    }\n\n    private String requireSelectTableName(String sql, DbType dbType) {\n        if (dbType == null) {\n            throw new BusinessException(\"dataSource.sqlAnalysisError\");\n        }\n        SQLStatement sqlStatement = SQLUtils.parseSingleStatement(sql, dbType);\n        if (!(sqlStatement instanceof SQLSelectStatement)) {\n            throw new BusinessException(\"dataSource.sqlAnalysisError\");\n        }\n        return SqlUtils.getTableName(sql, dbType);\n    }\n\n    @Data\n    private static class ExcelWrapper {\n        private ExcelWriterBuilder excelWriterBuilder;\n        private ExcelWriter excelWriter;\n        private WriteSheet writeSheet;\n    }\n}\n","sourceCodeStart":171,"sourceCodeEnd":205,"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#L171-L205","documentation":"Thrown by DbDmlExportServiceImpl.requireSelectTableName when dbType is null. dbType comes from JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType()); a null result means the connection's database type string did not map to a known Druid DbType. The i18n key 'dataSource.sqlAnalysisError' resolves to 'Invalid statements'. This guards the INSERT-export path which needs a concrete DbType to parse the SELECT and derive a table name.","triggerScenarios":"Exporting to INSERT/SQL format on a datasource whose dbType is unsupported or misconfigured (e.g. a custom/unknown type string in the connection config, or Chat2DBContext.getConnectInfo() returning a ConnectInfo with a blank dbType).","commonSituations":"Connecting to a database flavor the plugin set does not register; a connection saved with a dbType label that the build's DbType enum no longer recognizes after an upgrade; exporting before the connection type is fully resolved.","solutions":["Confirm the datasource dbType is one registered in the plugin map and recognized by JdbcUtils.parse2DruidDbType.","For unsupported dbTypes, use CSV/Excel export (which does not require requireSelectTableName) instead of INSERT/SQL export.","Upgrade or register the plugin that supplies the missing DbType."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"DbType dbType = JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType());\nif (dbType == null) {\n    // fall back to a non-INSERT export format that does not require table-name analysis\n    param.setExportType(ExportTypeEnum.CSV.name());\n}","typeGuard":"boolean dbTypeSupportsInsertExport() {\n    return JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType()) != null;\n}","tryCatchPattern":null,"preventionTips":["Offer INSERT/SQL export only for registered dbTypes.","Keep the plugin set current with the DbType enum."],"tags":["db-type","export","sql-analysis","plugin"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}