by Davo Smith.
To be fair, there are a lot of situations which call for gathering data from a large number of tables at once, via JOINS, etc. that would be very slow and inefficient if written using multiple calls to the DB functions instead of hand-coded SQL. What I am trying to say is that many times inline SQL is entirely justified.
That does, of course, make it more difficult to maintain code that works across all database engines (especially when considering some of the rarely-used ones such as Oracle). Maybe it would be worth adding a setting somewhere in Moodle that would automatically scan all executed SQL queries for common cross-DB compatibility issues (but then, apart from 'AS', I'm not really aware of what the other Oracle 'quirks' are)?