Skip to content

Commit

Permalink
fix sql
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Dec 5, 2024
1 parent f779d6e commit a547c6c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,15 +939,18 @@ func (m *dbMeta) doSyncUsedSpace(ctx Context) error {
return err
}
if err := m.roTxn(func(s *xorm.Session) error {
queryMap, err := s.QueryString("SELECT SUM(length) FROM jfs_node WHERE inode IN (SELECT inode FROM jfs_sustained)")
queryResultMap, err := s.QueryString("SELECT SUM(length) FROM jfs_node WHERE inode IN (SELECT inode FROM jfs_sustained)")
if err != nil {
return err
}
value, err := strconv.ParseInt(queryMap[0]["SUM(length)"], 10, 64)
if err != nil {
return err
// SUM(length) may return empty string if there is no record
if v := queryResultMap[0]["SUM(length)"]; v != "" {
value, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return err
}
used += align4K(uint64(value))
}
used += align4K(uint64(value))
return nil
}); err != nil {
return err
Expand Down

0 comments on commit a547c6c

Please sign in to comment.