OtterMind/Chat2DB · error · BusinessException

dataSource.sqlAnalysisError

dataSource.sqlAnalysisError

Error message

dataSource.sqlAnalysisError

What it means

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.

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:189

            IValueProcessor valueProcessor = Chat2DBContext.getDbMetaData().getValueProcessor();
            DefaultSQLExecutor.getInstance().execute(Chat2DBContext.getConnection(), param.getSql(),
                    headerList -> headerList.forEach(header -> headerColumns.add(header.getName())),
                    dataList -> {
                        String insertSql = sqlBuilder.dml().buildInsert(SingleInsertSqlRequest.builder()
                                .databaseName(databaseName)
                                .schemaName(schemaName)
                                .tableName(tableName)
                                .columnList(headerColumns)
                                .valueList(dataList)
                                .build());
                        printWriter.println(insertSql + ";");
                    }, valueProcessor::getJdbcSqlValueString, false, param.getResultSetId());
        }
    }

    private String requireSelectTableName(String sql, DbType dbType) {
        if (dbType == null) {
            throw new BusinessException("dataSource.sqlAnalysisError");
        }
        SQLStatement sqlStatement = SQLUtils.parseSingleStatement(sql, dbType);
        if (!(sqlStatement instanceof SQLSelectStatement)) {
            throw new BusinessException("dataSource.sqlAnalysisError");
        }
        return SqlUtils.getTableName(sql, dbType);
    }

    @Data
    private static class ExcelWrapper {
        private ExcelWriterBuilder excelWriterBuilder;
        private ExcelWriter excelWriter;
        private WriteSheet writeSheet;
    }
}

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Confirm the datasource dbType is one registered in the plugin map and recognized by JdbcUtils.parse2DruidDbType.
  2. For unsupported dbTypes, use CSV/Excel export (which does not require requireSelectTableName) instead of INSERT/SQL export.
  3. Upgrade or register the plugin that supplies the missing DbType.
Defensive patterns

Strategy: type-guard

Validate before calling

DbType dbType = JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType());
if (dbType == null) {
    // fall back to a non-INSERT export format that does not require table-name analysis
    param.setExportType(ExportTypeEnum.CSV.name());
}

Type guard

boolean dbTypeSupportsInsertExport() {
    return JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType()) != null;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/84b1727520d79799. Report an issue: GitHub.