mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
8bcf74e9bc
It is perfectly valid to have a query like: Match None of the following: - Role is ANY of the following: -- 'Teacher' -- 'Editing teacher' -- 'Manager'; AND - Keyword is NONE of the following: -- 'Kevin' However, due to the way in which the query is constructed, this leads to a query which includes WHERE NOT ef.id IS NOT NULL AND NOT u.id IN (SELECT userid FROM {role_assignments} WHERE roleid IN (...) AND contextid IN (...)) AND NOT NOT (u.firstname || ' ' || u.lastname LIKE '%Kevin%') The use of NOT NOT is valid in Postgres, MariaDB, MySQL, and MSSQL, but not in Oracle. To counter this when the outer jointype is of type NONE, we must wrap each of the inner WHERE clauses in a set of brackets, which makes the query: WHERE NOT ef.id IS NOT NULL AND NOT (u.id IN (SELECT userid FROM {role_assignments} WHERE roleid IN (...) AND contextid IN (...))) AND NOT (NOT (u.firstname || ' ' || u.lastname LIKE '%Kevin%')) Whilst Oracle does not support the use of `AND NOT NOT ...`, it does support `AND NOT (NOT ...)`