Skip to content

Commit

Permalink
null check in sql preventing null to int conversion error (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
karjo24 committed Jun 5, 2024
1 parent ad2afee commit 3b5f4c9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dao/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d statisticsDao) GetCourseNumStudents(courseID uint) (int64, error) {
// GetCourseNumVodViews returns the sum of vod views of a course
func (d statisticsDao) GetCourseNumVodViews(courseID uint) (int, error) {
var res int
err := DB.Raw(`SELECT SUM(stats.viewers) FROM stats
err := DB.Raw(`SELECT IFNULL(SUM(stats.viewers), 0) FROM stats
JOIN streams s ON s.id = stats.stream_id
WHERE (s.course_id = ? or ? = 0) AND live = 0`, courseID, courseID).Scan(&res).Error
return res, err
Expand All @@ -61,7 +61,7 @@ func (d statisticsDao) GetCourseNumLiveViews(courseID uint) (int, error) {
WHERE (s.course_id = ? OR ? = 0)
AND stats.live = 1
GROUP BY stats.stream_id)
SELECT SUM(y)
SELECT IFNULL(SUM(y), 0)
FROM views_per_stream WHERE y IS NOT NULL`, courseID, courseID).Scan(&res).Error
return res, err
}
Expand Down

0 comments on commit 3b5f4c9

Please sign in to comment.