Skip to content

Commit

Permalink
avoid passing zeroes to column widthes when do aligning
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Apr 29, 2020
1 parent 7bd2d79 commit 59c9394
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/stat/pgstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ func (r *PGresult) Sort(key int, desc bool) {
// SetAlign method aligns length of values depending of the columns width
func (r *PGresult) SetAlign(widthes map[int]int, truncLimit int, dynamic bool) (err error) {
var lastColTruncLimit, lastColMaxWidth int
lastColTruncLimit = truncLimit
lastColTruncLimit = utils.Max(truncLimit, colsTruncMinLimit)
truncLimit = utils.Max(truncLimit, colsTruncMinLimit)

// no rows in result, set width using length of a column name and return with error (because not aligned using result's values)
if len(r.Result) == 0 {
for colidx, colname := range r.Cols { // walk per-column
widthes[colidx] = len(colname)
widthes[colidx] = utils.Max(len(colname), colsTruncMinLimit)
}
return fmt.Errorf("RESULT_NO_ROWS")
}
Expand All @@ -449,7 +449,7 @@ func (r *PGresult) SetAlign(widthes map[int]int, truncLimit int, dynamic bool) (
var valuelen, colnamelen int
for colidx, colname := range r.Cols { // walk per-column
for rownum := 0; rownum < len(r.Result); rownum++ { // walk through rows
valuelen = len(r.Result[rownum][colidx].String)
valuelen = utils.Max(len(r.Result[rownum][colidx].String), colsTruncMinLimit)
colnamelen = utils.Max(len(colname), colsWidthMin)

switch {
Expand Down

0 comments on commit 59c9394

Please sign in to comment.