Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null check in sql preventing null to int conversion error (#1215) #1358

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading