{"record":{"id":"a1c052effd97fe61","repo":"OtterMind/Chat2DB","slug":"datasource-sqlanalysiserror-a1c052","errorCode":"dataSource.sqlAnalysisError","errorMessage":"Invalid statements","messagePattern":"Invalid statements","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-redis/src/main/java/ai/chat2db/plugin/redis/RedisScriptExecutor.java","lineNumber":124,"sourceCode":"\n    public String getTtl(String key) {\n        Connection connection = Chat2DBContext.getConnection();\n        return DefaultSQLExecutor.getInstance().execute(connection, String.format(RedisConstants.COMMAND_TTL_KEY, getRedisValue(key)), resultSet -> {\n            if (resultSet.next()) {\n                return resultSet.getString(1);\n            }\n            return null;\n        });\n    }\n\n    public List<ExecuteResponse> execute(SqlExecuteRequest command) {\n        String type = Chat2DBContext.getConnectInfo().getDbType();\n        DbType dbType = JdbcUtils.parse2DruidDbType(type);\n\n        List<String> sqlList = SqlUtils.parse(command.getScript(), dbType,true);\n\n        if (CollectionUtils.isEmpty(sqlList)) {\n            throw new BusinessException(RedisConstants.ERROR_SQL_ANALYSIS);\n        }\n        List<ExecuteResponse> result = new ArrayList<>();\n        for (String originalSql : sqlList) {\n            ExecuteResponse executeResult = executeCommand(originalSql);\n            result.add(executeResult);\n        }\n        return result;\n    }\n\n    private ExecuteResponse executeCommand(String originalSql) {\n        int pageNo = 1;\n        int pageSize = 0;\n        String sqlType = SqlTypeEnum.UNKNOWN.getCode();\n        ExecuteResponse executeResult = null;\n        try {\n            executeResult = doExecuteCommand(originalSql);\n        } catch (SQLException e) {\n            throw new IllegalStateException(\"Redis command execution failed, sql=\" + originalSql, e);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-redis/src/main/java/ai/chat2db/plugin/redis/RedisScriptExecutor.java#L106-L142","documentation":"Thrown by RedisScriptExecutor.execute as a BusinessException (code: dataSource.sqlAnalysisError) when SqlUtils.parse returns an empty list for the provided script. This means the Redis command script could not be parsed into any valid SQL-like statements. The parse uses Druid's SQL parser with the Redis dbType, and an empty result indicates the script is syntactically unrecognizable.","triggerScenarios":"Calling RedisScriptExecutor.execute(SqlExecuteRequest) where command.getScript() is empty, contains only comments/whitespace, or contains text that Druid's parser cannot split into statements. The check at line 123 uses CollectionUtils.isEmpty(sqlList).","commonSituations":"User submits an empty query in the Redis console; script contains only a semicolon or whitespace; Redis-specific command syntax that the Druid parser does not recognize; copy-paste of a malformed command.","solutions":["Validate that the script is non-blank before submitting to execute","Show a user-facing message that the command could not be parsed rather than throwing","Strip comments and whitespace before parsing to avoid empty-list results"],"exampleFix":"// before\nList<ExecuteResponse> results = executor.execute(command);\n\n// after\nif (StringUtils.isBlank(command.getScript())) {\n    return Collections.emptyList(); // or show user-facing error\n}\nList<ExecuteResponse> results = executor.execute(command);","handlingStrategy":"validation","validationCode":"if (command.getScript() == null || command.getScript().isBlank()) {\n    throw new IllegalArgumentException(\"Redis script must not be blank\");\n}\nList<ExecuteResponse> results = executor.execute(command);","typeGuard":null,"tryCatchPattern":"try {\n    List<ExecuteResponse> results = executor.execute(command);\n} catch (BusinessException e) {\n    if (RedisConstants.ERROR_SQL_ANALYSIS.equals(e.getCode())) {\n        // show user-facing parse error\n    }\n    throw e;\n}","preventionTips":["Validate the script is non-blank before submission","Test Redis commands against a live instance before scripting them","Show a user-facing message instead of throwing when the script is empty"],"tags":["redis","sql-parsing","validation","business-exception"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}