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

Errors in SQL queries #29

Open
tonyjbutler opened this issue Jan 16, 2020 · 1 comment · May be fixed by #37
Open

Errors in SQL queries #29

tonyjbutler opened this issue Jan 16, 2020 · 1 comment · May be fixed by #37

Comments

@tonyjbutler
Copy link

We use PostgreSQL and the following error is being logged frequently:

column "count_feedback" does not exist at character 1453

which refers to the query:

SELECT cs.id AS submissionid, COUNT(f.id) AS count_feedback
FROM mdl_coursework_submissions cs LEFT JOIN
mdl_coursework_feedbacks f ON cs.id = f.submissionid
, mdl_coursework_allocation_pairs cap
WHERE cs.finalised = 1
AND cs.courseworkid = $1
AND (f.assessorid != $2 OR f.assessorid IS NULL)
AND cap.courseworkid = cs.courseworkid
AND cap.allocatableid = cs.allocatableid
AND cap.allocatabletype = cs.allocatabletype
AND cap.assessorid = $3
AND cs.id NOT IN (SELECT sub.id FROM
mdl_coursework_feedbacks feed JOIN
mdl_coursework_submissions sub ON sub.id = feed.submissionid
WHERE assessorid = $4 AND sub.courseworkid= $5)
GROUP BY cs.id
HAVING (count_feedback < $6)

Less frequently, we're also seeing this error:

syntax error at or near "`" at character 39

which refers to:

update mdl_coursework_submissions set `allocatableuser`=0, `allocatablegroup`=0

I suspect PostgreSQL isn't the only database that doesn't support the use of backticks in SQL queries. If these are needed for e.g. MySQL it's worth bearing in mind that Moodle's database abstraction library will insert them automatically where needed, so they shouldn't be included in plugin code.

Thanks,
Tony

@tonyjbutler
Copy link
Author

tonyjbutler commented Jan 16, 2020

There should also be no hardcoded database prefixes (not everyone will be using the default 'mdl_'). I've just spotted some in the query at

LEFT JOIN `mdl_coursework_sample_set_mbrs` ssm
(which incidentally also contains backticks).

alexmorrisnz added a commit to alexmorrisnz/open-mod_coursework that referenced this issue Aug 17, 2023
@alexmorrisnz alexmorrisnz linked a pull request Aug 17, 2023 that will close this issue
sumaiyamannan pushed a commit to catalyst/open-mod_coursework that referenced this issue Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant