Skip to content

Commit

Permalink
null check in sql preventing null to int conversion error (#1215) (#1358
Browse files Browse the repository at this point in the history
)

* 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]>
  • Loading branch information
3 people committed Jun 12, 2024
1 parent ad2afee commit eace094
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 eace094

Please sign in to comment.