iflytek/astron-agent · error · BusinessException

8520

8520

Error message

database.table.query.data.failed

What it means

Thrown by DatabaseService.selectTableData when querying paginated table data fails with any exception. Code 8520, message 'database.table.query.data.failed'. Wraps failures of the rendered SELECT (dialect quoting, count query, page mapping) into one business error.

Solutions

  1. Check log 'Failed to query table data, params={...}' for the SQL and root-cause stack trace.
  2. Validate dto filters/sort fields still exist in current table field metadata.
  3. Retry in case of transient DB issues; check DB health/timeout settings.
  4. Verify the table name renders correctly for the configured dialect (quoting issues with reserved words).

Example fix

// before
Page<JSONObject> page = databaseService.selectTableData(dto); // dto.sortField="orde r" (renamed column)
// after
List<DbTableField> fields = getFields(dto.getTbId());
Set<String> names = fields.stream().map(DbTableField::getName).collect(Collectors.toSet());
if (dto.getSortField() != null && !names.contains(dto.getSortField())) {
    dto.setSortField(null); // fall back to default ordering
}
Page<JSONObject> page = databaseService.selectTableData(dto);
Defensive patterns

Strategy: validation

Validate before calling

Set<String> names = fields.stream().map(DbTableField::getName).collect(Collectors.toSet());
if (dto.getSortField() != null && !names.contains(dto.getSortField())) dto.setSortField(null);
if (dto.getFilters() != null) dto.getFilters().keySet().forEach(k -> { if (!names.contains(k)) throw new IllegalArgumentException("bad filter: " + k); });

Try / catch

try {
    return databaseService.selectTableData(dto);
} catch (BusinessException ex) {
    if ("database.table.query.data.failed".equals(ex.getMessage())) {
        log.warn("query failed; check filters/sort against current schema");
    }
    throw ex;
}

Prevention

When it happens

Trigger: Calling selectTableData(DbTableSelectDataDto) when the generated SQL fails: bad filter/sort values that survive validation, dialect quoting error on an odd table name, DB connection failure, or count-query mismatch.

Common situations: Sort/filter referencing a dropped column; table renamed concurrently; DB timeout under heavy load; invalid pagination offsets.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/c17062128107ef35. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java:879

                    dbInfo.getDbId(),
                    DBOperateEnum.SELECT.getCode(),
                    dto.getExecDev());

            String countDml = "SELECT COUNT(*) AS count FROM " + table;
            Long total = (Long) coreSystemService.execDML(
                    countDml,
                    UserInfoManagerHandler.getUserId(),
                    SpaceInfoUtil.getSpaceId(),
                    dbInfo.getDbId(),
                    DBOperateEnum.SELECT_TOTAL_COUNT.getCode(),
                    dto.getExecDev());

            page.setTotal(total == null ? 0 : total);
            page.setRecords(maps);
            return page;
        } catch (Exception ex) {
            log.error("Failed to query table data, params={}", JSONObject.toJSONString(dto), ex);
            throw new BusinessException(ResponseEnum.DATABASE_TABLE_QUERY_DATA_FAILED);
        }
    }


    public void importTableData(Long tbId, Integer execDev, MultipartFile file) {
        dataPermissionCheckTool.checkTbBelong(tbId);
        try {
            DbTable dbTable = dbTableMapper.selectById(tbId);
            DbInfo dbInfo = dbInfoMapper.selectById(dbTable.getDbId());

            List<DbTableField> dbTableFields = dbTableFieldMapper.selectList(new QueryWrapper<DbTableField>().lambda()
                    .eq(DbTableField::getTbId, tbId)
                    .orderByDesc(DbTableField::getCreateTime));

            // 1) read Excel -> rows
            List<Map<String, Object>> rows = new ArrayList<>();
            DBExcelReadListener listener = new DBExcelReadListener(
                    dbTableFields,

View on GitHub (pinned to 5e758547a8)