MDL-10405 updating sql queries to new syntax
MDL-10405 updating from deprecated function