database/gdb: fix confusing error message in Insert/Update operations when table not exist or the table contains no fields (#3553)

This commit is contained in:
wln32
2024-05-22 21:26:53 +08:00
committed by GitHub
parent 23df83cb0b
commit 17385eeaef
2 changed files with 62 additions and 0 deletions

View File

@ -381,6 +381,9 @@ func (c *Core) mappingAndFilterData(ctx context.Context, schema, table string, d
if err != nil {
return nil, err
}
if len(fieldsMap) == 0 {
return nil, gerror.Newf(`The table %s may not exist, or the table contains no fields`, table)
}
fieldsKeyMap := make(map[string]interface{}, len(fieldsMap))
for k := range fieldsMap {
fieldsKeyMap[k] = nil
@ -406,6 +409,9 @@ func (c *Core) mappingAndFilterData(ctx context.Context, schema, table string, d
delete(data, dataKey)
}
}
if len(data) == 0 {
return nil, gerror.Newf(`input data match no fields in table %s`, table)
}
}
return data, nil
}