Code cleanup, removed raw SQL queries.

git-svn-id: http://svn.redmine.org/redmine/trunk@13461 e93f8b46-1217-0410-a6f0-8f06a7374b81