Skip to content

Commit eace094

Browse files
karjo24SebiWrn
andauthored
null check in sql preventing null to int conversion error (#1215) (#1358)
* null check in sql preventing null to int conversion error (#1215) * go mod tidy * Revert "go mod tidy" This reverts commit 94986fc. * Fixed golangci * Fixed golangci * Fixed golangci * Reverted changes --------- Co-authored-by: johanneskarrer <[email protected]> Co-authored-by: Sebastian <[email protected]>
1 parent ad2afee commit eace094

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

dao/statistics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (d statisticsDao) GetCourseNumStudents(courseID uint) (int64, error) {
4646
// GetCourseNumVodViews returns the sum of vod views of a course
4747
func (d statisticsDao) GetCourseNumVodViews(courseID uint) (int, error) {
4848
var res int
49-
err := DB.Raw(`SELECT SUM(stats.viewers) FROM stats
49+
err := DB.Raw(`SELECT IFNULL(SUM(stats.viewers), 0) FROM stats
5050
JOIN streams s ON s.id = stats.stream_id
5151
WHERE (s.course_id = ? or ? = 0) AND live = 0`, courseID, courseID).Scan(&res).Error
5252
return res, err
@@ -61,7 +61,7 @@ func (d statisticsDao) GetCourseNumLiveViews(courseID uint) (int, error) {
6161
WHERE (s.course_id = ? OR ? = 0)
6262
AND stats.live = 1
6363
GROUP BY stats.stream_id)
64-
SELECT SUM(y)
64+
SELECT IFNULL(SUM(y), 0)
6565
FROM views_per_stream WHERE y IS NOT NULL`, courseID, courseID).Scan(&res).Error
6666
return res, err
6767
}

0 commit comments

Comments
 (0)