Skip to content

Commit

Permalink
handle null
Browse files Browse the repository at this point in the history
  • Loading branch information
tukeJonny committed Nov 1, 2023
1 parent 716285b commit 9fe8969
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions webapp/go/stats_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func getUserStatisticsHandler(c echo.Context) error {

var tips int64
query = `
SELECT SUM(l2.tip) FROM users u
SELECT IFNULL(SUM(l2.tip), 0) FROM users u
INNER JOIN livestreams l ON l.user_id = u.id
INNER JOIN livecomments l2 ON l2.livestream_id = l.id
WHERE u.id = ?`
Expand Down Expand Up @@ -220,7 +220,7 @@ func getLivestreamStatisticsHandler(c echo.Context) error {
}

var totalTips int64
if err := tx.GetContext(ctx, &totalTips, "SELECT SUM(l2.tip) FROM livestreams l INNER JOIN livecomments l2 ON l.id = l2.livestream_id WHERE l.id = ?", livestreamID); err != nil {
if err := tx.GetContext(ctx, &totalTips, "SELECT IFNULL(SUM(l2.tip), 0) FROM livestreams l INNER JOIN livecomments l2 ON l.id = l2.livestream_id WHERE l.id = ?", livestreamID); err != nil {
log.Println("failed to get total tips for livestream stats")
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand Down

0 comments on commit 9fe8969

Please sign in to comment.