Use database's lower function for case-insensitive match

This PR is for the same problem as PR #492 but with a diferent solution, since it was breaking the build. 
It's similar to PR #472 and relates to issue #464